Type cleanups
[invirt/third/libt4.git] / rsm_protocol.h
1 #ifndef rsm_protocol_h
2 #define rsm_protocol_h
3
4 #include "rpc/rpc.h"
5
6
7 class rsm_client_protocol {
8  public:
9   enum xxstatus { OK, ERR, NOTPRIMARY, BUSY};
10   typedef int status;
11   enum rpc_numbers {
12     invoke = 0x9001,
13     members,
14   };
15 };
16
17
18 struct viewstamp {
19   viewstamp (unsigned int _vid = 0, unsigned int _seqno = 0) :
20       vid(_vid), seqno(_seqno) {}
21   unsigned int vid;
22   unsigned int seqno;
23   inline void operator++(int) { seqno++; }
24 };
25
26 class rsm_protocol {
27  public:
28   enum xxstatus { OK, ERR, BUSY};
29   typedef int status;
30   enum rpc_numbers {
31     invoke = 0x10001,
32     transferreq,
33     transferdonereq,
34     joinreq,
35   };
36
37   struct transferres {
38     std::string state;
39     viewstamp last;
40   };
41   
42   struct joinres {
43     std::string log;
44   };
45 };
46
47 inline bool operator==(viewstamp a, viewstamp b) {
48   return a.vid == b.vid && a.seqno == b.seqno;
49 }
50
51 inline bool operator>(viewstamp a, viewstamp b) {
52   return (a.vid > b.vid) || ((a.vid == b.vid) && a.seqno > b.seqno);
53 }
54
55 inline bool operator!=(viewstamp a, viewstamp b) {
56   return a.vid != b.vid || a.seqno != b.seqno;
57 }
58
59 inline marshall& operator<<(marshall &m, viewstamp v)
60 {
61   m << v.vid;
62   m << v.seqno;
63   return m;
64 }
65
66 inline unmarshall& operator>>(unmarshall &u, viewstamp &v) {
67   u >> v.vid;
68   u >> v.seqno;
69   return u;
70 }
71
72 inline marshall &
73 operator<<(marshall &m, rsm_protocol::transferres r)
74 {
75   m << r.state;
76   m << r.last;
77   return m;
78 }
79
80 inline unmarshall &
81 operator>>(unmarshall &u, rsm_protocol::transferres &r)
82 {
83   u >> r.state;
84   u >> r.last;
85   return u;
86 }
87
88 inline marshall &
89 operator<<(marshall &m, rsm_protocol::joinres r)
90 {
91   m << r.log;
92   return m;
93 }
94
95 inline unmarshall &
96 operator>>(unmarshall &u, rsm_protocol::joinres &r)
97 {
98   u >> r.log;
99   return u;
100 }
101
102 class rsm_test_protocol {
103  public:
104   enum xxstatus { OK, ERR};
105   typedef int status;
106   enum rpc_numbers {
107     net_repair = 0x12001,
108     breakpoint = 0x12002,
109   };
110 };
111
112 #endif