GRPC C++  1.17.0
interceptor.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 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_IMPL_CODEGEN_INTERCEPTOR_H
20 #define GRPCPP_IMPL_CODEGEN_INTERCEPTOR_H
21 
27 
28 namespace grpc {
29 
30 class ChannelInterface;
31 class Status;
32 
33 namespace experimental {
35  public:
36  template <class M>
37  bool Extract(M* msg); // returns false if definitely invalid extraction
38  template <class M>
39  M* MutableExtract();
40  uint64_t length(); // length on wire
41 };
42 
44  /* The first two in this list are for clients and servers */
47  PRE_SEND_STATUS /* server only */,
48  PRE_SEND_CLOSE /* client only */,
49  /* The following three are for hijacked clients only and can only be
50  registered by the global interceptor */
54  /* The following two are for all clients and servers */
57  POST_RECV_STATUS /* client only */,
58  POST_RECV_CLOSE /* server only */,
59  /* This is a special hook point available to both clients and servers when
60  TryCancel() is performed.
61  - No other hook points will be present along with this.
62  - It is illegal for an interceptor to block/delay this operation.
63  - ALL interceptors see this hook point irrespective of whether the RPC was
64  hijacked or not. */
67 };
68 
70  public:
72  // Queries to check whether the current batch has an interception hook point
73  // of type \a type
74  virtual bool QueryInterceptionHookPoint(InterceptionHookPoints type) = 0;
75  // Calling this will signal that the interceptor is done intercepting the
76  // current batch of the RPC.
77  // Proceed is a no-op if the batch contains PRE_SEND_CANCEL. Simply returning
78  // from the Intercept method does the job of continuing the RPC in this case.
79  virtual void Proceed() = 0;
80  // Calling this indicates that the interceptor has hijacked the RPC (only
81  // valid if the batch contains send_initial_metadata on the client side)
82  virtual void Hijack() = 0;
83 
84  // Returns a modifable ByteBuffer holding serialized form of the message to be
85  // sent
86  virtual ByteBuffer* GetSendMessage() = 0;
87 
88  // Returns a modifiable multimap of the initial metadata to be sent
89  virtual std::multimap<grpc::string, grpc::string>*
90  GetSendInitialMetadata() = 0;
91 
92  // Returns the status to be sent
93  virtual Status GetSendStatus() = 0;
94 
95  // Modifies the status with \a status
96  virtual void ModifySendStatus(const Status& status) = 0;
97 
98  // Returns a modifiable multimap of the trailing metadata to be sent
99  virtual std::multimap<grpc::string, grpc::string>*
100  GetSendTrailingMetadata() = 0;
101 
102  // Returns a pointer to the modifiable received message. Note that the message
103  // is already deserialized
104  virtual void* GetRecvMessage() = 0;
105 
106  // Returns a modifiable multimap of the received initial metadata
107  virtual std::multimap<grpc::string_ref, grpc::string_ref>*
108  GetRecvInitialMetadata() = 0;
109 
110  // Returns a modifiable view of the received status
111  virtual Status* GetRecvStatus() = 0;
112 
113  // Returns a modifiable multimap of the received trailing metadata
114  virtual std::multimap<grpc::string_ref, grpc::string_ref>*
115  GetRecvTrailingMetadata() = 0;
116 
117  // Gets an intercepted channel. When a call is started on this interceptor,
118  // only interceptors after the current interceptor are created from the
119  // factory objects registered with the channel.
120  virtual std::unique_ptr<ChannelInterface> GetInterceptedChannel() = 0;
121 };
122 
123 class Interceptor {
124  public:
125  virtual ~Interceptor() {}
126 
127  virtual void Intercept(InterceptorBatchMethods* methods) = 0;
128 };
129 
130 } // namespace experimental
131 } // namespace grpc
132 
133 #endif // GRPCPP_IMPL_CODEGEN_INTERCEPTOR_H
virtual ~InterceptorBatchMethods()
Definition: interceptor.h:71
::google::protobuf::util::Status Status
Definition: config_protobuf.h:93
InterceptionHookPoints
Definition: interceptor.h:43
Definition: interceptor.h:34
An Alarm posts the user provided tag to its associated completion queue upon expiry or cancellation...
Definition: alarm.h:33
Definition: interceptor.h:123
virtual ~Interceptor()
Definition: interceptor.h:125
Did it work? If it didn&#39;t, why?
Definition: status.h:31
A sequence of bytes.
Definition: byte_buffer.h:62