1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_TEST_WATCH_NOTIFY_H
5 #define CEPH_TEST_WATCH_NOTIFY_H
7 #include "include/rados/librados.hpp"
8 #include "common/Cond.h"
9 #include "common/Mutex.h"
10 #include <boost/noncopyable.hpp>
11 #include <boost/shared_ptr.hpp>
20 class TestRadosClient;
22 class TestWatchNotify : boost::noncopyable {
24 typedef std::pair<uint64_t, uint64_t> WatcherID;
25 typedef std::set<WatcherID> WatcherIDs;
26 typedef std::map<std::pair<uint64_t, uint64_t>, bufferlist> NotifyResponses;
29 TestRadosClient *rados_client = nullptr;
30 WatcherIDs pending_watcher_ids;
31 NotifyResponses notify_responses;
32 bufferlist *pbl = nullptr;
33 Context *on_notify = nullptr;
35 typedef boost::shared_ptr<NotifyHandle> SharedNotifyHandle;
36 typedef std::map<uint64_t, SharedNotifyHandle> NotifyHandles;
39 TestRadosClient *rados_client = nullptr;
44 librados::WatchCtx* watch_ctx;
45 librados::WatchCtx2* watch_ctx2;
48 typedef std::map<uint64_t, WatchHandle> WatchHandles;
51 WatchHandles watch_handles;
52 NotifyHandles notify_handles;
54 typedef boost::shared_ptr<Watcher> SharedWatcher;
58 int list_watchers(const std::string& o,
59 std::list<obj_watch_t> *out_watchers);
61 void aio_flush(TestRadosClient *rados_client, Context *on_finish);
62 void aio_watch(TestRadosClient *rados_client, const std::string& o,
63 uint64_t gid, uint64_t *handle, librados::WatchCtx2 *watch_ctx,
65 void aio_unwatch(TestRadosClient *rados_client, uint64_t handle,
67 void aio_notify(TestRadosClient *rados_client, const std::string& oid,
68 bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl,
71 void flush(TestRadosClient *rados_client);
72 int notify(TestRadosClient *rados_client, const std::string& o,
73 bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl);
74 void notify_ack(TestRadosClient *rados_client, const std::string& o,
75 uint64_t notify_id, uint64_t handle, uint64_t gid,
77 int watch(TestRadosClient *rados_client, const std::string& o, uint64_t gid,
78 uint64_t *handle, librados::WatchCtx *ctx,
79 librados::WatchCtx2 *ctx2);
80 int unwatch(TestRadosClient *rados_client, uint64_t handle);
82 void blacklist(uint32_t nonce);
86 typedef std::map<std::string, SharedWatcher> FileWatchers;
88 uint64_t m_handle = 0;
89 uint64_t m_notify_id = 0;
92 uint64_t m_pending_notifies = 0;
94 Cond m_file_watcher_cond;
95 FileWatchers m_file_watchers;
97 SharedWatcher get_watcher(const std::string& oid);
99 void execute_notify(TestRadosClient *rados_client, const std::string &oid,
100 bufferlist &bl, uint64_t notify_id);
101 void ack_notify(TestRadosClient *rados_client, const std::string &oid,
102 uint64_t notify_id, const WatcherID &watcher_id,
103 const bufferlist &bl);
104 void finish_notify(TestRadosClient *rados_client, const std::string &oid,
108 } // namespace librados
110 #endif // CEPH_TEST_WATCH_NOTIFY_H