19 #ifndef GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H
20 #define GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H
43 static_cast<size_t>(i) + 1)) {
44 hooks_[
static_cast<size_t>(i)] =
false;
52 return hooks_[
static_cast<size_t>(
type)];
57 return ProceedClient();
70 rpc_info->hijacked_ =
true;
71 rpc_info->hijacked_interceptor_ = current_interceptor_index_;
74 ran_hijacking_interceptor_ =
true;
75 rpc_info->RunInterceptor(
this, current_interceptor_index_);
79 hooks_[
static_cast<size_t>(
type)] =
true;
84 if (*orig_send_message_ !=
nullptr) {
86 *orig_send_message_ =
nullptr;
93 return *orig_send_message_;
98 *orig_send_message_ = message;
104 return send_initial_metadata_;
119 return send_trailing_metadata_;
126 return recv_initial_metadata_->
map();
134 *fail_send_message_ =
true;
139 return recv_trailing_metadata_->
map();
143 bool* fail_send_message,
144 std::function<
Status(
const void*)> serializer) {
146 orig_send_message_ = msg;
147 fail_send_message_ = fail_send_message;
148 serializer_ = serializer;
152 std::multimap<std::string, std::string>* metadata) {
153 send_initial_metadata_ = metadata;
157 std::string* error_message) {
159 error_details_ = error_details;
160 error_message_ = error_message;
164 std::multimap<std::string, std::string>* metadata) {
165 send_trailing_metadata_ = metadata;
169 recv_message_ = message;
170 hijacked_recv_message_failed_ = hijacked_recv_message_failed;
174 recv_initial_metadata_ = map;
180 recv_trailing_metadata_ = map;
185 if (info ==
nullptr) {
186 return std::unique_ptr<ChannelInterface>(
nullptr);
191 info->channel(), current_interceptor_index_ + 1));
197 *hijacked_recv_message_failed_ =
true;
203 ran_hijacking_interceptor_ =
false;
210 ran_hijacking_interceptor_ =
false;
225 if (client_rpc_info !=
nullptr) {
226 return client_rpc_info->interceptors_.empty();
230 return server_rpc_info ==
nullptr || server_rpc_info->interceptors_.empty();
241 if (client_rpc_info !=
nullptr) {
242 if (client_rpc_info->interceptors_.empty()) {
245 RunClientInterceptors();
251 if (server_rpc_info ==
nullptr || server_rpc_info->interceptors_.empty()) {
254 RunServerInterceptors();
267 if (server_rpc_info ==
nullptr || server_rpc_info->interceptors_.empty()) {
270 callback_ = std::move(f);
271 RunServerInterceptors();
276 void RunClientInterceptors() {
279 current_interceptor_index_ = 0;
281 if (rpc_info->hijacked_) {
282 current_interceptor_index_ = rpc_info->hijacked_interceptor_;
284 current_interceptor_index_ = rpc_info->interceptors_.size() - 1;
287 rpc_info->RunInterceptor(
this, current_interceptor_index_);
290 void RunServerInterceptors() {
293 current_interceptor_index_ = 0;
295 current_interceptor_index_ = rpc_info->interceptors_.size() - 1;
297 rpc_info->RunInterceptor(
this, current_interceptor_index_);
300 void ProceedClient() {
302 if (rpc_info->hijacked_ && !reverse_ &&
303 current_interceptor_index_ == rpc_info->hijacked_interceptor_ &&
304 !ran_hijacking_interceptor_) {
308 ran_hijacking_interceptor_ =
true;
309 rpc_info->RunInterceptor(
this, current_interceptor_index_);
313 current_interceptor_index_++;
315 if (current_interceptor_index_ < rpc_info->interceptors_.size()) {
316 if (rpc_info->hijacked_ &&
317 current_interceptor_index_ > rpc_info->hijacked_interceptor_) {
321 rpc_info->RunInterceptor(
this, current_interceptor_index_);
329 if (current_interceptor_index_ > 0) {
331 current_interceptor_index_--;
332 rpc_info->RunInterceptor(
this, current_interceptor_index_);
340 void ProceedServer() {
343 current_interceptor_index_++;
344 if (current_interceptor_index_ < rpc_info->interceptors_.size()) {
345 return rpc_info->RunInterceptor(
this, current_interceptor_index_);
351 if (current_interceptor_index_ > 0) {
353 current_interceptor_index_--;
354 return rpc_info->RunInterceptor(
this, current_interceptor_index_);
363 void ClearHookPoints() {
367 static_cast<size_t>(i) + 1)) {
368 hooks_[
static_cast<size_t>(i)] =
false;
377 size_t current_interceptor_index_ = 0;
378 bool reverse_ =
false;
379 bool ran_hijacking_interceptor_ =
false;
380 Call* call_ =
nullptr;
382 CallOpSetInterface* ops_ =
nullptr;
383 std::function<void(
void)> callback_;
385 ByteBuffer* send_message_ =
nullptr;
386 bool* fail_send_message_ =
nullptr;
387 const void** orig_send_message_ =
nullptr;
388 std::function<
Status(
const void*)> serializer_;
390 std::multimap<std::string, std::string>* send_initial_metadata_;
393 std::string* error_details_ =
nullptr;
394 std::string* error_message_ =
nullptr;
396 std::multimap<std::string, std::string>* send_trailing_metadata_ =
nullptr;
398 void* recv_message_ =
nullptr;
399 bool* hijacked_recv_message_failed_ =
nullptr;
401 MetadataMap* recv_initial_metadata_ =
nullptr;
403 Status* recv_status_ =
nullptr;
405 MetadataMap* recv_trailing_metadata_ =
nullptr;
426 "It is illegal to call Hijack on a method which has a "
427 "Cancel notification");
432 "It is illegal to call GetSendMessage on a method which "
433 "has a Cancel notification");
440 "It is illegal to call GetSendMessageStatus on a method which "
441 "has a Cancel notification");
448 "It is illegal to call GetOriginalSendMessage on a method which "
449 "has a Cancel notification");
456 "It is illegal to call ModifySendMessage on a method which "
457 "has a Cancel notification");
462 "It is illegal to call GetSendInitialMetadata on a "
463 "method which has a Cancel notification");
469 "It is illegal to call GetSendStatus on a method which "
470 "has a Cancel notification");
476 "It is illegal to call ModifySendStatus on a method "
477 "which has a Cancel notification");
482 "It is illegal to call GetSendTrailingMetadata on a "
483 "method which has a Cancel notification");
489 "It is illegal to call GetRecvMessage on a method which "
490 "has a Cancel notification");
497 "It is illegal to call GetRecvInitialMetadata on a "
498 "method which has a Cancel notification");
504 "It is illegal to call GetRecvStatus on a method which "
505 "has a Cancel notification");
512 "It is illegal to call GetRecvTrailingMetadata on a "
513 "method which has a Cancel notification");
519 "It is illegal to call GetInterceptedChannel on a "
520 "method which has a Cancel notification");
521 return std::unique_ptr<ChannelInterface>(
nullptr);
526 "It is illegal to call FailHijackedRecvMessage on a "
527 "method which has a Cancel notification");
532 "It is illegal to call FailHijackedSendMessage on a "
533 "method which has a Cancel notification");
A sequence of bytes.
Definition: byte_buffer.h:60
Did it work? If it didn't, why?
Definition: status.h:31
std::string error_message() const
Return the instance's error message.
Definition: status.h:112
StatusCode error_code() const
Return the instance's error code.
Definition: status.h:110
std::string error_details() const
Return the (binary) error details.
Definition: status.h:115
Class that is passed as an argument to the Intercept method of the application's Interceptor interfac...
Definition: interceptor.h:93
Straightforward wrapping of the C call object.
Definition: call.h:35
experimental::ClientRpcInfo * client_rpc_info() const
Definition: call.h:74
experimental::ServerRpcInfo * server_rpc_info() const
Definition: call.h:78
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 SetHijackingState()=0
virtual void ContinueFillOpsAfterInterception()=0
virtual void ContinueFinalizeResultAfterInterception()=0
Definition: interceptor_common.h:411
void FailHijackedSendMessage() override
On a hijacked RPC/ to-be hijacked RPC, this can be called to fail a SEND MESSAGE op.
Definition: interceptor_common.h:530
void * GetRecvMessage() override
Returns a pointer to the modifiable received message.
Definition: interceptor_common.h:487
std::multimap< grpc::string_ref, grpc::string_ref > * GetRecvInitialMetadata() override
Returns a modifiable multimap of the received initial metadata.
Definition: interceptor_common.h:494
ByteBuffer * GetSerializedSendMessage() override
Send Message Methods GetSerializedSendMessage and GetSendMessage/ModifySendMessage are the available ...
Definition: interceptor_common.h:430
void ModifySendMessage(const void *) override
Overwrites the message to be sent with message.
Definition: interceptor_common.h:453
Status * GetRecvStatus() override
Returns a modifiable view of the received status on PRE_RECV_STATUS and POST_RECV_STATUS interception...
Definition: interceptor_common.h:502
std::multimap< grpc::string_ref, grpc::string_ref > * GetRecvTrailingMetadata() override
Returns a modifiable multimap of the received trailing metadata on PRE_RECV_STATUS and POST_RECV_STAT...
Definition: interceptor_common.h:509
void Hijack() override
Indicate that the interceptor has hijacked the RPC (only valid if the batch contains send_initial_met...
Definition: interceptor_common.h:423
std::unique_ptr< ChannelInterface > GetInterceptedChannel() override
Gets an intercepted channel.
Definition: interceptor_common.h:517
void FailHijackedRecvMessage() override
On a hijacked RPC, an interceptor can decide to fail a PRE_RECV_MESSAGE op.
Definition: interceptor_common.h:524
std::multimap< std::string, std::string > * GetSendInitialMetadata() override
Returns a modifiable multimap of the initial metadata to be sent.
Definition: interceptor_common.h:460
bool GetSendMessageStatus() override
Checks whether the SEND MESSAGE op succeeded.
Definition: interceptor_common.h:437
std::multimap< std::string, std::string > * GetSendTrailingMetadata() override
Returns a modifiable multimap of the trailing metadata to be sent.
Definition: interceptor_common.h:480
const void * GetSendMessage() override
Returns a non-modifiable pointer to the non-serialized form of the message to be sent.
Definition: interceptor_common.h:445
Status GetSendStatus() override
Returns the status to be sent. Valid for PRE_SEND_STATUS interceptions.
Definition: interceptor_common.h:467
bool QueryInterceptionHookPoint(experimental::InterceptionHookPoints type) override
Determine whether the current batch has an interception hook point of type type.
Definition: interceptor_common.h:413
void Proceed() override
Signal that the interceptor is done intercepting the current batch of the RPC.
Definition: interceptor_common.h:418
void ModifySendStatus(const Status &) override
Overwrites the status with status.
Definition: interceptor_common.h:474
An InterceptedChannel is available to client Interceptors.
Definition: intercepted_channel.h:35
Definition: interceptor_common.h:37
bool QueryInterceptionHookPoint(experimental::InterceptionHookPoints type) override
Determine whether the current batch has an interception hook point of type type.
Definition: interceptor_common.h:50
bool RunInterceptors(std::function< void(void)> f)
Definition: interceptor_common.h:262
std::unique_ptr< ChannelInterface > GetInterceptedChannel() override
Gets an intercepted channel.
Definition: interceptor_common.h:183
bool RunInterceptors()
Definition: interceptor_common.h:238
Status GetSendStatus() override
Returns the status to be sent. Valid for PRE_SEND_STATUS interceptions.
Definition: interceptor_common.h:107
void Proceed() override
Signal that the interceptor is done intercepting the current batch of the RPC.
Definition: interceptor_common.h:55
Status * GetRecvStatus() override
Returns a modifiable view of the received status on PRE_RECV_STATUS and POST_RECV_STATUS interception...
Definition: interceptor_common.h:129
InterceptorBatchMethodsImpl()
Definition: interceptor_common.h:39
std::multimap< std::string, std::string > * GetSendTrailingMetadata() override
Returns a modifiable multimap of the trailing metadata to be sent.
Definition: interceptor_common.h:118
void * GetRecvMessage() override
Returns a pointer to the modifiable received message.
Definition: interceptor_common.h:122
~InterceptorBatchMethodsImpl() override
Definition: interceptor_common.h:48
void ModifySendStatus(const Status &status) override
Overwrites the status with status.
Definition: interceptor_common.h:112
std::multimap< grpc::string_ref, grpc::string_ref > * GetRecvInitialMetadata() override
Returns a modifiable multimap of the received initial metadata.
Definition: interceptor_common.h:124
const void * GetSendMessage() override
Returns a non-modifiable pointer to the non-serialized form of the message to be sent.
Definition: interceptor_common.h:91
std::multimap< std::string, std::string > * GetSendInitialMetadata() override
Returns a modifiable multimap of the initial metadata to be sent.
Definition: interceptor_common.h:103
void SetCallOpSetInterface(CallOpSetInterface *ops)
Definition: interceptor_common.h:219
void FailHijackedRecvMessage() override
On a hijacked RPC, an interceptor can decide to fail a PRE_RECV_MESSAGE op.
Definition: interceptor_common.h:194
bool GetSendMessageStatus() override
Checks whether the SEND MESSAGE op succeeded.
Definition: interceptor_common.h:101
void SetRecvTrailingMetadata(MetadataMap *map)
Definition: interceptor_common.h:179
void ClearState()
Definition: interceptor_common.h:201
void SetSendTrailingMetadata(std::multimap< std::string, std::string > *metadata)
Definition: interceptor_common.h:163
void SetReverse()
Definition: interceptor_common.h:208
void SetSendMessage(ByteBuffer *buf, const void **msg, bool *fail_send_message, std::function< Status(const void *)> serializer)
Definition: interceptor_common.h:142
void FailHijackedSendMessage() override
On a hijacked RPC/ to-be hijacked RPC, this can be called to fail a SEND MESSAGE op.
Definition: interceptor_common.h:131
void SetRecvInitialMetadata(MetadataMap *map)
Definition: interceptor_common.h:173
void ModifySendMessage(const void *message) override
Overwrites the message to be sent with message.
Definition: interceptor_common.h:96
void SetSendStatus(grpc_status_code *code, std::string *error_details, std::string *error_message)
Definition: interceptor_common.h:156
void AddInterceptionHookPoint(experimental::InterceptionHookPoints type)
Definition: interceptor_common.h:78
ByteBuffer * GetSerializedSendMessage() override
Send Message Methods GetSerializedSendMessage and GetSendMessage/ModifySendMessage are the available ...
Definition: interceptor_common.h:82
bool InterceptorsListEmpty()
Definition: interceptor_common.h:223
void SetCall(Call *call)
Definition: interceptor_common.h:215
void SetRecvMessage(void *message, bool *hijacked_recv_message_failed)
Definition: interceptor_common.h:168
void Hijack() override
Indicate that the interceptor has hijacked the RPC (only valid if the batch contains send_initial_met...
Definition: interceptor_common.h:63
void SetRecvStatus(Status *status)
Definition: interceptor_common.h:177
void SetSendInitialMetadata(std::multimap< std::string, std::string > *metadata)
Definition: interceptor_common.h:151
std::multimap< grpc::string_ref, grpc::string_ref > * GetRecvTrailingMetadata() override
Returns a modifiable multimap of the received trailing metadata on PRE_RECV_STATUS and POST_RECV_STAT...
Definition: interceptor_common.h:137
grpc_status_code
Definition: status.h:26
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:146
InterceptionHookPoints
An enumeration of different possible points at which the Intercept method of the Interceptor interfac...
Definition: interceptor.h:54
@ PRE_SEND_CANCEL
This is a special hook point available to both clients and servers when TryCancel() is performed.
::google::protobuf::util::Status Status
Definition: config_protobuf.h:91
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
StatusCode
Definition: status_code_enum.h:24
DiscoveryMechanismType type
Definition: xds_cluster_resolver.cc:73