diff options
Diffstat (limited to 'src/cpp/client')
-rw-r--r-- | src/cpp/client/client_context.cc | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc index 9bb358b233..a4fdfcb0de 100644 --- a/src/cpp/client/client_context.cc +++ b/src/cpp/client/client_context.cc @@ -45,17 +45,29 @@ namespace grpc { +class DefaultGlobalCallbacks GRPC_FINAL : public ClientContext::GlobalCallbacks { + public: + void DefaultConstructor(ClientContext* context) GRPC_OVERRIDE {} + void Destructor(ClientContext* context) GRPC_OVERRIDE {} +}; + +static DefaultGlobalCallbacks g_default_callbacks; +static ClientContext::GlobalCallbacks* g_callbacks = &g_default_callbacks; + ClientContext::ClientContext() : initial_metadata_received_(false), call_(nullptr), call_canceled_(false), deadline_(gpr_inf_future(GPR_CLOCK_REALTIME)), - propagate_from_call_(nullptr) {} + propagate_from_call_(nullptr) { + g_callbacks->DefaultConstructor(this); +} ClientContext::~ClientContext() { if (call_) { grpc_call_destroy(call_); } + g_callbacks->Destructor(this); } std::unique_ptr<ClientContext> ClientContext::FromServerContext( @@ -124,4 +136,11 @@ grpc::string ClientContext::peer() const { return peer; } +void ClientContext::SetGlobalCallbacks(GlobalCallbacks* callbacks) { + GPR_ASSERT(g_callbacks == &g_default_callbacks); + GPR_ASSERT(callbacks != NULL); + GPR_ASSERT(callbacks != &g_default_callbacks); + g_callbacks = callbacks; +} + } // namespace grpc |