From a73dc1c708baf06e746f7a3f13fa14958a4ee2a1 Mon Sep 17 00:00:00 2001 From: yang-g Date: Wed, 5 Aug 2015 14:24:00 -0700 Subject: specialize deadline type and implementation --- src/cpp/client/channel.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/cpp/client/channel.h | 24 +++++++++++++++++++++--- 2 files changed, 66 insertions(+), 3 deletions(-) (limited to 'src/cpp') diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc index ee143d68a0..6696f19d76 100644 --- a/src/cpp/client/channel.cc +++ b/src/cpp/client/channel.cc @@ -48,6 +48,7 @@ #include #include #include +#include namespace grpc { @@ -93,4 +94,48 @@ void* Channel::RegisterMethod(const char* method) { host_.empty() ? NULL : host_.c_str()); } +grpc_connectivity_state Channel::GetState(bool try_to_connect) { + return grpc_channel_check_connectivity_state(c_channel_, try_to_connect); +} + +void Channel::NotifyOnStateChange(grpc_connectivity_state last_observed, + gpr_timespec deadline, + CompletionQueue* cq, void* tag) { + grpc_channel_watch_connectivity_state(c_channel_, last_observed, deadline, + cq->cq(), tag); +} + +bool Channel::WaitForStateChange(grpc_connectivity_state last_observed, + gpr_timespec deadline) { + CompletionQueue cq; + bool ok = false; + void* tag = NULL; + NotifyOnStateChange(last_observed, deadline, &cq, NULL); + cq.Next(&tag, &ok); + GPR_ASSERT(tag == NULL); + return ok; +} + +#ifndef GRPC_CXX0X_NO_CHRONO +void Channel::NotifyOnStateChange( + grpc_connectivity_state last_observed, + const std::chrono::system_clock::time_point& deadline, + CompletionQueue* cq, void* tag) { + TimePoint deadline_tp(deadline); + grpc_channel_watch_connectivity_state(c_channel_, last_observed, + deadline_tp.raw_time(), cq->cq(), tag); +} + +bool Channel::WaitForStateChange( + grpc_connectivity_state last_observed, + const std::chrono::system_clock::time_point& deadline) { + CompletionQueue cq; + bool ok = false; + void* tag = NULL; + NotifyOnStateChange(last_observed, deadline, &cq, NULL); + cq.Next(&tag, &ok); + GPR_ASSERT(tag == NULL); + return ok; +} +#endif // !GRPC_CXX0X_NO_CHRONO } // namespace grpc diff --git a/src/cpp/client/channel.h b/src/cpp/client/channel.h index 8660146856..fa3aedc9eb 100644 --- a/src/cpp/client/channel.h +++ b/src/cpp/client/channel.h @@ -56,12 +56,30 @@ class Channel GRPC_FINAL : public GrpcLibrary, public ChannelInterface { Channel(const grpc::string& host, grpc_channel* c_channel); ~Channel() GRPC_OVERRIDE; - virtual void* RegisterMethod(const char* method) GRPC_OVERRIDE; - virtual Call CreateCall(const RpcMethod& method, ClientContext* context, + void* RegisterMethod(const char* method) GRPC_OVERRIDE; + Call CreateCall(const RpcMethod& method, ClientContext* context, CompletionQueue* cq) GRPC_OVERRIDE; - virtual void PerformOpsOnCall(CallOpSetInterface* ops, + void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) GRPC_OVERRIDE; + grpc_connectivity_state GetState(bool try_to_connect) GRPC_OVERRIDE; + + void NotifyOnStateChange(grpc_connectivity_state last_observed, + gpr_timespec deadline, + CompletionQueue* cq, void* tag) GRPC_OVERRIDE; + + bool WaitForStateChange(grpc_connectivity_state last_observed, + gpr_timespec deadline) GRPC_OVERRIDE; + +#ifndef GRPC_CXX0X_NO_CHRONO + void NotifyOnStateChange( + grpc_connectivity_state last_observed, + const std::chrono::system_clock::time_point& deadline, + CompletionQueue* cq, void* tag) GRPC_OVERRIDE; + bool WaitForStateChange( + grpc_connectivity_state last_observed, + const std::chrono::system_clock::time_point& deadline) GRPC_OVERRIDE; +#endif // !GRPC_CXX0X_NO_CHRONO private: const grpc::string host_; grpc_channel* const c_channel_; // owned -- cgit v1.2.3