]>
git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/watcher/Utils.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_LIBRBD_WATCHER_UTILS_H
5 #define CEPH_LIBRBD_WATCHER_UTILS_H
7 #include "include/buffer_fwd.h"
8 #include "include/encoding.h"
9 #include "include/Context.h"
10 #include "librbd/Watcher.h"
12 namespace ceph
{ class Formatter
; }
18 template <typename Watcher
>
19 struct HandlePayloadVisitor
: public boost::static_visitor
<void> {
24 HandlePayloadVisitor(Watcher
*watcher_
, uint64_t notify_id_
,
26 : watcher(watcher_
), notify_id(notify_id_
), handle(handle_
)
31 inline void operator()(const P
&payload
) const {
32 typename
Watcher::C_NotifyAck
*ctx
=
33 new typename
Watcher::C_NotifyAck(watcher
, notify_id
, handle
);
34 if (watcher
->handle_payload(payload
, ctx
)) {
40 class EncodePayloadVisitor
: public boost::static_visitor
<void> {
42 explicit EncodePayloadVisitor(bufferlist
&bl
) : m_bl(bl
) {}
45 inline void operator()(const P
&payload
) const {
46 ::encode(static_cast<uint32_t>(P::NOTIFY_OP
), m_bl
);
54 class DecodePayloadVisitor
: public boost::static_visitor
<void> {
56 DecodePayloadVisitor(__u8 version
, bufferlist::iterator
&iter
)
57 : m_version(version
), m_iter(iter
) {}
60 inline void operator()(P
&payload
) const {
61 payload
.decode(m_version
, m_iter
);
66 bufferlist::iterator
&m_iter
;
70 } // namespace watcher
73 #endif // CEPH_LIBRBD_WATCHER_UTILS_H