OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * |
| 3 * Copyright 2016, Google Inc. |
| 4 * All rights reserved. |
| 5 * |
| 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions are |
| 8 * met: |
| 9 * |
| 10 * * Redistributions of source code must retain the above copyright |
| 11 * notice, this list of conditions and the following disclaimer. |
| 12 * * Redistributions in binary form must reproduce the above |
| 13 * copyright notice, this list of conditions and the following disclaimer |
| 14 * in the documentation and/or other materials provided with the |
| 15 * distribution. |
| 16 * * Neither the name of Google Inc. nor the names of its |
| 17 * contributors may be used to endorse or promote products derived from |
| 18 * this software without specific prior written permission. |
| 19 * |
| 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 * |
| 32 */ |
| 33 |
| 34 #ifndef GRPCXX_IMPL_CODEGEN_CHANNEL_INTERFACE_H |
| 35 #define GRPCXX_IMPL_CODEGEN_CHANNEL_INTERFACE_H |
| 36 |
| 37 #include <grpc++/impl/codegen/status.h> |
| 38 #include <grpc++/impl/codegen/time.h> |
| 39 #include <grpc/impl/codegen/connectivity_state.h> |
| 40 |
| 41 namespace grpc { |
| 42 class Call; |
| 43 class ClientContext; |
| 44 class RpcMethod; |
| 45 class CallOpSetInterface; |
| 46 class CompletionQueue; |
| 47 |
| 48 template <class R> |
| 49 class ClientReader; |
| 50 template <class W> |
| 51 class ClientWriter; |
| 52 template <class W, class R> |
| 53 class ClientReaderWriter; |
| 54 template <class R> |
| 55 class ClientAsyncReader; |
| 56 template <class W> |
| 57 class ClientAsyncWriter; |
| 58 template <class W, class R> |
| 59 class ClientAsyncReaderWriter; |
| 60 template <class R> |
| 61 class ClientAsyncResponseReader; |
| 62 |
| 63 /// Codegen interface for \a grpc::Channel. |
| 64 class ChannelInterface { |
| 65 public: |
| 66 virtual ~ChannelInterface() {} |
| 67 /// Get the current channel state. If the channel is in IDLE and |
| 68 /// \a try_to_connect is set to true, try to connect. |
| 69 virtual grpc_connectivity_state GetState(bool try_to_connect) = 0; |
| 70 |
| 71 /// Return the \a tag on \a cq when the channel state is changed or \a |
| 72 /// deadline expires. \a GetState needs to called to get the current state. |
| 73 template <typename T> |
| 74 void NotifyOnStateChange(grpc_connectivity_state last_observed, T deadline, |
| 75 CompletionQueue* cq, void* tag) { |
| 76 TimePoint<T> deadline_tp(deadline); |
| 77 NotifyOnStateChangeImpl(last_observed, deadline_tp.raw_time(), cq, tag); |
| 78 } |
| 79 |
| 80 /// Blocking wait for channel state change or \a deadline expiration. |
| 81 /// \a GetState needs to called to get the current state. |
| 82 template <typename T> |
| 83 bool WaitForStateChange(grpc_connectivity_state last_observed, T deadline) { |
| 84 TimePoint<T> deadline_tp(deadline); |
| 85 return WaitForStateChangeImpl(last_observed, deadline_tp.raw_time()); |
| 86 } |
| 87 |
| 88 private: |
| 89 template <class R> |
| 90 friend class ::grpc::ClientReader; |
| 91 template <class W> |
| 92 friend class ::grpc::ClientWriter; |
| 93 template <class W, class R> |
| 94 friend class ::grpc::ClientReaderWriter; |
| 95 template <class R> |
| 96 friend class ::grpc::ClientAsyncReader; |
| 97 template <class W> |
| 98 friend class ::grpc::ClientAsyncWriter; |
| 99 template <class W, class R> |
| 100 friend class ::grpc::ClientAsyncReaderWriter; |
| 101 template <class R> |
| 102 friend class ::grpc::ClientAsyncResponseReader; |
| 103 template <class InputMessage, class OutputMessage> |
| 104 friend Status BlockingUnaryCall(ChannelInterface* channel, |
| 105 const RpcMethod& method, |
| 106 ClientContext* context, |
| 107 const InputMessage& request, |
| 108 OutputMessage* result); |
| 109 friend class ::grpc::RpcMethod; |
| 110 virtual Call CreateCall(const RpcMethod& method, ClientContext* context, |
| 111 CompletionQueue* cq) = 0; |
| 112 virtual void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) = 0; |
| 113 virtual void* RegisterMethod(const char* method) = 0; |
| 114 virtual void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed, |
| 115 gpr_timespec deadline, |
| 116 CompletionQueue* cq, void* tag) = 0; |
| 117 virtual bool WaitForStateChangeImpl(grpc_connectivity_state last_observed, |
| 118 gpr_timespec deadline) = 0; |
| 119 }; |
| 120 |
| 121 } // namespace grpc |
| 122 |
| 123 #endif // GRPCXX_IMPL_CODEGEN_CHANNEL_INTERFACE_H |
OLD | NEW |