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 46 #else // GRPC_ALLOW_EXCEPTIONS 48 #endif // GRPC_ALLOW_EXCEPTIONS 52 template <
class ServiceType,
class RequestType,
class ResponseType>
57 const RequestType*, ResponseType*)>
60 : func_(func), service_(service) {}
64 Status status = param.status;
67 return func_(service_, param.server_context,
68 static_cast<RequestType*>(param.request), &rsp);
70 static_cast<RequestType*
>(param.request)->~RequestType();
77 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
78 param.server_context->initial_metadata_flags());
79 if (param.server_context->compression_level_set()) {
80 ops.set_compression_level(param.server_context->compression_level());
83 status = ops.SendMessagePtr(&rsp);
85 ops.ServerSendStatus(¶m.server_context->trailing_metadata_, status);
86 param.call->PerformOps(&ops);
87 param.call->cq()->Pluck(&ops);
91 void** handler_data)
final {
95 call,
sizeof(RequestType))) RequestType();
101 request->~RequestType();
108 const RequestType*, ResponseType*)>
111 ServiceType* service_;
115 template <
class ServiceType,
class RequestType,
class ResponseType>
122 ServiceType* service)
123 : func_(func), service_(service) {}
129 return func_(service_, param.server_context, &reader, &rsp);
135 if (!param.server_context->sent_initial_metadata_) {
136 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
137 param.server_context->initial_metadata_flags());
138 if (param.server_context->compression_level_set()) {
139 ops.set_compression_level(param.server_context->compression_level());
143 status = ops.SendMessagePtr(&rsp);
145 ops.ServerSendStatus(¶m.server_context->trailing_metadata_, status);
146 param.call->PerformOps(&ops);
147 param.call->cq()->Pluck(&ops);
154 ServiceType* service_;
158 template <
class ServiceType,
class RequestType,
class ResponseType>
165 ServiceType* service)
166 : func_(func), service_(service) {}
169 Status status = param.status;
173 return func_(service_, param.server_context,
174 static_cast<RequestType*>(param.request), &writer);
176 static_cast<RequestType*
>(param.request)->~RequestType();
180 if (!param.server_context->sent_initial_metadata_) {
181 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
182 param.server_context->initial_metadata_flags());
183 if (param.server_context->compression_level_set()) {
184 ops.set_compression_level(param.server_context->compression_level());
187 ops.ServerSendStatus(¶m.server_context->trailing_metadata_, status);
188 param.call->PerformOps(&ops);
189 if (param.server_context->has_pending_ops_) {
190 param.call->cq()->Pluck(¶m.server_context->pending_ops_);
192 param.call->cq()->Pluck(&ops);
196 void** handler_data)
final {
200 call,
sizeof(RequestType))) RequestType();
206 request->~RequestType();
214 ServiceType* service_;
224 template <
class Streamer,
bool WriteNeeded>
229 : func_(func), write_needed_(WriteNeeded) {}
232 Streamer stream(param.call, param.server_context);
234 return func_(param.server_context, &stream);
238 if (!param.server_context->sent_initial_metadata_) {
239 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
240 param.server_context->initial_metadata_flags());
241 if (param.server_context->compression_level_set()) {
242 ops.set_compression_level(param.server_context->compression_level());
244 if (write_needed_ && status.
ok()) {
248 "Service did not provide response message");
251 ops.ServerSendStatus(¶m.server_context->trailing_metadata_, status);
252 param.call->PerformOps(&ops);
253 if (param.server_context->has_pending_ops_) {
254 param.call->cq()->Pluck(¶m.server_context->pending_ops_);
256 param.call->cq()->Pluck(&ops);
260 std::function<Status(::grpc_impl::ServerContext*, Streamer*)> func_;
261 const bool write_needed_;
264 template <
class ServiceType,
class RequestType,
class ResponseType>
267 ServerReaderWriter<ResponseType, RequestType>, false> {
273 ServiceType* service)
276 func, service,
std::placeholders::_1,
std::placeholders::_2)) {}
279 template <
class RequestType,
class ResponseType>
282 ServerUnaryStreamer<RequestType, ResponseType>, true> {
292 template <
class RequestType,
class ResponseType>
295 ServerSplitStreamer<RequestType, ResponseType>, false> {
307 template <StatusCode code>
313 if (!context->sent_initial_metadata_) {
314 ops->SendInitialMetadata(&context->initial_metadata_,
315 context->initial_metadata_flags());
319 context->sent_initial_metadata_ =
true;
321 ops->ServerSendStatus(&context->trailing_metadata_, status);
326 FillOps(param.server_context, &ops);
327 param.call->PerformOps(&ops);
328 param.call->cq()->Pluck(&ops);
332 void** handler_data)
final {
334 if (req !=
nullptr) {
348 #endif // GRPCPP_IMPL_CODEGEN_METHOD_HANDLER_IMPL_H struct grpc_call grpc_call
A Call represents an RPC.
Definition: grpc_types.h:70
A wrapper class of an application provided server streaming handler.
Definition: byte_buffer.h:58
A wrapper class of an application provided bidi-streaming handler.
Definition: completion_queue_impl.h:82
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:125
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:145
RpcMethodHandler(std::function< Status(ServiceType *, ::grpc_impl::ServerContext *, const RequestType *, ResponseType *)> func, ServiceType *service)
Definition: method_handler_impl.h:55
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:324
Primary implementation of CallOpSetInterface.
Definition: call_op_set.h:821
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:168
void * Deserialize(grpc_call *call, grpc_byte_buffer *req, Status *status, void **handler_data) final
Definition: method_handler_impl.h:195
Definition: async_unary_call_impl.h:302
StreamedUnaryHandler(std::function< Status(::grpc_impl::ServerContext *, ServerUnaryStreamer< RequestType, ResponseType > *)> func)
Definition: method_handler_impl.h:284
Definition: grpc_types.h:40
A ServerContext allows the person implementing a service handler to:
Definition: server_context_impl.h:118
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:231
ErrorMethodHandler< StatusCode::RESOURCE_EXHAUSTED > ResourceExhaustedHandler
Definition: method_handler_impl.h:343
::google::protobuf::util::Status Status
Definition: config_protobuf.h:96
ClientStreamingHandler(std::function< Status(ServiceType *, ::grpc_impl::ServerContext *, ServerReader< RequestType > *, ResponseType *)> func, ServiceType *service)
Definition: method_handler_impl.h:118
void * Deserialize(grpc_call *call, grpc_byte_buffer *req, Status *status, void **handler_data) final
Definition: method_handler_impl.h:331
virtual void grpc_byte_buffer_destroy(grpc_byte_buffer *bb)=0
Defines how to serialize and deserialize some type.
Definition: serialization_traits.h:58
Synchronous (blocking) server-side API for doing client-streaming RPCs, where the incoming message st...
Definition: completion_queue_impl.h:57
Definition: call_op_set.h:629
SplitServerStreamingHandler(std::function< Status(::grpc_impl::ServerContext *, ServerSplitStreamer< RequestType, ResponseType > *)> func)
Definition: method_handler_impl.h:297
Definition: method_handler_impl.h:293
BidiStreamingHandler(std::function< Status(ServiceType *, ::grpc_impl::ServerContext *, ServerReaderWriter< ResponseType, RequestType > *)> func, ServiceType *service)
Definition: method_handler_impl.h:269
void Release()
Forget underlying byte buffer without destroying Use this only for un-owned byte buffers.
Definition: byte_buffer.h:151
Definition: call_op_set.h:288
ErrorMethodHandler< StatusCode::UNIMPLEMENTED > UnknownMethodHandler
Definition: method_handler_impl.h:341
grpc_compression_level compression_level() const
Return the compression algorithm to be used by the server call.
Definition: server_context_impl.h:211
Synchronous (blocking) server-side API for doing for doing a server-streaming RPCs, where the outgoing message stream coming from the server has messages of type W.
Definition: completion_queue_impl.h:59
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
A wrapper class of an application provided client streaming handler.
Definition: completion_queue_impl.h:76
A wrapper class of an application provided rpc method handler.
Definition: byte_buffer.h:56
CoreCodegenInterface * g_core_codegen_interface
Definition: completion_queue_impl.h:91
Definition: rpc_service_method.h:44
A class to represent a flow-controlled unary call.
Definition: sync_stream_impl.h:819
A class to represent a flow-controlled server-side streaming call.
Definition: sync_stream_impl.h:886
virtual void * grpc_call_arena_alloc(grpc_call *call, size_t length)=0
bool ok() const
Is the status OK?
Definition: status.h:118
static void FillOps(::grpc_impl::ServerContext *context, T *ops)
Definition: method_handler_impl.h:311
Base class for running an RPC handler.
Definition: rpc_service_method.h:41
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:226
General method handler class for errors that prevent real method use e.g., handle unknown method by r...
Definition: byte_buffer.h:60
Did it work? If it didn't, why?
Definition: status.h:31
Definition: method_handler_impl.h:280
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:62
Definition: completion_queue_impl.h:80
void * Deserialize(grpc_call *call, grpc_byte_buffer *req, Status *status, void **handler_data) final
Definition: method_handler_impl.h:90
Status CatchingFunctionHandler(Callable &&handler)
Definition: method_handler_impl.h:39
TemplatedBidiStreamingHandler(std::function< Status(::grpc_impl::ServerContext *, Streamer *)> func)
Definition: method_handler_impl.h:227
Synchronous (blocking) server-side API for a bidirectional streaming call, where the incoming message...
Definition: sync_stream_impl.h:777
Unknown error.
Definition: status_code_enum.h:35
Internal errors.
Definition: status_code_enum.h:119
A sequence of bytes.
Definition: byte_buffer.h:72
ServerStreamingHandler(std::function< Status(ServiceType *, ::grpc_impl::ServerContext *, const RequestType *, ServerWriter< ResponseType > *)> func, ServiceType *service)
Definition: method_handler_impl.h:161