Go to the documentation of this file.
19 #ifndef GRPCPP_IMPL_CODEGEN_METHOD_HANDLER_IMPL_H
20 #define GRPCPP_IMPL_CODEGEN_METHOD_HANDLER_IMPL_H
38 template <
class Callable>
40 #if GRPC_ALLOW_EXCEPTIONS
45 "Unexpected error in RPC handling");
47 #else // GRPC_ALLOW_EXCEPTIONS
49 #endif // GRPC_ALLOW_EXCEPTIONS
53 template <
class ServiceType,
class RequestType,
class ResponseType>
58 const RequestType*, ResponseType*)>
61 : func_(func), service_(service) {}
70 static_cast<::grpc_impl::ServerContext*>(param.server_context),
71 static_cast<RequestType*>(param.request), &rsp);
73 static_cast<RequestType*>(param.request)->~RequestType();
81 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
82 param.server_context->initial_metadata_flags());
83 if (param.server_context->compression_level_set()) {
84 ops.set_compression_level(param.server_context->compression_level());
87 status = ops.SendMessagePtr(&rsp);
89 ops.ServerSendStatus(¶m.server_context->trailing_metadata_, status);
90 param.call->PerformOps(&ops);
91 param.call->cq()->Pluck(&ops);
100 call,
sizeof(RequestType))) RequestType();
107 request->~RequestType();
114 const RequestType*, ResponseType*)>
117 ServiceType* service_;
121 template <
class ServiceType,
class RequestType,
class ResponseType>
129 ServiceType* service)
130 : func_(func), service_(service) {}
135 static_cast<::grpc_impl::ServerContext*>(param.server_context));
141 static_cast<::grpc_impl::ServerContext*>(param.server_context),
149 if (!param.server_context->sent_initial_metadata_) {
150 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
151 param.server_context->initial_metadata_flags());
152 if (param.server_context->compression_level_set()) {
153 ops.set_compression_level(param.server_context->compression_level());
157 status = ops.SendMessagePtr(&rsp);
159 ops.ServerSendStatus(¶m.server_context->trailing_metadata_, status);
160 param.call->PerformOps(&ops);
161 param.call->cq()->Pluck(&ops);
169 ServiceType* service_;
173 template <
class ServiceType,
class RequestType,
class ResponseType>
181 ServiceType* service)
182 : func_(func), service_(service) {}
189 static_cast<::grpc_impl::ServerContext*>(param.server_context));
193 static_cast<::grpc_impl::ServerContext*>(param.server_context),
194 static_cast<RequestType*>(param.request), &writer);
196 static_cast<RequestType*>(param.request)->~RequestType();
202 if (!param.server_context->sent_initial_metadata_) {
203 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
204 param.server_context->initial_metadata_flags());
205 if (param.server_context->compression_level_set()) {
206 ops.set_compression_level(param.server_context->compression_level());
210 param.call->PerformOps(&ops);
211 if (param.server_context->has_pending_ops_) {
212 param.call->cq()->Pluck(¶m.server_context->pending_ops_);
214 param.call->cq()->Pluck(&ops);
223 call,
sizeof(RequestType))) RequestType();
230 request->~RequestType();
239 ServiceType* service_;
249 template <
class Streamer,
bool WriteNeeded>
255 : func_(func), write_needed_(WriteNeeded) {}
258 Streamer stream(param.call, static_cast<::grpc_impl::ServerContext*>(
259 param.server_context));
262 static_cast<::grpc_impl::ServerContext*>(param.server_context),
269 if (!param.server_context->sent_initial_metadata_) {
270 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
271 param.server_context->initial_metadata_flags());
272 if (param.server_context->compression_level_set()) {
273 ops.set_compression_level(param.server_context->compression_level());
275 if (write_needed_ && status.
ok()) {
279 "Service did not provide response message");
282 ops.ServerSendStatus(¶m.server_context->trailing_metadata_, status);
283 param.call->PerformOps(&ops);
284 if (param.server_context->has_pending_ops_) {
285 param.call->cq()->Pluck(¶m.server_context->pending_ops_);
287 param.call->cq()->Pluck(&ops);
292 const bool write_needed_;
295 template <
class ServiceType,
class RequestType,
class ResponseType>
298 ::grpc_impl::ServerReaderWriter<ResponseType, RequestType>, false> {
305 ServiceType* service)
312 streamer) {
return func(service, ctx, streamer); }) {}
315 template <
class RequestType,
class ResponseType>
318 ::grpc_impl::ServerUnaryStreamer<RequestType, ResponseType>, true> {
330 template <
class RequestType,
class ResponseType>
333 ::grpc_impl::ServerSplitStreamer<RequestType, ResponseType>, false> {
347 template <::grpc::StatusCode code>
353 if (!context->sent_initial_metadata_) {
354 ops->SendInitialMetadata(&context->initial_metadata_,
355 context->initial_metadata_flags());
359 context->sent_initial_metadata_ =
true;
361 ops->ServerSendStatus(&context->trailing_metadata_, status);
368 FillOps(param.server_context, &ops);
369 param.call->PerformOps(&ops);
370 param.call->cq()->Pluck(&ops);
376 if (req !=
nullptr) {
383 typedef ErrorMethodHandler<::grpc::StatusCode::UNIMPLEMENTED>
391 #endif // GRPCPP_IMPL_CODEGEN_METHOD_HANDLER_IMPL_H
RpcMethodHandler(std::function<::grpc::Status(ServiceType *, ::grpc_impl::ServerContext *, const RequestType *, ResponseType *)> func, ServiceType *service)
Definition: method_handler_impl.h:56
General method handler class for errors that prevent real method use e.g., handle unknown method by r...
Definition: byte_buffer.h:44
BidiStreamingHandler(std::function<::grpc::Status(ServiceType *, ::grpc_impl::ServerContext *, ::grpc_impl::ServerReaderWriter< ResponseType, RequestType > *)> func, ServiceType *service)
Definition: method_handler_impl.h:300
::grpc_impl::internal::RpcMethodHandler< ServiceType, RequestType, ResponseType > RpcMethodHandler
Definition: method_handler.h:36
StreamedUnaryHandler(std::function<::grpc::Status(::grpc_impl::ServerContext *, ::grpc_impl::ServerUnaryStreamer< RequestType, ResponseType > *)> func)
Definition: method_handler_impl.h:320
Definition: call_op_set.h:652
::grpc_impl::internal::TemplatedBidiStreamingHandler< Streamer, WriteNeeded > TemplatedBidiStreamingHandler
Definition: method_handler.h:50
Primary implementation of CallOpSetInterface.
Definition: call_op_set.h:849
Definition: method_handler_impl.h:296
Definition: call_op_set.h:286
Definition: rpc_service_method.h:44
virtual void * grpc_call_arena_alloc(grpc_call *call, size_t length)=0
A class to represent a flow-controlled unary call.
Definition: sync_stream_impl.h:823
Synchronous (blocking) server-side API for a bidirectional streaming call, where the incoming message...
Definition: sync_stream_impl.h:781
Base class of ServerContext. Experimental until callback API is final.
Definition: server_context_impl.h:123
SplitServerStreamingHandler(std::function<::grpc::Status(::grpc_impl::ServerContext *, ::grpc_impl::ServerSplitStreamer< RequestType, ResponseType > *)> func)
Definition: method_handler_impl.h:335
bool ok() const
Is the status OK?
Definition: status.h:118
virtual void grpc_byte_buffer_destroy(grpc_byte_buffer *bb)=0
Did it work? If it didn't, why?
Definition: status.h:31
A ServerContext or CallbackServerContext allows the code implementing a service handler to:
Definition: server_context_impl.h:510
Definition: method_handler_impl.h:331
::grpc_impl::internal::ServerStreamingHandler< ServiceType, RequestType, ResponseType > ServerStreamingHandler
Definition: method_handler.h:46
struct grpc_call grpc_call
A Call represents an RPC.
Definition: grpc_types.h:70
ErrorMethodHandler<::grpc::StatusCode::RESOURCE_EXHAUSTED > ResourceExhaustedHandler
Definition: method_handler_impl.h:386
Definition: grpc_types.h:40
A sequence of bytes.
Definition: byte_buffer.h:67
void * Deserialize(grpc_call *call, grpc_byte_buffer *req, ::grpc::Status *status, void **) final
Definition: method_handler_impl.h:94
Synchronous (blocking) server-side API for doing for doing a server-streaming RPCs,...
Definition: completion_queue_impl.h:61
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:184
void ServerSendStatus(std::multimap< grpc::string, grpc::string > *trailing_metadata, const Status &status)
Definition: call_op_set.h:656
A class to represent a flow-controlled server-side streaming call.
Definition: sync_stream_impl.h:890
Defines how to serialize and deserialize some type.
Definition: serialization_traits.h:58
Base class for running an RPC handler.
Definition: rpc_service_method.h:41
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:63
::google::protobuf::util::Status Status
Definition: config_protobuf.h:90
ServerStreamingHandler(std::function<::grpc::Status(ServiceType *, ::grpc_impl::ServerContext *, const RequestType *, ::grpc_impl::ServerWriter< ResponseType > *)> func, ServiceType *service)
Definition: method_handler_impl.h:176
ErrorMethodHandler<::grpc::StatusCode::UNIMPLEMENTED > UnknownMethodHandler
Definition: method_handler_impl.h:384
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:132
static void FillOps(::grpc_impl::ServerContextBase *context, T *ops)
Definition: method_handler_impl.h:351
grpc_compression_level compression_level() const
Return the compression algorithm to be used by the server call.
Definition: server_context_impl.h:215
A wrapper class of an application provided bidi-streaming handler.
Definition: completion_queue_impl.h:74
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:257
Definition: async_unary_call_impl.h:301
TemplatedBidiStreamingHandler(std::function<::grpc::Status(::grpc_impl::ServerContext *, Streamer *)> func)
Definition: method_handler_impl.h:252
Synchronous (blocking) server-side API for doing client-streaming RPCs, where the incoming message st...
Definition: completion_queue_impl.h:59
void * Deserialize(grpc_call *, grpc_byte_buffer *req, ::grpc::Status *, void **) final
Definition: method_handler_impl.h:373
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm_impl.h:33
ClientStreamingHandler(std::function<::grpc::Status(ServiceType *, ::grpc_impl::ServerContext *, ::grpc_impl::ServerReader< RequestType > *, ResponseType *)> func, ServiceType *service)
Definition: method_handler_impl.h:124
void * Deserialize(grpc_call *call, grpc_byte_buffer *req, ::grpc::Status *status, void **) final
Definition: method_handler_impl.h:217
::grpc::Status CatchingFunctionHandler(Callable &&handler)
Definition: method_handler_impl.h:39
CoreCodegenInterface * g_core_codegen_interface
Definition: completion_queue_impl.h:93
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:146
Unknown error.
Definition: status_code_enum.h:35
void Release()
Forget underlying byte buffer without destroying Use this only for un-owned byte buffers.
Definition: byte_buffer.h:146
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:364
::grpc_impl::internal::ErrorMethodHandler< code > ErrorMethodHandler
Definition: method_handler.h:62
::grpc_impl::internal::ClientStreamingHandler< ServiceType, RequestType, ResponseType > ClientStreamingHandler
Definition: method_handler.h:41
Definition: method_handler_impl.h:316
bool compression_level_set() const
Return a bool indicating whether the compression level for this call has been set (either implicitly ...
Definition: server_context_impl.h:230
Internal errors.
Definition: status_code_enum.h:119