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) {}
64 param.request.bbuf_ptr(), &req);
68 return func_(service_, param.server_context, &req, &rsp);
76 ops.SendInitialMetadata(param.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.SendMessage(rsp);
84 ops.ServerSendStatus(param.server_context->trailing_metadata_, status);
85 param.call->PerformOps(&ops);
86 param.call->cq()->Pluck(&ops);
95 ServiceType* service_;
99 template <
class ServiceType,
class RequestType,
class ResponseType>
106 ServiceType* service)
107 : func_(func), service_(service) {}
113 return func_(service_, param.server_context, &reader, &rsp);
120 ops.SendInitialMetadata(param.server_context->initial_metadata_,
121 param.server_context->initial_metadata_flags());
122 if (param.server_context->compression_level_set()) {
123 ops.set_compression_level(param.server_context->compression_level());
126 status = ops.SendMessage(rsp);
128 ops.ServerSendStatus(param.server_context->trailing_metadata_, status);
129 param.call->PerformOps(&ops);
130 param.call->cq()->Pluck(&ops);
134 std::function<Status(ServiceType*, ServerContext*, ServerReader<RequestType>*,
137 ServiceType* service_;
141 template <
class ServiceType,
class RequestType,
class ResponseType>
148 ServiceType* service)
149 : func_(func), service_(service) {}
154 param.request.bbuf_ptr(), &req);
159 return func_(service_, param.server_context, &req, &writer);
164 if (!param.server_context->sent_initial_metadata_) {
165 ops.SendInitialMetadata(param.server_context->initial_metadata_,
166 param.server_context->initial_metadata_flags());
167 if (param.server_context->compression_level_set()) {
168 ops.set_compression_level(param.server_context->compression_level());
171 ops.ServerSendStatus(param.server_context->trailing_metadata_, status);
172 param.call->PerformOps(&ops);
173 if (param.server_context->has_pending_ops_) {
174 param.call->cq()->Pluck(¶m.server_context->pending_ops_);
176 param.call->cq()->Pluck(&ops);
183 ServiceType* service_;
193 template <
class Streamer,
bool WriteNeeded>
198 : func_(func), write_needed_(WriteNeeded) {}
201 Streamer stream(param.call, param.server_context);
203 return func_(param.server_context, &stream);
207 if (!param.server_context->sent_initial_metadata_) {
208 ops.SendInitialMetadata(param.server_context->initial_metadata_,
209 param.server_context->initial_metadata_flags());
210 if (param.server_context->compression_level_set()) {
211 ops.set_compression_level(param.server_context->compression_level());
213 if (write_needed_ && status.
ok()) {
217 "Service did not provide response message");
220 ops.ServerSendStatus(param.server_context->trailing_metadata_, status);
221 param.call->PerformOps(&ops);
222 if (param.server_context->has_pending_ops_) {
223 param.call->cq()->Pluck(¶m.server_context->pending_ops_);
225 param.call->cq()->Pluck(&ops);
229 std::function<Status(ServerContext*, Streamer*)> func_;
230 const bool write_needed_;
233 template <
class ServiceType,
class RequestType,
class ResponseType>
236 ServerReaderWriter<ResponseType, RequestType>, false> {
242 ServiceType* service)
245 func, service,
std::placeholders::_1,
std::placeholders::_2)) {}
248 template <
class RequestType,
class ResponseType>
251 ServerUnaryStreamer<RequestType, ResponseType>, true> {
261 template <
class RequestType,
class ResponseType>
264 ServerSplitStreamer<RequestType, ResponseType>, false> {
280 if (!context->sent_initial_metadata_) {
281 ops->SendInitialMetadata(context->initial_metadata_,
282 context->initial_metadata_flags());
286 context->sent_initial_metadata_ =
true;
288 ops->ServerSendStatus(context->trailing_metadata_, status);
293 FillOps(param.server_context, &ops);
294 param.call->PerformOps(&ops);
295 param.call->cq()->Pluck(&ops);
302 #endif // GRPCPP_IMPL_CODEGEN_METHOD_HANDLER_IMPL_H A wrapper class of an application provided server streaming handler.
Definition: byte_buffer.h:47
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:291
A wrapper class of an application provided bidi-streaming handler.
Definition: completion_queue.h:83
ServerStreamingHandler(std::function< Status(ServiceType *, ServerContext *, const RequestType *, ServerWriter< ResponseType > *)> func, ServiceType *service)
Definition: method_handler_impl.h:144
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:109
StreamedUnaryHandler(std::function< Status(ServerContext *, ServerUnaryStreamer< RequestType, ResponseType > *)> func)
Definition: method_handler_impl.h:253
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:138
A class to represent a flow-controlled server-side streaming call.
Definition: sync_stream.h:878
static void FillOps(ServerContext *context, T *ops)
Definition: method_handler_impl.h:278
A class to represent a flow-controlled unary call.
Definition: sync_stream.h:813
Primary implementation of CallOpSetInterface.
Definition: call.h:619
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:151
ClientStreamingHandler(std::function< Status(ServiceType *, ServerContext *, ServerReader< RequestType > *, ResponseType *)> func, ServiceType *service)
Definition: method_handler_impl.h:102
Handle unknown method by returning UNIMPLEMENTED error.
Definition: method_handler_impl.h:275
Definition: async_unary_call.h:303
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:175
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:200
Synchronous (blocking) server-side API for doing client-streaming RPCs, where the incoming message st...
Definition: completion_queue.h:53
SplitServerStreamingHandler(std::function< Status(ServerContext *, ServerSplitStreamer< RequestType, ResponseType > *)> func)
Definition: method_handler_impl.h:266
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:190
Defines how to serialize and deserialize some type.
Definition: serialization_traits.h:58
Definition: method_handler_impl.h:262
An Alarm posts the user provided tag to its associated completion queue upon expiry or cancellation...
Definition: alarm.h:31
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
Definition: rpc_service_method.h:41
A ServerContext allows the person implementing a service handler to:
Definition: server_context.h:96
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
bool ok() const
Is the status OK?
Definition: status.h:118
TemplatedBidiStreamingHandler(std::function< Status(ServerContext *, Streamer *)> func)
Definition: method_handler_impl.h:196
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:38
Did it work? If it didn't, why?
Definition: status.h:31
Definition: method_handler_impl.h:249
Operation is not implemented or not supported/enabled in this service.
Definition: status_code_enum.h:115
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
BidiStreamingHandler(std::function< Status(ServiceType *, ServerContext *, ServerReaderWriter< ResponseType, RequestType > *)> func, ServiceType *service)
Definition: method_handler_impl.h:238