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