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

source code of include/grpcpp/impl/codegen/intercepted_channel.h