19 #ifndef GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H 20 #define GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H 40 for (
auto i = static_cast<experimental::InterceptionHookPoints>(0);
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_;
108 return Status(static_cast<StatusCode>(*code_), *error_message_,
120 return send_trailing_metadata_;
127 return recv_initial_metadata_->
map();
135 *fail_send_message_ =
true;
140 return recv_trailing_metadata_->
map();
144 bool* fail_send_message,
145 std::function<
Status(
const void*)> serializer) {
147 orig_send_message_ = msg;
148 fail_send_message_ = fail_send_message;
149 serializer_ = serializer;
153 std::multimap<grpc::string, grpc::string>* metadata) {
154 send_initial_metadata_ = metadata;
160 error_details_ = error_details;
161 error_message_ = error_message;
165 std::multimap<grpc::string, grpc::string>* metadata) {
166 send_trailing_metadata_ = metadata;
170 recv_message_ = message;
171 got_message_ = got_message;
175 recv_initial_metadata_ = map;
181 recv_trailing_metadata_ = map;
186 if (info ==
nullptr) {
187 return std::unique_ptr<ChannelInterface>(
nullptr);
192 info->channel(), current_interceptor_index_ + 1));
198 *got_message_ =
false;
204 ran_hijacking_interceptor_ =
false;
211 ran_hijacking_interceptor_ =
false;
231 if (client_rpc_info !=
nullptr) {
232 if (client_rpc_info->interceptors_.size() == 0) {
235 RunClientInterceptors();
241 if (server_rpc_info ==
nullptr ||
242 server_rpc_info->interceptors_.size() == 0) {
245 RunServerInterceptors();
258 if (server_rpc_info ==
nullptr ||
259 server_rpc_info->interceptors_.size() == 0) {
262 callback_ = std::move(f);
263 RunServerInterceptors();
268 void RunClientInterceptors() {
271 current_interceptor_index_ = 0;
273 if (rpc_info->hijacked_) {
274 current_interceptor_index_ = rpc_info->hijacked_interceptor_;
276 current_interceptor_index_ = rpc_info->interceptors_.size() - 1;
279 rpc_info->RunInterceptor(
this, current_interceptor_index_);
282 void RunServerInterceptors() {
285 current_interceptor_index_ = 0;
287 current_interceptor_index_ = rpc_info->interceptors_.size() - 1;
289 rpc_info->RunInterceptor(
this, current_interceptor_index_);
292 void ProceedClient() {
294 if (rpc_info->hijacked_ && !reverse_ &&
295 current_interceptor_index_ == rpc_info->hijacked_interceptor_ &&
296 !ran_hijacking_interceptor_) {
300 ran_hijacking_interceptor_ =
true;
301 rpc_info->RunInterceptor(
this, current_interceptor_index_);
305 current_interceptor_index_++;
307 if (current_interceptor_index_ < rpc_info->interceptors_.size()) {
308 if (rpc_info->hijacked_ &&
309 current_interceptor_index_ > rpc_info->hijacked_interceptor_) {
313 rpc_info->RunInterceptor(
this, current_interceptor_index_);
321 if (current_interceptor_index_ > 0) {
323 current_interceptor_index_--;
324 rpc_info->RunInterceptor(
this, current_interceptor_index_);
332 void ProceedServer() {
335 current_interceptor_index_++;
336 if (current_interceptor_index_ < rpc_info->interceptors_.size()) {
337 return rpc_info->RunInterceptor(
this, current_interceptor_index_);
343 if (current_interceptor_index_ > 0) {
345 current_interceptor_index_--;
346 return rpc_info->RunInterceptor(
this, current_interceptor_index_);
355 void ClearHookPoints() {
356 for (
auto i = static_cast<experimental::InterceptionHookPoints>(0);
359 static_cast<size_t>(i) + 1)) {
360 hooks_[
static_cast<size_t>(i)] =
false;
369 size_t current_interceptor_index_ = 0;
370 bool reverse_ =
false;
371 bool ran_hijacking_interceptor_ =
false;
372 Call* call_ =
nullptr;
375 std::function<void(void)> callback_;
378 bool* fail_send_message_ =
nullptr;
379 const void** orig_send_message_ =
nullptr;
380 std::function<Status(const void*)> serializer_;
382 std::multimap<grpc::string, grpc::string>* send_initial_metadata_;
389 std::multimap<grpc::string, grpc::string>* send_trailing_metadata_ =
nullptr;
391 void* recv_message_ =
nullptr;
392 bool* got_message_ =
nullptr;
396 Status* recv_status_ =
nullptr;
423 "It is illegal to call Hijack on a method which has a " 424 "Cancel notification");
429 "It is illegal to call GetSendMessage on a method which " 430 "has a Cancel notification");
437 "It is illegal to call GetSendMessageStatus on a method which " 438 "has a Cancel notification");
445 "It is illegal to call GetOriginalSendMessage on a method which " 446 "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");
481 "It is illegal to call GetSendTrailingMetadata on a " 482 "method which has a Cancel notification");
488 "It is illegal to call GetRecvMessage on a method which " 489 "has a Cancel notification");
496 "It is illegal to call GetRecvInitialMetadata on a " 497 "method which has a Cancel notification");
503 "It is illegal to call GetRecvStatus on a method which " 504 "has a Cancel notification");
511 "It is illegal to call GetRecvTrailingMetadata on a " 512 "method which has a Cancel notification");
518 "It is illegal to call GetInterceptedChannel on a " 519 "method which has a Cancel notification");
520 return std::unique_ptr<ChannelInterface>(
nullptr);
525 "It is illegal to call FailHijackedRecvMessage on a " 526 "method which has a Cancel notification");
531 "It is illegal to call FailHijackedSendMessage on a " 532 "method which has a Cancel notification");
538 #endif // GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H bool RunInterceptors(std::function< void(void)> f)
Definition: interceptor_common.h:253
ByteBuffer * GetSerializedSendMessage() override
Returns a modifable ByteBuffer holding the serialized form of the message that is going to be sent...
Definition: interceptor_common.h:427
std::multimap< grpc::string_ref, grpc::string_ref > * GetRecvInitialMetadata() override
Returns a modifiable multimap of the received initial metadata.
Definition: interceptor_common.h:493
void SetCall(Call *call)
Definition: interceptor_common.h:216
grpc_status_code
Definition: status.h:26
void ModifySendStatus(const Status &status) override
Overwrites the status with status.
Definition: interceptor_common.h:112
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:141
Definition: interceptor_common.h:403
void ModifySendMessage(const void *message) override
Overwrites the message to be sent with message.
Definition: interceptor_common.h:96
std::string string
Definition: config.h:35
Status * GetRecvStatus() override
Returns a modifiable view of the received status on POST_RECV_STATUS interceptions; nullptr if not va...
Definition: interceptor_common.h:130
std::multimap< grpc::string, grpc::string > * GetSendInitialMetadata() override
Returns a modifiable multimap of the initial metadata to be sent.
Definition: interceptor_common.h:457
Class that is passed as an argument to the Intercept method of the application's Interceptor interfac...
Definition: interceptor.h:87
void FailHijackedRecvMessage() override
On a hijacked RPC, an interceptor can decide to fail a PRE_RECV_MESSAGE op.
Definition: interceptor_common.h:195
std::multimap< grpc::string_ref, grpc::string_ref > * GetRecvTrailingMetadata() override
Returns a modifiable multimap of the received trailing metadata on POST_RECV_STATUS interceptions; nu...
Definition: interceptor_common.h:508
void * GetRecvMessage() override
Returns a pointer to the modifiable received message.
Definition: interceptor_common.h:486
std::multimap< grpc::string_ref, grpc::string_ref > * GetRecvInitialMetadata() override
Returns a modifiable multimap of the received initial metadata.
Definition: interceptor_common.h:125
void SetRecvMessage(void *message, bool *got_message)
Definition: interceptor_common.h:169
void SetReverse()
Definition: interceptor_common.h:209
void SetRecvStatus(Status *status)
Definition: interceptor_common.h:178
InterceptorBatchMethodsImpl()
Definition: interceptor_common.h:39
std::unique_ptr< ChannelInterface > GetInterceptedChannel() override
Gets an intercepted channel.
Definition: interceptor_common.h:516
std::multimap< grpc::string_ref, grpc::string_ref > * GetRecvTrailingMetadata() override
Returns a modifiable multimap of the received trailing metadata on POST_RECV_STATUS interceptions; nu...
Definition: interceptor_common.h:138
void ModifySendStatus(const Status &status) override
Overwrites the status with status.
Definition: interceptor_common.h:471
bool GetSendMessageStatus() override
Checks whether the SEND MESSAGE op succeeded.
Definition: interceptor_common.h:434
bool QueryInterceptionHookPoint(experimental::InterceptionHookPoints type) override
Determine whether the current batch has an interception hook point of type type.
Definition: interceptor_common.h:50
virtual void ContinueFillOpsAfterInterception()=0
void ModifySendMessage(const void *message) override
Overwrites the message to be sent with message.
Definition: interceptor_common.h:450
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 FailHijackedSendMessage() override
On a hijacked RPC/ to-be hijacked RPC, this can be called to fail a SEND MESSAGE op.
Definition: interceptor_common.h:529
bool RunInterceptors()
Definition: interceptor_common.h:228
Status GetSendStatus() override
Returns the status to be sent. Valid for PRE_SEND_STATUS interceptions.
Definition: interceptor_common.h:464
::google::protobuf::util::Status Status
Definition: config_protobuf.h:93
InterceptionHookPoints
An enumeration of different possible points at which the Intercept method of the Interceptor interfac...
Definition: interceptor.h:48
Status * GetRecvStatus() override
Returns a modifiable view of the received status on POST_RECV_STATUS interceptions; nullptr if not va...
Definition: interceptor_common.h:501
grpc::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
void Proceed() override
Signal that the interceptor is done intercepting the current batch of the RPC.
Definition: interceptor_common.h:415
An InterceptedChannel is available to client Interceptors.
Definition: intercepted_channel.h:34
virtual void ContinueFinalizeResultAfterInterception()=0
const void * GetSendMessage() override
Returns a non-modifiable pointer to the non-serialized form of the message to be sent.
Definition: interceptor_common.h:442
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:132
void * GetRecvMessage() override
Returns a pointer to the modifiable received message.
Definition: interceptor_common.h:123
experimental::ServerRpcInfo * server_rpc_info() const
Definition: call.h:79
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
bool GetSendMessageStatus() override
Checks whether the SEND MESSAGE op succeeded.
Definition: interceptor_common.h:101
std::multimap< grpc::string, grpc::string > * GetSendTrailingMetadata() override
Returns a modifiable multimap of the trailing metadata to be sent.
Definition: interceptor_common.h:118
Definition: interceptor_common.h:36
Status GetSendStatus() override
Returns the status to be sent. Valid for PRE_SEND_STATUS interceptions.
Definition: interceptor_common.h:107
experimental::ClientRpcInfo * client_rpc_info() const
Definition: call.h:75
std::multimap< grpc::string, grpc::string > * GetSendInitialMetadata() override
Returns a modifiable multimap of the initial metadata to be sent.
Definition: interceptor_common.h:103
virtual void SetHijackingState()=0
~InterceptorBatchMethodsImpl()
Definition: interceptor_common.h:48
bool QueryInterceptionHookPoint(experimental::InterceptionHookPoints type) override
Determine whether the current batch has an interception hook point of type type.
Definition: interceptor_common.h:406
This is a special hook point available to both clients and servers when TryCancel() is performed...
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
void SetSendStatus(grpc_status_code *code, grpc::string *error_details, grpc::string *error_message)
Definition: interceptor_common.h:157
void SetSendTrailingMetadata(std::multimap< grpc::string, grpc::string > *metadata)
Definition: interceptor_common.h:164
void SetRecvInitialMetadata(MetadataMap *map)
Definition: interceptor_common.h:174
void ClearState()
Definition: interceptor_common.h:202
void Hijack() override
Indicate that the interceptor has hijacked the RPC (only valid if the batch contains send_initial_met...
Definition: interceptor_common.h:420
std::multimap< grpc::string, grpc::string > * GetSendTrailingMetadata() override
Returns a modifiable multimap of the trailing metadata to be sent.
Definition: interceptor_common.h:478
void SetSendInitialMetadata(std::multimap< grpc::string, grpc::string > *metadata)
Definition: interceptor_common.h:152
void FailHijackedRecvMessage() override
On a hijacked RPC, an interceptor can decide to fail a PRE_RECV_MESSAGE op.
Definition: interceptor_common.h:523
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
Did it work? If it didn't, why?
Definition: status.h:31
void Proceed() override
Signal that the interceptor is done intercepting the current batch of the RPC.
Definition: interceptor_common.h:55
void AddInterceptionHookPoint(experimental::InterceptionHookPoints type)
Definition: interceptor_common.h:78
std::unique_ptr< ChannelInterface > GetInterceptedChannel() override
Gets an intercepted channel.
Definition: interceptor_common.h:184
void SetRecvTrailingMetadata(MetadataMap *map)
Definition: interceptor_common.h:180
ByteBuffer * GetSerializedSendMessage() override
Returns a modifable ByteBuffer holding the serialized form of the message that is going to be sent...
Definition: interceptor_common.h:82
void SetCallOpSetInterface(CallOpSetInterface *ops)
Definition: interceptor_common.h:220
void SetSendMessage(ByteBuffer *buf, const void **msg, bool *fail_send_message, std::function< Status(const void *)> serializer)
Definition: interceptor_common.h:143
A sequence of bytes.
Definition: byte_buffer.h:64
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