More cleaning
[invirt/third/libt4.git] / paxos_protocol.h
1 #ifndef paxos_protocol_h
2 #define paxos_protocol_h
3
4 #include "types.h"
5 #include "rpc/rpc.h"
6
7 struct prop_t {
8     unsigned n;
9     string m;
10 };
11
12 class paxos_protocol {
13     public:
14         enum status : status_t { OK, ERR };
15         enum rpc_numbers : proc_t {
16             preparereq = 0x11001,
17             acceptreq,
18             decidereq,
19             heartbeat,
20         };
21
22         struct prepareres {
23             bool oldinstance;
24             bool accept;
25             prop_t n_a;
26             string v_a;
27         };
28 };
29
30 inline unmarshall & operator>>(unmarshall &u, prop_t &a) { return u >> a.n >> a.m; }
31 inline marshall & operator<<(marshall &m, prop_t a) { return m << a.n << a.m; }
32 inline bool operator>(const prop_t &a, const prop_t &b) { return tie(a.n, a.m) > tie(b.n, b.m); }
33 inline bool operator>=(const prop_t &a, const prop_t &b) { return tie(a.n, a.m) >= tie(b.n, b.m); }
34
35 inline unmarshall & operator>>(unmarshall &u, paxos_protocol::prepareres &r) {
36     return u >> r.oldinstance >> r.accept >> r.n_a >> r.v_a;
37 }
38
39 inline marshall & operator<<(marshall &m, paxos_protocol::prepareres r) {
40     return m << r.oldinstance << r.accept << r.n_a << r.v_a;
41 }
42
43 #endif