intercepted_channel.h 2.8 KB

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