6b508d8ebc92a0a86920bbe16728fd3663b6e378
[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 class rsm_client_protocol {
7     public:
8         enum status : status_t {OK, ERR, NOTPRIMARY, BUSY};
9         enum rpc_numbers : proc_t {
10             invoke = 0x9001,
11             members,
12         };
13 };
14
15 struct viewstamp {
16     viewstamp (unsigned int _vid = 0, unsigned int _seqno = 0) : vid(_vid), seqno(_seqno) {}
17     unsigned int vid;
18     unsigned int seqno;
19     inline void operator++(int) { seqno++; }
20 };
21
22 class rsm_protocol {
23     public:
24         enum status : status_t { OK, ERR, BUSY};
25         enum rpc_numbers : proc_t {
26             invoke = 0x10001,
27             transferreq,
28             transferdonereq,
29             joinreq,
30         };
31
32         struct transferres {
33             std::string state;
34             viewstamp last;
35         };
36
37         struct joinres {
38             std::string log;
39         };
40 };
41
42 inline bool operator==(viewstamp a, viewstamp b) {
43     return a.vid == b.vid && a.seqno == b.seqno;
44 }
45
46 inline bool operator>(viewstamp a, viewstamp b) {
47     return (a.vid > b.vid) || ((a.vid == b.vid) && a.seqno > b.seqno);
48 }
49
50 inline bool operator!=(viewstamp a, viewstamp b) {
51     return a.vid != b.vid || a.seqno != b.seqno;
52 }
53
54 inline marshall& operator<<(marshall &m, viewstamp v) {
55     return m << v.vid << v.seqno;
56 }
57
58 inline unmarshall& operator>>(unmarshall &u, viewstamp &v) {
59     return u >> v.vid >> v.seqno;
60 }
61
62 inline marshall & operator<<(marshall &m, rsm_protocol::transferres r) {
63     return m << r.state << r.last;
64 }
65
66 inline unmarshall & operator>>(unmarshall &u, rsm_protocol::transferres &r) {
67     return u >> r.state >> r.last;
68 }
69
70 inline marshall & operator<<(marshall &m, rsm_protocol::joinres r) {
71     return m << r.log;
72 }
73
74 inline unmarshall & operator>>(unmarshall &u, rsm_protocol::joinres &r) {
75     return u >> r.log;
76 }
77
78 class rsm_test_protocol {
79     public:
80         enum status : status_t {OK, ERR};
81         enum rpc_numbers : proc_t {
82             net_repair = 0x12001,
83             breakpoint = 0x12002,
84         };
85 };
86
87 #endif