19 #ifndef GRPCPP_IMPL_CODEGEN_CALL_H 20 #define GRPCPP_IMPL_CODEGEN_CALL_H 58 const std::multimap<grpc::string, grpc::string>& metadata,
59 size_t* metadata_count,
const grpc::string& optional_error_details) {
60 *metadata_count = metadata.size() + (optional_error_details.empty() ? 0 : 1);
61 if (*metadata_count == 0) {
68 for (
auto iter = metadata.cbegin(); iter != metadata.cend(); ++iter, ++i) {
72 if (!optional_error_details.empty()) {
73 metadata_array[i].
key =
75 kBinaryErrorDetailsKey,
sizeof(kBinaryErrorDetailsKey) - 1);
78 return metadata_array;
87 : flags_(other.flags_), last_message_(other.last_message_) {}
90 inline void Clear() { flags_ = 0; }
93 inline uint32_t
flags()
const {
return flags_; }
163 last_message_ =
true;
170 last_message_ =
false;
195 void SetBit(
const uint32_t mask) { flags_ |= mask; }
197 void ClearBit(
const uint32_t mask) { flags_ &= ~mask; }
199 bool GetBit(
const uint32_t mask)
const {
return (flags_ & mask) != 0; }
218 maybe_compression_level_.is_set =
false;
222 const std::multimap<grpc::string, grpc::string>& metadata,
224 maybe_compression_level_.is_set =
false;
232 maybe_compression_level_.is_set =
true;
233 maybe_compression_level_.level = level;
246 maybe_compression_level_.is_set;
247 if (maybe_compression_level_.is_set) {
249 maybe_compression_level_.level;
254 g_core_codegen_interface->
gpr_free(initial_metadata_);
265 } maybe_compression_level_;
275 Status SendMessage(
const M& message,
283 if (!send_buf_.Valid())
return;
286 op->
flags = write_options_.flags();
290 write_options_.Clear();
301 write_options_ = options;
308 message, send_buf_.bbuf_ptr(), &own_buf);
310 send_buf_.Duplicate();
324 : got_message(false),
326 allow_not_getting_message_(false) {}
337 if (message_ ==
nullptr)
return;
346 if (message_ ==
nullptr)
return;
347 if (recv_buf_.Valid()) {
349 got_message = *status =
359 if (!allow_not_getting_message_) {
369 bool allow_not_getting_message_;
395 : got_message(false), allow_not_getting_message_(false) {}
402 deserialize_.reset(func);
412 if (!deserialize_)
return;
421 if (!deserialize_)
return;
422 if (recv_buf_.Valid()) {
425 *status = deserialize_->Deserialize(&recv_buf_).ok();
433 if (!allow_not_getting_message_) {
437 deserialize_.reset();
441 std::unique_ptr<DeserializeFunc> deserialize_;
443 bool allow_not_getting_message_;
471 const std::multimap<grpc::string, grpc::string>& trailing_metadata,
475 trailing_metadata, &trailing_metadata_count_, send_error_details_);
476 send_status_available_ =
true;
483 if (!send_status_available_)
return;
487 trailing_metadata_count_;
492 send_error_message_.empty() ? nullptr : &error_message_slice_;
498 if (!send_status_available_)
return;
499 g_core_codegen_interface->
gpr_free(trailing_metadata_);
500 send_status_available_ =
false;
504 bool send_status_available_;
508 size_t trailing_metadata_count_;
518 context->initial_metadata_received_ =
true;
519 metadata_map_ = &context->recv_initial_metadata_;
524 if (metadata_map_ ==
nullptr)
return;
533 if (metadata_map_ ==
nullptr)
return;
534 metadata_map_->FillMap();
535 metadata_map_ =
nullptr;
545 : recv_status_(nullptr), debug_error_string_(nullptr) {}
548 client_context_ = context;
549 metadata_map_ = &client_context_->trailing_metadata_;
550 recv_status_ = status;
556 if (recv_status_ ==
nullptr)
return;
568 if (recv_status_ ==
nullptr)
return;
569 metadata_map_->FillMap();
572 if (iter != metadata_map_->map()->end()) {
573 binary_error_details =
574 grpc::string(iter->second.begin(), iter->second.length());
576 *recv_status_ =
Status(static_cast<StatusCode>(status_code_),
579 binary_error_details);
580 client_context_->set_debug_error_string(
581 debug_error_string_ !=
nullptr ? debug_error_string_ :
"");
583 if (debug_error_string_ !=
nullptr) {
584 g_core_codegen_interface->
gpr_free((
void*)debug_error_string_);
586 recv_status_ =
nullptr;
593 const char* debug_error_string_;
616 template <
class Op1 = CallNoOp<1>,
class Op2 = CallNoOp<2>,
617 class Op3 = CallNoOp<3>,
class Op4 = CallNoOp<4>,
618 class Op5 = CallNoOp<5>,
class Op6 = CallNoOp<6>>
629 this->Op1::AddOp(ops, nops);
630 this->Op2::AddOp(ops, nops);
631 this->Op3::AddOp(ops, nops);
632 this->Op4::AddOp(ops, nops);
633 this->Op5::AddOp(ops, nops);
634 this->Op6::AddOp(ops, nops);
640 this->Op1::FinishOp(status);
641 this->Op2::FinishOp(status);
642 this->Op3::FinishOp(status);
643 this->Op4::FinishOp(status);
644 this->Op5::FinishOp(status);
645 this->Op6::FinishOp(status);
664 : call_hook_(call_hook),
667 max_receive_message_size_(-1) {}
670 int max_receive_message_size)
671 : call_hook_(call_hook),
674 max_receive_message_size_(max_receive_message_size) {}
677 call_hook_->PerformOpsOnCall(ops,
this);
689 int max_receive_message_size_;
694 #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:529
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:115
void * reserved
Reserved for future usage.
Definition: grpc_types.h:533
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:132
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:123
void FinishOp(bool *status)
Definition: call.h:497
void ClientSendClose()
Definition: call.h:450
virtual void grpc_call_ref(grpc_call *call)=0
CallOpRecvMessage()
Definition: call.h:323
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:141
WriteOptions & clear_no_compression()
Clears flag for the disabling of compression for the next message write.
Definition: call.h:106
struct grpc_byte_buffer ** recv_message
Definition: grpc_types.h:580
struct grpc_byte_buffer * send_message
This op takes ownership of the slices in send_message.
Definition: grpc_types.h:555
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:494
Send status from the server: one and only one instance MUST be sent from the server unless the call w...
Definition: grpc_types.h:499
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:282
void AllowNoMessage()
Definition: call.h:406
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:162
#define GRPC_WRITE_NO_COMPRESS
Force compression to be disabled for a particular write (start_write/add_metadata).
Definition: grpc_types.h:394
Status Deserialize(ByteBuffer *buf) override
Definition: call.h:382
struct grpc_op::grpc_op_data::grpc_op_recv_message recv_message
Primary implementation of CallOpSetInterface.
Definition: call.h:619
#define GRPC_WRITE_THROUGH
Force this message to be written to the socket before completing it.
Definition: grpc_types.h:396
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:594
grpc_slice * status_details
Definition: grpc_types.h:590
void Clear()
Clear all flags.
Definition: call.h:90
virtual grpc_slice grpc_empty_slice()=0
WriteOptions & set_write_through()
Guarantee that all bytes have been written to the wire before completing this write (usually writes a...
Definition: call.h:176
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:391
Call(grpc_call *call, CallHook *call_hook, CompletionQueue *cq)
call is owned by the caller
Definition: call.h:663
Send a message: 0 or more of these operations can occur for each call.
Definition: grpc_types.h:489
bool got_message
Definition: call.h:333
virtual void grpc_call_unref(grpc_call *call)=0
CompletionQueue * cq() const
Definition: call.h:681
bool is_write_through() const
Definition: call.h:181
WriteOptions()
Definition: call.h:85
WriteOptions & clear_last_message()
Clears flag indicating that this is the last message in a stream, disabling coalescing.
Definition: call.h:169
grpc_slice SliceReferencingString(const grpc::string &str)
Definition: slice.h:131
void ClientRecvStatus(ClientContext *context, Status *status)
Definition: call.h:547
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:680
#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:588
WriteOptions & clear_corked()
Definition: call.h:150
WriteOptions & set_no_compression()
Sets flag for the disabling of compression for the next message write.
Definition: call.h:98
#define GRPC_SLICE_END_PTR(slice)
Definition: slice.h:125
CallOpClientSendClose()
Definition: call.h:448
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:162
WriteOptions & operator=(const WriteOptions &rhs)
Definition: call.h:189
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:555
Definition: byte_buffer.h:49
Default argument for CallOpSet.
Definition: call.h:209
void FinishOp(bool *status)
Definition: call.h:567
bool got_message
Definition: call.h:408
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:468
bool FinalizeResult(void **tag, bool *status) override
Called prior to returning from Next(), return value is the status of the operation (return status is ...
Definition: call.h:639
bool is_corked() const
Definition: call.h:155
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:411
Status SendMessage(const M &message, WriteOptions options) GRPC_MUST_USE_RESULT
Send message using options for the write.
Definition: call.h:300
uint32_t flags() const
Returns raw flags bitset.
Definition: call.h:93
grpc_metadata * FillMetadataArray(const std::multimap< grpc::string, grpc::string > &metadata, size_t *metadata_count, const grpc::string &optional_error_details)
Definition: call.h:57
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:669
struct grpc_op::grpc_op_data::grpc_op_send_initial_metadata send_initial_metadata
void FinishOp(bool *status)
Definition: call.h:420
Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT which has no arguments) ...
Definition: grpc_types.h:527
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:504
void RecvMessage(R *message)
Definition: call.h:398
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:482
Send initial metadata: one and only one instance MUST be sent for each call, unless the call was canc...
Definition: grpc_types.h:485
WriteOptions(const WriteOptions &other)
Definition: call.h:86
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:453
CallOpClientRecvStatus()
Definition: call.h:544
Definition: byte_buffer.h:41
void FinishOp(bool *status)
Definition: call.h:460
Per-message write options.
Definition: call.h:83
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:564
void AllowNoMessage()
Definition: call.h:331
size_t trailing_metadata_count
Definition: grpc_types.h:558
CallOpSendMessage()
Definition: call.h:270
void FinishOp(bool *status)
Definition: call.h:212
void FinishOp(bool *status)
Definition: call.h:345
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue.h:94
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call.h:603
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:628
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:470
virtual ~DeserializeFunc()
Definition: call.h:375
void RecvMessage(R *message)
Definition: call.h:328
int max_receive_message_size() const
Definition: call.h:683
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:652
WriteOptions & set_corked()
corked bit: aliases set_buffer_hint currently, with the intent that set_buffer_hint will be removed i...
Definition: call.h:145
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:211
Did it work? If it didn't, why?
Definition: status.h:31
void FinishOp(bool *status)
Definition: call.h:292
Receive status on the client: one and only one must be made on the client.
Definition: grpc_types.h:514
DeserializeFuncType(R *message)
Definition: call.h:381
grpc_status_code status
Definition: grpc_types.h:560
grpc_status_code * status
Definition: grpc_types.h:589
void PerformOps(CallOpSetInterface *ops)
Definition: call.h:676
uint32_t flags
Write flags bitset for grpc_begin_messages.
Definition: grpc_types.h:531
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:187
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:508
A sequence of bytes.
Definition: byte_buffer.h:53
CallOpGenericRecvMessage()
Definition: call.h:394
void AddOp(grpc_op *ops, size_t *nops)
Definition: call.h:336
CallOpSet()
Definition: call.h:627
const char kBinaryErrorDetailsKey[]
Definition: call.h:53
grpc::string error_details() const
Return the (binary) error details.
Definition: status.h:115
Straightforward wrapping of the C call object.
Definition: call.h:660
grpc_metadata * trailing_metadata
Definition: grpc_types.h:559
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:386