Go to the documentation of this file.
19 #ifndef GRPCPP_SUPPORT_ASYNC_UNARY_CALL_H
20 #define GRPCPP_SUPPORT_ASYNC_UNARY_CALL_H
22 #include "absl/log/absl_check.h"
39 class ClientAsyncResponseReader;
94 template <
class R,
class W,
class BaseR = R,
class BaseW = W>
103 SetupRequest<BaseR, BaseW>(
104 call.
call(), &result->single_buf_, &result->read_initial_metadata_,
105 &result->finish_,
static_cast<const BaseW&
>(request));
112 template <
class R,
class W>
118 read_initial_metadata,
124 using SingleBufType =
131 SingleBufType* single_buf =
133 *single_buf_ptr = single_buf;
135 ABSL_CHECK(single_buf->SendMessage(request).ok());
136 single_buf->ClientSendClose();
143 *read_initial_metadata =
146 auto* single_buf =
static_cast<SingleBufType*
>(single_buf_view);
147 single_buf->set_output_tag(tag);
148 single_buf->RecvInitialMetadata(context);
149 call->PerformOps(single_buf);
160 bool initial_metadata_read,
163 Status* status,
void* tag) {
164 if (initial_metadata_read) {
165 using FinishBufType =
168 FinishBufType* finish_buf =
171 *finish_buf_ptr = finish_buf;
172 finish_buf->set_output_tag(tag);
173 finish_buf->RecvMessage(
static_cast<R*
>(msg));
174 finish_buf->AllowNoMessage();
176 call->PerformOps(finish_buf);
178 auto* single_buf =
static_cast<SingleBufType*
>(single_buf_view);
179 single_buf->set_output_tag(tag);
180 single_buf->RecvInitialMetadata(context);
181 single_buf->RecvMessage(
static_cast<R*
>(msg));
182 single_buf->AllowNoMessage();
183 single_buf->ClientRecvStatus(context, status);
184 call->PerformOps(single_buf);
192 context->initial_metadata_flags());
205 const W& request,
bool start) {
206 auto* result = ClientAsyncResponseReaderHelper::Create<R>(
207 channel, cq, method, context, request);
220 class ClientAsyncResponseReader final
221 :
public ClientAsyncResponseReaderInterface<R> {
224 static void operator delete(
void* , std::size_t size) {
233 static void operator delete(
void*,
void*) { ABSL_CHECK(
false); }
236 ABSL_DCHECK(!started_);
248 ABSL_DCHECK(started_);
249 ABSL_DCHECK(!context_->initial_metadata_received_);
250 read_initial_metadata_(context_, &call_, single_buf_, tag);
251 initial_metadata_read_ =
true;
260 ABSL_DCHECK(started_);
261 finish_(context_, &call_, initial_metadata_read_, single_buf_, &finish_buf_,
262 static_cast<void*
>(msg), status, tag);
269 bool started_ =
false;
270 bool initial_metadata_read_ =
false;
274 : context_(context), call_(call) {}
277 static void*
operator new(std::size_t size);
278 static void*
operator new(std::size_t ,
void* p) {
return p; }
280 internal::CallOpSendInitialMetadata* single_buf_;
281 internal::CallOpSetInterface* finish_buf_ =
nullptr;
282 std::function<void(ClientContext*, internal::Call*,
283 internal::CallOpSendInitialMetadata*,
void*)>
284 read_initial_metadata_;
285 std::function<void(ClientContext*, internal::Call*,
286 bool initial_metadata_read,
287 internal::CallOpSendInitialMetadata*,
288 internal::CallOpSetInterface**,
void*,
Status*,
void*)>
295 class ServerAsyncResponseWriter final
299 : call_(nullptr, nullptr, nullptr), ctx_(ctx) {}
309 ABSL_CHECK(!ctx_->sent_initial_metadata_);
312 meta_buf_.SendInitialMetadata(&ctx_->initial_metadata_,
313 ctx_->initial_metadata_flags());
317 ctx_->sent_initial_metadata_ =
true;
343 if (!ctx_->sent_initial_metadata_) {
344 finish_buf_.SendInitialMetadata(&ctx_->initial_metadata_,
345 ctx_->initial_metadata_flags());
349 ctx_->sent_initial_metadata_ =
true;
353 finish_buf_.ServerSendStatus(&ctx_->trailing_metadata_,
354 finish_buf_.SendMessage(msg));
356 finish_buf_.ServerSendStatus(&ctx_->trailing_metadata_, status);
378 ABSL_CHECK(!status.
ok());
380 if (!ctx_->sent_initial_metadata_) {
381 finish_buf_.SendInitialMetadata(&ctx_->initial_metadata_,
382 ctx_->initial_metadata_flags());
386 ctx_->sent_initial_metadata_ =
true;
388 finish_buf_.ServerSendStatus(&ctx_->trailing_metadata_, status);
409 class default_delete<
grpc::ClientAsyncResponseReader<R>> {
414 class default_delete<
grpc::ClientAsyncResponseReaderInterface<R>> {
420 #endif // GRPCPP_SUPPORT_ASYNC_UNARY_CALL_H
void StartCall() override
Definition: async_unary_call.h:235
Definition: service_type.h:39
Definition: call_op_set.h:621
GRPCAPI void * grpc_call_arena_alloc(grpc_call *call, size_t size)
Allocate memory in the grpc_call arena: this memory is automatically discarded at call completion.
A ServerContext or CallbackServerContext allows the code implementing a service handler to:
Definition: server_context.h:578
Definition: call_op_set.h:656
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
Primary implementation of CallOpSetInterface.
Definition: completion_queue.h:98
Definition: call_op_set.h:288
static ClientAsyncResponseReader< R > * Create(grpc::ChannelInterface *channel, grpc::CompletionQueue *cq, const grpc::internal::RpcMethod &method, grpc::ClientContext *context, const W &request)
Start a call and write the request out if start is set.
Definition: async_unary_call.h:95
Definition: async_unary_call.h:199
Straightforward wrapping of the C call object.
Definition: call.h:36
bool ok() const
Is the status OK?
Definition: status.h:125
void Finish(const W &msg, const grpc::Status &status, void *tag)
Indicate that the stream is to be finished and request notification when the server has sent the appr...
Definition: async_unary_call.h:340
void operator()(void *)
Definition: async_unary_call.h:411
virtual void Finish(R *msg, grpc::Status *status, void *tag)=0
Request to receive the server's response msg and final status for the call, and to notify tag on this...
Did it work? If it didn't, why?
Definition: status.h:34
An interface relevant for async client side unary RPCs (which send one request message to a server an...
Definition: async_unary_call.h:44
virtual void StartCall()=0
Start the call that was set up by the constructor, but only if the constructor was invoked through th...
virtual void ReadInitialMetadata(void *tag)=0
Request notification of the reading of initial metadata.
grpc_compression_level compression_level() const
Return the compression algorithm to be used by the server call.
Definition: server_context.h:236
void ClientRecvStatus(grpc::ClientContext *context, Status *status)
Definition: call_op_set.h:778
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:195
Async API for client-side unary RPCs, where the message response received from the server is of type ...
Definition: client_context.h:93
struct grpc_call grpc_call
A Call represents an RPC.
Definition: grpc_types.h:69
void operator()(void *)
Definition: async_unary_call.h:416
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call_op_set_interface.h:36
ServerAsyncResponseWriter(grpc::ServerContext *ctx)
Definition: async_unary_call.h:298
Codegen interface for grpc::Channel.
Definition: channel_interface.h:71
void FinishWithError(const grpc::Status &status, void *tag)
Indicate that the stream is to be finished with a non-OK status, and request notification for when th...
Definition: async_unary_call.h:377
Definition: async_unary_call.h:80
static void SetupRequest(grpc_call *call, grpc::internal::CallOpSendInitialMetadata **single_buf_ptr, std::function< void(ClientContext *, internal::Call *, internal::CallOpSendInitialMetadata *, void *)> *read_initial_metadata, std::function< void(ClientContext *, internal::Call *, bool initial_metadata_read, internal::CallOpSendInitialMetadata *, internal::CallOpSetInterface **, void *, Status *, void *)> *finish, const W &request)
Definition: async_unary_call.h:113
virtual ~ClientAsyncResponseReaderInterface()
Definition: async_unary_call.h:46
void Finish(R *msg, grpc::Status *status, void *tag) override
See ClientAsyncResponseReaderInterface::Finish for semantics.
Definition: async_unary_call.h:259
void ReadInitialMetadata(void *tag) override
See ClientAsyncResponseReaderInterface::ReadInitialMetadata for semantics.
Definition: async_unary_call.h:247
void set_output_tag(void *return_tag)
Definition: call_op_set.h:939
static ClientAsyncResponseReader< R > * Create(grpc::ChannelInterface *channel, grpc::CompletionQueue *cq, const grpc::internal::RpcMethod &method, grpc::ClientContext *context, const W &request, bool start)
Definition: async_unary_call.h:202
static void StartCall(grpc::ClientContext *context, grpc::internal::CallOpSendInitialMetadata *single_buf)
Definition: async_unary_call.h:189
void SendInitialMetadata(void *tag) override
See ServerAsyncStreamingInterface::SendInitialMetadata for semantics.
Definition: async_unary_call.h:308
void PerformOps(CallOpSetInterface *ops)
Definition: call.h:66
grpc_call * call() const
Definition: call.h:70
Definition: async_unary_call.h:407
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:251
Definition: call_op_set.h:771
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue.h:105
Definition: call_op_set.h:426
Descriptor of an RPC method.
Definition: rpc_method.h:29
::absl::Status Status
Definition: config_protobuf.h:106
void set_core_cq_tag(void *core_cq_tag)
set_core_cq_tag is used to provide a different core CQ tag than "this".
Definition: call_op_set.h:947