19 #ifndef GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H 20 #define GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H 60 const std::multimap<grpc::string, grpc::string>& metadata,
61 size_t* metadata_count,
const grpc::string& optional_error_details) {
62 *metadata_count = metadata.size() + (optional_error_details.empty() ? 0 : 1);
63 if (*metadata_count == 0) {
70 for (
auto iter = metadata.cbegin(); iter != metadata.cend(); ++iter, ++i) {
74 if (!optional_error_details.empty()) {
75 metadata_array[i].
key =
80 return metadata_array;
89 : flags_(other.flags_), last_message_(other.last_message_) {}
92 inline void Clear() { flags_ = 0; }
95 inline uint32_t
flags()
const {
return flags_; }
165 last_message_ =
true;
172 last_message_ =
false;
197 void SetBit(
const uint32_t mask) { flags_ |= mask; }
199 void ClearBit(
const uint32_t mask) { flags_ &= ~mask; }
201 bool GetBit(
const uint32_t mask)
const {
return (flags_ & mask) != 0; }
226 maybe_compression_level_.is_set =
false;
231 maybe_compression_level_.is_set =
false;
234 metadata_map_ = metadata;
238 maybe_compression_level_.is_set =
true;
239 maybe_compression_level_.level = level;
244 if (!send_ || hijacked_)
return;
254 maybe_compression_level_.is_set;
255 if (maybe_compression_level_.is_set) {
257 maybe_compression_level_.level;
261 if (!send_ || hijacked_)
return;
262 g_core_codegen_interface->
gpr_free(initial_metadata_);
281 bool hijacked_ =
false;
290 } maybe_compression_level_;
300 Status SendMessage(
const M& message,
308 if (!send_buf_.Valid() || hijacked_)
return;
311 op->
flags = write_options_.flags();
315 write_options_.Clear();
321 if (!send_buf_.Valid())
return;
339 bool hijacked_ =
false;
346 write_options_ = options;
353 message, send_buf_.bbuf_ptr(), &own_buf);
355 send_buf_.Duplicate();
369 : got_message(false),
371 allow_not_getting_message_(false) {}
382 if (message_ ==
nullptr || hijacked_)
return;
391 if (message_ ==
nullptr || hijacked_)
return;
392 if (recv_buf_.Valid()) {
394 got_message = *status =
404 if (!allow_not_getting_message_) {
418 if (!got_message)
return;
424 if (message_ ==
nullptr)
return;
433 bool allow_not_getting_message_;
434 bool hijacked_ =
false;
460 : got_message(false), allow_not_getting_message_(false) {}
467 deserialize_.reset(func);
478 if (!deserialize_ || hijacked_)
return;
487 if (!deserialize_ || hijacked_)
return;
488 if (recv_buf_.Valid()) {
491 *status = deserialize_->Deserialize(&recv_buf_).ok();
499 if (!allow_not_getting_message_) {
503 deserialize_.reset();
513 if (!got_message)
return;
519 if (!deserialize_)
return;
526 bool hijacked_ =
false;
527 std::unique_ptr<DeserializeFunc> deserialize_;
529 bool allow_not_getting_message_;
540 if (!send_ || hijacked_)
return;
563 bool hijacked_ =
false;
572 std::multimap<grpc::string, grpc::string>* trailing_metadata,
575 metadata_map_ = trailing_metadata;
576 send_status_available_ =
true;
583 if (!send_status_available_ || hijacked_)
return;
585 *metadata_map_, &trailing_metadata_count_, send_error_details_);
589 trailing_metadata_count_;
594 send_error_message_.empty() ? nullptr : &error_message_slice_;
600 if (!send_status_available_ || hijacked_)
return;
601 g_core_codegen_interface->
gpr_free(trailing_metadata_);
602 send_status_available_ =
false;
607 if (!send_status_available_)
return;
611 interceptor_methods->
SetSendStatus(&send_status_code_, &send_error_details_,
612 &send_error_message_);
623 bool hijacked_ =
false;
624 bool send_status_available_;
628 size_t trailing_metadata_count_;
629 std::multimap<grpc::string, grpc::string>* metadata_map_;
639 context->initial_metadata_received_ =
true;
640 metadata_map_ = &context->recv_initial_metadata_;
645 if (metadata_map_ ==
nullptr || hijacked_)
return;
654 if (metadata_map_ ==
nullptr || hijacked_)
return;
664 if (metadata_map_ ==
nullptr)
return;
667 metadata_map_ =
nullptr;
672 if (metadata_map_ ==
nullptr)
return;
678 bool hijacked_ =
false;
685 : recv_status_(nullptr), debug_error_string_(nullptr) {}
688 client_context_ = context;
689 metadata_map_ = &client_context_->trailing_metadata_;
690 recv_status_ = status;
696 if (recv_status_ ==
nullptr || hijacked_)
return;
708 if (recv_status_ ==
nullptr || hijacked_)
return;
709 grpc::string binary_error_details = metadata_map_->GetBinaryErrorDetails();
711 Status(static_cast<StatusCode>(status_code_),
716 binary_error_details);
717 client_context_->set_debug_error_string(
718 debug_error_string_ !=
nullptr ? debug_error_string_ :
"");
720 if (debug_error_string_ !=
nullptr) {
721 g_core_codegen_interface->
gpr_free((
void*)debug_error_string_);
733 if (recv_status_ ==
nullptr)
return;
736 recv_status_ =
nullptr;
741 if (recv_status_ ==
nullptr)
return;
747 bool hijacked_ =
false;
751 const char* debug_error_string_;
756 template <
class Op1 = CallNoOp<1>,
class Op2 = CallNoOp<2>,
757 class Op3 = CallNoOp<3>,
class Op4 = CallNoOp<4>,
758 class Op5 = CallNoOp<5>,
class Op6 = CallNoOp<6>>
767 template <
class Op1,
class Op2,
class Op3,
class Op4,
class Op5,
class Op6>
781 : core_cq_tag_(this),
784 done_intercepting_(false),
791 done_intercepting_ =
false;
797 done_intercepting_ =
false;
802 if (RunInterceptors()) {
803 ContinueFillOpsAfterInterception();
811 if (done_intercepting_) {
816 *status = saved_status_;
821 this->Op1::FinishOp(status);
822 this->Op2::FinishOp(status);
823 this->Op3::FinishOp(status);
824 this->Op4::FinishOp(status);
825 this->Op5::FinishOp(status);
826 this->Op6::FinishOp(status);
827 saved_status_ = *status;
828 if (RunInterceptorsPostRecv()) {
851 this->Op1::SetHijackingState(&interceptor_methods_);
852 this->Op2::SetHijackingState(&interceptor_methods_);
853 this->Op3::SetHijackingState(&interceptor_methods_);
854 this->Op4::SetHijackingState(&interceptor_methods_);
855 this->Op5::SetHijackingState(&interceptor_methods_);
856 this->Op6::SetHijackingState(&interceptor_methods_);
861 static const size_t MAX_OPS = 6;
864 this->Op1::AddOp(ops, &nops);
865 this->Op2::AddOp(ops, &nops);
866 this->Op3::AddOp(ops, &nops);
867 this->Op4::AddOp(ops, &nops);
868 this->Op5::AddOp(ops, &nops);
869 this->Op6::AddOp(ops, &nops);
872 call_.call(), ops, nops, core_cq_tag(),
nullptr));
878 done_intercepting_ =
true;
881 call_.call(),
nullptr, 0, core_cq_tag(),
nullptr));
886 bool RunInterceptors() {
887 interceptor_methods_.ClearState();
888 interceptor_methods_.SetCallOpSetInterface(
this);
889 interceptor_methods_.SetCall(&call_);
890 this->Op1::SetInterceptionHookPoint(&interceptor_methods_);
891 this->Op2::SetInterceptionHookPoint(&interceptor_methods_);
892 this->Op3::SetInterceptionHookPoint(&interceptor_methods_);
893 this->Op4::SetInterceptionHookPoint(&interceptor_methods_);
894 this->Op5::SetInterceptionHookPoint(&interceptor_methods_);
895 this->Op6::SetInterceptionHookPoint(&interceptor_methods_);
896 return interceptor_methods_.RunInterceptors();
899 bool RunInterceptorsPostRecv() {
902 interceptor_methods_.SetReverse();
903 this->Op1::SetFinishInterceptionHookPoint(&interceptor_methods_);
904 this->Op2::SetFinishInterceptionHookPoint(&interceptor_methods_);
905 this->Op3::SetFinishInterceptionHookPoint(&interceptor_methods_);
906 this->Op4::SetFinishInterceptionHookPoint(&interceptor_methods_);
907 this->Op5::SetFinishInterceptionHookPoint(&interceptor_methods_);
908 this->Op6::SetFinishInterceptionHookPoint(&interceptor_methods_);
909 return interceptor_methods_.RunInterceptors();
915 bool done_intercepting_ =
false;
923 #endif // GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H void ContinueFillOpsAfterInterception() override
Definition: call_op_set.h:860
everything went ok
Definition: grpc_types.h:366
grpc_op_type op
Operation type, as defined by grpc_op_type.
Definition: grpc_types.h:548
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:555
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_op_set.h:117
void * reserved
Reserved for future usage.
Definition: grpc_types.h:552
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:216
WriteOptions & clear_buffer_hint()
Clears flag indicating that the write may be buffered and need not go out on the wire immediately...
Definition: call_op_set.h:134
void SetRecvMessage(void *message)
Definition: interceptor_common.h:137
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_op_set.h:125
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:141
void FinishOp(bool *status)
Definition: call_op_set.h:599
void SetHijackingState() override
Definition: call_op_set.h:850
void ClientSendClose()
Definition: call_op_set.h:536
virtual void grpc_call_ref(grpc_call *call)=0
void SetHijackingState(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:558
void SetHijackingState(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:739
CallOpRecvMessage()
Definition: call_op_set.h:368
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_op_set.h:143
WriteOptions & clear_no_compression()
Clears flag for the disabling of compression for the next message write.
Definition: call_op_set.h:108
struct grpc_byte_buffer ** recv_message
Definition: grpc_types.h:599
void SetSendMessage(ByteBuffer *buf)
Definition: interceptor_common.h:118
struct grpc_byte_buffer * send_message
This op takes ownership of the slices in send_message.
Definition: grpc_types.h:574
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:513
CallOpSet(const CallOpSet &other)
Definition: call_op_set.h:780
Send status from the server: one and only one instance MUST be sent from the server unless the call w...
Definition: grpc_types.h:518
void AddOp(grpc_op *ops, size_t *nops)
Definition: call_op_set.h:307
void AllowNoMessage()
Definition: call_op_set.h:472
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:164
#define GRPC_WRITE_NO_COMPRESS
Force compression to be disabled for a particular write (start_write/add_metadata).
Definition: grpc_types.h:413
Status Deserialize(ByteBuffer *buf) override
Definition: call_op_set.h:447
struct grpc_op::grpc_op_data::grpc_op_recv_message recv_message
void SetRecvStatus(Status *status)
Definition: interceptor_common.h:143
Primary implementation of CallOpSetInterface.
Definition: call_op_set.h:759
#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:415
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:613
grpc_slice * status_details
Definition: grpc_types.h:609
void Clear()
Clear all flags.
Definition: call_op_set.h:92
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_op_set.h:178
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:506
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:410
Send a message: 0 or more of these operations can occur for each call.
Definition: grpc_types.h:508
bool got_message
Definition: call_op_set.h:378
virtual void grpc_call_unref(grpc_call *call)=0
The first two in this list are for clients and servers.
bool is_write_through() const
Definition: call_op_set.h:183
WriteOptions()
Definition: call_op_set.h:87
WriteOptions & clear_last_message()
Clears flag indicating that this is the last message in a stream, disabling coalescing.
Definition: call_op_set.h:171
grpc_slice SliceReferencingString(const grpc::string &str)
Definition: slice.h:131
void ClientRecvStatus(ClientContext *context, Status *status)
Definition: call_op_set.h:687
grpc_compression_level
Compression levels allow a party with knowledge of its peer's accepted encodings to request compressi...
Definition: compression_types.h:71
grpc_call * call() const
Definition: call.h:70
#define GRPC_SLICE_START_PTR(slice)
Definition: slice.h:116
void ContinueFinalizeResultAfterInterception() override
Definition: call_op_set.h:877
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:607
WriteOptions & clear_corked()
Definition: call_op_set.h:152
WriteOptions & set_no_compression()
Sets flag for the disabling of compression for the next message write.
Definition: call_op_set.h:100
#define GRPC_SLICE_END_PTR(slice)
Definition: slice.h:125
CallOpClientSendClose()
Definition: call_op_set.h:534
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:174
WriteOptions & operator=(const WriteOptions &rhs)
Definition: call_op_set.h:191
void AddOp(grpc_op *ops, size_t *nops)
Definition: call_op_set.h:695
Definition: byte_buffer.h:55
::google::protobuf::util::Status Status
Definition: config_protobuf.h:93
Default argument for CallOpSet.
Definition: call_op_set.h:212
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:511
void FinishOp(bool *status)
Definition: call_op_set.h:707
bool got_message
Definition: call_op_set.h:474
grpc::string error_message() const
Return the instance's error message.
Definition: status.h:112
Definition: call_op_set.h:437
Defines how to serialize and deserialize some type.
Definition: serialization_traits.h:58
The following three are for hijacked clients only and can only be registered by the global intercepto...
StatusCode error_code() const
Return the instance's error code.
Definition: status.h:110
CallOpServerSendStatus()
Definition: call_op_set.h:569
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_op_set.h:810
Definition: call_op_set.h:567
bool is_corked() const
Definition: call_op_set.h:157
void AddOp(grpc_op *ops, size_t *nops)
Definition: call_op_set.h:477
Status SendMessage(const M &message, WriteOptions options) GRPC_MUST_USE_RESULT
Send message using options for the write.
Definition: call_op_set.h:345
uint32_t flags() const
Returns raw flags bitset.
Definition: call_op_set.h:95
grpc_metadata * FillMetadataArray(const std::multimap< grpc::string, grpc::string > &metadata, size_t *metadata_count, const grpc::string &optional_error_details)
Definition: call_op_set.h:59
struct grpc_op::grpc_op_data::grpc_op_recv_initial_metadata recv_initial_metadata
Definition: call_op_set.h:293
struct grpc_op::grpc_op_data::grpc_op_send_initial_metadata send_initial_metadata
void FinishOp(bool *status)
Definition: call_op_set.h:486
Operation data: one field for each op type (except SEND_CLOSE_FROM_CLIENT which has no arguments) ...
Definition: grpc_types.h:546
virtual grpc_slice grpc_slice_from_static_buffer(const void *buffer, size_t length)=0
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:548
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
Receive initial metadata: one and only one MUST be made on the client, must not be made on the server...
Definition: grpc_types.h:523
void RecvMessage(R *message)
Definition: call_op_set.h:463
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:218
void FillOps(Call *call) override
Fills in grpc_op, starting from ops[*nops] and moving upwards.
Definition: call_op_set.h:796
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:327
struct grpc_op::grpc_op_data::grpc_op_send_message send_message
CoreCodegenInterface * g_core_codegen_interface
Definition: call_op_set.h:50
void AddOp(grpc_op *ops, size_t *nops)
Definition: call_op_set.h:582
void * core_cq_tag() override
Get the tag to be used at the core completion queue.
Definition: call_op_set.h:840
Send initial metadata: one and only one instance MUST be sent for each call, unless the call was canc...
Definition: grpc_types.h:504
WriteOptions(const WriteOptions &other)
Definition: call_op_set.h:88
void AddOp(grpc_op *ops, size_t *nops)
Definition: call_op_set.h:539
CallOpClientRecvStatus()
Definition: call_op_set.h:684
Definition: interceptor_common.h:36
Definition: byte_buffer.h:41
void ServerSendStatus(std::multimap< grpc::string, grpc::string > *trailing_metadata, const Status &status)
Definition: call_op_set.h:571
void FinishOp(bool *status)
Definition: call_op_set.h:546
Per-message write options.
Definition: call_op_set.h:85
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:583
CallOpSet & operator=(const CallOpSet &other)
Definition: call_op_set.h:787
void AllowNoMessage()
Definition: call_op_set.h:376
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:615
size_t trailing_metadata_count
Definition: grpc_types.h:577
CallOpSendMessage()
Definition: call_op_set.h:295
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:319
void FinishOp(bool *status)
Definition: call_op_set.h:215
virtual grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops, size_t nops, void *tag, void *reserved)=0
void FinishOp(bool *status)
Definition: call_op_set.h:390
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue.h:95
Definition: call_op_set.h:532
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.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:34
virtual void grpc_slice_unref(grpc_slice slice)=0
void SetSendStatus(grpc_status_code *code, grpc::string *error_details, grpc::string *error_message)
Definition: interceptor_common.h:125
void SetSendTrailingMetadata(std::multimap< grpc::string, grpc::string > *metadata)
Definition: interceptor_common.h:132
virtual ~DeserializeFunc()
Definition: call_op_set.h:440
void SetRecvInitialMetadata(MetadataMap *map)
Definition: interceptor_common.h:139
void RecvMessage(R *message)
Definition: call_op_set.h:373
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_op_set.h:838
void SetSendInitialMetadata(std::multimap< grpc::string, grpc::string > *metadata)
Definition: interceptor_common.h:120
WriteOptions & set_corked()
corked bit: aliases set_buffer_hint currently, with the intent that set_buffer_hint will be removed i...
Definition: call_op_set.h:147
void SetHijackingState(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:220
void AddOp(grpc_op *ops, size_t *nops)
Definition: call_op_set.h:214
Did it work? If it didn't, why?
Definition: status.h:31
void FinishOp(bool *status)
Definition: call_op_set.h:317
Receive status on the client: one and only one must be made on the client.
Definition: grpc_types.h:533
void SetHijackingState(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:618
void AddInterceptionHookPoint(experimental::InterceptionHookPoints type)
Definition: interceptor_common.h:78
void SetHijackingState(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:517
DeserializeFuncType(R *message)
Definition: call_op_set.h:446
void SetFinishInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:731
void SetRecvTrailingMetadata(MetadataMap *map)
Definition: interceptor_common.h:145
grpc_status_code status
Definition: grpc_types.h:579
grpc_status_code * status
Definition: grpc_types.h:608
Definition: call_op_set.h:457
uint32_t flags
Write flags bitset for grpc_begin_messages.
Definition: grpc_types.h:550
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:189
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:725
Definition: call_op_set.h:682
virtual void gpr_free(void *p)=0
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:605
void SetHijackingState(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:422
Receive a message: 0 or more of these operations can occur for each call.
Definition: grpc_types.h:527
A sequence of bytes.
Definition: byte_buffer.h:64
CallOpGenericRecvMessage()
Definition: call_op_set.h:459
void AddOp(grpc_op *ops, size_t *nops)
Definition: call_op_set.h:381
void SetInterceptionHookPoint(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:411
CallOpSet()
Definition: call_op_set.h:776
const char kBinaryErrorDetailsKey[]
Definition: metadata_map.h:31
The following two are for all clients and servers.
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:846
grpc::string error_details() const
Return the (binary) error details.
Definition: status.h:115
Straightforward wrapping of the C call object.
Definition: call.h:36
grpc_metadata * trailing_metadata
Definition: grpc_types.h:578
void SetHijackingState(InterceptorBatchMethodsImpl *interceptor_methods)
Definition: call_op_set.h:334
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_op_set.h:451