53908f3588f7d66148f0ec32e3d70df016ca2dab
[invirt/third/libt4.git] / rsm_protocol.h
1 #ifndef rsm_protocol_h
2 #define rsm_protocol_h
3
4 #include "types.h"
5 #include "rpc/rpc.h"
6
7 class rsm_client_protocol {
8     public:
9         enum status : status_t {OK, ERR, NOTPRIMARY, BUSY};
10         enum rpc_numbers : proc_t {
11             invoke = 0x9001,
12             members,
13         };
14 };
15
16 struct viewstamp {
17     viewstamp (unsigned int _vid = 0, unsigned int _seqno = 0) : vid(_vid), seqno(_seqno) {}
18     unsigned int vid;
19     unsigned int seqno;
20     inline void operator++(int) { seqno++; }
21 };
22
23 class rsm_protocol {
24     public:
25         enum status : status_t { OK, ERR, BUSY};
26         enum rpc_numbers : proc_t {
27             invoke = 0xa001,
28             transferreq,
29             transferdonereq,
30             joinreq,
31         };
32
33         struct transferres {
34             string state;
35             viewstamp last;
36         };
37 };
38
39 inline bool operator==(viewstamp a, viewstamp b) { return tie(a.vid, a.seqno) == tie(b.vid, b.seqno); }
40 inline bool operator>(viewstamp a, viewstamp b) { return tie(a.vid, a.seqno) > tie(b.vid, b.seqno); }
41 inline bool operator!=(viewstamp a, viewstamp b) { return tie(a.vid, a.seqno) != tie(b.vid, b.seqno); }
42
43 inline marshall& operator<<(marshall &m, viewstamp v) {
44     return m << v.vid << v.seqno;
45 }
46
47 inline unmarshall& operator>>(unmarshall &u, viewstamp &v) {
48     return u >> v.vid >> v.seqno;
49 }
50
51 inline marshall & operator<<(marshall &m, rsm_protocol::transferres r) {
52     return m << r.state << r.last;
53 }
54
55 inline unmarshall & operator>>(unmarshall &u, rsm_protocol::transferres &r) {
56     return u >> r.state >> r.last;
57 }
58
59 class rsm_test_protocol {
60     public:
61         enum status : status_t {OK, ERR};
62         enum rpc_numbers : proc_t {
63             net_repair = 0x12001,
64             breakpoint = 0x12002,
65         };
66 };
67
68 #endif