aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp
diff options
context:
space:
mode:
authorGravatar yang-g <yangg@google.com>2015-08-05 14:24:00 -0700
committerGravatar yang-g <yangg@google.com>2015-08-05 14:24:00 -0700
commita73dc1c708baf06e746f7a3f13fa14958a4ee2a1 (patch)
tree0b8f072d396e74127c779db4daec6b1f86220e90 /src/cpp
parentc0f32791754a7892078c4388ded9bd057c2d2e73 (diff)
specialize deadline type and implementation
Diffstat (limited to 'src/cpp')
-rw-r--r--src/cpp/client/channel.cc45
-rw-r--r--src/cpp/client/channel.h24
2 files changed, 66 insertions, 3 deletions
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 <grpc++/impl/call.h>
#include <grpc++/impl/rpc_method.h>
#include <grpc++/status.h>
+#include <grpc++/time.h>
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<std::chrono::system_clock::time_point> 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