f2bdb3fed7507edb30be7789313a37cc285be96d
[invirt/third/libt4.git] / paxos_protocol.h
1 #ifndef paxos_protocol_h
2 #define paxos_protocol_h
3
4 #include "rpc/rpc.h"
5
6 struct prop_t {
7     unsigned n;
8     std::string m;
9 };
10
11 class paxos_protocol {
12     public:
13         enum status : status_t { OK, ERR };
14         enum rpc_numbers : proc_t {
15             preparereq = 0x11001,
16             acceptreq,
17             decidereq,
18             heartbeat,
19         };
20
21         struct preparearg {
22             unsigned instance;
23             prop_t n;
24         };
25
26         struct prepareres {
27             bool oldinstance;
28             bool accept;
29             prop_t n_a;
30             std::string v_a;
31         };
32
33         struct acceptarg {
34             unsigned instance;
35             prop_t n;
36             std::string v;
37         };
38
39         struct decidearg {
40             unsigned instance;
41             std::string v;
42         };
43 };
44
45 inline unmarshall & operator>>(unmarshall &u, prop_t &a) {
46     return u >> a.n >> a.m;
47 }
48
49 inline marshall & operator<<(marshall &m, prop_t a) {
50     return m << a.n << a.m;
51 }
52
53 inline unmarshall & operator>>(unmarshall &u, paxos_protocol::preparearg &a) {
54     return u >> a.instance >> a.n;
55 }
56
57 inline marshall & operator<<(marshall &m, paxos_protocol::preparearg a) {
58     return m << a.instance << a.n;
59 }
60
61 inline unmarshall & operator>>(unmarshall &u, paxos_protocol::prepareres &r) {
62     return u >> r.oldinstance >> r.accept >> r.n_a >> r.v_a;
63 }
64
65 inline marshall & operator<<(marshall &m, paxos_protocol::prepareres r) {
66     return m << r.oldinstance << r.accept << r.n_a << r.v_a;
67 }
68
69 inline unmarshall & operator>>(unmarshall &u, paxos_protocol::acceptarg &a) {
70     return u >> a.instance >> a.n >> a.v;
71 }
72
73 inline marshall & operator<<(marshall &m, paxos_protocol::acceptarg a) {
74     return m << a.instance << a.n << a.v;
75 }
76
77 inline unmarshall & operator>>(unmarshall &u, paxos_protocol::decidearg &a) {
78     return u >> a.instance >> a.v;
79 }
80
81 inline marshall & operator<<(marshall &m, paxos_protocol::decidearg a) {
82     return m << a.instance << a.v;
83 }
84
85 #endif