Go to the documentation of this file.
19 #ifndef GRPCPP_IMPL_INTERCEPTOR_COMMON_H
20 #define GRPCPP_IMPL_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) {
85 GPR_ASSERT(serializer_(*orig_send_message_).ok());
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");
439 "It is illegal to call GetSendMessageStatus on a method which "
440 "has a Cancel notification");
446 "It is illegal to call GetOriginalSendMessage on a method which "
447 "has a Cancel notification");
453 "It is illegal to call ModifySendMessage on a method which "
454 "has a Cancel notification");
459 "It is illegal to call GetSendInitialMetadata on a "
460 "method which has a Cancel notification");
466 "It is illegal to call GetSendStatus on a method which "
467 "has a Cancel notification");
473 "It is illegal to call ModifySendStatus on a method "
474 "which has a Cancel notification");
479 "It is illegal to call GetSendTrailingMetadata on a "
480 "method which has a Cancel notification");
486 "It is illegal to call GetRecvMessage on a method which "
487 "has a Cancel notification");
494 "It is illegal to call GetRecvInitialMetadata on a "
495 "method which has a Cancel notification");
501 "It is illegal to call GetRecvStatus on a method which "
502 "has a Cancel notification");
509 "It is illegal to call GetRecvTrailingMetadata on a "
510 "method which has a Cancel notification");
516 "It is illegal to call GetInterceptedChannel on a "
517 "method which has a Cancel notification");
518 return std::unique_ptr<ChannelInterface>(
nullptr);
523 "It is illegal to call FailHijackedRecvMessage on a "
524 "method which has a Cancel notification");
529 "It is illegal to call FailHijackedSendMessage on a "
530 "method which has a Cancel notification");
536 #endif // GRPCPP_IMPL_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:477
void ModifySendMessage(const void *) override
Overwrites the message to be sent with message.
Definition: interceptor_common.h:451
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
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:32
void ModifySendMessage(const void *message) override
Overwrites the message to be sent with message.
Definition: interceptor_common.h:96
grpc_status_code
Definition: status.h:28
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:464
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:521
void ClearState()
Definition: interceptor_common.h:201
Straightforward wrapping of the C call object.
Definition: call.h:36
#define GPR_ASSERT(x)
abort() the process if x is zero, having written a line to the log.
Definition: log.h:95
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:514
Did it work? If it didn't, why?
Definition: status.h:35
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:484
bool RunInterceptors(std::function< void(void)> f)
Definition: interceptor_common.h:262
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:444
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:36
A sequence of bytes.
Definition: byte_buffer.h:60
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:491
void ModifySendStatus(const Status &) override
Overwrites the status with status.
Definition: interceptor_common.h:471
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:120
StatusCode
Definition: status_code_enum.h:26
ByteBuffer * GetSerializedSendMessage() override
Send Message Methods GetSerializedSendMessage and GetSendMessage/ModifySendMessage are the available ...
Definition: interceptor_common.h:430
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:93
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:118
Status * GetRecvStatus() override
Returns a modifiable view of the received status on PRE_RECV_STATUS and POST_RECV_STATUS interception...
Definition: interceptor_common.h:499
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
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:79
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:95
void Proceed() override
Signal that the interceptor is done intercepting the current batch of the RPC.
Definition: interceptor_common.h:418
bool GetSendMessageStatus() override
Checks whether the SEND MESSAGE op succeeded.
Definition: interceptor_common.h:437
bool RunInterceptors()
Definition: interceptor_common.h:238
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:527
Definition: interceptor_common.h:410
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:413
InterceptionHookPoints
An enumeration of different possible points at which the Intercept method of the Interceptor interfac...
Definition: interceptor.h:56
Definition: interceptor_common.h:36
std::string error_details() const
Return the (binary) error details.
Definition: status.h:123
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:457
void AddInterceptionHookPoint(experimental::InterceptionHookPoints type)
Definition: interceptor_common.h:78
experimental::ClientRpcInfo * client_rpc_info() const
Definition: call.h:75
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:506