-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientStub.cpp
More file actions
76 lines (71 loc) · 1.66 KB
/
ClientStub.cpp
File metadata and controls
76 lines (71 loc) · 1.66 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "ClientStub.h"
#include <iostream>
ClientStub::ClientStub() {}
int ClientStub::Init(std::string ip, int port)
{
try
{
return socket.Init(ip, port);
}
catch (const char *msg)
{
// std::cerr << msg << std::endl;
return 0;
}
}
LaptopInfo ClientStub::OrderLaptop(CustomerRequest order)
{
LaptopInfo info;
char buffer[32];
int size;
order.Marshal(buffer);
size = order.Size();
if (socket.Send(buffer, size, 0))
{
// std::cout << "ClientStub::OrderLaptop: sent order" << std::endl;
size = info.Size();
// std::cout << "ClientStub::OrderLaptop: waiting for laptopinfo = " << std::endl;
if (socket.Recv(buffer, size, 0))
{
info.Unmarshal(buffer);
}
}
return info;
}
CustomerRecord ClientStub::ReadRecord(CustomerRequest order)
{
CustomerRecord record;
char buffer[32];
int size;
order.Marshal(buffer);
size = order.Size();
if (socket.Send(buffer, size, 0))
{
// std::cout << "ClientStub::ReadRecord: sent order" << std::endl;
size = record.Size();
// std::cout << "ClientStub::ReadRecord: waiting for record = " << std::endl;
if (socket.Recv(buffer, size, 0))
{
// std::cout << "ClientStub::ReadRecord: received record" << std::endl;
record.Unmarshal(buffer);
}
}
return record;
}
ReplicaResponse ClientStub::SendReplicaRequest(ReplicaRequest replicaRequest)
{
char buffer[32];
replicaRequest.Marshal(buffer);
int size = replicaRequest.Size();
ReplicaResponse response;
if (socket.Send(buffer, size, 0))
{
// std::cout << "ClientStub::SendReplicaRequest: waiting for ReplicaResponse = " << std::endl;
size = response.Size();
if (socket.Recv(buffer, size, 0))
{
response.Unmarshal(buffer);
}
}
return response;
}