diff options
author | 2016-01-13 15:27:33 -0800 | |
---|---|---|
committer | 2016-01-13 15:27:33 -0800 | |
commit | bef0d8744e1bd2227e19c13ac93a04a0fe2458ae (patch) | |
tree | d2588e2ae364ad1d3c0c3ba2e01935ed5a25f996 /include | |
parent | dc548ed65db8704906864586d5bc1ba08933ee78 (diff) |
Support sync/async methods in the same service
Diffstat (limited to 'include')
-rw-r--r-- | include/grpc++/impl/rpc_service_method.h | 3 | ||||
-rw-r--r-- | include/grpc++/impl/service_type.h | 13 |
2 files changed, 14 insertions, 2 deletions
diff --git a/include/grpc++/impl/rpc_service_method.h b/include/grpc++/impl/rpc_service_method.h index c6451dcbc3..3b47a4d64d 100644 --- a/include/grpc++/impl/rpc_service_method.h +++ b/include/grpc++/impl/rpc_service_method.h @@ -48,8 +48,6 @@ namespace grpc { class ServerContext; class StreamContextInterface; -// TODO(rocking): we might need to split this file into multiple ones. - // Base class for running an RPC handler. class MethodHandler { public: @@ -82,6 +80,7 @@ class RpcServiceMethod : public RpcMethod { void* server_tag() const { return server_tag_; } // if MethodHandler is nullptr, then this is an async method MethodHandler* handler() const { return handler_.get(); } + void ResetHandler() { handler_.reset(); } private: void* server_tag_; diff --git a/include/grpc++/impl/service_type.h b/include/grpc++/impl/service_type.h index 96b42c94fe..655aa91cdc 100644 --- a/include/grpc++/impl/service_type.h +++ b/include/grpc++/impl/service_type.h @@ -61,6 +61,7 @@ class ServerAsyncStreamingInterface { class Service { public: + Service() : server_(nullptr) {} virtual ~Service() {} bool has_async_methods() const { @@ -117,6 +118,18 @@ class Service { notification_cq, tag); } + void AddMethod(RpcServiceMethod* method) { methods_.emplace_back(method); } + + void MarkMethodAsync(const grpc::string& method_name) { + for (auto it = methods_.begin(); it != methods_.end(); ++it) { + if ((*it)->name() == method_name) { + (*it)->ResetHandler(); + return; + } + } + abort(); + } + private: friend class Server; |