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_.size() == 0) {
234 if (server_rpc_info ==
nullptr ||
235 server_rpc_info->interceptors_.size() == 0) {
249 if (client_rpc_info !=
nullptr) {
250 if (client_rpc_info->interceptors_.size() == 0) {
253 RunClientInterceptors();
259 if (server_rpc_info ==
nullptr ||
260 server_rpc_info->interceptors_.size() == 0) {
263 RunServerInterceptors();
276 if (server_rpc_info ==
nullptr ||
277 server_rpc_info->interceptors_.size() == 0) {
280 callback_ = std::move(f);
281 RunServerInterceptors();
286 void RunClientInterceptors() {
289 current_interceptor_index_ = 0;
291 if (rpc_info->hijacked_) {
292 current_interceptor_index_ = rpc_info->hijacked_interceptor_;
294 current_interceptor_index_ = rpc_info->interceptors_.size() - 1;
297 rpc_info->RunInterceptor(
this, current_interceptor_index_);
300 void RunServerInterceptors() {
303 current_interceptor_index_ = 0;
305 current_interceptor_index_ = rpc_info->interceptors_.size() - 1;
307 rpc_info->RunInterceptor(
this, current_interceptor_index_);
310 void ProceedClient() {
312 if (rpc_info->hijacked_ && !reverse_ &&
313 current_interceptor_index_ == rpc_info->hijacked_interceptor_ &&
314 !ran_hijacking_interceptor_) {
318 ran_hijacking_interceptor_ =
true;
319 rpc_info->RunInterceptor(
this, current_interceptor_index_);
323 current_interceptor_index_++;
325 if (current_interceptor_index_ < rpc_info->interceptors_.size()) {
326 if (rpc_info->hijacked_ &&
327 current_interceptor_index_ > rpc_info->hijacked_interceptor_) {
331 rpc_info->RunInterceptor(
this, current_interceptor_index_);
339 if (current_interceptor_index_ > 0) {
341 current_interceptor_index_--;
342 rpc_info->RunInterceptor(
this, current_interceptor_index_);
350 void ProceedServer() {
353 current_interceptor_index_++;
354 if (current_interceptor_index_ < rpc_info->interceptors_.size()) {
355 return rpc_info->RunInterceptor(
this, current_interceptor_index_);
361 if (current_interceptor_index_ > 0) {
363 current_interceptor_index_--;
364 return rpc_info->RunInterceptor(
this, current_interceptor_index_);
373 void ClearHookPoints() {
377 static_cast<size_t>(i) + 1)) {
378 hooks_[
static_cast<size_t>(i)] =
false;
387 size_t current_interceptor_index_ = 0;
388 bool reverse_ =
false;
389 bool ran_hijacking_interceptor_ =
false;
390 Call* call_ =
nullptr;
392 CallOpSetInterface* ops_ =
nullptr;
393 std::function<void(
void)> callback_;
395 ByteBuffer* send_message_ =
nullptr;
396 bool* fail_send_message_ =
nullptr;
397 const void** orig_send_message_ =
nullptr;
398 std::function<
Status(
const void*)> serializer_;
400 std::multimap<std::string, std::string>* send_initial_metadata_;
403 std::string* error_details_ =
nullptr;
404 std::string* error_message_ =
nullptr;
406 std::multimap<std::string, std::string>* send_trailing_metadata_ =
nullptr;
408 void* recv_message_ =
nullptr;
409 bool* hijacked_recv_message_failed_ =
nullptr;
411 MetadataMap* recv_initial_metadata_ =
nullptr;
413 Status* recv_status_ =
nullptr;
415 MetadataMap* recv_trailing_metadata_ =
nullptr;
440 "It is illegal to call Hijack on a method which has a "
441 "Cancel notification");
446 "It is illegal to call GetSendMessage on a method which "
447 "has a Cancel notification");
454 "It is illegal to call GetSendMessageStatus on a method which "
455 "has a Cancel notification");
462 "It is illegal to call GetOriginalSendMessage on a method which "
463 "has a Cancel notification");
470 "It is illegal to call ModifySendMessage on a method which "
471 "has a Cancel notification");
476 "It is illegal to call GetSendInitialMetadata on a "
477 "method which has a Cancel notification");
483 "It is illegal to call GetSendStatus on a method which "
484 "has a Cancel notification");
490 "It is illegal to call ModifySendStatus on a method "
491 "which has a Cancel notification");
497 "It is illegal to call GetSendTrailingMetadata on a "
498 "method which has a Cancel notification");
504 "It is illegal to call GetRecvMessage on a method which "
505 "has a Cancel notification");
512 "It is illegal to call GetRecvInitialMetadata on a "
513 "method which has a Cancel notification");
519 "It is illegal to call GetRecvStatus on a method which "
520 "has a Cancel notification");
527 "It is illegal to call GetRecvTrailingMetadata on a "
528 "method which has a Cancel notification");
534 "It is illegal to call GetInterceptedChannel on a "
535 "method which has a Cancel notification");
536 return std::unique_ptr<ChannelInterface>(
nullptr);
541 "It is illegal to call FailHijackedRecvMessage on a "
542 "method which has a Cancel notification");
547 "It is illegal to call FailHijackedSendMessage on a "
548 "method which has a Cancel notification");
554 #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:495
void ModifySendMessage(const void *) override
Overwrites the message to be sent with message.
Definition: interceptor_common.h:467
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
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
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:481
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:539
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:532
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
~InterceptorBatchMethodsImpl()
Definition: interceptor_common.h:48
void * GetRecvMessage() override
Returns a pointer to the modifiable received message.
Definition: interceptor_common.h:502
bool RunInterceptors(std::function< void(void)> f)
Definition: interceptor_common.h:271
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:459
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:67
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:509
void ModifySendStatus(const Status &) override
Overwrites the status with status.
Definition: interceptor_common.h:488
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:444
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:90
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:517
void Hijack() override
Indicate that the interceptor has hijacked the RPC (only valid if the batch contains send_initial_met...
Definition: interceptor_common.h:437
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
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:432
bool GetSendMessageStatus() override
Checks whether the SEND MESSAGE op succeeded.
Definition: interceptor_common.h:451
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:146
bool RunInterceptors()
Definition: interceptor_common.h:246
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:545
Definition: interceptor_common.h:420
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:423
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:474
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:524