Go to the documentation of this file.
19 #ifndef GRPCPP_IMPL_CODEGEN_METHOD_HANDLER_H
20 #define GRPCPP_IMPL_CODEGEN_METHOD_HANDLER_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) {}
68 return func_(service_,
70 static_cast<RequestType*
>(param.request), &rsp);
72 static_cast<RequestType*
>(param.request)->~RequestType();
80 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
81 param.server_context->initial_metadata_flags());
82 if (param.server_context->compression_level_set()) {
83 ops.set_compression_level(param.server_context->compression_level());
86 status = ops.SendMessagePtr(&rsp);
88 ops.ServerSendStatus(¶m.server_context->trailing_metadata_, status);
89 param.call->PerformOps(&ops);
90 param.call->cq()->Pluck(&ops);
99 call,
sizeof(RequestType))) RequestType();
106 request->~RequestType();
113 const RequestType*, ResponseType*)>
116 ServiceType* service_;
120 template <
class ServiceType,
class RequestType,
class ResponseType>
127 ServiceType* service)
128 : func_(func), service_(service) {}
136 return func_(service_,
145 if (!param.server_context->sent_initial_metadata_) {
146 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
147 param.server_context->initial_metadata_flags());
148 if (param.server_context->compression_level_set()) {
149 ops.set_compression_level(param.server_context->compression_level());
153 status = ops.SendMessagePtr(&rsp);
155 ops.ServerSendStatus(¶m.server_context->trailing_metadata_, status);
156 param.call->PerformOps(&ops);
157 param.call->cq()->Pluck(&ops);
164 ServiceType* service_;
168 template <
class ServiceType,
class RequestType,
class ResponseType>
175 ServiceType* service)
176 : func_(func), service_(service) {}
185 return func_(service_,
187 static_cast<RequestType*
>(param.request), &writer);
189 static_cast<RequestType*
>(param.request)->~RequestType();
195 if (!param.server_context->sent_initial_metadata_) {
196 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
197 param.server_context->initial_metadata_flags());
198 if (param.server_context->compression_level_set()) {
199 ops.set_compression_level(param.server_context->compression_level());
203 param.call->PerformOps(&ops);
204 if (param.server_context->has_pending_ops_) {
205 param.call->cq()->Pluck(¶m.server_context->pending_ops_);
207 param.call->cq()->Pluck(&ops);
216 call,
sizeof(RequestType))) RequestType();
223 request->~RequestType();
231 ServiceType* service_;
241 template <
class Streamer,
bool WriteNeeded>
246 : func_(func), write_needed_(WriteNeeded) {}
249 Streamer stream(param.call,
259 if (!param.server_context->sent_initial_metadata_) {
260 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
261 param.server_context->initial_metadata_flags());
262 if (param.server_context->compression_level_set()) {
263 ops.set_compression_level(param.server_context->compression_level());
265 if (write_needed_ && status.
ok()) {
269 "Service did not provide response message");
272 ops.ServerSendStatus(¶m.server_context->trailing_metadata_, status);
273 param.call->PerformOps(&ops);
274 if (param.server_context->has_pending_ops_) {
275 param.call->cq()->Pluck(¶m.server_context->pending_ops_);
277 param.call->cq()->Pluck(&ops);
282 const bool write_needed_;
285 template <
class ServiceType,
class RequestType,
class ResponseType>
288 ServerReaderWriter<ResponseType, RequestType>, false> {
294 ServiceType* service)
301 return func(service, ctx, streamer);
305 template <
class RequestType,
class ResponseType>
308 ServerUnaryStreamer<RequestType, ResponseType>, true> {
320 template <
class RequestType,
class ResponseType>
323 ServerSplitStreamer<RequestType, ResponseType>, false> {
337 template <::grpc::StatusCode code>
343 if (!context->sent_initial_metadata_) {
344 ops->SendInitialMetadata(&context->initial_metadata_,
345 context->initial_metadata_flags());
349 context->sent_initial_metadata_ =
true;
351 ops->ServerSendStatus(&context->trailing_metadata_, status);
358 FillOps(param.server_context, &ops);
359 param.call->PerformOps(&ops);
360 param.call->cq()->Pluck(&ops);
366 if (req !=
nullptr) {
373 typedef ErrorMethodHandler<::grpc::StatusCode::UNIMPLEMENTED>
381 #endif // GRPCPP_IMPL_CODEGEN_METHOD_HANDLER_H
ErrorMethodHandler<::grpc::StatusCode::RESOURCE_EXHAUSTED > ResourceExhaustedHandler
Definition: method_handler.h:376
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler.h:130
A ServerContext or CallbackServerContext allows the code implementing a service handler to:
Definition: server_context.h:527
Definition: call_op_set.h:653
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
Primary implementation of CallOpSetInterface.
Definition: call_op_set.h:850
Definition: call_op_set.h:287
General method handler class for errors that prevent real method use e.g., handle unknown method by r...
Definition: byte_buffer.h:48
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler.h:178
virtual void * grpc_call_arena_alloc(grpc_call *call, size_t length)=0
StreamedUnaryHandler(std::function< ::grpc::Status(::grpc::ServerContext *, ServerUnaryStreamer< RequestType, ResponseType > *)> func)
Definition: method_handler.h:310
Synchronous (blocking) server-side API for doing for doing a server-streaming RPCs,...
Definition: completion_queue.h:57
Definition: method_handler.h:321
SplitServerStreamingHandler(std::function< ::grpc::Status(::grpc::ServerContext *, ServerSplitStreamer< RequestType, ResponseType > *)> func)
Definition: method_handler.h:325
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler.h:248
Base class of ServerContext. Experimental until callback API is final.
Definition: server_context.h:125
void ServerSendStatus(std::multimap< std::string, std::string > *trailing_metadata, const Status &status)
Definition: call_op_set.h:657
bool ok() const
Is the status OK?
Definition: status.h:118
virtual void grpc_byte_buffer_destroy(grpc_byte_buffer *bb)=0
A class to represent a flow-controlled server-side streaming call.
Definition: sync_stream.h:886
void * Deserialize(grpc_call *call, grpc_byte_buffer *req, ::grpc::Status *status, void **) final
Definition: method_handler.h:93
ClientStreamingHandler(std::function<::grpc::Status(ServiceType *, ::grpc::ServerContext *, ServerReader< RequestType > *, ResponseType *)> func, ServiceType *service)
Definition: method_handler.h:123
Did it work? If it didn't, why?
Definition: status.h:31
ServerStreamingHandler(std::function<::grpc::Status(ServiceType *, ::grpc::ServerContext *, const RequestType *, ServerWriter< ResponseType > *)> func, ServiceType *service)
Definition: method_handler.h:171
Synchronous (blocking) server-side API for doing client-streaming RPCs, where the incoming message st...
Definition: completion_queue.h:55
struct grpc_call grpc_call
A Call represents an RPC.
Definition: grpc_types.h:70
Definition: grpc_types.h:40
A sequence of bytes.
Definition: byte_buffer.h:60
bool compression_level_set() const
Return a bool indicating whether the compression level for this call has been set (either implicitly ...
Definition: server_context.h:242
Defines how to serialize and deserialize some type.
Definition: serialization_traits.h:58
void * Deserialize(grpc_call *, grpc_byte_buffer *req, ::grpc::Status *, void **) final
Definition: method_handler.h:363
Base class for running an RPC handler.
Definition: rpc_service_method.h:38
::google::protobuf::util::Status Status
Definition: config_protobuf.h:90
Synchronous (blocking) server-side API for a bidirectional streaming call, where the incoming message...
Definition: sync_stream.h:779
void * Deserialize(grpc_call *call, grpc_byte_buffer *req, ::grpc::Status *status, void **) final
Definition: method_handler.h:210
A wrapper class of an application provided bidi-streaming handler.
Definition: completion_queue.h:69
Definition: method_handler.h:286
BidiStreamingHandler(std::function<::grpc::Status(ServiceType *, ::grpc::ServerContext *, ServerReaderWriter< ResponseType, RequestType > *)> func, ServiceType *service)
Definition: method_handler.h:290
Definition: async_unary_call.h:301
ErrorMethodHandler<::grpc::StatusCode::UNIMPLEMENTED > UnknownMethodHandler
Definition: method_handler.h:374
TemplatedBidiStreamingHandler(std::function<::grpc::Status(::grpc::ServerContext *, Streamer *)> func)
Definition: method_handler.h:244
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler.h:354
::grpc::Status CatchingFunctionHandler(Callable &&handler)
Definition: method_handler.h:39
A class to represent a flow-controlled unary call.
Definition: sync_stream.h:820
CoreCodegenInterface * g_core_codegen_interface
Definition: completion_queue.h:90
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:146
@ UNKNOWN
Unknown error.
Definition: status_code_enum.h:35
static void FillOps(::grpc::ServerContextBase *context, T *ops)
Definition: method_handler.h:341
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler.h:63
RpcMethodHandler(std::function<::grpc::Status(ServiceType *, ::grpc::ServerContext *, const RequestType *, ResponseType *)> func, ServiceType *service)
Definition: method_handler.h:56
void Release()
Forget underlying byte buffer without destroying Use this only for un-owned byte buffers.
Definition: byte_buffer.h:139
Definition: method_handler.h:306
@ INTERNAL
Internal errors.
Definition: status_code_enum.h:119
grpc_compression_level compression_level() const
Return the compression algorithm to be used by the server call.
Definition: server_context.h:227