]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MWatchNotify.h
Import ceph 15.2.8
[ceph.git] / ceph / src / messages / MWatchNotify.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15
16 #ifndef CEPH_MWATCHNOTIFY_H
17 #define CEPH_MWATCHNOTIFY_H
18
19 #include "msg/Message.h"
20
21
22 class MWatchNotify : public Message {
23 private:
24 static constexpr int HEAD_VERSION = 3;
25 static constexpr int COMPAT_VERSION = 1;
26
27 public:
28 uint64_t cookie; ///< client unique id for this watch or notify
29 uint64_t ver; ///< unused
30 uint64_t notify_id; ///< osd unique id for a notify notification
31 uint8_t opcode; ///< CEPH_WATCH_EVENT_*
32 ceph::buffer::list bl; ///< notify payload (osd->client)
33 errorcode32_t return_code; ///< notify result (osd->client)
34 uint64_t notifier_gid; ///< who sent the notify
35
36 MWatchNotify()
37 : Message{CEPH_MSG_WATCH_NOTIFY, HEAD_VERSION, COMPAT_VERSION} { }
38 MWatchNotify(uint64_t c, uint64_t v, uint64_t i, uint8_t o, ceph::buffer::list b, uint64_t n=0)
39 : Message{CEPH_MSG_WATCH_NOTIFY, HEAD_VERSION, COMPAT_VERSION},
40 cookie(c),
41 ver(v),
42 notify_id(i),
43 opcode(o),
44 bl(b),
45 return_code(0),
46 notifier_gid(n) { }
47 private:
48 ~MWatchNotify() override {}
49
50 public:
51 void decode_payload() override {
52 using ceph::decode;
53 uint8_t msg_ver;
54 auto p = payload.cbegin();
55 decode(msg_ver, p);
56 decode(opcode, p);
57 decode(cookie, p);
58 decode(ver, p);
59 decode(notify_id, p);
60 if (msg_ver >= 1)
61 decode(bl, p);
62 if (header.version >= 2)
63 decode(return_code, p);
64 else
65 return_code = 0;
66 if (header.version >= 3)
67 decode(notifier_gid, p);
68 else
69 notifier_gid = 0;
70 }
71 void encode_payload(uint64_t features) override {
72 using ceph::encode;
73 uint8_t msg_ver = 1;
74 encode(msg_ver, payload);
75 encode(opcode, payload);
76 encode(cookie, payload);
77 encode(ver, payload);
78 encode(notify_id, payload);
79 encode(bl, payload);
80 encode(return_code, payload);
81 encode(notifier_gid, payload);
82 }
83
84 std::string_view get_type_name() const override { return "watch-notify"; }
85 void print(std::ostream& out) const override {
86 out << "watch-notify("
87 << ceph_watch_event_name(opcode) << " (" << (int)opcode << ")"
88 << " cookie " << cookie
89 << " notify " << notify_id
90 << " ret " << return_code
91 << ")";
92 }
93 private:
94 template<class T, typename... Args>
95 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
96 };
97
98 #endif