-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialization.cpp
More file actions
48 lines (43 loc) · 1.38 KB
/
Serialization.cpp
File metadata and controls
48 lines (43 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "Serialization.h"
//get Location From Driver
Node* getLocationFromDriver(DetailsDriver* detailsDrivers) {
Node* location = NULL;
Tcp* tcp = detailsDrivers->getTcp();
int socketId = detailsDrivers->getSocketId();
sendTo<string>("location", tcp, socketId);
location = receive<Node>(tcp, socketId);
return location;
}
//send trip.
void sendTrip(DetailsDriver* detailsDrivers, Trip* trip) {
Tcp* tcp = detailsDrivers->getTcp();
int socketId = detailsDrivers->getSocketId();
sendTo<string>("ride", tcp, socketId);
ifSuccess(tcp, socketId);
//waiting for the trip to be calculated
while (!trip->isDoneCalculatePath()) {
usleep(10000);
}
sendTo<Trip>(trip, tcp, socketId);
ifSuccess(tcp, socketId);
}
//send taxi.
void sendTaxi(DetailsDriver* detailsDrivers, Taxi* taxi) {
Tcp* tcp = detailsDrivers->getTcp();
int socketId = detailsDrivers->getSocketId();
sendTo<string>("taxi", tcp, socketId);
ifSuccess(tcp, socketId);
sendTo<Taxi>(taxi, tcp, socketId);
ifSuccess(tcp, socketId);
}
//send move.
string sendMove(DetailsDriver* dd) {
sendTo<string>("move", dd->getTcp(), dd->getSocketId());
string ifDone = receive<string>(1, dd->getTcp(), dd->getSocketId());
return ifDone;
}
//if success.
void ifSuccess(Tcp* tcp, int socketId) {
string ifReceive;
ifReceive = receive<string>(1, tcp, socketId);
}