1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef RBD_MIRROR_LEADER_WATCHER_TYPES_H
5 #define RBD_MIRROR_LEADER_WATCHER_TYPES_H
7 #include "include/int_types.h"
8 #include "include/buffer_fwd.h"
9 #include "include/encoding.h"
10 #include <boost/variant.hpp>
12 namespace ceph { class Formatter; }
16 namespace leader_watcher {
19 NOTIFY_OP_HEARTBEAT = 0,
20 NOTIFY_OP_LOCK_ACQUIRED = 1,
21 NOTIFY_OP_LOCK_RELEASED = 2,
24 struct HeartbeatPayload {
25 static const NotifyOp NOTIFY_OP = NOTIFY_OP_HEARTBEAT;
30 void encode(bufferlist &bl) const;
31 void decode(__u8 version, bufferlist::iterator &iter);
32 void dump(Formatter *f) const;
35 struct LockAcquiredPayload {
36 static const NotifyOp NOTIFY_OP = NOTIFY_OP_LOCK_ACQUIRED;
38 LockAcquiredPayload() {
41 void encode(bufferlist &bl) const;
42 void decode(__u8 version, bufferlist::iterator &iter);
43 void dump(Formatter *f) const;
46 struct LockReleasedPayload {
47 static const NotifyOp NOTIFY_OP = NOTIFY_OP_LOCK_RELEASED;
49 LockReleasedPayload() {
52 void encode(bufferlist &bl) const;
53 void decode(__u8 version, bufferlist::iterator &iter);
54 void dump(Formatter *f) const;
57 struct UnknownPayload {
58 static const NotifyOp NOTIFY_OP = static_cast<NotifyOp>(-1);
63 void encode(bufferlist &bl) const;
64 void decode(__u8 version, bufferlist::iterator &iter);
65 void dump(Formatter *f) const;
68 typedef boost::variant<HeartbeatPayload,
71 UnknownPayload> Payload;
73 struct NotifyMessage {
74 NotifyMessage(const Payload &payload = UnknownPayload()) : payload(payload) {
79 void encode(bufferlist& bl) const;
80 void decode(bufferlist::iterator& it);
81 void dump(Formatter *f) const;
83 static void generate_test_instances(std::list<NotifyMessage *> &o);
86 WRITE_CLASS_ENCODER(NotifyMessage);
88 std::ostream &operator<<(std::ostream &out, const NotifyOp &op);
90 } // namespace leader_watcher
94 using rbd::mirror::leader_watcher::encode;
95 using rbd::mirror::leader_watcher::decode;
97 #endif // RBD_MIRROR_LEADER_WATCHER_TYPES_H