delegating_channel.h 3.0 KB

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