You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

delegating_channel.h 3.3 kB

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