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.

intercepted_channel.h 3.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. *
  3. * Copyright 2018 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_INTERCEPTED_CHANNEL_H
  19. #define GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H
  20. // IWYU pragma: private
  21. #include <grpcpp/impl/codegen/channel_interface.h>
  22. namespace grpc
  23. {
  24. class CompletionQueue;
  25. namespace internal
  26. {
  27. class InterceptorBatchMethodsImpl;
  28. /// An InterceptedChannel is available to client Interceptors. An
  29. /// InterceptedChannel is unique to an interceptor, and when an RPC is started
  30. /// on this channel, only those interceptors that come after this interceptor
  31. /// see the RPC.
  32. class InterceptedChannel : public ChannelInterface
  33. {
  34. public:
  35. ~InterceptedChannel() override
  36. {
  37. channel_ = nullptr;
  38. }
  39. /// Get the current channel state. If the channel is in IDLE and
  40. /// \a try_to_connect is set to true, try to connect.
  41. grpc_connectivity_state GetState(bool try_to_connect) override
  42. {
  43. return channel_->GetState(try_to_connect);
  44. }
  45. private:
  46. InterceptedChannel(ChannelInterface* channel, size_t pos) :
  47. channel_(channel),
  48. interceptor_pos_(pos)
  49. {
  50. }
  51. Call CreateCall(const RpcMethod& method, grpc::ClientContext* context, grpc::CompletionQueue* cq) override
  52. {
  53. return channel_->CreateCallInternal(method, context, cq, interceptor_pos_);
  54. }
  55. void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) override
  56. {
  57. return channel_->PerformOpsOnCall(ops, call);
  58. }
  59. void* RegisterMethod(const char* method) override
  60. {
  61. return channel_->RegisterMethod(method);
  62. }
  63. void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed, gpr_timespec deadline, grpc::CompletionQueue* cq, void* tag) override
  64. {
  65. return channel_->NotifyOnStateChangeImpl(last_observed, deadline, cq, tag);
  66. }
  67. bool WaitForStateChangeImpl(grpc_connectivity_state last_observed, gpr_timespec deadline) override
  68. {
  69. return channel_->WaitForStateChangeImpl(last_observed, deadline);
  70. }
  71. grpc::CompletionQueue* CallbackCQ() override
  72. {
  73. return channel_->CallbackCQ();
  74. }
  75. ChannelInterface* channel_;
  76. size_t interceptor_pos_;
  77. friend class InterceptorBatchMethodsImpl;
  78. };
  79. } // namespace internal
  80. } // namespace grpc
  81. #endif // GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H