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_INTERCEPTED_CHANNEL_H |
20 | #define GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H |
21 | |
22 | #include <grpcpp/impl/codegen/channel_interface.h> |
23 | |
24 | namespace grpc_impl { |
25 | class CompletionQueue; |
26 | } |
27 | |
28 | namespace grpc { |
29 | |
30 | namespace internal { |
31 | |
32 | class InterceptorBatchMethodsImpl; |
33 | |
34 | /// An InterceptedChannel is available to client Interceptors. An |
35 | /// InterceptedChannel is unique to an interceptor, and when an RPC is started |
36 | /// on this channel, only those interceptors that come after this interceptor |
37 | /// see the RPC. |
38 | class InterceptedChannel : public ChannelInterface { |
39 | public: |
40 | virtual ~InterceptedChannel() { channel_ = nullptr; } |
41 | |
42 | /// Get the current channel state. If the channel is in IDLE and |
43 | /// \a try_to_connect is set to true, try to connect. |
44 | grpc_connectivity_state GetState(bool try_to_connect) override { |
45 | return channel_->GetState(try_to_connect); |
46 | } |
47 | |
48 | private: |
49 | InterceptedChannel(ChannelInterface* channel, size_t pos) |
50 | : channel_(channel), interceptor_pos_(pos) {} |
51 | |
52 | Call CreateCall(const RpcMethod& method, ::grpc_impl::ClientContext* context, |
53 | ::grpc_impl::CompletionQueue* cq) override { |
54 | return channel_->CreateCallInternal(method, context, cq, interceptor_pos_); |
55 | } |
56 | |
57 | void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) override { |
58 | return channel_->PerformOpsOnCall(ops, call); |
59 | } |
60 | void* RegisterMethod(const char* method) override { |
61 | return channel_->RegisterMethod(method); |
62 | } |
63 | |
64 | void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed, |
65 | gpr_timespec deadline, |
66 | ::grpc_impl::CompletionQueue* cq, |
67 | void* tag) override { |
68 | return channel_->NotifyOnStateChangeImpl(last_observed, deadline, cq, tag); |
69 | } |
70 | bool WaitForStateChangeImpl(grpc_connectivity_state last_observed, |
71 | gpr_timespec deadline) override { |
72 | return channel_->WaitForStateChangeImpl(last_observed, deadline); |
73 | } |
74 | |
75 | ::grpc_impl::CompletionQueue* CallbackCQ() override { |
76 | return channel_->CallbackCQ(); |
77 | } |
78 | |
79 | ChannelInterface* channel_; |
80 | size_t interceptor_pos_; |
81 | |
82 | friend class InterceptorBatchMethodsImpl; |
83 | }; |
84 | } // namespace internal |
85 | } // namespace grpc |
86 | |
87 | #endif // GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H |
88 | |