delegating_channel.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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,
  52. ::grpc::CompletionQueue* cq,
  53. void* tag) override {
  54. delegate_channel()->NotifyOnStateChangeImpl(last_observed, deadline, cq,
  55. tag);
  56. }
  57. bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
  58. gpr_timespec deadline) override {
  59. return delegate_channel()->WaitForStateChangeImpl(last_observed, deadline);
  60. }
  61. internal::Call CreateCallInternal(const internal::RpcMethod& method,
  62. ClientContext* context,
  63. ::grpc::CompletionQueue* cq,
  64. size_t interceptor_pos) final {
  65. return delegate_channel()->CreateCallInternal(method, context, cq,
  66. interceptor_pos);
  67. }
  68. ::grpc::CompletionQueue* CallbackCQ() final {
  69. return delegate_channel()->CallbackCQ();
  70. }
  71. std::shared_ptr<::grpc::ChannelInterface> delegate_channel_;
  72. };
  73. } // namespace experimental
  74. } // namespace grpc
  75. #endif // GRPCPP_IMPL_CODEGEN_DELEGATING_CHANNEL_H