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>
56 const RequestType*, ResponseType*)>
59 : func_(func), service_(service) {}
63 Status status = param.status;
66 return func_(service_, param.server_context,
67 static_cast<RequestType*>(param.request), &rsp);
69 static_cast<RequestType*
>(param.request)->~RequestType();
76 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
77 param.server_context->initial_metadata_flags());
78 if (param.server_context->compression_level_set()) {
79 ops.set_compression_level(param.server_context->compression_level());
82 status = ops.SendMessagePtr(&rsp);
84 ops.ServerSendStatus(¶m.server_context->trailing_metadata_, status);
85 param.call->PerformOps(&ops);
86 param.call->cq()->Pluck(&ops);
94 call,
sizeof(RequestType))) RequestType();
100 request->~RequestType();
110 ServiceType* service_;
114 template <
class ServiceType,
class RequestType,
class ResponseType>
121 ServiceType* service)
122 : func_(func), service_(service) {}
128 return func_(service_, param.server_context, &reader, &rsp);
134 if (!param.server_context->sent_initial_metadata_) {
135 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
136 param.server_context->initial_metadata_flags());
137 if (param.server_context->compression_level_set()) {
138 ops.set_compression_level(param.server_context->compression_level());
142 status = ops.SendMessagePtr(&rsp);
144 ops.ServerSendStatus(¶m.server_context->trailing_metadata_, status);
145 param.call->PerformOps(&ops);
146 param.call->cq()->Pluck(&ops);
150 std::function<Status(ServiceType*, ServerContext*, ServerReader<RequestType>*,
153 ServiceType* service_;
157 template <
class ServiceType,
class RequestType,
class ResponseType>
164 ServiceType* service)
165 : func_(func), service_(service) {}
168 Status status = param.status;
172 return func_(service_, param.server_context,
173 static_cast<RequestType*>(param.request), &writer);
175 static_cast<RequestType*
>(param.request)->~RequestType();
179 if (!param.server_context->sent_initial_metadata_) {
180 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
181 param.server_context->initial_metadata_flags());
182 if (param.server_context->compression_level_set()) {
183 ops.set_compression_level(param.server_context->compression_level());
186 ops.ServerSendStatus(¶m.server_context->trailing_metadata_, status);
187 param.call->PerformOps(&ops);
188 if (param.server_context->has_pending_ops_) {
189 param.call->cq()->Pluck(¶m.server_context->pending_ops_);
191 param.call->cq()->Pluck(&ops);
199 call,
sizeof(RequestType))) RequestType();
205 request->~RequestType();
213 ServiceType* service_;
223 template <
class Streamer,
bool WriteNeeded>
228 : func_(func), write_needed_(WriteNeeded) {}
231 Streamer stream(param.call, param.server_context);
233 return func_(param.server_context, &stream);
237 if (!param.server_context->sent_initial_metadata_) {
238 ops.SendInitialMetadata(¶m.server_context->initial_metadata_,
239 param.server_context->initial_metadata_flags());
240 if (param.server_context->compression_level_set()) {
241 ops.set_compression_level(param.server_context->compression_level());
243 if (write_needed_ && status.
ok()) {
247 "Service did not provide response message");
250 ops.ServerSendStatus(¶m.server_context->trailing_metadata_, status);
251 param.call->PerformOps(&ops);
252 if (param.server_context->has_pending_ops_) {
253 param.call->cq()->Pluck(¶m.server_context->pending_ops_);
255 param.call->cq()->Pluck(&ops);
259 std::function<Status(ServerContext*, Streamer*)> func_;
260 const bool write_needed_;
263 template <
class ServiceType,
class RequestType,
class ResponseType>
266 ServerReaderWriter<ResponseType, RequestType>, false> {
272 ServiceType* service)
275 func, service,
std::placeholders::_1,
std::placeholders::_2)) {}
278 template <
class RequestType,
class ResponseType>
281 ServerUnaryStreamer<RequestType, ResponseType>, true> {
291 template <
class RequestType,
class ResponseType>
294 ServerSplitStreamer<RequestType, ResponseType>, false> {
306 template <StatusCode code>
312 if (!context->sent_initial_metadata_) {
313 ops->SendInitialMetadata(&context->initial_metadata_,
314 context->initial_metadata_flags());
318 context->sent_initial_metadata_ =
true;
320 ops->ServerSendStatus(&context->trailing_metadata_, status);
325 FillOps(param.server_context, &ops);
326 param.call->PerformOps(&ops);
327 param.call->cq()->Pluck(&ops);
333 if (req !=
nullptr) {
347 #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:47
A wrapper class of an application provided bidi-streaming handler.
Definition: completion_queue.h:82
ServerStreamingHandler(std::function< Status(ServiceType *, ServerContext *, const RequestType *, ServerWriter< ResponseType > *)> func, ServiceType *service)
Definition: method_handler_impl.h:160
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:124
StreamedUnaryHandler(std::function< Status(ServerContext *, ServerUnaryStreamer< RequestType, ResponseType > *)> func)
Definition: method_handler_impl.h:283
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:142
A class to represent a flow-controlled server-side streaming call.
Definition: sync_stream.h:878
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:323
A class to represent a flow-controlled unary call.
Definition: sync_stream.h:813
Primary implementation of CallOpSetInterface.
Definition: call_op_set.h:828
void * Deserialize(grpc_call *call, grpc_byte_buffer *req, Status *status) final
Definition: method_handler_impl.h:330
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:167
ClientStreamingHandler(std::function< Status(ServiceType *, ServerContext *, ServerReader< RequestType > *, ResponseType *)> func, ServiceType *service)
Definition: method_handler_impl.h:117
Definition: async_unary_call.h:304
Definition: grpc_types.h:40
RpcMethodHandler(std::function< Status(ServiceType *, ServerContext *, const RequestType *, ResponseType *)> func, ServiceType *service)
Definition: method_handler_impl.h:55
grpc_compression_level compression_level() const
Return the compression algorithm to be used by the server call.
Definition: server_context.h:202
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:230
Synchronous (blocking) server-side API for doing client-streaming RPCs, where the incoming message st...
Definition: completion_queue.h:53
ErrorMethodHandler< StatusCode::RESOURCE_EXHAUSTED > ResourceExhaustedHandler
Definition: method_handler_impl.h:342
::google::protobuf::util::Status Status
Definition: config_protobuf.h:93
SplitServerStreamingHandler(std::function< Status(ServerContext *, ServerSplitStreamer< RequestType, ResponseType > *)> func)
Definition: method_handler_impl.h:296
void * Deserialize(grpc_call *call, grpc_byte_buffer *req, Status *status) final
Definition: method_handler_impl.h:89
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:217
virtual void grpc_byte_buffer_destroy(grpc_byte_buffer *bb)=0
Defines how to serialize and deserialize some type.
Definition: serialization_traits.h:58
Definition: call_op_set.h:636
Definition: method_handler_impl.h:292
void Release()
Forget underlying byte buffer without destroying Use this only for un-owned byte buffers.
Definition: byte_buffer.h:134
Definition: call_op_set.h:294
ErrorMethodHandler< StatusCode::UNIMPLEMENTED > UnknownMethodHandler
Definition: method_handler_impl.h:340
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.h:76
A wrapper class of an application provided rpc method handler.
Definition: byte_buffer.h:45
CoreCodegenInterface * g_core_codegen_interface
Definition: call_op_set.h:51
Definition: rpc_service_method.h:42
A ServerContext allows the person implementing a service handler to:
Definition: server_context.h:109
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.h:55
virtual void * grpc_call_arena_alloc(grpc_call *call, size_t length)=0
bool ok() const
Is the status OK?
Definition: status.h:118
TemplatedBidiStreamingHandler(std::function< Status(ServerContext *, Streamer *)> func)
Definition: method_handler_impl.h:226
void * Deserialize(grpc_call *call, grpc_byte_buffer *req, Status *status) final
Definition: method_handler_impl.h:194
Synchronous (blocking) server-side API for a bidirectional streaming call, where the incoming message...
Definition: sync_stream.h:772
Base class for running an RPC handler.
Definition: rpc_service_method.h:39
General method handler class for errors that prevent real method use e.g., handle unknown method by r...
Definition: byte_buffer.h:53
Did it work? If it didn't, why?
Definition: status.h:31
Definition: method_handler_impl.h:279
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:61
Definition: completion_queue.h:80
Status CatchingFunctionHandler(Callable &&handler)
Definition: method_handler_impl.h:39
Unknown error.
Definition: status_code_enum.h:35
Internal errors.
Definition: status_code_enum.h:119
A sequence of bytes.
Definition: byte_buffer.h:64
static void FillOps(ServerContext *context, T *ops)
Definition: method_handler_impl.h:310
BidiStreamingHandler(std::function< Status(ServiceType *, ServerContext *, ServerReaderWriter< ResponseType, RequestType > *)> func, ServiceType *service)
Definition: method_handler_impl.h:268