diff options
Diffstat (limited to 'include/grpc++/impl/codegen/method_handler_impl.h')
-rw-r--r-- | include/grpc++/impl/codegen/method_handler_impl.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/include/grpc++/impl/codegen/method_handler_impl.h b/include/grpc++/impl/codegen/method_handler_impl.h index 2f4be644ba..9c3af53b3a 100644 --- a/include/grpc++/impl/codegen/method_handler_impl.h +++ b/include/grpc++/impl/codegen/method_handler_impl.h @@ -35,6 +35,7 @@ #define GRPCXX_IMPL_CODEGEN_METHOD_HANDLER_IMPL_H #include <grpc++/impl/codegen/core_codegen_interface.h> +#include <grpc++/impl/codegen/fc_unary.h> #include <grpc++/impl/codegen/rpc_service_method.h> #include <grpc++/impl/codegen/sync_stream.h> @@ -202,6 +203,41 @@ class BidiStreamingHandler : public MethodHandler { ServiceType* service_; }; +// A wrapper class of an application provided rpc method handler +// specifically to apply to the flow-controlled implementation of a unary +// method. +/// The argument to the constructor should be a member function already +/// bound to the appropriate service instance. The declaration gets too +/// complicated +/// otherwise. +template <class ServiceType, class RequestType, class ResponseType> +class FCUnaryMethodHandler : public MethodHandler { + public: + FCUnaryMethodHandler( + std::function<Status(ServerContext*, FCUnary<RequestType, ResponseType>*)> + func) + : func_(func) {} + + void RunHandler(const HandlerParameter& param) GRPC_FINAL { + FCUnary<RequestType, ResponseType> fc_unary(param.call, + param.server_context); + Status status = func_(param.server_context, &fc_unary); + if (!param.server_context->sent_initial_metadata_) { + // means that the write never happened, which is bad + } else { + CallOpSet<CallOpServerSendStatus> ops; + ops.ServerSendStatus(param.server_context->trailing_metadata_, status); + param.call->PerformOps(&ops); + param.call->cq()->Pluck(&ops); + } + } + + private: + // Application provided rpc handler function, already bound to its service. + std::function<Status(ServerContext*, FCUnary<RequestType, ResponseType>*)> + func_; +}; + // Handle unknown method by returning UNIMPLEMENTED error. class UnknownMethodHandler : public MethodHandler { public: |