delegating_channel.h 3.0 KB

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