19 #ifndef GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H 20 #define GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H 37 template <
class ServiceType,
class RequestType,
class ResponseType>
38 class CallbackUnaryHandler;
41 namespace experimental {
51 virtual void Finish(
Status s) = 0;
55 virtual void SendInitialMetadata(std::function<
void(
bool)>) = 0;
62 template <
class ServiceType,
class RequestType,
class ResponseType>
63 class CallbackUnaryHandler :
public MethodHandler {
66 std::function<
void(
ServerContext*,
const RequestType*, ResponseType*,
75 param.call->call(),
sizeof(ServerCallbackRpcControllerImpl)))
76 ServerCallbackRpcControllerImpl(
77 param.server_context, param.call,
78 static_cast<RequestType*>(param.request),
79 std::move(param.call_requester));
80 Status status = param.status;
85 controller->request(), controller->response(),
89 controller->Finish(status);
98 call,
sizeof(RequestType))) RequestType();
104 request->~RequestType();
109 std::function<void(
ServerContext*,
const RequestType*, ResponseType*,
116 class ServerCallbackRpcControllerImpl
119 void Finish(
Status s)
override {
124 auto call_requester = std::move(call_requester_);
125 this->~ServerCallbackRpcControllerImpl();
131 if (!ctx_->sent_initial_metadata_) {
133 ctx_->initial_metadata_flags());
134 if (ctx_->compression_level_set()) {
135 finish_buf_.set_compression_level(ctx_->compression_level());
137 ctx_->sent_initial_metadata_ =
true;
141 finish_buf_.ServerSendStatus(&ctx_->trailing_metadata_,
142 finish_buf_.SendMessage(resp_));
144 finish_buf_.ServerSendStatus(&ctx_->trailing_metadata_, s);
146 finish_buf_.set_core_cq_tag(&finish_tag_);
147 call_.PerformOps(&finish_buf_);
150 void SendInitialMetadata(std::function<
void(
bool)> f)
override {
153 meta_tag_.Set(call_.call(), std::move(f), &meta_buf_);
154 meta_buf_.SendInitialMetadata(&ctx_->initial_metadata_,
155 ctx_->initial_metadata_flags());
156 if (ctx_->compression_level_set()) {
157 meta_buf_.set_compression_level(ctx_->compression_level());
159 ctx_->sent_initial_metadata_ =
true;
160 meta_buf_.set_core_cq_tag(&meta_tag_);
161 call_.PerformOps(&meta_buf_);
165 template <
class SrvType,
class ReqType,
class RespType>
170 std::function<
void()> call_requester)
174 call_requester_(std::move(call_requester)) {}
176 ~ServerCallbackRpcControllerImpl() { req_->~RequestType(); }
178 RequestType* request() {
return req_; }
179 ResponseType* response() {
return &resp_; }
192 std::function<void()> call_requester_;
200 #endif // GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H
struct grpc_call grpc_call
A Call represents an RPC.
Definition: grpc_types.h:70
void RunHandler(const HandlerParameter ¶m) final
Definition: server_callback.h:71
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:141
virtual void grpc_call_ref(grpc_call *call)=0
Primary implementation of CallOpSetInterface.
Definition: call_op_set.h:755
virtual void grpc_call_unref(grpc_call *call)=0
virtual void SendInitialMetadata(std::function< void(bool)>)=0
Definition: grpc_types.h:40
Defines how to serialize and deserialize some type.
Definition: serialization_traits.h:58
Definition: call_op_set.h:563
void Release()
Forget underlying byte buffer without destroying Use this only for un-owned byte buffers.
Definition: byte_buffer.h:125
Definition: call_op_set.h:293
An Alarm posts the user provided tag to its associated completion queue upon expiry or cancellation...
Definition: alarm.h:33
CoreCodegenInterface * g_core_codegen_interface
Definition: call_op_set.h:50
Definition: rpc_service_method.h:42
A ServerContext allows the person implementing a service handler to:
Definition: server_context.h:102
CallbackUnaryHandler(std::function< void(ServerContext *, const RequestType *, ResponseType *, experimental::ServerCallbackRpcController *)> func, ServiceType *service)
Definition: server_callback.h:65
Definition: byte_buffer.h:49
virtual void * grpc_call_arena_alloc(grpc_call *call, size_t length)=0
CallbackWithSuccessTag can be reused multiple times, and will be used in this fashion for streaming o...
Definition: callback_common.h:116
bool ok() const
Is the status OK?
Definition: status.h:118
Did it work? If it didn't, why?
Definition: status.h:31
void CatchingCallback(Func &&func, Args &&... args)
An exception-safe way of invoking a user-specified callback function.
Definition: callback_common.h:36
Definition: server_callback.h:45
virtual ~ServerCallbackRpcController()
Definition: server_callback.h:47
A sequence of bytes.
Definition: byte_buffer.h:62
void * Deserialize(grpc_call *call, grpc_byte_buffer *req, Status *status) final
Definition: server_callback.h:93
Straightforward wrapping of the C call object.
Definition: call.h:36