]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MMonSubscribe.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / messages / MMonSubscribe.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 #ifndef CEPH_MMONSUBSCRIBE_H
16 #define CEPH_MMONSUBSCRIBE_H
17
18 #include "msg/Message.h"
19 #include "include/ceph_features.h"
20
21 /*
22 * compatibility with old crap
23 */
24 struct ceph_mon_subscribe_item_old {
25 __le64 unused;
26 __le64 have;
27 __u8 onetime;
28 } __attribute__ ((packed));
29 WRITE_RAW_ENCODER(ceph_mon_subscribe_item_old)
30
31
32 struct MMonSubscribe : public Message {
33
34 static const int HEAD_VERSION = 2;
35
36 map<string, ceph_mon_subscribe_item> what;
37
38 MMonSubscribe() : Message(CEPH_MSG_MON_SUBSCRIBE, HEAD_VERSION) { }
39 private:
40 ~MMonSubscribe() override {}
41
42 public:
43 void sub_want(const char *w, version_t start, unsigned flags) {
44 what[w].start = start;
45 what[w].flags = flags;
46 }
47
48 const char *get_type_name() const override { return "mon_subscribe"; }
49 void print(ostream& o) const override {
50 o << "mon_subscribe(" << what << ")";
51 }
52
53 void decode_payload() override {
54 bufferlist::iterator p = payload.begin();
55 if (header.version < 2) {
56 map<string, ceph_mon_subscribe_item_old> oldwhat;
57 ::decode(oldwhat, p);
58 what.clear();
59 for (map<string, ceph_mon_subscribe_item_old>::iterator q = oldwhat.begin();
60 q != oldwhat.end();
61 q++) {
62 if (q->second.have)
63 what[q->first].start = q->second.have + 1;
64 else
65 what[q->first].start = 0;
66 what[q->first].flags = 0;
67 if (q->second.onetime)
68 what[q->first].flags |= CEPH_SUBSCRIBE_ONETIME;
69 }
70 } else {
71 ::decode(what, p);
72 }
73 }
74 void encode_payload(uint64_t features) override {
75 if (features & CEPH_FEATURE_SUBSCRIBE2) {
76 ::encode(what, payload);
77 header.version = HEAD_VERSION;
78 } else {
79 header.version = 0;
80 map<string, ceph_mon_subscribe_item_old> oldwhat;
81 for (map<string, ceph_mon_subscribe_item>::iterator q = what.begin();
82 q != what.end();
83 q++) {
84 if (q->second.start)
85 // warning: start=1 -> have=0, which was ambiguous
86 oldwhat[q->first].have = q->second.start - 1;
87 else
88 oldwhat[q->first].have = 0;
89 oldwhat[q->first].onetime = q->second.flags & CEPH_SUBSCRIBE_ONETIME;
90 }
91 ::encode(oldwhat, payload);
92 }
93 }
94 };
95
96 #endif