GRPC C++  1.66.0
interceptor.h
Go to the documentation of this file.
1 //
2 //
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
19 #ifndef GRPCPP_SUPPORT_INTERCEPTOR_H
20 #define GRPCPP_SUPPORT_INTERCEPTOR_H
21 
22 #include <map>
23 #include <memory>
24 #include <string>
25 
26 #include <grpc/impl/grpc_types.h>
29 #include <grpcpp/support/config.h>
31 
32 namespace grpc {
33 
34 class ChannelInterface;
35 class Status;
36 
37 namespace experimental {
38 
61  PRE_SEND_STATUS, // server only
62  PRE_SEND_CLOSE, // client only: WritesDone for stream; after write in unary
71  POST_RECV_STATUS, // client only
72  POST_RECV_CLOSE, // server only
81 };
82 
96  public:
100  virtual bool QueryInterceptionHookPoint(InterceptionHookPoints type) = 0;
110  virtual void Proceed() = 0;
116  virtual void Hijack() = 0;
117 
135 
139  virtual ByteBuffer* GetSerializedSendMessage() = 0;
140 
144  virtual const void* GetSendMessage() = 0;
145 
153  virtual void ModifySendMessage(const void* message) = 0;
154 
157  virtual bool GetSendMessageStatus() = 0;
158 
162  virtual std::multimap<std::string, std::string>* GetSendInitialMetadata() = 0;
163 
165  virtual Status GetSendStatus() = 0;
166 
169  virtual void ModifySendStatus(const Status& status) = 0;
170 
174  virtual std::multimap<std::string, std::string>*
176 
182  virtual void* GetRecvMessage() = 0;
183 
187  virtual std::multimap<grpc::string_ref, grpc::string_ref>*
189 
192  virtual Status* GetRecvStatus() = 0;
193 
196  virtual std::multimap<grpc::string_ref, grpc::string_ref>*
198 
204  virtual std::unique_ptr<ChannelInterface> GetInterceptedChannel() = 0;
205 
209  virtual void FailHijackedRecvMessage() = 0;
210 
213  virtual void FailHijackedSendMessage() = 0;
214 };
215 
218 class Interceptor {
219  public:
220  virtual ~Interceptor() {}
221 
224  virtual void Intercept(InterceptorBatchMethods* methods) = 0;
225 };
226 
227 } // namespace experimental
228 } // namespace grpc
229 
230 #endif // GRPCPP_SUPPORT_INTERCEPTOR_H
grpc::experimental::InterceptorBatchMethods::GetRecvStatus
virtual Status * GetRecvStatus()=0
Returns a modifiable view of the received status on PRE_RECV_STATUS and POST_RECV_STATUS interception...
grpc::experimental::Interceptor::Intercept
virtual void Intercept(InterceptorBatchMethods *methods)=0
The one public method of an Interceptor interface.
grpc::experimental::InterceptionHookPoints::POST_RECV_STATUS
@ POST_RECV_STATUS
grpc::experimental::InterceptionHookPoints::PRE_SEND_CLOSE
@ PRE_SEND_CLOSE
grpc::experimental::InterceptorBatchMethods::QueryInterceptionHookPoint
virtual bool QueryInterceptionHookPoint(InterceptionHookPoints type)=0
Determine whether the current batch has an interception hook point of type type.
grpc::experimental::InterceptorBatchMethods::FailHijackedRecvMessage
virtual void FailHijackedRecvMessage()=0
On a hijacked RPC, an interceptor can decide to fail a PRE_RECV_MESSAGE op.
grpc::experimental::InterceptionHookPoints::PRE_SEND_INITIAL_METADATA
@ PRE_SEND_INITIAL_METADATA
The first three in this list are for clients and servers.
grpc
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
grpc::experimental::InterceptorBatchMethods::GetSendInitialMetadata
virtual std::multimap< std::string, std::string > * GetSendInitialMetadata()=0
Returns a modifiable multimap of the initial metadata to be sent.
grpc::experimental::InterceptionHookPoints::POST_RECV_INITIAL_METADATA
@ POST_RECV_INITIAL_METADATA
The following two are for all clients and servers.
grpc::experimental::InterceptorBatchMethods::FailHijackedSendMessage
virtual void FailHijackedSendMessage()=0
On a hijacked RPC/ to-be hijacked RPC, this can be called to fail a SEND MESSAGE op.
grpc::experimental::InterceptionHookPoints::POST_RECV_MESSAGE
@ POST_RECV_MESSAGE
grpc::experimental::InterceptionHookPoints::PRE_RECV_MESSAGE
@ PRE_RECV_MESSAGE
grpc::experimental::InterceptionHookPoints::PRE_RECV_STATUS
@ PRE_RECV_STATUS
grpc::experimental::InterceptorBatchMethods::GetSendMessage
virtual const void * GetSendMessage()=0
Returns a non-modifiable pointer to the non-serialized form of the message to be sent.
grpc::experimental::InterceptorBatchMethods::Hijack
virtual void Hijack()=0
Indicate that the interceptor has hijacked the RPC (only valid if the batch contains send_initial_met...
grpc::experimental::InterceptorBatchMethods::GetRecvMessage
virtual void * GetRecvMessage()=0
Returns a pointer to the modifiable received message.
grpc::experimental::InterceptorBatchMethods::GetSendMessageStatus
virtual bool GetSendMessageStatus()=0
Checks whether the SEND MESSAGE op succeeded.
grpc::experimental::InterceptionHookPoints::PRE_SEND_STATUS
@ PRE_SEND_STATUS
grpc::experimental::InterceptionHookPoints::PRE_SEND_CANCEL
@ PRE_SEND_CANCEL
This is a special hook point available to both clients and servers when TryCancel() is performed.
grpc::experimental::InterceptorBatchMethods::ModifySendMessage
virtual void ModifySendMessage(const void *message)=0
Overwrites the message to be sent with message.
grpc_types.h
grpc::Status
Did it work? If it didn't, why?
Definition: status.h:34
grpc::experimental::InterceptorBatchMethods::GetInterceptedChannel
virtual std::unique_ptr< ChannelInterface > GetInterceptedChannel()=0
Gets an intercepted channel.
grpc::experimental::InterceptorBatchMethods::GetRecvTrailingMetadata
virtual std::multimap< grpc::string_ref, grpc::string_ref > * GetRecvTrailingMetadata()=0
Returns a modifiable multimap of the received trailing metadata on PRE_RECV_STATUS and POST_RECV_STAT...
grpc::experimental::InterceptorBatchMethods::GetRecvInitialMetadata
virtual std::multimap< grpc::string_ref, grpc::string_ref > * GetRecvInitialMetadata()=0
Returns a modifiable multimap of the received initial metadata.
grpc::ByteBuffer
A sequence of bytes.
Definition: byte_buffer.h:60
grpc::experimental::Interceptor::~Interceptor
virtual ~Interceptor()
Definition: interceptor.h:220
grpc::experimental::InterceptorBatchMethods::GetSerializedSendMessage
virtual ByteBuffer * GetSerializedSendMessage()=0
Send Message Methods GetSerializedSendMessage and GetSendMessage/ModifySendMessage are the available ...
grpc::experimental::InterceptorBatchMethods::~InterceptorBatchMethods
virtual ~InterceptorBatchMethods()
Definition: interceptor.h:97
grpc::experimental::Interceptor
Interface for an interceptor.
Definition: interceptor.h:218
grpc::experimental::InterceptionHookPoints::NUM_INTERCEPTION_HOOKS
@ NUM_INTERCEPTION_HOOKS
grpc::experimental::InterceptionHookPoints::PRE_SEND_MESSAGE
@ PRE_SEND_MESSAGE
grpc::experimental::InterceptorBatchMethods::GetSendStatus
virtual Status GetSendStatus()=0
Returns the status to be sent. Valid for PRE_SEND_STATUS interceptions.
grpc::experimental::InterceptorBatchMethods::ModifySendStatus
virtual void ModifySendStatus(const Status &status)=0
Overwrites the status with status.
grpc::experimental::InterceptionHookPoints::POST_SEND_MESSAGE
@ POST_SEND_MESSAGE
config.h
byte_buffer.h
grpc::experimental::InterceptorBatchMethods
Class that is passed as an argument to the Intercept method of the application's Interceptor interfac...
Definition: interceptor.h:95
grpc::experimental::InterceptorBatchMethods::GetSendTrailingMetadata
virtual std::multimap< std::string, std::string > * GetSendTrailingMetadata()=0
Returns a modifiable multimap of the trailing metadata to be sent.
grpc::experimental::InterceptionHookPoints::POST_RECV_CLOSE
@ POST_RECV_CLOSE
grpc::experimental::InterceptorBatchMethods::Proceed
virtual void Proceed()=0
Signal that the interceptor is done intercepting the current batch of the RPC.
grpc::protobuf::util::Status
::absl::Status Status
Definition: config_protobuf.h:106
grpc::experimental::InterceptionHookPoints
InterceptionHookPoints
An enumeration of different possible points at which the Intercept method of the Interceptor interfac...
Definition: interceptor.h:56
string_ref.h
metadata_map.h
grpc::experimental::InterceptionHookPoints::PRE_RECV_INITIAL_METADATA
@ PRE_RECV_INITIAL_METADATA
The following three are for hijacked clients only.