1 // 2 // 3 // Copyright 2019 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_DELEGATING_CHANNEL_H 20 #define GRPCPP_IMPL_DELEGATING_CHANNEL_H 21 22 #include <memory> 23 24 #include <grpcpp/impl/channel_interface.h> 25 26 namespace grpc { 27 namespace experimental { 28 29 class DelegatingChannel : public grpc::ChannelInterface { 30 public: ~DelegatingChannel()31 ~DelegatingChannel() override {} 32 DelegatingChannel(std::shared_ptr<grpc::ChannelInterface> delegate_channel)33 explicit DelegatingChannel( 34 std::shared_ptr<grpc::ChannelInterface> delegate_channel) 35 : delegate_channel_(delegate_channel) {} 36 GetState(bool try_to_connect)37 grpc_connectivity_state GetState(bool try_to_connect) override { 38 return delegate_channel()->GetState(try_to_connect); 39 } 40 delegate_channel()41 std::shared_ptr<grpc::ChannelInterface> delegate_channel() { 42 return delegate_channel_; 43 } 44 45 private: CreateCall(const internal::RpcMethod & method,ClientContext * context,grpc::CompletionQueue * cq)46 internal::Call CreateCall(const internal::RpcMethod& method, 47 ClientContext* context, 48 grpc::CompletionQueue* cq) final { 49 return delegate_channel()->CreateCall(method, context, cq); 50 } 51 PerformOpsOnCall(internal::CallOpSetInterface * ops,internal::Call * call)52 void PerformOpsOnCall(internal::CallOpSetInterface* ops, 53 internal::Call* call) final { 54 delegate_channel()->PerformOpsOnCall(ops, call); 55 } 56 RegisterMethod(const char * method)57 void* RegisterMethod(const char* method) final { 58 return delegate_channel()->RegisterMethod(method); 59 } 60 NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,gpr_timespec deadline,grpc::CompletionQueue * cq,void * tag)61 void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed, 62 gpr_timespec deadline, grpc::CompletionQueue* cq, 63 void* tag) override { 64 delegate_channel()->NotifyOnStateChangeImpl(last_observed, deadline, cq, 65 tag); 66 } 67 WaitForStateChangeImpl(grpc_connectivity_state last_observed,gpr_timespec deadline)68 bool WaitForStateChangeImpl(grpc_connectivity_state last_observed, 69 gpr_timespec deadline) override { 70 return delegate_channel()->WaitForStateChangeImpl(last_observed, deadline); 71 } 72 CreateCallInternal(const internal::RpcMethod & method,ClientContext * context,grpc::CompletionQueue * cq,size_t interceptor_pos)73 internal::Call CreateCallInternal(const internal::RpcMethod& method, 74 ClientContext* context, 75 grpc::CompletionQueue* cq, 76 size_t interceptor_pos) final { 77 return delegate_channel()->CreateCallInternal(method, context, cq, 78 interceptor_pos); 79 } 80 CallbackCQ()81 grpc::CompletionQueue* CallbackCQ() final { 82 return delegate_channel()->CallbackCQ(); 83 } 84 85 std::shared_ptr<grpc::ChannelInterface> delegate_channel_; 86 }; 87 88 } // namespace experimental 89 } // namespace grpc 90 91 #endif // GRPCPP_IMPL_DELEGATING_CHANNEL_H 92