#ifndef __ETCD_KEEPALIVE_HPP__ #define __ETCD_KEEPALIVE_HPP__ #include #include "etcd/Client.hpp" #include "etcd/Response.hpp" #include #if BOOST_VERSION >= 106600 #include #else #include #endif #include #include #include "proto/rpc.grpc.pb.h" namespace etcdv3 { class AsyncLeaseKeepAliveAction; } using etcdserverpb::KV; using etcdserverpb::Lease; using grpc::Channel; namespace etcd { /** * If ID is set to 0, etcd will choose an ID. */ class KeepAlive { public: KeepAlive(Client const &client, int ttl, int64_t lease_id=0); KeepAlive(std::string const & address, int ttl, int64_t lease_id=0); KeepAlive(std::string const & address, std::string const & username, std::string const & password, int ttl, int64_t lease_id=0); KeepAlive(KeepAlive const &) = delete; KeepAlive(KeepAlive &&) = delete; /** * Stop the keep alive action. */ void Cancel(); ~KeepAlive(); protected: void refresh(); pplx::task currentTask; std::unique_ptr leaseServiceStub; std::unique_ptr call; private: int ttl; int64_t lease_id; bool continue_next; #if BOOST_VERSION >= 106600 boost::asio::io_context context; #else boost::asio::io_service context; #endif std::unique_ptr keepalive_timer_; }; } #endif