Build on wheezy, and presumably precise
[invirt/third/libt4.git] / paxos_protocol.h
1 #ifndef paxos_protocol_h
2 #define paxos_protocol_h
3
4 #include "rpc.h"
5
6 struct prop_t {
7   unsigned n;
8   std::string m;
9 };
10
11 class paxos_protocol {
12  public:
13   enum xxstatus { OK, ERR };
14   typedef int status;
15   enum rpc_numbers {
16     preparereq = 0x11001,
17     acceptreq,
18     decidereq,
19     heartbeat,
20   };
21
22   struct preparearg {
23     unsigned instance;
24     prop_t n;
25   };
26
27   struct prepareres {
28     bool oldinstance;
29     bool accept;
30     prop_t n_a;
31     std::string v_a;
32   };
33
34   struct acceptarg {
35     unsigned instance;
36     prop_t n;
37     std::string v;
38   };
39
40   struct decidearg {
41     unsigned instance;
42     std::string v;
43   };
44
45 };
46
47 inline unmarshall &
48 operator>>(unmarshall &u, prop_t &a)
49 {
50   u >> a.n;
51   u >> a.m;
52   return u;
53 }
54
55 inline marshall &
56 operator<<(marshall &m, prop_t a)
57 {
58   m << a.n;
59   m << a.m;
60   return m;
61 }
62
63 inline unmarshall &
64 operator>>(unmarshall &u, paxos_protocol::preparearg &a)
65 {
66   u >> a.instance;
67   u >> a.n;
68   return u;
69 }
70
71 inline marshall &
72 operator<<(marshall &m, paxos_protocol::preparearg a)
73 {
74   m << a.instance;
75   m << a.n;
76   return m;
77 }
78
79 inline unmarshall &
80 operator>>(unmarshall &u, paxos_protocol::prepareres &r)
81 {
82   u >> r.oldinstance;
83   u >> r.accept;
84   u >> r.n_a;
85   u >> r.v_a;
86   return u;
87 }
88
89 inline marshall &
90 operator<<(marshall &m, paxos_protocol::prepareres r)
91 {
92   m << r.oldinstance;
93   m << r.accept;
94   m << r.n_a;
95   m << r.v_a;
96   return m;
97 }
98
99 inline unmarshall &
100 operator>>(unmarshall &u, paxos_protocol::acceptarg &a)
101 {
102   u >> a.instance;
103   u >> a.n;
104   u >> a.v;
105   return u;
106 }
107
108 inline marshall &
109 operator<<(marshall &m, paxos_protocol::acceptarg a)
110 {
111   m << a.instance;
112   m << a.n;
113   m << a.v;
114   return m;
115 }
116
117 inline unmarshall &
118 operator>>(unmarshall &u, paxos_protocol::decidearg &a)
119 {
120   u >> a.instance;
121   u >> a.v;
122   return u;
123 }
124
125 inline marshall &
126 operator<<(marshall &m, paxos_protocol::decidearg a)
127 {
128   m << a.instance;
129   m << a.v;
130   return m;
131 }
132
133 #endif