-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientStub.cpp
71 lines (60 loc) · 1.56 KB
/
ClientStub.cpp
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
#include "ClientStub.h"
#include <arpa/inet.h>
#include <iostream>
ClientStub::ClientStub() {}
int ClientStub::Init(std::string ip, int port) {
return socket.Init(ip, port);
}
LaptopInfo ClientStub::OrderLaptop(CustomerRequest request) {
//std::cout<<"Ordering laptop for custid "<<request.GetCustomerId()<<std::endl;
//std::cout<<"request received custid "<< request.GetCustomerId()<<std::endl;
LaptopInfo info;
char buffer[32];
int size;
request.Marshal(buffer);
size = request.Size();
if (socket.Send(buffer, size, 0)) {
size = info.Size();
if (socket.Recv(buffer, size, 0)) {
info.Unmarshal(buffer);
}
}
// std::cout<<"laptop info for ";
// info.Print();
return info;
}
CustomerRecord ClientStub::ReadRecord(CustomerRequest order) {
//std::cout<<"read request received custid "<< order.GetCustomerId()<<std::endl;
CustomerRecord record;
char buffer[32];
int size;
order.Marshal(buffer);
size = order.Size();
if (socket.Send(buffer, size, 0)) {
size = record.Size();
if (socket.Recv(buffer, size, 0)) {
record.Unmarshal(buffer);
}
}
// std::cout<<"record sending for ";
// record.Print();
return record;
}
ResponseLog ClientStub::BackupRecord(RequestLog log) {
ResponseLog resp;
char buffer[32];
int size;
log.Marshal(buffer);
size = log.Size();
if (socket.Send(buffer, size, 0)) {
size = resp.Size();
if (socket.Recv(buffer, size, 0)) {
resp.Unmarshal(buffer);
}
}
return resp;
}
void ClientStub::SetRole(int role) {
int net_role = htonl(role);
socket.Send((char *)&net_role, sizeof(net_role), 0);
}