19 #ifndef GRPCPP_IMPL_CODEGEN_CALL_H 20 #define GRPCPP_IMPL_CODEGEN_CALL_H 56 const std::multimap<grpc::string, grpc::string>& metadata,
57 size_t* metadata_count,
const grpc::string& optional_error_details) {
58 *metadata_count = metadata.size() + (optional_error_details.empty() ? 0 : 1);
59 if (*metadata_count == 0) {
66 for (
auto iter = metadata.cbegin(); iter != metadata.cend(); ++iter, ++i) {
70 if (!optional_error_details.empty()) {
71 metadata_array[i].
key =
76 return metadata_array;
85 : flags_(other.flags_), last_message_(other.last_message_) {}
88 inline void Clear() { flags_ = 0; }
91 inline uint32_t
flags()
const {
return flags_; }
161 last_message_ =
true;
168 last_message_ =
false;
193 void SetBit(
const uint32_t mask) { flags_ |= mask; }
195 void ClearBit(
const uint32_t mask) { flags_ &= ~mask; }
197 bool GetBit(
const uint32_t mask)
const {
return (flags_ & mask) != 0; }
216 maybe_compression_level_.is_set =
false;
220 const std::multimap<grpc::string, grpc::string>& metadata,
222 maybe_compression_level_.is_set =
false;
230 maybe_compression_level_.is_set =
true;
231 maybe_compression_level_.level = level;
244 maybe_compression_level_.is_set;
245 if (maybe_compression_level_.is_set) {
247 maybe_compression_level_.level;
252 g_core_codegen_interface->
gpr_free(initial_metadata_);
263 } maybe_compression_level_;
273 Status SendMessage(
const M& message,
281 if (!send_buf_.Valid())
return;
284 op->
flags = write_options_.flags();
288 write_options_.Clear();
299 write_options_ = options;
306 message, send_buf_.bbuf_ptr(), &own_buf);
308 send_buf_.Duplicate();
322 : got_message(false),
324 allow_not_getting_message_(false) {}
335 if (message_ ==
nullptr)
return;
344 if (message_ ==
nullptr)
return;
345 if (recv_buf_.Valid()) {
347 got_message = *status =
357 if (!allow_not_getting_message_) {
367 bool allow_not_getting_message_;
393 : got_message(false), allow_not_getting_message_(false) {}
400 deserialize_.reset(func);
410 if (!deserialize_)
return;
419 if (!deserialize_)
return;
420 if (recv_buf_.Valid()) {
423 *status = deserialize_->Deserialize(&recv_buf_).ok();
431 if (!allow_not_getting_message_) {
435 deserialize_.reset();
439 std::unique_ptr<DeserializeFunc> deserialize_;
441 bool allow_not_getting_message_;
469 const std::multimap<grpc::string, grpc::string>& trailing_metadata,
473 trailing_metadata, &trailing_metadata_count_, send_error_details_);
474 send_status_available_ =
true;
481 if (!send_status_available_)
return;
485 trailing_metadata_count_;
490 send_error_message_.empty() ? nullptr : &error_message_slice_;
496 if (!send_status_available_)
return;
497 g_core_codegen_interface->
gpr_free(trailing_metadata_);
498 send_status_available_ =
false;
502 bool send_status_available_;
506 size_t trailing_metadata_count_;
516 context->initial_metadata_received_ =
true;
517 metadata_map_ = &context->recv_initial_metadata_;
522 if (metadata_map_ ==
nullptr)
return;
531 if (metadata_map_ ==
nullptr)
return;
532 metadata_map_ =
nullptr;
542 : recv_status_(nullptr), debug_error_string_(nullptr) {}
545 client_context_ = context;
546 metadata_map_ = &client_context_->trailing_metadata_;
547 recv_status_ = status;
553 if (recv_status_ ==
nullptr)
return;
565 if (recv_status_ ==
nullptr)
return;
566 grpc::string binary_error_details = metadata_map_->GetBinaryErrorDetails();
568 Status(static_cast<StatusCode>(status_code_),
573 binary_error_details);
574 client_context_->set_debug_error_string(
575 debug_error_string_ !=
nullptr ? debug_error_string_ :
"");
577 if (debug_error_string_ !=
nullptr) {
578 g_core_codegen_interface->
gpr_free((
void*)debug_error_string_);
580 recv_status_ =
nullptr;
587 const char* debug_error_string_;
606 virtual void* cq_tag() = 0;
615 template <
class Op1 = CallNoOp<1>,
class Op2 = CallNoOp<2>,
616 class Op3 = CallNoOp<3>,
class Op4 = CallNoOp<4>,
617 class Op5 = CallNoOp<5>,
class Op6 = CallNoOp<6>>
626 CallOpSet() : cq_tag_(this), return_tag_(this), call_(nullptr) {}
628 this->Op1::AddOp(ops, nops);
629 this->Op2::AddOp(ops, nops);
630 this->Op3::AddOp(ops, nops);
631 this->Op4::AddOp(ops, nops);
632 this->Op5::AddOp(ops, nops);
633 this->Op6::AddOp(ops, nops);
639 this->Op1::FinishOp(status);
640 this->Op2::FinishOp(status);
641 this->Op3::FinishOp(status);
642 this->Op4::FinishOp(status);
643 this->Op5::FinishOp(status);
644 this->Op6::FinishOp(status);
653 void*
cq_tag()
override {
return cq_tag_; }
672 : call_hook_(call_hook),
675 max_receive_message_size_(-1) {}
678 int max_receive_message_size)
679 : call_hook_(call_hook),
682 max_receive_message_size_(max_receive_message_size) {}
685 call_hook_->PerformOpsOnCall(ops,
this);
697 int max_receive_message_size_;
702 #endif // GRPCPP_IMPL_CODEGEN_CALL_H
struct grpc_call grpc_call
A Call represents an RPC.
Definition: grpc_types.h:70
grpc_op_type op
Operation type, as defined by grpc_op_type.
Definition: grpc_types.h:538
union grpc_op::grpc_op_data data
bool get_no_compression() const
Get value for the flag indicating whether compression for the next message write is forcefully disabl...
Definition: call.h:113
void * reserved
Reserved for future usage.
Definition: grpc_types.h:542
WriteOptions & clear_buffer_hint()
Clears flag indicating that the write may be buffered and need not go out on the wire immediately...
Definition: call.h:130
grpc_status_code
Definition: status.h:26
WriteOptions & set_buffer_hint()
Sets flag indicating that the write may be buffered and need not go out on the wire immediately...
Definition: call.h:121
void FinishOp(bool *status)
Definition: call.h:495
void ClientSendClose()
Definition: call.h:448
virtual void grpc_call_ref(grpc_call *call)=0
CallOpRecvMessage()
Definition: call.h:321
std::string string
Definition: config.h:35
bool get_buffer_hint() const
Get value for the flag indicating that the write may be buffered and need not go out on the wire imme...
Definition: call.h:139
WriteOptions & clear_no_compression()
Clears flag for the disabling of compression for the next message write.
Definition: call.h:104
struct grpc_byte_buffer ** recv_message
Definition: grpc_types.h:589
struct grpc_byte_buffer * send_message
This op takes ownership of the slices in send_message.
Definition: grpc_types.h:564
Send a close from the client: one and only one instance MUST be sent from the client, unless the call was cancelled - in which case this can be skipped.
Definition: grpc_types.h:503
Send status from the server: one and only one instance MUST be sent from the server unless the call w...
Definition: grpc_types.h:508
An interface allowing implementors to process and filter event tags.
Definition: completion_queue_tag.h:26
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:280
void AllowNoMessage()
Definition: call.h:404
WriteOptions & set_last_message()
last-message bit: indicates this is the last message in a stream client-side: makes Write the equival...
Definition: call.h:160
#define GRPC_WRITE_NO_COMPRESS
Force compression to be disabled for a particular write (start_write/add_metadata).
Definition: grpc_types.h:403
Status Deserialize(ByteBuffer *buf) override
Definition: call.h:380
struct grpc_op::grpc_op_data::grpc_op_recv_message recv_message
Primary implementation of CallOpSetInterface.
Definition: call.h:618
#define GRPC_SLICE_IS_EMPTY(slice)
Definition: slice.h:127
#define GRPC_WRITE_THROUGH
Force this message to be written to the socket before completing it.
Definition: grpc_types.h:405
const char ** error_string
If this is not nullptr, it will be populated with the full fidelity error string for debugging purpos...
Definition: grpc_types.h:603
grpc_slice * status_details
Definition: grpc_types.h:599
void Clear()
Clear all flags.
Definition: call.h:88
virtual grpc_slice grpc_empty_slice()=0
WriteOptions & set_write_through()
Guarantee that all bytes have been written to the socket before completing this write (usually writes...
Definition: call.h:174
A grpc_slice s, if initialized, represents the byte range s.bytes[0..s.length-1]. ...
Definition: slice.h:80
#define GRPC_WRITE_BUFFER_HINT
Write Flags:
Definition: grpc_types.h:400
Call(grpc_call *call, CallHook *call_hook, CompletionQueue *cq)
call is owned by the caller
Definition: call.h:671
Send a message: 0 or more of these operations can occur for each call.
Definition: grpc_types.h:498
bool got_message
Definition: call.h:331
virtual void grpc_call_unref(grpc_call *call)=0
CompletionQueue * cq() const
Definition: call.h:689
bool is_write_through() const
Definition: call.h:179
WriteOptions()
Definition: call.h:83
WriteOptions & clear_last_message()
Clears flag indicating that this is the last message in a stream, disabling coalescing.
Definition: call.h:167
grpc_slice SliceReferencingString(const grpc::string &str)
Definition: slice.h:131
void ClientRecvStatus(ClientContext *context, Status *status)
Definition: call.h:544
grpc_compression_level
Compression levels allow a party with knowledge of its peer's accepted encodings to request compressi...
Definition: compression_types.h:70
grpc_call * call() const
Definition: call.h:688
#define GRPC_SLICE_START_PTR(slice)
Definition: slice.h:116
grpc_metadata_array * trailing_metadata
ownership of the array is with the caller, but ownership of the elements stays with the call object (...
Definition: grpc_types.h:597
WriteOptions & clear_corked()
Definition: call.h:148
WriteOptions & set_no_compression()
Sets flag for the disabling of compression for the next message write.
Definition: call.h:96
#define GRPC_SLICE_END_PTR(slice)
Definition: slice.h:125
CallOpClientSendClose()
Definition: call.h:446
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:164
WriteOptions & operator=(const WriteOptions &rhs)
Definition: call.h:187
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:552
Definition: byte_buffer.h:51
Default argument for CallOpSet.
Definition: call.h:207
void FinishOp(bool *status)
Definition: call.h:564
bool got_message
Definition: call.h:406
grpc::string error_message() const
Return the instance's error message.
Definition: status.h:112
Defines how to serialize and deserialize some type.
Definition: serialization_traits.h:58
StatusCode error_code() const
Return the instance's error code.
Definition: status.h:110
CallOpServerSendStatus()
Definition: call.h:466
bool FinalizeResult(void **tag, bool *status) override
FinalizeResult must be called before informing user code that the operation bound to the underlying c...
Definition: call.h:638
bool is_corked() const
Definition: call.h:153
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:409
Status SendMessage(const M &message, WriteOptions options) GRPC_MUST_USE_RESULT
Send message using options for the write.
Definition: call.h:298
uint32_t flags() const
Returns raw flags bitset.
Definition: call.h:91
grpc_metadata * FillMetadataArray(const std::multimap< grpc::string, grpc::string > &metadata, size_t *metadata_count, const grpc::string &optional_error_details)
Definition: call.h:55
struct grpc_op::grpc_op_data::grpc_op_recv_initial_metadata recv_initial_metadata
Call(grpc_call *call, CallHook *call_hook, CompletionQueue *cq, int max_receive_message_size)
Definition: call.h:677
struct grpc_op::grpc_op_data::grpc_op_send_initial_metadata send_initial_metadata
void FinishOp(bool *status)
Definition: call.h:418
void * cq_tag() override
Get the tag to be used at the core completion queue.
Definition: call.h:653
Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT which has no arguments) ...
Definition: grpc_types.h:536
virtual grpc_slice grpc_slice_from_static_buffer(const void *buffer, size_t length)=0
An Alarm posts the user provided tag to its associated completion queue upon expiry or cancellation...
Definition: alarm.h:31
Receive initial metadata: one and only one MUST be made on the client, must not be made on the server...
Definition: grpc_types.h:513
void RecvMessage(R *message)
Definition: call.h:396
struct grpc_op::grpc_op_data::grpc_op_send_message send_message
CoreCodegenInterface * g_core_codegen_interface
Definition: call.h:46
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:480
Send initial metadata: one and only one instance MUST be sent for each call, unless the call was canc...
Definition: grpc_types.h:494
WriteOptions(const WriteOptions &other)
Definition: call.h:84
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:451
CallOpClientRecvStatus()
Definition: call.h:541
Definition: byte_buffer.h:41
void FinishOp(bool *status)
Definition: call.h:458
Per-message write options.
Definition: call.h:81
void set_cq_tag(void *cq_tag)
set_cq_tag is used to provide a different core CQ tag than "this".
Definition: call.h:659
grpc_slice * status_details
optional: set to NULL if no details need sending, non-NULL if they do pointer will not be retained pa...
Definition: grpc_types.h:573
void AllowNoMessage()
Definition: call.h:329
size_t trailing_metadata_count
Definition: grpc_types.h:567
CallOpSendMessage()
Definition: call.h:268
void FinishOp(bool *status)
Definition: call.h:210
void FinishOp(bool *status)
Definition: call.h:343
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue.h:95
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call.h:597
void FillOps(grpc_call *call, grpc_op *ops, size_t *nops) override
Fills in grpc_op, starting from ops[*nops] and moving upwards.
Definition: call.h:627
virtual void grpc_slice_unref(grpc_slice slice)=0
void ServerSendStatus(const std::multimap< grpc::string, grpc::string > &trailing_metadata, const Status &status)
Definition: call.h:468
virtual ~DeserializeFunc()
Definition: call.h:373
void RecvMessage(R *message)
Definition: call.h:326
int max_receive_message_size() const
Definition: call.h:691
struct grpc_op::grpc_op_data::grpc_op_send_status_from_server send_status_from_server
Interface between the codegen library and the minimal subset of core features required by the generat...
Definition: core_codegen_interface.h:37
void set_output_tag(void *return_tag)
Definition: call.h:651
WriteOptions & set_corked()
corked bit: aliases set_buffer_hint currently, with the intent that set_buffer_hint will be removed i...
Definition: call.h:143
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:209
Did it work? If it didn't, why?
Definition: status.h:31
void FinishOp(bool *status)
Definition: call.h:290
Receive status on the client: one and only one must be made on the client.
Definition: grpc_types.h:523
DeserializeFuncType(R *message)
Definition: call.h:379
grpc_status_code status
Definition: grpc_types.h:569
grpc_status_code * status
Definition: grpc_types.h:598
void PerformOps(CallOpSetInterface *ops)
Definition: call.h:684
uint32_t flags
Write flags bitset for grpc_begin_messages.
Definition: grpc_types.h:540
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.h:185
virtual void gpr_free(void *p)=0
This is an interface that Channel and Server implement to allow them to hook performing ops...
Definition: call_hook.h:30
Receive a message: 0 or more of these operations can occur for each call.
Definition: grpc_types.h:517
A sequence of bytes.
Definition: byte_buffer.h:55
CallOpGenericRecvMessage()
Definition: call.h:392
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:334
CallOpSet()
Definition: call.h:626
const char kBinaryErrorDetailsKey[]
Definition: metadata_map.h:29
grpc::string error_details() const
Return the (binary) error details.
Definition: status.h:115
Straightforward wrapping of the C call object.
Definition: call.h:668
grpc_metadata * trailing_metadata
Definition: grpc_types.h:568
struct grpc_op::grpc_op_data::grpc_op_recv_status_on_client recv_status_on_client
virtual void * gpr_malloc(size_t size)=0
~DeserializeFuncType() override
Definition: call.h:384