zookeeper-cpp
ZooKeeper Client for C++
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups
connection_zk.hpp
1 #pragma once
2 
3 #include <zk/config.hpp>
4 
5 #include <chrono>
6 #include <memory>
7 #include <mutex>
8 #include <unordered_map>
9 
10 #include "connection.hpp"
11 #include "string_view.hpp"
12 
13 typedef struct _zhandle zhandle_t;
14 
15 namespace zk
16 {
17 
20 
21 class connection_zk final :
22  public connection
23 {
24 public:
25  explicit connection_zk(const connection_params& params);
26 
27  virtual ~connection_zk() noexcept;
28 
29  virtual void close() override;
30 
31  virtual zk::state state() const override;
32 
33  virtual future<get_result> get(string_view path) override;
34 
35  virtual future<watch_result> watch(string_view path) override;
36 
37  virtual future<get_children_result> get_children(string_view path) override;
38 
39  virtual future<watch_children_result> watch_children(string_view path) override;
40 
41  virtual future<exists_result> exists(string_view path) override;
42 
43  virtual future<watch_exists_result> watch_exists(string_view path) override;
44 
45  virtual future<create_result> create(string_view path,
46  const buffer& data,
47  const acl& rules,
48  create_mode mode
49  ) override;
50 
51  virtual future<set_result> set(string_view path, const buffer& data, version check) override;
52 
53  virtual future<void> erase(string_view path, version check) override;
54 
55  virtual future<get_acl_result> get_acl(string_view path) const override;
56 
57  virtual future<void> set_acl(string_view path, const acl& rules, acl_version check) override;
58 
59  virtual future<multi_result> commit(multi_op&& txn) override;
60 
61  virtual future<void> load_fence() override;
62 
63 private:
64  static void on_session_event_raw(ptr<zhandle_t> handle,
65  int ev_type,
66  int state,
67  ptr<const char> path,
68  ptr<void> watcher_ctx
69  ) noexcept;
70 
71  using watch_function = void (*)(ptr<zhandle_t>, int type_in, int state_in, ptr<const char>, ptr<void>);
72 
73  class watcher;
74 
75  template <typename TResult>
76  class basic_watcher;
77 
78  class data_watcher;
79 
80  class child_watcher;
81 
82  class exists_watcher;
83 
88  std::shared_ptr<watcher> try_extract_watch(ptr<const void> p);
89 
90  static void deliver_watch(ptr<zhandle_t> zh, int type_in, int state_in, ptr<const char>, ptr<void> proms_in);
91 
92 private:
93  ptr<zhandle_t> _handle;
94  std::unordered_map<ptr<const void>, std::shared_ptr<watcher>> _watches;
95  mutable std::mutex _watches_protect;
96 };
97 
99 
100 }
T * ptr
A simple, unowned pointer.
Definition: config.hpp:37
state
Enumeration of states the client may be at when a watch triggers.
Definition: types.hpp:385
Represents a version of the ACL of an entry.
Definition: types.hpp:171
create_mode
When used in client::set, this value determines how the entry is created on the server.
Definition: types.hpp:283
Used to specify parameters for a connection.
Definition: connection.hpp:84
A collection of operations that will be performed atomically.
Definition: multi.hpp:162
Imports the string_view type as std::string_view.
An access control list is a wrapper around acl_rule instances.
Definition: acl.hpp:139
Represents a version of the data.
Definition: types.hpp:158
ZKPP_BUFFER_TYPE buffer
The buffer type.
Definition: buffer.hpp:79
An actual connection to the server.
Definition: connection.hpp:26