-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessages.h
188 lines (153 loc) · 3.66 KB
/
Messages.h
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#ifndef __MESSAGES_H__
#define __MESSAGES_H__
#include <string>
class CustomerRequest {
private:
int customer_id;// For laptop order: customer id who placed order.
// For read request: customer id to read from map.
int order_number;// # of orders issued by this customer so far.
// Record-read request does not count as an order.
// Set to -1 for read requests.
int request_type;// Either 1 - regular laptop order request, or
// 2 - customer record read request
public:
CustomerRequest();
void operator = (const CustomerRequest &order) {
customer_id = order.customer_id;
order_number = order.order_number;
request_type = order.request_type;
}
void SetOrder(int cid, int order_num, int type);
int GetCustomerId();
int GetOrderNumber();
int GetRequestType();
int Size();
void Marshal(char *buffer);
void Unmarshal(char *buffer);
bool IsValid();
void Print();
};
class LaptopInfo {
private:
int customer_id;
int order_number;
int request_type;
int engineer_id;
int admin_id;
public:
LaptopInfo();
void operator = (const LaptopInfo &info) {
customer_id = info.customer_id;
order_number = info.order_number;
request_type = info.request_type;
engineer_id = info.engineer_id;
admin_id = info.admin_id;
}
void SetInfo(int cid, int order_num, int type, int engid, int expid);
void CopyOrder(CustomerRequest order);
void SetEngineerId(int id);
void SetExpertId(int id);
int GetCustomerId();
int GetOrderNumber();
int GetRequestType();
int GetEngineerId();
int GetExpertId();
int Size();
void Marshal(char *buffer);
void Unmarshal(char *buffer);
bool IsValid();
void Print();
};
class CustomerRecord {
private:
int customer_id;
int last_order;
public:
CustomerRecord();
void operator = (const CustomerRecord &record) {
customer_id = record.customer_id;
last_order = record.last_order;
}
void SetCustomerRecord(int customer_id, int last_order);
void SetCustomerId(int customer_id);
void SetLastOrder(int last_order);
int GetCustomerId();
int GetLastOrder();
int Size();
void Marshal(char *buffer);
void Unmarshal(char *buffer);
bool IsValid();
void Print();
};
class MapOp {
private:
int opcode; // operation code: 1 - update value int arg1;
int arg1; // customer_id to apply the operation int arg2;
int arg2; // parameter for the operation
public:
MapOp();
void operator = (const MapOp &op ) {
opcode = op.opcode;
arg1 = op.arg1;
arg2 = op.arg2;
}
int GetOpcode();
int GetArg1();
int GetArg2();
void SetMapOp(int op, int arg1, int arg2);
void SetOpcode(int op);
void SetArg1(int arg1);
void SetArg2(int arg2);
void CopyMapOp(MapOp op);
int Size();
void Marshal(char *buffer);
void Unmarshal(char *buffer);
bool isValid();
void Print();
};
class RequestLog {
private:
int factoryId;
int commitIndex;
int lastIndex;
MapOp mapOp;
public:
RequestLog();
void operator = (const RequestLog &req) {
factoryId = req.factoryId;
commitIndex = req.commitIndex;
lastIndex = req.lastIndex;
mapOp = req.mapOp;
}
int GetFactoryId();
int GetCommitIndex();
int GetLastIndex();
MapOp GetMapOp();
void SetFactoryId(int facId);
void SetCommitIndex(int idx);
void SetLastIndex(int lastIdx);
void SetMapOp(MapOp mapOp);
void CopyRequest(RequestLog req);
int Size();
void Marshal(char *buffer);
void Unmarshal(char *buffer);
bool IsValid();
void Print();
};
class ResponseLog {
private:
int factoryId;
public:
ResponseLog();
void operator = (const ResponseLog &res) {
factoryId = res.factoryId;
}
int GetFactoryId();
void SetFactoryId(int facId);
int Size();
void Marshal(char * buffer);
void Unmarshal(char *buffer);
bool IsValid();
void Print();
};
#endif // #ifndef __MESSAGES_H__