Go to the documentation of this file.
18 #ifndef GRPCPP_IMPL_CODEGEN_CLIENT_CALLBACK_IMPL_H
19 #define GRPCPP_IMPL_CODEGEN_CLIENT_CALLBACK_IMPL_H
45 template <
class InputMessage,
class OutputMessage>
47 const ::grpc::internal::RpcMethod& method,
49 const InputMessage* request, OutputMessage* result,
52 channel, method, context, request, result, on_completion);
55 template <
class InputMessage,
class OutputMessage>
56 class CallbackUnaryCallImpl {
59 const ::grpc::internal::RpcMethod& method,
61 const InputMessage* request, OutputMessage* result,
79 const size_t alloc_sz =
sizeof(OpSetAndTag);
80 auto*
const alloced = static_cast<OpSetAndTag*>(
83 auto* ops =
new (&alloced->opset) FullCallOpSet;
84 auto* tag =
new (&alloced->tag)
93 ops->SendInitialMetadata(&context->send_initial_metadata_,
94 context->initial_metadata_flags());
95 ops->RecvInitialMetadata(context);
96 ops->RecvMessage(result);
97 ops->AllowNoMessage();
98 ops->ClientSendClose();
99 ops->ClientRecvStatus(context, tag->status_ptr());
100 ops->set_core_cq_tag(tag);
101 call.PerformOps(ops);
107 template <
class Request,
class Response>
109 template <
class Response>
111 template <
class Request>
118 template <
class Request,
class Response>
125 virtual void Read(Response* resp) = 0;
126 virtual void AddHold(
int holds) = 0;
131 reactor->BindStream(
this);
135 template <
class Response>
140 virtual void Read(Response* resp) = 0;
141 virtual void AddHold(
int holds) = 0;
146 reactor->BindReader(
this);
150 template <
class Request>
162 virtual void AddHold(
int holds) = 0;
167 reactor->BindWriter(
this);
191 template <
class Request,
class Response>
226 stream_->Write(req, std::move(options));
274 stream_->AddHold(holds);
329 template <
class Response>
340 reader_->AddHold(holds);
356 template <
class Request>
366 writer_->Write(req, std::move(options));
376 writer_->AddHold(holds);
418 reactor->BindCall(
this);
424 template <
class Request,
class Response>
425 class ClientCallbackReaderWriterFactory;
426 template <
class Response>
427 class ClientCallbackReaderFactory;
428 template <
class Request>
429 class ClientCallbackWriterFactory;
431 template <
class Request,
class Response>
436 static void operator delete(
void* , std::size_t size) {
449 1, std::memory_order_acq_rel) == 1)) {
451 auto* reactor = reactor_;
452 auto* call = call_.
call();
469 reactor_->OnReadInitialMetadataDone(ok);
473 if (!start_corked_) {
475 context_->initial_metadata_flags());
485 reactor_->OnWriteDone(ok);
493 reactor_->OnReadDone(ok);
498 if (read_ops_at_start_) {
502 if (write_ops_at_start_) {
506 if (writes_done_ops_at_start_) {
511 &finish_ops_,
false);
517 void Read(Response* msg)
override {
519 callbacks_outstanding_.fetch_add(1, std::memory_order_relaxed);
523 read_ops_at_start_ =
true;
530 context_->initial_metadata_flags());
531 start_corked_ =
false;
540 callbacks_outstanding_.fetch_add(1, std::memory_order_relaxed);
544 write_ops_at_start_ =
true;
550 context_->initial_metadata_flags());
551 start_corked_ =
false;
554 writes_done_tag_.
Set(call_.
call(),
556 reactor_->OnWritesDoneDone(ok);
559 &writes_done_ops_,
false);
561 callbacks_outstanding_.fetch_add(1, std::memory_order_relaxed);
565 writes_done_ops_at_start_ =
true;
570 callbacks_outstanding_.fetch_add(holds, std::memory_order_relaxed);
583 start_corked_(context_->initial_metadata_corked_) {
606 bool write_ops_at_start_{
false};
612 bool writes_done_ops_at_start_{
false};
617 bool read_ops_at_start_{
false};
620 std::atomic<intptr_t> callbacks_outstanding_{2};
621 bool started_{
false};
624 template <
class Request,
class Response>
625 class ClientCallbackReaderWriterFactory {
628 const ::grpc::internal::RpcMethod& method,
632 channel->CreateCall(method, context, channel->CallbackCQ());
642 template <
class Response>
646 static void operator delete(
void* , std::size_t size) {
659 1, std::memory_order_acq_rel) == 1)) {
661 auto* reactor = reactor_;
662 auto* call = call_.
call();
678 reactor_->OnReadInitialMetadataDone(ok);
683 context_->initial_metadata_flags());
691 reactor_->OnReadDone(ok);
696 if (read_ops_at_start_) {
701 &finish_ops_,
false);
707 void Read(Response* msg)
override {
709 callbacks_outstanding_.fetch_add(1, std::memory_order_relaxed);
713 read_ops_at_start_ =
true;
718 callbacks_outstanding_.fetch_add(holds, std::memory_order_relaxed);
725 template <
class Request>
730 : context_(context), call_(call), reactor_(reactor) {
755 bool read_ops_at_start_{
false};
758 std::atomic<intptr_t> callbacks_outstanding_{2};
759 bool started_{
false};
762 template <
class Response>
763 class ClientCallbackReaderFactory {
765 template <
class Request>
767 const ::grpc::internal::RpcMethod& method,
769 const Request* request,
772 channel->CreateCall(method, context, channel->CallbackCQ());
781 template <
class Request>
785 static void operator delete(
void* , std::size_t size) {
798 1, std::memory_order_acq_rel) == 1)) {
800 auto* reactor = reactor_;
801 auto* call = call_.
call();
817 reactor_->OnReadInitialMetadataDone(ok);
821 if (!start_corked_) {
823 context_->initial_metadata_flags());
833 reactor_->OnWriteDone(ok);
839 if (write_ops_at_start_) {
843 if (writes_done_ops_at_start_) {
848 &finish_ops_,
false);
857 context_->initial_metadata_flags());
858 start_corked_ =
false;
867 callbacks_outstanding_.fetch_add(1, std::memory_order_relaxed);
871 write_ops_at_start_ =
true;
877 context_->initial_metadata_flags());
878 start_corked_ =
false;
881 writes_done_tag_.
Set(call_.
call(),
883 reactor_->OnWritesDoneDone(ok);
886 &writes_done_ops_,
false);
888 callbacks_outstanding_.fetch_add(1, std::memory_order_relaxed);
892 writes_done_ops_at_start_ =
true;
897 callbacks_outstanding_.fetch_add(holds, std::memory_order_relaxed);
904 template <
class Response>
912 start_corked_(context_->initial_metadata_corked_) {
939 bool write_ops_at_start_{
false};
945 bool writes_done_ops_at_start_{
false};
948 std::atomic<intptr_t> callbacks_outstanding_{2};
949 bool started_{
false};
952 template <
class Request>
953 class ClientCallbackWriterFactory {
955 template <
class Response>
957 const ::grpc::internal::RpcMethod& method,
961 channel->CreateCall(method, context, channel->CallbackCQ());
973 static void operator delete(
void* , std::size_t size) {
997 context_->initial_metadata_flags());
1003 &finish_ops_,
false);
1011 1, std::memory_order_acq_rel) == 1)) {
1013 auto* reactor = reactor_;
1014 auto* call = call_.
call();
1024 template <
class Request,
class Response>
1028 : context_(context), call_(call), reactor_(reactor) {
1055 std::atomic<intptr_t> callbacks_outstanding_{2};
1056 bool started_{
false};
1061 template <
class Request,
class Response>
1063 const ::grpc::internal::RpcMethod& method,
1065 const Request* request, Response* response,
1068 channel->CreateCall(method, context, channel->CallbackCQ());
1080 #endif // GRPCPP_IMPL_CODEGEN_CLIENT_CALLBACK_IMPL_H
CallbackWithSuccessTag can be reused multiple times, and will be used in this fashion for streaming o...
Definition: callback_common.h:136
Status SendMessagePtr(const M *message, WriteOptions options) GRPC_MUST_USE_RESULT
Send message using options for the write.
Definition: call_op_set.h:409
virtual void WritesDone()=0
void StartCall() override
Definition: client_callback_impl.h:808
void RemoveHold() override
Definition: client_callback_impl.h:720
void Write(const Request *msg, ::grpc::WriteOptions options) override
Definition: client_callback_impl.h:854
Definition: channel_interface.h:48
Definition: client_callback_impl.h:151
Definition: call_op_set.h:617
void StartCall()
Definition: client_callback_impl.h:406
Definition: client_callback_impl.h:782
virtual void OnReadDone(bool)
Definition: client_callback_impl.h:346
void Read(Response *msg) override
Definition: client_callback_impl.h:707
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.
Definition: call_op_set.h:524
void Write(const Request *req)
Definition: client_callback_impl.h:155
void StartRead(Response *resp)
Initiate a read operation (or post it for later initiation if StartCall has not yet been invoked).
Definition: client_callback_impl.h:207
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
Primary implementation of CallOpSetInterface.
Definition: call_op_set.h:849
virtual void grpc_call_ref(grpc_call *call)=0
Definition: call_op_set.h:286
WriteOptions & set_last_message()
last-message bit: indicates this is the last message in a stream client-side: makes Write the equival...
Definition: call_op_set.h:161
virtual void StartCall()=0
void MaybeFinish()
Definition: client_callback_impl.h:796
virtual void * grpc_call_arena_alloc(grpc_call *call, size_t length)=0
virtual void RemoveHold()=0
virtual void OnReadInitialMetadataDone(bool)
Definition: client_callback_impl.h:408
virtual ~ClientCallbackReaderWriter()
Definition: client_callback_impl.h:121
void RecvMessage(R *message)
Definition: call_op_set.h:527
virtual void WritesDone()=0
void StartWriteLast(const Request *req, ::grpc::WriteOptions options)
Definition: client_callback_impl.h:368
Definition: channel_interface.h:38
virtual ~ClientUnaryReactor()
Definition: client_callback_impl.h:404
Straightforward wrapping of the C call object.
Definition: call.h:38
Definition: channel_interface.h:52
void StartCall() override
Definition: client_callback_impl.h:984
void BindReactor(ClientWriteReactor< Request > *reactor)
Definition: client_callback_impl.h:166
void RemoveHold()
Definition: client_callback_impl.h:276
virtual void StartCall()=0
Definition: callback_common.h:68
void StartRead(Response *resp)
Definition: client_callback_impl.h:335
bool ok() const
Is the status OK?
Definition: status.h:118
void StartWriteLast(const Request *req, ::grpc::WriteOptions options)
Initiate/post a write operation with specified options and an indication that this is the last write ...
Definition: client_callback_impl.h:238
static void Create(::grpc::ChannelInterface *channel, const ::grpc::internal::RpcMethod &method, ::grpc_impl::ClientContext *context, Response *response, ClientWriteReactor< Request > *reactor)
Definition: client_callback_impl.h:956
virtual void StartCall()=0
virtual void StartCall()=0
ClientBidiReactor is the interface for a bidirectional streaming RPC.
Definition: client_callback_impl.h:108
void RemoveHold()
Definition: client_callback_impl.h:342
void StartCall() override
Definition: client_callback_impl.h:669
void AddHold(int holds) override
Definition: client_callback_impl.h:717
Did it work? If it didn't, why?
Definition: status.h:31
virtual void Read(Response *resp)=0
void StartWrite(const Request *req)
Initiate a write operation (or post it for later initiation if StartCall has not yet been invoked).
Definition: client_callback_impl.h:215
ClientReadReactor is the interface for a server-streaming RPC.
Definition: client_callback_impl.h:110
void Write(const Request *msg, ::grpc::WriteOptions options) override
Definition: client_callback_impl.h:527
Definition: client_callback_impl.h:136
virtual void OnReadDone(bool)
Notifies the application that a StartRead operation completed.
Definition: client_callback_impl.h:301
void AddMultipleHolds(int holds)
Definition: client_callback_impl.h:272
Definition: client_callback_impl.h:432
virtual ~ClientBidiReactor()
Definition: client_callback_impl.h:194
Definition: client_callback_impl.h:171
void RemoveHold() override
Definition: client_callback_impl.h:572
virtual void RemoveHold()=0
virtual void OnDone(const ::grpc::Status &)
Definition: client_callback_impl.h:380
virtual ~ClientReadReactor()
Definition: client_callback_impl.h:332
ClientUnaryReactor is a reactor-style interface for a unary RPC.
Definition: client_callback_impl.h:402
virtual void Write(const Request *req, ::grpc::WriteOptions options)=0
void AddHold()
Holds are needed if (and only if) this stream has operations that take place on it after StartCall bu...
Definition: client_callback_impl.h:271
::grpc_impl::ClientReadReactor< Response > ClientReadReactor
Definition: client_callback.h:63
Codegen interface for grpc::Channel.
Definition: channel_interface.h:74
void MaybeFinish()
Definition: client_callback_impl.h:657
void AddHold(int holds) override
Definition: client_callback_impl.h:569
void StartCall()
Definition: client_callback_impl.h:361
virtual void OnWriteDone(bool)
Definition: client_callback_impl.h:382
virtual void OnWritesDoneDone(bool)
Notifies the application that a StartWritesDone operation completed.
Definition: client_callback_impl.h:317
void RemoveHold() override
Definition: client_callback_impl.h:899
void StartCall()
Activate the RPC and initiate any reads or writes that have been Start'ed before this call.
Definition: client_callback_impl.h:200
void RemoveHold()
Definition: client_callback_impl.h:378
virtual ~ClientCallbackUnary()
Definition: client_callback_impl.h:173
virtual void OnDone(const ::grpc::Status &)
Definition: client_callback_impl.h:344
void StartCall()
Definition: client_callback_impl.h:334
void StartWritesDone()
Definition: client_callback_impl.h:371
virtual void Read(Response *resp)=0
::google::protobuf::util::Status Status
Definition: config_protobuf.h:90
Definition: client_callback_impl.h:643
static void Create(::grpc::ChannelInterface *channel, const ::grpc::internal::RpcMethod &method, ::grpc_impl::ClientContext *context, const Request *request, Response *response, ClientUnaryReactor *reactor)
Definition: client_callback_impl.h:1062
virtual void AddHold(int holds)=0
virtual void OnReadInitialMetadataDone(bool)
Definition: client_callback_impl.h:345
void StartCall() override
Definition: client_callback_impl.h:459
virtual void grpc_call_unref(grpc_call *call)=0
Definition: channel_interface.h:50
void StartWritesDone()
Indicate that the RPC will have no more write operations.
Definition: client_callback_impl.h:247
virtual void RemoveHold()=0
virtual ~ClientWriteReactor()
Definition: client_callback_impl.h:359
Definition: client_callback_impl.h:119
virtual void OnDone(const ::grpc::Status &)
Notifies the application that all operations associated with this RPC have completed and all Holds ha...
Definition: client_callback_impl.h:285
Per-message write options.
Definition: call_op_set.h:79
void AddMultipleHolds(int holds)
Definition: client_callback_impl.h:338
void Set(grpc_call *call, std::function< void(bool)> f, CompletionQueueTag *ops, bool can_inline)
Definition: callback_common.h:164
ClientWriteReactor is the interface for a client-streaming RPC.
Definition: client_callback_impl.h:112
virtual ~ClientCallbackReader()
Definition: client_callback_impl.h:138
void MaybeFinish()
Definition: client_callback_impl.h:1009
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue_impl.h:103
void MaybeFinish()
Definition: client_callback_impl.h:447
static void Create(::grpc::ChannelInterface *channel, const ::grpc::internal::RpcMethod &method, ::grpc_impl::ClientContext *context, const Request *request, ClientReadReactor< Response > *reactor)
Definition: client_callback_impl.h:766
void AddMultipleHolds(int holds)
Definition: client_callback_impl.h:374
Definition: client_callback_impl.h:1059
static void Create(::grpc::ChannelInterface *channel, const ::grpc::internal::RpcMethod &method, ::grpc_impl::ClientContext *context, ClientBidiReactor< Request, Response > *reactor)
Definition: client_callback_impl.h:627
void WriteLast(const Request *req, ::grpc::WriteOptions options)
Definition: client_callback_impl.h:157
void PerformOps(CallOpSetInterface *ops)
Definition: call.h:68
grpc_call * call() const
Definition: call.h:72
void BindReactor(ClientReadReactor< Response > *reactor)
Definition: client_callback_impl.h:145
Definition: call_op_set.h:767
WriteOptions & set_buffer_hint()
Sets flag indicating that the write may be buffered and need not go out on the wire immediately.
Definition: call_op_set.h:122
void BindReactor(ClientUnaryReactor *reactor)
Definition: client_callback_impl.h:417
CallbackUnaryCallImpl(::grpc::ChannelInterface *channel, const ::grpc::internal::RpcMethod &method, ::grpc_impl::ClientContext *context, const InputMessage *request, OutputMessage *result, std::function< void(::grpc::Status)> on_completion)
Definition: client_callback_impl.h:58
void WritesDone() override
Definition: client_callback_impl.h:547
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm_impl.h:33
virtual void OnWritesDoneDone(bool)
Definition: client_callback_impl.h:383
void StartWrite(const Request *req)
Definition: client_callback_impl.h:362
virtual void OnDone(const ::grpc::Status &)
Definition: client_callback_impl.h:407
void StartWrite(const Request *req, ::grpc::WriteOptions options)
Initiate/post a write operation with specified options.
Definition: client_callback_impl.h:225
virtual void AddHold(int holds)=0
Definition: client_callback_impl.h:970
CoreCodegenInterface * g_core_codegen_interface
Definition: completion_queue_impl.h:93
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:146
void CallbackUnaryCall(::grpc::ChannelInterface *channel, const ::grpc::internal::RpcMethod &method, ::grpc_impl::ClientContext *context, const InputMessage *request, OutputMessage *result, std::function< void(::grpc::Status)> on_completion)
Perform a callback-based unary call TODO(vjpai): Combine as much as possible with the blocking unary ...
Definition: client_callback_impl.h:46
bool is_last_message() const
Get value for the flag indicating that this is the last message, and should be coalesced with trailin...
Definition: call_op_set.h:186
A ClientContext allows the person implementing a service client to:
Definition: client_context_impl.h:184
void AddHold()
Definition: client_callback_impl.h:373
void WritesDone() override
Definition: client_callback_impl.h:874
void BindReactor(ClientBidiReactor< Request, Response > *reactor)
Definition: client_callback_impl.h:130
void StartWrite(const Request *req, ::grpc::WriteOptions options)
Definition: client_callback_impl.h:365
::grpc_impl::ClientBidiReactor< Request, Response > ClientBidiReactor
Definition: client_callback.h:69
void AddHold()
Definition: client_callback_impl.h:337
Definition: byte_buffer.h:58
::grpc_impl::ClientContext ClientContext
Definition: client_context.h:26
void Read(Response *msg) override
Definition: client_callback_impl.h:517
virtual ~ClientCallbackWriter()
Definition: client_callback_impl.h:153
void ClientSendClose()
Definition: call_op_set.h:621
virtual void OnReadInitialMetadataDone(bool)
Notifies the application that a read of initial metadata from the server is done.
Definition: client_callback_impl.h:295
virtual void AddHold(int holds)=0
void AllowNoMessage()
Definition: call_op_set.h:536
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:938
::grpc_impl::ClientWriteReactor< Request > ClientWriteReactor
Definition: client_callback.h:66
virtual void OnReadInitialMetadataDone(bool)
Definition: client_callback_impl.h:381
void RecvMessage(R *message)
Definition: call_op_set.h:424
void AddHold(int holds) override
Definition: client_callback_impl.h:896
::grpc_impl::Channel Channel
Definition: channel.h:26
virtual void OnWriteDone(bool)
Notifies the application that a StartWrite or StartWriteLast operation completed.
Definition: client_callback_impl.h:308
#define GPR_CODEGEN_DEBUG_ASSERT(x)
Codegen specific version of GPR_DEBUG_ASSERT.
Definition: core_codegen_interface.h:155
void ClientRecvStatus(::grpc_impl::ClientContext *context, Status *status)
Definition: call_op_set.h:772