intercepted_channel.h 2.7 KB

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