GRPC C++  1.6.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 GRPCXX_IMPL_CODEGEN_CHANNEL_INTERFACE_H
20 #define GRPCXX_IMPL_CODEGEN_CHANNEL_INTERFACE_H
21 
25 
26 namespace grpc {
27 class Call;
28 class ClientContext;
29 class RpcMethod;
30 class CallOpSetInterface;
31 class CompletionQueue;
32 
33 template <class R>
35 template <class W>
37 template <class W, class R>
39 template <class R>
40 class ClientAsyncReader;
41 template <class W>
42 class ClientAsyncWriter;
43 template <class W, class R>
45 template <class R>
47 
50  public:
51  virtual ~ChannelInterface() {}
54  virtual grpc_connectivity_state GetState(bool try_to_connect) = 0;
55 
58  template <typename T>
59  void NotifyOnStateChange(grpc_connectivity_state last_observed, T deadline,
60  CompletionQueue* cq, void* tag) {
61  TimePoint<T> deadline_tp(deadline);
62  NotifyOnStateChangeImpl(last_observed, deadline_tp.raw_time(), cq, tag);
63  }
64 
67  template <typename T>
68  bool WaitForStateChange(grpc_connectivity_state last_observed, T deadline) {
69  TimePoint<T> deadline_tp(deadline);
70  return WaitForStateChangeImpl(last_observed, deadline_tp.raw_time());
71  }
72 
74  template <typename T>
75  bool WaitForConnected(T deadline) {
77  while ((state = GetState(true)) != GRPC_CHANNEL_READY) {
78  if (!WaitForStateChange(state, deadline)) return false;
79  }
80  return true;
81  }
82 
83  private:
84  template <class R>
85  friend class ::grpc::ClientReader;
86  template <class W>
87  friend class ::grpc::ClientWriter;
88  template <class W, class R>
89  friend class ::grpc::ClientReaderWriter;
90  template <class R>
91  friend class ::grpc::ClientAsyncReader;
92  template <class W>
93  friend class ::grpc::ClientAsyncWriter;
94  template <class W, class R>
95  friend class ::grpc::ClientAsyncReaderWriter;
96  template <class R>
97  friend class ::grpc::ClientAsyncResponseReader;
98  template <class InputMessage, class OutputMessage>
100  const RpcMethod& method,
101  ClientContext* context,
102  const InputMessage& request,
103  OutputMessage* result);
104  friend class ::grpc::RpcMethod;
105  virtual Call CreateCall(const RpcMethod& method, ClientContext* context,
106  CompletionQueue* cq) = 0;
107  virtual void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) = 0;
108  virtual void* RegisterMethod(const char* method) = 0;
109  virtual void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
110  gpr_timespec deadline,
111  CompletionQueue* cq, void* tag) = 0;
112  virtual bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
113  gpr_timespec deadline) = 0;
114 };
115 
116 } // namespace grpc
117 
118 #endif // GRPCXX_IMPL_CODEGEN_CHANNEL_INTERFACE_H
Async client-side interface for bi-directional streaming, where the outgoing message stream going to ...
Definition: async_stream.h:388
Synchronous (blocking) client-side API for doing server-streaming RPCs, where the stream of messages ...
Definition: channel_interface.h:34
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call.h:575
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:59
virtual grpc_connectivity_state GetState(bool try_to_connect)=0
Get the current channel state.
gpr_timespec raw_time()
Definition: time.h:41
If you are trying to use CompletionQueue::AsyncNext with a time class that isn't either gpr_timespec ...
Definition: time.h:38
Async API for client-side unary RPCs, where the message response received from the server is of type ...
Definition: async_unary_call.h:70
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:153
friend Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method, ClientContext *context, const InputMessage &request, OutputMessage *result)
Wrapper that performs a blocking unary call.
Definition: client_unary_call.h:37
grpc_connectivity_state
Connectivity state of a channel.
Definition: connectivity_state.h:27
Straightforward wrapping of the C call object.
Definition: call.h:647
Codegen interface for grpc::Channel.
Definition: channel_interface.h:49
Async API on the client side for doing client-streaming RPCs, where the outgoing message stream going...
Definition: async_stream.h:258
channel is ready for work
Definition: connectivity_state.h:35
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue.h:86
Descriptor of an RPC method.
Definition: rpc_method.h:29
virtual ~ChannelInterface()
Definition: channel_interface.h:51
bool WaitForStateChange(grpc_connectivity_state last_observed, T deadline)
Blocking wait for channel state change or deadline expiration.
Definition: channel_interface.h:68
Did it work? If it didn't, why?
Definition: status.h:30
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:38
Async client-side API for doing server-streaming RPCs, where the incoming message stream coming from ...
Definition: async_stream.h:157
bool WaitForConnected(T deadline)
Wait for this channel to be connected.
Definition: channel_interface.h:75
Synchronous (blocking) client-side API for doing client-streaming RPCs, where the outgoing message st...
Definition: channel_interface.h:36