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);
119 if (!param.server_context->sent_initial_metadata_) {
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());
127 status = ops.SendMessage(rsp);
129 ops.ServerSendStatus(param.server_context->trailing_metadata_, status);
130 param.call->PerformOps(&ops);
131 param.call->cq()->Pluck(&ops);
135 std::function<Status(ServiceType*, ServerContext*, ServerReader<RequestType>*,
138 ServiceType* service_;
142 template <
class ServiceType,
class RequestType,
class ResponseType>
149 ServiceType* service)
150 : func_(func), service_(service) {}
155 param.request.bbuf_ptr(), &req);
160 return func_(service_, param.server_context, &req, &writer);
165 if (!param.server_context->sent_initial_metadata_) {
166 ops.SendInitialMetadata(param.server_context->initial_metadata_,
167 param.server_context->initial_metadata_flags());
168 if (param.server_context->compression_level_set()) {
169 ops.set_compression_level(param.server_context->compression_level());
172 ops.ServerSendStatus(param.server_context->trailing_metadata_, status);
173 param.call->PerformOps(&ops);
174 if (param.server_context->has_pending_ops_) {
175 param.call->cq()->Pluck(¶m.server_context->pending_ops_);
177 param.call->cq()->Pluck(&ops);
184 ServiceType* service_;
194 template <
class Streamer,
bool WriteNeeded>
199 : func_(func), write_needed_(WriteNeeded) {}
202 Streamer stream(param.call, param.server_context);
204 return func_(param.server_context, &stream);
208 if (!param.server_context->sent_initial_metadata_) {
209 ops.SendInitialMetadata(param.server_context->initial_metadata_,
210 param.server_context->initial_metadata_flags());
211 if (param.server_context->compression_level_set()) {
212 ops.set_compression_level(param.server_context->compression_level());
214 if (write_needed_ && status.
ok()) {
218 "Service did not provide response message");
221 ops.ServerSendStatus(param.server_context->trailing_metadata_, status);
222 param.call->PerformOps(&ops);
223 if (param.server_context->has_pending_ops_) {
224 param.call->cq()->Pluck(¶m.server_context->pending_ops_);
226 param.call->cq()->Pluck(&ops);
230 std::function<Status(ServerContext*, Streamer*)> func_;
231 const bool write_needed_;
234 template <
class ServiceType,
class RequestType,
class ResponseType>
237 ServerReaderWriter<ResponseType, RequestType>, false> {
243 ServiceType* service)
246 func, service,
std::placeholders::_1,
std::placeholders::_2)) {}
249 template <
class RequestType,
class ResponseType>
252 ServerUnaryStreamer<RequestType, ResponseType>, true> {
262 template <
class RequestType,
class ResponseType>
265 ServerSplitStreamer<RequestType, ResponseType>, false> {
277 template <StatusCode code>
283 if (!context->sent_initial_metadata_) {
284 ops->SendInitialMetadata(context->initial_metadata_,
285 context->initial_metadata_flags());
289 context->sent_initial_metadata_ =
true;
291 ops->ServerSendStatus(context->trailing_metadata_, status);
296 FillOps(param.server_context, &ops);
297 param.call->PerformOps(&ops);
298 param.call->cq()->Pluck(&ops);
300 ByteBuffer* payload = param.request.bbuf_ptr();
301 if (payload !=
nullptr) {
314 #endif // GRPCPP_IMPL_CODEGEN_METHOD_HANDLER_IMPL_H void Clear()
Remove all data.
Definition: byte_buffer.h:102
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:145
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:254
#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
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:294
A class to represent a flow-controlled unary call.
Definition: sync_stream.h:813
Primary implementation of CallOpSetInterface.
Definition: call.h:618
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:152
ClientStreamingHandler(std::function< Status(ServiceType *, ServerContext *, ServerReader< RequestType > *, ResponseType *)> func, ServiceType *service)
Definition: method_handler_impl.h:102
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:176
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:201
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:309
SplitServerStreamingHandler(std::function< Status(ServerContext *, ServerSplitStreamer< RequestType, ResponseType > *)> func)
Definition: method_handler_impl.h:267
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:191
Defines how to serialize and deserialize some type.
Definition: serialization_traits.h:58
Definition: method_handler_impl.h:263
ErrorMethodHandler< StatusCode::UNIMPLEMENTED > UnknownMethodHandler
Definition: method_handler_impl.h:307
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:42
A ServerContext allows the person implementing a service handler to:
Definition: server_context.h:97
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:197
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:49
Did it work? If it didn't, why?
Definition: status.h:31
Definition: method_handler_impl.h:250
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:55
static void FillOps(ServerContext *context, T *ops)
Definition: method_handler_impl.h:281
BidiStreamingHandler(std::function< Status(ServiceType *, ServerContext *, ServerReaderWriter< ResponseType, RequestType > *)> func, ServiceType *service)
Definition: method_handler_impl.h:239