19 #ifndef GRPCXX_IMPL_CODEGEN_METHOD_HANDLER_IMPL_H
20 #define GRPCXX_IMPL_CODEGEN_METHOD_HANDLER_IMPL_H
31 template <
class ServiceType,
class RequestType,
class ResponseType>
32 class RpcMethodHandler :
public MethodHandler {
35 const RequestType*, ResponseType*)>
38 : func_(func), service_(service) {}
43 param.request.bbuf_ptr(), &req);
46 status = func_(service_, param.server_context, &req, &rsp);
53 ops.SendInitialMetadata(param.server_context->initial_metadata_,
54 param.server_context->initial_metadata_flags());
55 if (param.server_context->compression_level_set()) {
56 ops.set_compression_level(param.server_context->compression_level());
59 status = ops.SendMessage(rsp);
61 ops.ServerSendStatus(param.server_context->trailing_metadata_, status);
62 param.call->PerformOps(&ops);
63 param.call->cq()->Pluck(&ops);
72 ServiceType* service_;
76 template <
class ServiceType,
class RequestType,
class ResponseType>
77 class ClientStreamingHandler :
public MethodHandler {
84 : func_(func), service_(service) {}
89 Status status = func_(service_, param.server_context, &reader, &rsp);
95 ops.SendInitialMetadata(param.server_context->initial_metadata_,
96 param.server_context->initial_metadata_flags());
97 if (param.server_context->compression_level_set()) {
98 ops.set_compression_level(param.server_context->compression_level());
101 status = ops.SendMessage(rsp);
103 ops.ServerSendStatus(param.server_context->trailing_metadata_, status);
104 param.call->PerformOps(&ops);
105 param.call->cq()->Pluck(&ops);
109 std::function<Status(ServiceType*, ServerContext*, ServerReader<RequestType>*,
112 ServiceType* service_;
116 template <
class ServiceType,
class RequestType,
class ResponseType>
117 class ServerStreamingHandler :
public MethodHandler {
123 ServiceType* service)
124 : func_(func), service_(service) {}
129 param.request.bbuf_ptr(), &req);
133 status = func_(service_, param.server_context, &req, &writer);
137 if (!param.server_context->sent_initial_metadata_) {
138 ops.SendInitialMetadata(param.server_context->initial_metadata_,
139 param.server_context->initial_metadata_flags());
140 if (param.server_context->compression_level_set()) {
141 ops.set_compression_level(param.server_context->compression_level());
144 ops.ServerSendStatus(param.server_context->trailing_metadata_, status);
145 param.call->PerformOps(&ops);
146 if (param.server_context->has_pending_ops_) {
147 param.call->cq()->Pluck(¶m.server_context->pending_ops_);
149 param.call->cq()->Pluck(&ops);
156 ServiceType* service_;
166 template <
class Streamer,
bool WriteNeeded>
167 class TemplatedBidiStreamingHandler :
public MethodHandler {
171 : func_(func), write_needed_(WriteNeeded) {}
174 Streamer stream(param.call, param.server_context);
175 Status status = func_(param.server_context, &stream);
178 if (!param.server_context->sent_initial_metadata_) {
179 ops.SendInitialMetadata(param.server_context->initial_metadata_,
180 param.server_context->initial_metadata_flags());
181 if (param.server_context->compression_level_set()) {
182 ops.set_compression_level(param.server_context->compression_level());
184 if (write_needed_ && status.
ok()) {
188 "Service did not provide response message");
191 ops.ServerSendStatus(param.server_context->trailing_metadata_, status);
192 param.call->PerformOps(&ops);
193 if (param.server_context->has_pending_ops_) {
194 param.call->cq()->Pluck(¶m.server_context->pending_ops_);
196 param.call->cq()->Pluck(&ops);
200 std::function<Status(ServerContext*, Streamer*)> func_;
201 const bool write_needed_;
204 template <
class ServiceType,
class RequestType,
class ResponseType>
205 class BidiStreamingHandler
206 :
public TemplatedBidiStreamingHandler<
207 ServerReaderWriter<ResponseType, RequestType>, false> {
213 ServiceType* service)
216 func, service, std::placeholders::_1, std::placeholders::_2)) {}
219 template <
class RequestType,
class ResponseType>
222 ServerUnaryStreamer<RequestType, ResponseType>, true> {
232 template <
class RequestType,
class ResponseType>
235 ServerSplitStreamer<RequestType, ResponseType>, false> {
251 if (!context->sent_initial_metadata_) {
252 ops->SendInitialMetadata(context->initial_metadata_,
253 context->initial_metadata_flags());
257 context->sent_initial_metadata_ =
true;
259 ops->ServerSendStatus(context->trailing_metadata_, status);
264 FillOps(param.server_context, &ops);
265 param.call->PerformOps(&ops);
266 param.call->cq()->Pluck(&ops);
273 #endif // GRPCXX_IMPL_CODEGEN_METHOD_HANDLER_IMPL_H
grpc_compression_level compression_level() const
Return the compression algorithm to be used by the server call.
Definition: server_context.h:171
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:262
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:119
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:86
StreamedUnaryHandler(std::function< Status(ServerContext *, ServerUnaryStreamer< RequestType, ResponseType > *)> func)
Definition: method_handler_impl.h:224
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:249
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:135
A class to represent a flow-controlled unary call.
Definition: sync_stream.h:813
Primary implementaiton of CallOpSetInterface.
Definition: call.h:627
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:126
ClientStreamingHandler(std::function< Status(ServiceType *, ServerContext *, ServerReader< RequestType > *, ResponseType *)> func, ServiceType *service)
Definition: method_handler_impl.h:79
Handle unknown method by returning UNIMPLEMENTED error.
Definition: method_handler_impl.h:246
RpcMethodHandler(std::function< Status(ServiceType *, ServerContext *, const RequestType *, ResponseType *)> func, ServiceType *service)
Definition: method_handler_impl.h:34
void RunHandler(const HandlerParameter ¶m) final
Definition: method_handler_impl.h:173
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:237
Defines how to serialize and deserialize some type.
Definition: serialization_traits.h:58
Definition: method_handler_impl.h:233
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
TemplatedBidiStreamingHandler(std::function< Status(ServerContext *, Streamer *)> func)
Definition: method_handler_impl.h:169
Base class for running an RPC handler.
Definition: rpc_service_method.h:38
Synchronous (blocking) server-side API for a bidirectional streaming call, where the incoming message...
Definition: sync_stream.h:772
bool ok() const
Is the status OK?
Definition: status.h:64
Did it work? If it didn't, why?
Definition: status.h:30
Definition: method_handler_impl.h:220
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:40
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:186
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:209