• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CODEGEN_DELEGATING_CHANNEL_H
20 #define GRPCPP_IMPL_CODEGEN_DELEGATING_CHANNEL_H
21 
22 #include <memory>
23 
24 #include <grpcpp/impl/codegen/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,
63                                ::grpc::CompletionQueue* cq,
64                                void* tag) override {
65     delegate_channel()->NotifyOnStateChangeImpl(last_observed, deadline, cq,
66                                                 tag);
67   }
68 
WaitForStateChangeImpl(grpc_connectivity_state last_observed,gpr_timespec deadline)69   bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
70                               gpr_timespec deadline) override {
71     return delegate_channel()->WaitForStateChangeImpl(last_observed, deadline);
72   }
73 
CreateCallInternal(const internal::RpcMethod & method,ClientContext * context,::grpc::CompletionQueue * cq,size_t interceptor_pos)74   internal::Call CreateCallInternal(const internal::RpcMethod& method,
75                                     ClientContext* context,
76                                     ::grpc::CompletionQueue* cq,
77                                     size_t interceptor_pos) final {
78     return delegate_channel()->CreateCallInternal(method, context, cq,
79                                                   interceptor_pos);
80   }
81 
CallbackCQ()82   ::grpc::CompletionQueue* CallbackCQ() final {
83     return delegate_channel()->CallbackCQ();
84   }
85 
86   std::shared_ptr<::grpc::ChannelInterface> delegate_channel_;
87 };
88 
89 }  // namespace experimental
90 }  // namespace grpc
91 
92 #endif  // GRPCPP_IMPL_CODEGEN_DELEGATING_CHANNEL_H
93