Go to the documentation of this file.
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 if (client_rpc_info->interceptors_.empty()) {
234 if (server_rpc_info ==
nullptr || server_rpc_info->interceptors_.empty()) {
248 if (client_rpc_info !=
nullptr) {
249 if (client_rpc_info->interceptors_.empty()) {
252 RunClientInterceptors();
258 if (server_rpc_info ==
nullptr || server_rpc_info->interceptors_.empty()) {
261 RunServerInterceptors();
274 if (server_rpc_info ==
nullptr || server_rpc_info->interceptors_.empty()) {
277 callback_ = std::move(f);
278 RunServerInterceptors();
283 void RunClientInterceptors() {
286 current_interceptor_index_ = 0;
288 if (rpc_info->hijacked_) {
289 current_interceptor_index_ = rpc_info->hijacked_interceptor_;
291 current_interceptor_index_ = rpc_info->interceptors_.size() - 1;
294 rpc_info->RunInterceptor(
this, current_interceptor_index_);
297 void RunServerInterceptors() {
300 current_interceptor_index_ = 0;
302 current_interceptor_index_ = rpc_info->interceptors_.size() - 1;
304 rpc_info->RunInterceptor(
this, current_interceptor_index_);
307 void ProceedClient() {
309 if (rpc_info->hijacked_ && !reverse_ &&
310 current_interceptor_index_ == rpc_info->hijacked_interceptor_ &&
311 !ran_hijacking_interceptor_) {
315 ran_hijacking_interceptor_ =
true;
316 rpc_info->RunInterceptor(
this, current_interceptor_index_);
320 current_interceptor_index_++;
322 if (current_interceptor_index_ < rpc_info->interceptors_.size()) {
323 if (rpc_info->hijacked_ &&
324 current_interceptor_index_ > rpc_info->hijacked_interceptor_) {
328 rpc_info->RunInterceptor(
this, current_interceptor_index_);
336 if (current_interceptor_index_ > 0) {
338 current_interceptor_index_--;
339 rpc_info->RunInterceptor(
this, current_interceptor_index_);
347 void ProceedServer() {
350 current_interceptor_index_++;
351 if (current_interceptor_index_ < rpc_info->interceptors_.size()) {
352 return rpc_info->RunInterceptor(
this, current_interceptor_index_);
358 if (current_interceptor_index_ > 0) {
360 current_interceptor_index_--;
361 return rpc_info->RunInterceptor(
this, current_interceptor_index_);
370 void ClearHookPoints() {
374 static_cast<size_t>(i) + 1)) {
375 hooks_[
static_cast<size_t>(i)] =
false;
384 size_t current_interceptor_index_ = 0;
385 bool reverse_ =
false;
386 bool ran_hijacking_interceptor_ =
false;
387 Call* call_ =
nullptr;
389 CallOpSetInterface* ops_ =
nullptr;
390 std::function<void(
void)> callback_;
392 ByteBuffer* send_message_ =
nullptr;
393 bool* fail_send_message_ =
nullptr;
394 const void** orig_send_message_ =
nullptr;
395 std::function<
Status(
const void*)> serializer_;
397 std::multimap<std::string, std::string>* send_initial_metadata_;
400 std::string* error_details_ =
nullptr;
401 std::string* error_message_ =
nullptr;
403 std::multimap<std::string, std::string>* send_trailing_metadata_ =
nullptr;
405 void* recv_message_ =
nullptr;
406 bool* hijacked_recv_message_failed_ =
nullptr;
408 MetadataMap* recv_initial_metadata_ =
nullptr;
410 Status* recv_status_ =
nullptr;
412 MetadataMap* recv_trailing_metadata_ =
nullptr;
437 "It is illegal to call Hijack on a method which has a "
438 "Cancel notification");
443 "It is illegal to call GetSendMessage on a method which "
444 "has a Cancel notification");
451 "It is illegal to call GetSendMessageStatus on a method which "
452 "has a Cancel notification");
459 "It is illegal to call GetOriginalSendMessage on a method which "
460 "has a Cancel notification");
467 "It is illegal to call ModifySendMessage on a method which "
468 "has a Cancel notification");
473 "It is illegal to call GetSendInitialMetadata on a "
474 "method which has a Cancel notification");
480 "It is illegal to call GetSendStatus on a method which "
481 "has a Cancel notification");
487 "It is illegal to call ModifySendStatus on a method "
488 "which has a Cancel notification");
493 "It is illegal to call GetSendTrailingMetadata on a "
494 "method which has a Cancel notification");
500 "It is illegal to call GetRecvMessage on a method which "
501 "has a Cancel notification");
508 "It is illegal to call GetRecvInitialMetadata on a "
509 "method which has a Cancel notification");
515 "It is illegal to call GetRecvStatus on a method which "
516 "has a Cancel notification");
523 "It is illegal to call GetRecvTrailingMetadata on a "
524 "method which has a Cancel notification");
530 "It is illegal to call GetInterceptedChannel on a "
531 "method which has a Cancel notification");
532 return std::unique_ptr<ChannelInterface>(
nullptr);
537 "It is illegal to call FailHijackedRecvMessage on a "
538 "method which has a Cancel notification");
543 "It is illegal to call FailHijackedSendMessage on a "
544 "method which has a Cancel notification");
550 #endif // GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H
ByteBuffer * GetSerializedSendMessage() override
Send Message Methods GetSerializedSendMessage and GetSendMessage/ModifySendMessage are the available ...
Definition: interceptor_common.h:82
void Proceed() override
Signal that the interceptor is done intercepting the current batch of the RPC.
Definition: interceptor_common.h:55
void ModifySendStatus(const Status &status) override
Overwrites the status with status.
Definition: interceptor_common.h:112
std::multimap< std::string, std::string > * GetSendTrailingMetadata() override
Returns a modifiable multimap of the trailing metadata to be sent.
Definition: interceptor_common.h:491
void ModifySendMessage(const void *) override
Overwrites the message to be sent with message.
Definition: interceptor_common.h:464
Status GetSendStatus() override
Returns the status to be sent. Valid for PRE_SEND_STATUS interceptions.
Definition: interceptor_common.h:107
virtual void SetHijackingState()=0
bool QueryInterceptionHookPoint(experimental::InterceptionHookPoints type) override
Determine whether the current batch has an interception hook point of type type.
Definition: interceptor_common.h:50
grpc_status_code
Definition: status.h:26
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
void ModifySendMessage(const void *message) override
Overwrites the message to be sent with message.
Definition: interceptor_common.h:96
void SetRecvInitialMetadata(MetadataMap *map)
Definition: interceptor_common.h:173
Status GetSendStatus() override
Returns the status to be sent. Valid for PRE_SEND_STATUS interceptions.
Definition: interceptor_common.h:478
void SetCallOpSetInterface(CallOpSetInterface *ops)
Definition: interceptor_common.h:219
std::multimap< grpc::string_ref, grpc::string_ref > * GetRecvInitialMetadata() override
Returns a modifiable multimap of the received initial metadata.
Definition: interceptor_common.h:124
void SetCall(Call *call)
Definition: interceptor_common.h:215
bool InterceptorsListEmpty()
Definition: interceptor_common.h:223
InterceptorBatchMethodsImpl()
Definition: interceptor_common.h:39
void FailHijackedRecvMessage() override
On a hijacked RPC, an interceptor can decide to fail a PRE_RECV_MESSAGE op.
Definition: interceptor_common.h:535
void ClearState()
Definition: interceptor_common.h:201
Straightforward wrapping of the C call object.
Definition: call.h:35
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
@ PRE_SEND_CANCEL
This is a special hook point available to both clients and servers when TryCancel() is performed.
bool GetSendMessageStatus() override
Checks whether the SEND MESSAGE op succeeded.
Definition: interceptor_common.h:101
std::unique_ptr< ChannelInterface > GetInterceptedChannel() override
Gets an intercepted channel.
Definition: interceptor_common.h:528
Did it work? If it didn't, why?
Definition: status.h:31
void SetSendStatus(grpc_status_code *code, std::string *error_details, std::string *error_message)
Definition: interceptor_common.h:156
void * GetRecvMessage() override
Returns a pointer to the modifiable received message.
Definition: interceptor_common.h:498
bool RunInterceptors(std::function< void(void)> f)
Definition: interceptor_common.h:269
std::multimap< std::string, std::string > * GetSendTrailingMetadata() override
Returns a modifiable multimap of the trailing metadata to be sent.
Definition: interceptor_common.h:118
const void * GetSendMessage() override
Returns a non-modifiable pointer to the non-serialized form of the message to be sent.
Definition: interceptor_common.h:456
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
A sequence of bytes.
Definition: byte_buffer.h:61
void SetReverse()
Definition: interceptor_common.h:208
void SetRecvStatus(Status *status)
Definition: interceptor_common.h:177
void * GetRecvMessage() override
Returns a pointer to the modifiable received message.
Definition: interceptor_common.h:122
std::multimap< grpc::string_ref, grpc::string_ref > * GetRecvInitialMetadata() override
Returns a modifiable multimap of the received initial metadata.
Definition: interceptor_common.h:505
void ModifySendStatus(const Status &) override
Overwrites the status with status.
Definition: interceptor_common.h:485
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
An InterceptedChannel is available to client Interceptors.
Definition: intercepted_channel.h:35
std::string error_message() const
Return the instance's error message.
Definition: status.h:112
StatusCode
Definition: status_code_enum.h:24
ByteBuffer * GetSerializedSendMessage() override
Send Message Methods GetSerializedSendMessage and GetSendMessage/ModifySendMessage are the available ...
Definition: interceptor_common.h:441
std::multimap< std::string, std::string > * GetSendInitialMetadata() override
Returns a modifiable multimap of the initial metadata to be sent.
Definition: interceptor_common.h:103
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
::google::protobuf::util::Status Status
Definition: config_protobuf.h:91
void SetRecvMessage(void *message, bool *hijacked_recv_message_failed)
Definition: interceptor_common.h:168
StatusCode error_code() const
Return the instance's error code.
Definition: status.h:110
Status * GetRecvStatus() override
Returns a modifiable view of the received status on PRE_RECV_STATUS and POST_RECV_STATUS interception...
Definition: interceptor_common.h:513
void Hijack() override
Indicate that the interceptor has hijacked the RPC (only valid if the batch contains send_initial_met...
Definition: interceptor_common.h:434
void FailHijackedRecvMessage() override
On a hijacked RPC, an interceptor can decide to fail a PRE_RECV_MESSAGE op.
Definition: interceptor_common.h:194
experimental::ServerRpcInfo * server_rpc_info() const
Definition: call.h:78
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
virtual void ContinueFillOpsAfterInterception()=0
void SetSendMessage(ByteBuffer *buf, const void **msg, bool *fail_send_message, std::function< Status(const void *)> serializer)
Definition: interceptor_common.h:142
~InterceptorBatchMethodsImpl() override
Definition: interceptor_common.h:48
virtual void ContinueFinalizeResultAfterInterception()=0
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
std::unique_ptr< ChannelInterface > GetInterceptedChannel() override
Gets an intercepted channel.
Definition: interceptor_common.h:183
Class that is passed as an argument to the Intercept method of the application's Interceptor interfac...
Definition: interceptor.h:93
void Proceed() override
Signal that the interceptor is done intercepting the current batch of the RPC.
Definition: interceptor_common.h:429
bool GetSendMessageStatus() override
Checks whether the SEND MESSAGE op succeeded.
Definition: interceptor_common.h:448
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:146
bool RunInterceptors()
Definition: interceptor_common.h:245
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:541
Definition: interceptor_common.h:417
void SetRecvTrailingMetadata(MetadataMap *map)
Definition: interceptor_common.h:179
void SetSendInitialMetadata(std::multimap< std::string, std::string > *metadata)
Definition: interceptor_common.h:151
bool QueryInterceptionHookPoint(experimental::InterceptionHookPoints type) override
Determine whether the current batch has an interception hook point of type type.
Definition: interceptor_common.h:420
InterceptionHookPoints
An enumeration of different possible points at which the Intercept method of the Interceptor interfac...
Definition: interceptor.h:54
Definition: interceptor_common.h:36
std::string error_details() const
Return the (binary) error details.
Definition: status.h:115
void SetSendTrailingMetadata(std::multimap< std::string, std::string > *metadata)
Definition: interceptor_common.h:163
std::multimap< std::string, std::string > * GetSendInitialMetadata() override
Returns a modifiable multimap of the initial metadata to be sent.
Definition: interceptor_common.h:471
void AddInterceptionHookPoint(experimental::InterceptionHookPoints type)
Definition: interceptor_common.h:78
experimental::ClientRpcInfo * client_rpc_info() const
Definition: call.h:74
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:520