Line data Source code
1 : // 2 : // Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. 3 : // Copyright Contributors to the OpenSDN project 4 : // 5 : 6 : #ifndef ZOOKEEPER_ZOOKEEPER_CLIENT_IMPL_H_ 7 : #define ZOOKEEPER_ZOOKEEPER_CLIENT_IMPL_H_ 8 : 9 : #include <zookeeper/zookeeper.h> 10 : 11 : #include <zookeeper/zookeeper_interface.h> 12 : 13 : namespace zookeeper { 14 : namespace client { 15 : namespace impl { 16 : 17 : // 18 : // Blocking, synchronous, non-thread safe Zookeeper client 19 : // 20 : class ZookeeperClientImpl { 21 : public: 22 : ZookeeperClientImpl(const char *hostname, const char *servers, 23 : zookeeper::interface::ZookeeperInterface *zki); 24 : virtual ~ZookeeperClientImpl(); 25 : 26 : bool Connect(); 27 : void Shutdown(); 28 : bool Reconnect(); 29 : bool IsConnected() const; 30 : bool CreateNode(const char *path, const char *value, int flag); 31 : bool DeleteNode(const char *path); 32 : int CreateNodeSync(const char *path, const char *value, int *err, int flag); 33 : int GetNodeDataSync(const char *path, char *buf, int *buf_len, int *err); 34 : int DeleteNodeSync(const char *path, int *err); 35 : bool CheckNodeExist(const char *path); 36 0 : void SetClient(void *client) {client_ = client;} 37 0 : void *GetClient() {return client_;} 38 : std::string Name() const; 39 : 40 : private: 41 : static const int kSessionTimeoutMSec_ = 60000; 42 : 43 : std::string hostname_; 44 : std::string servers_; 45 : zhandle_t *zk_handle_; 46 : bool connected_; 47 : void *client_; 48 : std::unique_ptr<zookeeper::interface::ZookeeperInterface> zki_; 49 : }; 50 : 51 : } // namespace impl 52 : } // namespace client 53 : } // namespace zookeeper 54 : 55 : #endif // ZOOKEEPER_ZOOKEEPER_CLIENT_IMPL_H_