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;
32 class InterceptorBatchMethodsImpl;
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
38 class InterceptedChannel : public ChannelInterface {
40 virtual ~InterceptedChannel() { channel_ = nullptr; }
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);
49 InterceptedChannel(ChannelInterface* channel, size_t pos)
50 : channel_(channel), interceptor_pos_(pos) {}
52 Call CreateCall(const RpcMethod& method, ClientContext* context,
53 ::grpc_impl::CompletionQueue* cq) override {
54 return channel_->CreateCallInternal(method, context, cq, interceptor_pos_);
57 void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) override {
58 return channel_->PerformOpsOnCall(ops, call);
60 void* RegisterMethod(const char* method) override {
61 return channel_->RegisterMethod(method);
64 void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
65 gpr_timespec deadline,
66 ::grpc_impl::CompletionQueue* cq,
68 return channel_->NotifyOnStateChangeImpl(last_observed, deadline, cq, tag);
70 bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
71 gpr_timespec deadline) override {
72 return channel_->WaitForStateChangeImpl(last_observed, deadline);
75 ::grpc_impl::CompletionQueue* CallbackCQ() override {
76 return channel_->CallbackCQ();
79 ChannelInterface* channel_;
80 size_t interceptor_pos_;
82 friend class InterceptorBatchMethodsImpl;
84 } // namespace internal
87 #endif // GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H