GRPC C++  1.81.0
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_CHANNEL_INTERFACE_H
20 #define GRPCPP_IMPL_CHANNEL_INTERFACE_H
21 
24 #include <grpcpp/impl/call.h>
25 #include <grpcpp/support/status.h>
26 #include <grpcpp/support/time.h>
27 
28 #include <functional>
29 
30 namespace grpc {
31 template <class R>
32 class ClientReader;
33 template <class W>
34 class ClientWriter;
35 template <class W, class R>
36 class ClientReaderWriter;
37 namespace internal {
38 template <class InputMessage, class OutputMessage>
39 class CallbackUnaryCallImpl;
40 template <class R>
42 template <class W>
44 template <class W, class R>
47 template <class W, class R>
49 template <class R>
51 template <class W>
54 } // namespace internal
55 
56 class ChannelInterface;
57 class ClientContext;
58 
59 namespace experimental {
60 class DelegatingChannel;
61 class ClientSessionReactor;
62 namespace internal {
63 class ClientCallbackSessionImpl;
64 class ClientCallbackSessionFactory;
65 } // namespace internal
66 } // namespace experimental
67 
68 namespace internal {
69 class Call;
70 class CallOpSetInterface;
71 class RpcMethod;
72 class InterceptedChannel;
73 template <class InputMessage, class OutputMessage>
74 class BlockingUnaryCallImpl;
75 
76 } // namespace internal
77 
80  public:
81  virtual ~ChannelInterface() {}
84  virtual grpc_connectivity_state GetState(bool try_to_connect) = 0;
85 
88  template <typename T>
89  void NotifyOnStateChange(grpc_connectivity_state last_observed, T deadline,
90  grpc::CompletionQueue* cq, void* tag) {
91  TimePoint<T> deadline_tp(deadline);
92  NotifyOnStateChangeImpl(last_observed, deadline_tp.raw_time(), cq, tag);
93  }
94 
97  template <typename T>
98  bool WaitForStateChange(grpc_connectivity_state last_observed, T deadline) {
99  TimePoint<T> deadline_tp(deadline);
100  return WaitForStateChangeImpl(last_observed, deadline_tp.raw_time());
101  }
102 
104  template <typename T>
105  bool WaitForConnected(T deadline) {
107  while ((state = GetState(true)) != GRPC_CHANNEL_READY) {
108  if (!WaitForStateChange(state, deadline)) return false;
109  }
110  return true;
111  }
112 
114  const {
115  return nullptr;
116  }
117 
118  private:
119  template <class R>
120  friend class grpc::ClientReader;
121  template <class W>
122  friend class grpc::ClientWriter;
123  template <class W, class R>
125  template <class R>
127  template <class W>
129  template <class W, class R>
132  template <class W, class R>
134  template <class R>
136  template <class W>
140  template <class InputMessage, class OutputMessage>
142  template <class InputMessage, class OutputMessage>
145 
149  virtual internal::Call CreateCall(const internal::RpcMethod& method,
150  grpc::ClientContext* context,
151  grpc::CompletionQueue* cq) = 0;
152  virtual void PerformOpsOnCall(internal::CallOpSetInterface* ops,
153  internal::Call* call) = 0;
154  virtual void* RegisterMethod(const char* method) = 0;
155  virtual void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
156  gpr_timespec deadline,
158  void* tag) = 0;
159  virtual bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
160  gpr_timespec deadline) = 0;
161 
162  // EXPERIMENTAL
163  // This is needed to keep codegen_test_minimal happy. InterceptedChannel needs
164  // to make use of this but can't directly call Channel's implementation
165  // because of the test.
166  // Returns an empty Call object (rather than being pure) since this is a new
167  // method and adding a new pure method to an interface would be a breaking
168  // change (even though this is private and non-API)
169  virtual internal::Call CreateCallInternal(
170  const internal::RpcMethod& /*method*/, grpc::ClientContext* /*context*/,
171  grpc::CompletionQueue* /*cq*/, size_t /*interceptor_pos*/) {
172  return internal::Call();
173  }
174 
175  // A method to get the callbackable completion queue associated with this
176  // channel. If the return value is nullptr, this channel doesn't support
177  // callback operations.
178  // TODO(vjpai): Consider a better default like using a global CQ
179  // Returns nullptr (rather than being pure) since this is a post-1.0 method
180  // and adding a new pure method to an interface would be a breaking change
181  // (even though this is private and non-API)
182  virtual grpc::CompletionQueue* CallbackCQ() { return nullptr; }
183 };
184 } // namespace grpc
185 
186 #endif // GRPCPP_IMPL_CHANNEL_INTERFACE_H
time.h
grpc::ClientWriter
Synchronous (blocking) client-side API for doing client-streaming RPCs, where the outgoing message st...
Definition: client_context.h:91
grpc
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
grpc::internal::ClientAsyncReaderWriterFactory
Definition: channel_interface.h:45
grpc::internal::BlockingUnaryCallImpl
Definition: client_context.h:111
grpc::internal::Call
Straightforward wrapping of the C call object.
Definition: call.h:34
status.h
grpc::ChannelInterface::WaitForStateChange
bool WaitForStateChange(grpc_connectivity_state last_observed, T deadline)
Blocking wait for channel state change or deadline expiration.
Definition: channel_interface.h:98
grpc::internal::ClientAsyncReaderFactory
Definition: channel_interface.h:41
grpc::ClientReader
Synchronous (blocking) client-side API for doing server-streaming RPCs, where the stream of messages ...
Definition: client_context.h:89
grpc::internal::ClientCallbackWriterFactory
Definition: channel_interface.h:52
grpc::ClientContext
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:203
grpc_connectivity_state
grpc_connectivity_state
Connectivity state of a channel.
Definition: connectivity_state.h:30
grpc::internal::ClientCallbackReaderWriterFactory
Definition: channel_interface.h:48
grpc::internal::CallOpSetInterface
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call_op_set_interface.h:36
grpc::internal::CallbackUnaryCallImpl
Definition: client_context.h:69
connectivity_state.h
grpc::ChannelInterface::WaitForConnected
bool WaitForConnected(T deadline)
Wait for this channel to be connected.
Definition: channel_interface.h:105
grpc::TimePoint::raw_time
gpr_timespec raw_time()=delete
grpc::experimental::DelegatingChannel
Definition: delegating_channel.h:29
grpc::ChannelInterface
Codegen interface for grpc::Channel.
Definition: channel_interface.h:79
grpc::internal::ClientAsyncResponseReaderHelper
Definition: async_unary_call.h:79
grpc::internal::InterceptedChannel
An InterceptedChannel is available to client Interceptors.
Definition: intercepted_channel.h:35
grpc::internal::ClientCallbackUnaryFactory
Definition: client_callback.h:1272
grpc::ChannelInterface::~ChannelInterface
virtual ~ChannelInterface()
Definition: channel_interface.h:81
grpc::ChannelInterface::NotifyOnStateChange
void NotifyOnStateChange(grpc_connectivity_state last_observed, T deadline, grpc::CompletionQueue *cq, void *tag)
Return the tag on cq when the channel state is changed or deadline expires.
Definition: channel_interface.h:89
grpc::ClientReaderWriter
Synchronous (blocking) client-side API for bi-directional streaming RPCs, where the outgoing message ...
Definition: client_context.h:93
grpc::ChannelInterface::GetState
virtual grpc_connectivity_state GetState(bool try_to_connect)=0
Get the current channel state.
call.h
grpc::CompletionQueue
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue.h:104
grpc::internal::ClientCallbackReaderFactory
Definition: channel_interface.h:50
grpc::experimental::internal::ClientCallbackSessionImpl
Definition: client_callback.h:1296
grpc::internal::ClientAsyncWriterFactory
Definition: channel_interface.h:43
grpc::experimental::internal::ClientCallbackSessionFactory
Definition: client_callback.h:1397
grpc_event_engine::experimental::MemoryAllocator
Definition: memory_allocator.h:33
memory_allocator.h
grpc::internal::RpcMethod
Descriptor of an RPC method.
Definition: rpc_method.h:29
gpr_timespec
Analogous to struct timespec.
Definition: time.h:47
GRPC_CHANNEL_READY
@ GRPC_CHANNEL_READY
channel is ready for work
Definition: connectivity_state.h:36
grpc::ChannelInterface::memory_allocator
virtual grpc_event_engine::experimental::MemoryAllocator * memory_allocator() const
Definition: channel_interface.h:113
grpc::TimePoint
If you are trying to use CompletionQueue::AsyncNext with a time class that isn't either gpr_timespec ...
Definition: time.h:45