GRPC C++  1.13.0-dev
channel_interface.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 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 
19 #ifndef GRPCPP_IMPL_CODEGEN_CHANNEL_INTERFACE_H
20 #define GRPCPP_IMPL_CODEGEN_CHANNEL_INTERFACE_H
21 
25 
26 namespace grpc {
27 class ChannelInterface;
28 class ClientContext;
29 class CompletionQueue;
30 
31 template <class R>
33 template <class W>
35 template <class W, class R>
37 
38 namespace internal {
39 class Call;
40 class CallOpSetInterface;
41 class RpcMethod;
42 template <class InputMessage, class OutputMessage>
44 template <class R>
46 template <class W>
48 template <class W, class R>
50 template <class R>
52 } // namespace internal
53 
56  public:
57  virtual ~ChannelInterface() {}
60  virtual grpc_connectivity_state GetState(bool try_to_connect) = 0;
61 
64  template <typename T>
65  void NotifyOnStateChange(grpc_connectivity_state last_observed, T deadline,
66  CompletionQueue* cq, void* tag) {
67  TimePoint<T> deadline_tp(deadline);
68  NotifyOnStateChangeImpl(last_observed, deadline_tp.raw_time(), cq, tag);
69  }
70 
73  template <typename T>
74  bool WaitForStateChange(grpc_connectivity_state last_observed, T deadline) {
75  TimePoint<T> deadline_tp(deadline);
76  return WaitForStateChangeImpl(last_observed, deadline_tp.raw_time());
77  }
78 
80  template <typename T>
81  bool WaitForConnected(T deadline) {
83  while ((state = GetState(true)) != GRPC_CHANNEL_READY) {
84  if (!WaitForStateChange(state, deadline)) return false;
85  }
86  return true;
87  }
88 
89  private:
90  template <class R>
91  friend class ::grpc::ClientReader;
92  template <class W>
93  friend class ::grpc::ClientWriter;
94  template <class W, class R>
95  friend class ::grpc::ClientReaderWriter;
96  template <class R>
97  friend class ::grpc::internal::ClientAsyncReaderFactory;
98  template <class W>
99  friend class ::grpc::internal::ClientAsyncWriterFactory;
100  template <class W, class R>
101  friend class ::grpc::internal::ClientAsyncReaderWriterFactory;
102  template <class R>
103  friend class ::grpc::internal::ClientAsyncResponseReaderFactory;
104  template <class InputMessage, class OutputMessage>
105  friend class ::grpc::internal::BlockingUnaryCallImpl;
106  friend class ::grpc::internal::RpcMethod;
107  virtual internal::Call CreateCall(const internal::RpcMethod& method,
108  ClientContext* context,
109  CompletionQueue* cq) = 0;
110  virtual void PerformOpsOnCall(internal::CallOpSetInterface* ops,
111  internal::Call* call) = 0;
112  virtual void* RegisterMethod(const char* method) = 0;
113  virtual void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
114  gpr_timespec deadline,
115  CompletionQueue* cq, void* tag) = 0;
116  virtual bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
117  gpr_timespec deadline) = 0;
118 };
119 } // namespace grpc
120 
121 #endif // GRPCPP_IMPL_CODEGEN_CHANNEL_INTERFACE_H
Synchronous (blocking) client-side API for doing server-streaming RPCs, where the stream of messages ...
Definition: channel_interface.h:32
Definition: async_unary_call.h:74
void NotifyOnStateChange(grpc_connectivity_state last_observed, T deadline, CompletionQueue *cq, void *tag)
Return the tag on cq when the channel state is changed or deadline expires.
Definition: channel_interface.h:65
gpr_timespec raw_time()
Definition: time.h:43
If you are trying to use CompletionQueue::AsyncNext with a time class that isn&#39;t either gpr_timespec ...
Definition: time.h:40
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:162
Definition: async_stream.h:301
Definition: async_stream.h:164
Descriptor of an RPC method.
Definition: rpc_method.h:29
grpc_connectivity_state
Connectivity state of a channel.
Definition: connectivity_state.h:27
An Alarm posts the user provided tag to its associated completion queue upon expiry or cancellation...
Definition: alarm.h:31
Codegen interface for grpc::Channel.
Definition: channel_interface.h:55
channel is ready for work
Definition: connectivity_state.h:33
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue.h:94
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call.h:603
virtual ~ChannelInterface()
Definition: channel_interface.h:57
Definition: channel_interface.h:43
bool WaitForStateChange(grpc_connectivity_state last_observed, T deadline)
Blocking wait for channel state change or deadline expiration.
Definition: channel_interface.h:74
Analogous to struct timespec.
Definition: gpr_types.h:47
Synchronous (blocking) client-side API for bi-directional streaming RPCs, where the outgoing message ...
Definition: channel_interface.h:36
bool WaitForConnected(T deadline)
Wait for this channel to be connected.
Definition: channel_interface.h:81
Synchronous (blocking) client-side API for doing client-streaming RPCs, where the outgoing message st...
Definition: channel_interface.h:34
Straightforward wrapping of the C call object.
Definition: call.h:660