diff options
Diffstat (limited to 'src/cpp')
-rw-r--r-- | src/cpp/server/server.cc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index 695e811654..377c1ed167 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -51,6 +51,22 @@ namespace grpc { +class DefaultGlobalCallbacks GRPC_FINAL : public Server::GlobalCallbacks { + public: + void PreSynchronousRequest(ServerContext* context) GRPC_OVERRIDE {} + void PostSynchronousRequest(ServerContext* context) GRPC_OVERRIDE {} +}; + +static Server::GlobalCallbacks* g_callbacks = nullptr; +static gpr_once g_once_init_callbacks = GPR_ONCE_INIT; + +static void InitGlobalCallbacks() { + if (g_callbacks == nullptr) { + static DefaultGlobalCallbacks default_global_callbacks; + g_callbacks = &default_global_callbacks; + } +} + class Server::UnimplementedAsyncRequestContext { protected: UnimplementedAsyncRequestContext() : generic_stream_(&server_context_) {} @@ -220,8 +236,10 @@ class Server::SyncRequest GRPC_FINAL : public CompletionQueueTag { void Run() { ctx_.BeginCompletionOp(&call_); + g_callbacks->PreSynchronousRequest(&ctx_); method_->handler()->RunHandler(MethodHandler::HandlerParameter( &call_, &ctx_, request_payload_, call_.max_message_size())); + g_callbacks->PostSynchronousRequest(&ctx_); request_payload_ = nullptr; void* ignored_tag; bool ignored_ok; @@ -283,6 +301,7 @@ Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned, server_(CreateServer(max_message_size, compression_options)), thread_pool_(thread_pool), thread_pool_owned_(thread_pool_owned) { + gpr_once_init(&g_once_init_callbacks, InitGlobalCallbacks); grpc_server_register_completion_queue(server_, cq_.cq(), nullptr); } @@ -304,6 +323,12 @@ Server::~Server() { delete sync_methods_; } +void Server::SetGlobalCallbacks(GlobalCallbacks* callbacks) { + GPR_ASSERT(g_callbacks == nullptr); + GPR_ASSERT(callbacks != nullptr); + g_callbacks = callbacks; +} + bool Server::RegisterService(const grpc::string* host, RpcService* service) { for (int i = 0; i < service->GetMethodCount(); ++i) { RpcServiceMethod* method = service->GetMethod(i); |