3 * Copyright 2018 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H
20 #define GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H
22 #include <grpcpp/impl/codegen/channel_interface.h>
25 class CompletionQueue;
29 class InterceptorBatchMethodsImpl;
31 /// An InterceptedChannel is available to client Interceptors. An
32 /// InterceptedChannel is unique to an interceptor, and when an RPC is started
33 /// on this channel, only those interceptors that come after this interceptor
35 class InterceptedChannel : public ChannelInterface {
37 ~InterceptedChannel() override { channel_ = nullptr; }
39 /// Get the current channel state. If the channel is in IDLE and
40 /// \a try_to_connect is set to true, try to connect.
41 grpc_connectivity_state GetState(bool try_to_connect) override {
42 return channel_->GetState(try_to_connect);
46 InterceptedChannel(ChannelInterface* channel, size_t pos)
47 : channel_(channel), interceptor_pos_(pos) {}
49 Call CreateCall(const RpcMethod& method, ::grpc::ClientContext* context,
50 ::grpc::CompletionQueue* cq) override {
51 return channel_->CreateCallInternal(method, context, cq, interceptor_pos_);
54 void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) override {
55 return channel_->PerformOpsOnCall(ops, call);
57 void* RegisterMethod(const char* method) override {
58 return channel_->RegisterMethod(method);
61 void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
62 gpr_timespec deadline,
63 ::grpc::CompletionQueue* cq,
65 return channel_->NotifyOnStateChangeImpl(last_observed, deadline, cq, tag);
67 bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
68 gpr_timespec deadline) override {
69 return channel_->WaitForStateChangeImpl(last_observed, deadline);
72 ::grpc::CompletionQueue* CallbackCQ() override {
73 return channel_->CallbackCQ();
76 ChannelInterface* channel_;
77 size_t interceptor_pos_;
79 friend class InterceptorBatchMethodsImpl;
81 } // namespace internal
84 #endif // GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H