delegating_channel.h 3.0 KB

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