grpcpp/impl/codegen/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 
22 // IWYU pragma: private
23 
28 
29 namespace grpc {
30 template <class R>
32 template <class W>
34 template <class W, class R>
36 namespace internal {
37 template <class InputMessage, class OutputMessage>
39 template <class R>
41 template <class W>
43 template <class W, class R>
46 template <class W, class R>
48 template <class R>
50 template <class W>
53 } // namespace internal
54 
55 class ChannelInterface;
56 class ClientContext;
57 class CompletionQueue;
58 
59 namespace experimental {
60 class DelegatingChannel;
61 }
62 
63 namespace internal {
64 class Call;
65 class CallOpSetInterface;
66 class RpcMethod;
67 class InterceptedChannel;
68 template <class InputMessage, class OutputMessage>
70 } // namespace internal
71 
74  public:
75  virtual ~ChannelInterface() {}
79 
82  template <typename T>
83  void NotifyOnStateChange(grpc_connectivity_state last_observed, T deadline,
84  grpc::CompletionQueue* cq, void* tag) {
85  TimePoint<T> deadline_tp(deadline);
86  NotifyOnStateChangeImpl(last_observed, deadline_tp.raw_time(), cq, tag);
87  }
88 
91  template <typename T>
92  bool WaitForStateChange(grpc_connectivity_state last_observed, T deadline) {
93  TimePoint<T> deadline_tp(deadline);
94  return WaitForStateChangeImpl(last_observed, deadline_tp.raw_time());
95  }
96 
98  template <typename T>
99  bool WaitForConnected(T deadline) {
101  while ((state = GetState(true)) != GRPC_CHANNEL_READY) {
102  if (!WaitForStateChange(state, deadline)) return false;
103  }
104  return true;
105  }
106 
107  private:
108  template <class R>
109  friend class grpc::ClientReader;
110  template <class W>
111  friend class grpc::ClientWriter;
112  template <class W, class R>
114  template <class R>
116  template <class W>
118  template <class W, class R>
121  template <class W, class R>
123  template <class R>
125  template <class W>
128  template <class InputMessage, class OutputMessage>
130  template <class InputMessage, class OutputMessage>
139  internal::Call* call) = 0;
140  virtual void* RegisterMethod(const char* method) = 0;
141  virtual void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
142  gpr_timespec deadline,
144  void* tag) = 0;
145  virtual bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
146  gpr_timespec deadline) = 0;
147 
148  // EXPERIMENTAL
149  // This is needed to keep codegen_test_minimal happy. InterceptedChannel needs
150  // to make use of this but can't directly call Channel's implementation
151  // because of the test.
152  // Returns an empty Call object (rather than being pure) since this is a new
153  // method and adding a new pure method to an interface would be a breaking
154  // change (even though this is private and non-API)
156  const internal::RpcMethod& /*method*/, grpc::ClientContext* /*context*/,
157  grpc::CompletionQueue* /*cq*/, size_t /*interceptor_pos*/) {
158  return internal::Call();
159  }
160 
161  // A method to get the callbackable completion queue associated with this
162  // channel. If the return value is nullptr, this channel doesn't support
163  // callback operations.
164  // TODO(vjpai): Consider a better default like using a global CQ
165  // Returns nullptr (rather than being pure) since this is a post-1.0 method
166  // and adding a new pure method to an interface would be a breaking change
167  // (even though this is private and non-API)
168  virtual grpc::CompletionQueue* CallbackCQ() { return nullptr; }
169 };
170 } // namespace grpc
171 
172 #endif // GRPCPP_IMPL_CODEGEN_CHANNEL_INTERFACE_H
grpc.Call
Definition: src/python/grpcio/grpc/__init__.py:359
GRPC_CHANNEL_READY
@ GRPC_CHANNEL_READY
Definition: include/grpc/impl/codegen/connectivity_state.h:36
grpc::ChannelInterface::CallbackCQ
virtual grpc::CompletionQueue * CallbackCQ()
Definition: grpcpp/impl/codegen/channel_interface.h:168
grpc::ChannelInterface::~ChannelInterface
virtual ~ChannelInterface()
Definition: grpcpp/impl/codegen/channel_interface.h:75
grpc
Definition: grpcpp/alarm.h:33
grpc::internal::BlockingUnaryCallImpl
Definition: grpcpp/impl/codegen/channel_interface.h:69
grpc::internal::ClientCallbackReaderWriterFactory
Definition: grpcpp/impl/codegen/channel_interface.h:47
grpc::internal::InterceptedChannel
Definition: intercepted_channel.h:37
grpc::internal::CallOpSetInterface
Definition: call_op_set_interface.h:36
grpc::internal::ClientAsyncReaderWriterFactory
Definition: grpcpp/impl/codegen/async_stream.h:486
grpc::internal::ClientCallbackWriterFactory
Definition: grpcpp/impl/codegen/channel_interface.h:51
grpc::internal::CallbackUnaryCallImpl
Definition: grpcpp/impl/codegen/channel_interface.h:38
grpc::ChannelInterface::CreateCallInternal
virtual internal::Call CreateCallInternal(const internal::RpcMethod &, grpc::ClientContext *, grpc::CompletionQueue *, size_t)
Definition: grpcpp/impl/codegen/channel_interface.h:155
grpc::internal::ClientAsyncWriterFactory
Definition: grpcpp/impl/codegen/async_stream.h:316
grpc::ChannelInterface::NotifyOnStateChange
void NotifyOnStateChange(grpc_connectivity_state last_observed, T deadline, grpc::CompletionQueue *cq, void *tag)
Definition: grpcpp/impl/codegen/channel_interface.h:83
grpc::TimePoint
Definition: include/grpcpp/impl/codegen/time.h:42
T
#define T(upbtypeconst, upbtype, ctype, default_value)
grpc_connectivity_state
grpc_connectivity_state
Definition: include/grpc/impl/codegen/connectivity_state.h:30
call
FilterStackCall * call
Definition: call.cc:750
grpc::ChannelInterface::NotifyOnStateChangeImpl
virtual void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed, gpr_timespec deadline, grpc::CompletionQueue *cq, void *tag)=0
grpc::ChannelInterface::WaitForStateChange
bool WaitForStateChange(grpc_connectivity_state last_observed, T deadline)
Definition: grpcpp/impl/codegen/channel_interface.h:92
grpc::ChannelInterface
Codegen interface for grpc::Channel.
Definition: grpcpp/impl/codegen/channel_interface.h:73
grpc::ClientReaderWriter
Definition: grpcpp/impl/codegen/channel_interface.h:35
grpc::internal::RpcMethod
Descriptor of an RPC method.
Definition: grpcpp/impl/codegen/rpc_method.h:31
tag
static void * tag(intptr_t t)
Definition: bad_client.cc:318
grpc::ChannelInterface::WaitForStateChangeImpl
virtual bool WaitForStateChangeImpl(grpc_connectivity_state last_observed, gpr_timespec deadline)=0
grpc::ChannelInterface::RegisterMethod
virtual void * RegisterMethod(const char *method)=0
connectivity_state.h
grpc::internal::ClientAsyncReaderFactory
Definition: grpcpp/impl/codegen/async_stream.h:172
grpc::ClientWriter
Definition: grpcpp/impl/codegen/channel_interface.h:33
grpc::internal::Call
Straightforward wrapping of the C call object.
Definition: include/grpcpp/impl/codegen/call.h:37
grpc::ClientContext
Definition: grpcpp/impl/codegen/client_context.h:195
grpc::internal::ClientCallbackUnaryFactory
Definition: impl/codegen/client_callback.h:1206
status.h
grpc::internal::ClientCallbackReaderFactory
Definition: grpcpp/impl/codegen/channel_interface.h:49
tests.unit._server_ssl_cert_config_test.Call
Call
Definition: _server_ssl_cert_config_test.py:70
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
grpc::experimental::DelegatingChannel
Definition: delegating_channel.h:31
time.h
internal
Definition: benchmark/test/output_test_helper.cc:20
grpc::ChannelInterface::CreateCall
virtual internal::Call CreateCall(const internal::RpcMethod &method, grpc::ClientContext *context, grpc::CompletionQueue *cq)=0
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
grpc::internal::ClientAsyncResponseReaderHelper
Definition: grpcpp/impl/codegen/async_unary_call.h:78
grpc::CompletionQueue
Definition: include/grpcpp/impl/codegen/completion_queue.h:104
gpr_timespec
Definition: gpr_types.h:50
tests.unit._exit_scenarios.try_to_connect
try_to_connect
Definition: _exit_scenarios.py:189
grpc::ChannelInterface::GetState
virtual grpc_connectivity_state GetState(bool try_to_connect)=0
method
NSString * method
Definition: ProtoMethod.h:28
grpc::ChannelInterface::WaitForConnected
bool WaitForConnected(T deadline)
Wait for this channel to be connected.
Definition: grpcpp/impl/codegen/channel_interface.h:99
grpc::TimePoint::raw_time
gpr_timespec raw_time()=delete
ops
static grpc_op ops[6]
Definition: test/core/fling/client.cc:39
grpc::ChannelInterface::PerformOpsOnCall
virtual void PerformOpsOnCall(internal::CallOpSetInterface *ops, internal::Call *call)=0
cq
static grpc_completion_queue * cq
Definition: test/core/fling/client.cc:37
grpc::ClientReader
Definition: grpcpp/impl/codegen/channel_interface.h:31
state
static struct rpc_state state
Definition: bad_server_response_test.cc:87
call.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:44