Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / tools / rbd_mirror / leader_watcher / Types.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef RBD_MIRROR_LEADER_WATCHER_TYPES_H
5 #define RBD_MIRROR_LEADER_WATCHER_TYPES_H
6
7 #include "include/int_types.h"
8 #include "include/buffer_fwd.h"
9 #include "include/encoding.h"
10 #include <boost/variant.hpp>
11
12 namespace ceph { class Formatter; }
13
14 namespace rbd {
15 namespace mirror {
16 namespace leader_watcher {
17
18 enum NotifyOp {
19   NOTIFY_OP_HEARTBEAT        = 0,
20   NOTIFY_OP_LOCK_ACQUIRED    = 1,
21   NOTIFY_OP_LOCK_RELEASED    = 2,
22 };
23
24 struct HeartbeatPayload {
25   static const NotifyOp NOTIFY_OP = NOTIFY_OP_HEARTBEAT;
26
27   HeartbeatPayload() {
28   }
29
30   void encode(bufferlist &bl) const;
31   void decode(__u8 version, bufferlist::iterator &iter);
32   void dump(Formatter *f) const;
33 };
34
35 struct LockAcquiredPayload {
36   static const NotifyOp NOTIFY_OP = NOTIFY_OP_LOCK_ACQUIRED;
37
38   LockAcquiredPayload() {
39   }
40
41   void encode(bufferlist &bl) const;
42   void decode(__u8 version, bufferlist::iterator &iter);
43   void dump(Formatter *f) const;
44 };
45
46 struct LockReleasedPayload {
47   static const NotifyOp NOTIFY_OP = NOTIFY_OP_LOCK_RELEASED;
48
49   LockReleasedPayload() {
50   }
51
52   void encode(bufferlist &bl) const;
53   void decode(__u8 version, bufferlist::iterator &iter);
54   void dump(Formatter *f) const;
55 };
56
57 struct UnknownPayload {
58   static const NotifyOp NOTIFY_OP = static_cast<NotifyOp>(-1);
59
60   UnknownPayload() {
61   }
62
63   void encode(bufferlist &bl) const;
64   void decode(__u8 version, bufferlist::iterator &iter);
65   void dump(Formatter *f) const;
66 };
67
68 typedef boost::variant<HeartbeatPayload,
69                        LockAcquiredPayload,
70                        LockReleasedPayload,
71                        UnknownPayload> Payload;
72
73 struct NotifyMessage {
74   NotifyMessage(const Payload &payload = UnknownPayload()) : payload(payload) {
75   }
76
77   Payload payload;
78
79   void encode(bufferlist& bl) const;
80   void decode(bufferlist::iterator& it);
81   void dump(Formatter *f) const;
82
83   static void generate_test_instances(std::list<NotifyMessage *> &o);
84 };
85
86 WRITE_CLASS_ENCODER(NotifyMessage);
87
88 std::ostream &operator<<(std::ostream &out, const NotifyOp &op);
89
90 } // namespace leader_watcher
91 } // namespace mirror
92 } // namespace librbd
93
94 using rbd::mirror::leader_watcher::encode;
95 using rbd::mirror::leader_watcher::decode;
96
97 #endif // RBD_MIRROR_LEADER_WATCHER_TYPES_H