grpcpp/impl/codegen/server_interface.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 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_SERVER_INTERFACE_H
20 #define GRPCPP_IMPL_CODEGEN_SERVER_INTERFACE_H
21 
22 // IWYU pragma: private
23 
25 
35 
36 namespace grpc {
37 
38 class AsyncGenericService;
39 class Channel;
40 class CompletionQueue;
41 class GenericServerContext;
42 class ServerCompletionQueue;
43 class ServerCredentials;
44 class Service;
45 
46 extern CoreCodegenInterface* g_core_codegen_interface;
47 
51 namespace internal {
52 class ServerAsyncStreamingInterface;
53 } // namespace internal
54 
55 class CallbackGenericService;
56 
57 namespace experimental {
58 class ServerInterceptorFactoryInterface;
59 } // namespace experimental
60 
62  public:
63  ~ServerInterface() override {}
64 
97  template <class T>
98  void Shutdown(const T& deadline) {
99  ShutdownInternal(TimePoint<T>(deadline).raw_time());
100  }
101 
107  void Shutdown() {
110  }
111 
116  virtual void Wait() = 0;
117 
118  protected:
119  friend class grpc::Service;
120 
123  virtual bool RegisterService(const std::string* host, Service* service) = 0;
124 
128 
132 
134  /*service*/) {}
135 
147  virtual int AddListeningPort(const std::string& addr,
148  ServerCredentials* creds) = 0;
149 
156  virtual void Start(grpc::ServerCompletionQueue** cqs, size_t num_cqs) = 0;
157 
158  virtual void ShutdownInternal(gpr_timespec deadline) = 0;
159 
160  virtual int max_receive_message_size() const = 0;
161 
162  virtual grpc_server* server() = 0;
163 
165  internal::Call* call) override = 0;
166 
168  public:
171  grpc::CompletionQueue* call_cq,
172  grpc::ServerCompletionQueue* notification_cq, void* tag,
173  bool delete_on_finalize);
174  ~BaseAsyncRequest() override;
175 
176  bool FinalizeResult(void** tag, bool* status) override;
177 
178  private:
180 
181  protected:
187  void* const tag_;
193  };
194 
197  public:
201  grpc::CompletionQueue* call_cq,
202  grpc::ServerCompletionQueue* notification_cq,
203  void* tag, const char* name,
205 
206  bool FinalizeResult(void** tag, bool* status) override {
207  /* If we are done intercepting, then there is nothing more for us to do */
208  if (done_intercepting_) {
210  }
216  }
217 
218  protected:
219  void IssueRequest(void* registered_method, grpc_byte_buffer** payload,
220  grpc::ServerCompletionQueue* notification_cq);
221  const char* name_;
223  };
224 
226  public:
230  grpc::CompletionQueue* call_cq,
231  grpc::ServerCompletionQueue* notification_cq,
232  void* tag)
234  server, context, stream, call_cq, notification_cq, tag,
235  registered_method->name(), registered_method->method_type()) {
236  IssueRequest(registered_method->server_tag(), nullptr, notification_cq);
237  }
238 
239  // uses RegisteredAsyncRequest::FinalizeResult
240  };
241 
242  template <class Message>
244  public:
248  grpc::CompletionQueue* call_cq,
249  grpc::ServerCompletionQueue* notification_cq, void* tag,
250  Message* request)
252  server, context, stream, call_cq, notification_cq, tag,
253  registered_method->name(), registered_method->method_type()),
254  registered_method_(registered_method),
255  request_(request) {
256  IssueRequest(registered_method->server_tag(), payload_.bbuf_ptr(),
257  notification_cq);
258  }
259 
260  ~PayloadAsyncRequest() override {
261  payload_.Release(); // We do not own the payload_
262  }
263 
264  bool FinalizeResult(void** tag, bool* status) override {
265  /* If we are done intercepting, then there is nothing more for us to do */
266  if (done_intercepting_) {
268  }
269  if (*status) {
272  .ok()) {
273  // If deserialization fails, we cancel the call and instantiate
274  // a new instance of ourselves to request another call. We then
275  // return false, which prevents the call from being returned to
276  // the application.
278  call_, GRPC_STATUS_INTERNAL, "Unable to parse request", nullptr);
282  request_);
283  delete this;
284  return false;
285  }
286  }
287  /* Set interception point for recv message */
292  }
293 
294  private:
298  };
299 
301  public:
304  grpc::CompletionQueue* call_cq,
305  grpc::ServerCompletionQueue* notification_cq, void* tag,
306  bool delete_on_finalize);
307 
308  bool FinalizeResult(void** tag, bool* status) override;
309 
310  private:
312  };
313 
314  template <class Message>
318  grpc::CompletionQueue* call_cq,
319  grpc::ServerCompletionQueue* notification_cq, void* tag,
320  Message* message) {
322  new PayloadAsyncRequest<Message>(method, this, context, stream, call_cq,
323  notification_cq, tag, message);
324  }
325 
329  grpc::CompletionQueue* call_cq,
330  grpc::ServerCompletionQueue* notification_cq,
331  void* tag) {
333  new NoPayloadAsyncRequest(method, this, context, stream, call_cq,
334  notification_cq, tag);
335  }
336 
339  grpc::CompletionQueue* call_cq,
340  grpc::ServerCompletionQueue* notification_cq,
341  void* tag) {
342  new GenericAsyncRequest(this, context, stream, call_cq, notification_cq,
343  tag, true);
344  }
345 
346  private:
347  // EXPERIMENTAL
348  // Getter method for the vector of interceptor factory objects.
349  // Returns a nullptr (rather than being pure) since this is a post-1.0 method
350  // and adding a new pure method to an interface would be a breaking change
351  // (even though this is private and non-API)
352  virtual std::vector<
353  std::unique_ptr<experimental::ServerInterceptorFactoryInterface>>*
355  return nullptr;
356  }
357 
358  // A method to get the callbackable completion queue associated with this
359  // server. If the return value is nullptr, this server doesn't support
360  // callback operations.
361  // TODO(vjpai): Consider a better default like using a global CQ
362  // Returns nullptr (rather than being pure) since this is a post-1.0 method
363  // and adding a new pure method to an interface would be a breaking change
364  // (even though this is private and non-API)
365  virtual grpc::CompletionQueue* CallbackCQ() { return nullptr; }
366 };
367 
368 } // namespace grpc
369 
370 #endif // GRPCPP_IMPL_CODEGEN_SERVER_INTERFACE_H
grpc::ServerInterface::RegisteredAsyncRequest::RegisteredAsyncRequest
RegisteredAsyncRequest(ServerInterface *server, grpc::ServerContext *context, internal::ServerAsyncStreamingInterface *stream, grpc::CompletionQueue *call_cq, grpc::ServerCompletionQueue *notification_cq, void *tag, const char *name, internal::RpcMethod::RpcType type)
Definition: server_cc.cc:228
grpc::status
auto status
Definition: cpp/client/credentials_test.cc:200
grpc::internal::CallHook
Definition: grpcpp/impl/codegen/call_hook.h:32
grpc::ServerCompletionQueue
Definition: include/grpcpp/impl/codegen/completion_queue.h:436
grpc::AsyncGenericService
Definition: grpcpp/impl/codegen/async_generic_service.h:70
grpc::ServerContext
Definition: grpcpp/impl/codegen/server_context.h:566
grpc::internal::InterceptorBatchMethodsImpl::SetRecvMessage
void SetRecvMessage(void *message, bool *hijacked_recv_message_failed)
Definition: interceptor_common.h:169
grpc::ServerInterface::~ServerInterface
~ServerInterface() override
Definition: grpcpp/impl/codegen/server_interface.h:63
rpc_service_method.h
grpc
Definition: grpcpp/alarm.h:33
interceptor_common.h
grpc::experimental::InterceptionHookPoints::POST_RECV_MESSAGE
@ POST_RECV_MESSAGE
grpc_call_details
Definition: grpc_types.h:585
grpc::ServerInterface::BaseAsyncRequest::done_intercepting_
bool done_intercepting_
Definition: grpcpp/impl/codegen/server_interface.h:192
grpc::ServerInterface::BaseAsyncRequest::FinalizeResult
bool FinalizeResult(void **tag, bool *status) override
Definition: server_cc.cc:170
benchmark.request
request
Definition: benchmark.py:77
grpc::internal::CallOpSetInterface
Definition: call_op_set_interface.h:36
grpc::CoreCodegenInterface::grpc_call_cancel_with_status
virtual grpc_call_error grpc_call_cancel_with_status(grpc_call *call, grpc_status_code status, const char *description, void *reserved)=0
grpc::CoreCodegenInterface::gpr_inf_future
virtual gpr_timespec gpr_inf_future(gpr_clock_type type)=0
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc::internal::InterceptorBatchMethodsImpl
Definition: interceptor_common.h:37
grpc::GenericServerContext
Definition: grpcpp/impl/codegen/async_generic_service.h:41
grpc::ServerInterface::RegisteredAsyncRequest::type_
const internal::RpcMethod::RpcType type_
Definition: grpcpp/impl/codegen/server_interface.h:222
core_codegen_interface.h
setup.name
name
Definition: setup.py:542
method_type
zend_class_entry * method_type
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/message.c:2232
grpc::ServerInterface::BaseAsyncRequest::context_
grpc::ServerContext *const context_
Definition: grpcpp/impl/codegen/server_interface.h:183
grpc::TimePoint
Definition: include/grpcpp/impl/codegen/time.h:42
grpc::internal::InterceptorBatchMethodsImpl::AddInterceptionHookPoint
void AddInterceptionHookPoint(experimental::InterceptionHookPoints type)
Definition: interceptor_common.h:79
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
T
#define T(upbtypeconst, upbtype, ctype, default_value)
grpc::ByteBuffer::Release
void Release()
Definition: include/grpcpp/impl/codegen/byte_buffer.h:147
grpc::ServerInterface::RegisteredAsyncRequest::name_
const char * name_
Definition: grpcpp/impl/codegen/server_interface.h:221
grpc::ServerInterface::max_receive_message_size
virtual int max_receive_message_size() const =0
call
FilterStackCall * call
Definition: call.cc:750
grpc::ServerInterface::RequestAsyncGenericCall
void RequestAsyncGenericCall(GenericServerContext *context, internal::ServerAsyncStreamingInterface *stream, grpc::CompletionQueue *call_cq, grpc::ServerCompletionQueue *notification_cq, void *tag)
Definition: grpcpp/impl/codegen/server_interface.h:337
grpc::internal::RpcServiceMethod::server_tag
void * server_tag() const
Definition: grpcpp/impl/codegen/rpc_service_method.h:105
grpc::Service
Desriptor of an RPC service and its various RPC methods.
Definition: grpcpp/impl/codegen/service_type.h:58
grpc::ServerInterface::PerformOpsOnCall
void PerformOpsOnCall(internal::CallOpSetInterface *ops, internal::Call *call) override=0
grpc_types.h
grpc::ServerInterface::BaseAsyncRequest::notification_cq_
grpc::ServerCompletionQueue *const notification_cq_
Definition: grpcpp/impl/codegen/server_interface.h:186
grpc::ServerInterface::Shutdown
void Shutdown(const T &deadline)
Definition: grpcpp/impl/codegen/server_interface.h:98
grpc::SerializationTraits
Definition: grpcpp/impl/codegen/serialization_traits.h:60
grpc::ServerInterface::PayloadAsyncRequest::~PayloadAsyncRequest
~PayloadAsyncRequest() override
Definition: grpcpp/impl/codegen/server_interface.h:260
grpc::ServerInterface::GenericAsyncRequest::call_details_
grpc_call_details call_details_
Definition: grpcpp/impl/codegen/server_interface.h:311
grpc::ByteBuffer::Valid
bool Valid() const
Is this ByteBuffer valid?
Definition: include/grpcpp/impl/codegen/byte_buffer.h:164
grpc::g_core_codegen_interface
CoreCodegenInterface * g_core_codegen_interface
Definition: include/grpcpp/impl/codegen/completion_queue.h:98
framework.rpc.grpc_channelz.Channel
Channel
Definition: grpc_channelz.py:32
grpc::internal::RpcServiceMethod
Server side rpc method class.
Definition: grpcpp/impl/codegen/rpc_service_method.h:86
grpc::ServerInterface::PayloadAsyncRequest::request_
Message *const request_
Definition: grpcpp/impl/codegen/server_interface.h:296
grpc::ServerInterface::Shutdown
void Shutdown()
Definition: grpcpp/impl/codegen/server_interface.h:107
tag
static void * tag(intptr_t t)
Definition: bad_client.cc:318
grpc::ServerInterface::PayloadAsyncRequest::FinalizeResult
bool FinalizeResult(void **tag, bool *status) override
Definition: grpcpp/impl/codegen/server_interface.h:264
grpc::ServerInterface::BaseAsyncRequest::call_
grpc_call * call_
Definition: grpcpp/impl/codegen/server_interface.h:189
grpc::ServerInterface::RequestAsyncCall
void RequestAsyncCall(internal::RpcServiceMethod *method, grpc::ServerContext *context, internal::ServerAsyncStreamingInterface *stream, grpc::CompletionQueue *call_cq, grpc::ServerCompletionQueue *notification_cq, void *tag)
Definition: grpcpp/impl/codegen/server_interface.h:326
grpc::ServerCredentials
Wrapper around grpc_server_credentials, a way to authenticate a server.
Definition: include/grpcpp/security/server_credentials.h:76
grpc_call
struct grpc_call grpc_call
Definition: grpc_types.h:70
grpc_byte_buffer
Definition: grpc_types.h:43
grpc::ServerInterface::RegisterCallbackGenericService
virtual void RegisterCallbackGenericService(CallbackGenericService *)
Definition: grpcpp/impl/codegen/server_interface.h:133
grpc::ServerInterface::BaseAsyncRequest::call_wrapper_
internal::Call call_wrapper_
Definition: grpcpp/impl/codegen/server_interface.h:190
completion_queue_tag.h
grpc::ServerInterface::BaseAsyncRequest::stream_
internal::ServerAsyncStreamingInterface *const stream_
Definition: grpcpp/impl/codegen/server_interface.h:184
grpc::ServerInterface::PayloadAsyncRequest::payload_
ByteBuffer payload_
Definition: grpcpp/impl/codegen/server_interface.h:297
grpc::ByteBuffer
A sequence of bytes.
Definition: include/grpcpp/impl/codegen/byte_buffer.h:61
GPR_CLOCK_MONOTONIC
@ GPR_CLOCK_MONOTONIC
Definition: gpr_types.h:36
grpc_server
struct grpc_server grpc_server
Definition: grpc_types.h:65
grpc::ServerInterface::GenericAsyncRequest::GenericAsyncRequest
GenericAsyncRequest(ServerInterface *server, GenericServerContext *context, internal::ServerAsyncStreamingInterface *stream, grpc::CompletionQueue *call_cq, grpc::ServerCompletionQueue *notification_cq, void *tag, bool delete_on_finalize)
Definition: server_cc.cc:250
grpc::ServerInterface
Definition: grpcpp/impl/codegen/server_interface.h:61
grpc::ServerInterface::CallbackCQ
virtual grpc::CompletionQueue * CallbackCQ()
Definition: grpcpp/impl/codegen/server_interface.h:365
grpc::ServerInterface::ShutdownInternal
virtual void ShutdownInternal(gpr_timespec deadline)=0
byte_buffer.h
grpc::ServerInterface::interceptor_creators
virtual std::vector< std::unique_ptr< experimental::ServerInterceptorFactoryInterface > > * interceptor_creators()
Definition: grpcpp/impl/codegen/server_interface.h:354
grpc::ServerInterface::NoPayloadAsyncRequest::NoPayloadAsyncRequest
NoPayloadAsyncRequest(internal::RpcServiceMethod *registered_method, ServerInterface *server, grpc::ServerContext *context, internal::ServerAsyncStreamingInterface *stream, grpc::CompletionQueue *call_cq, grpc::ServerCompletionQueue *notification_cq, void *tag)
Definition: grpcpp/impl/codegen/server_interface.h:227
grpc::internal::Call
Straightforward wrapping of the C call object.
Definition: include/grpcpp/impl/codegen/call.h:37
grpc::internal::RpcMethod::RpcType
RpcType
Definition: grpcpp/impl/codegen/rpc_method.h:33
grpc::CallbackGenericService
Definition: grpcpp/impl/codegen/async_generic_service.h:104
grpc::ServerInterface::BaseAsyncRequest::interceptor_methods_
internal::InterceptorBatchMethodsImpl interceptor_methods_
Definition: grpcpp/impl/codegen/server_interface.h:191
grpc::internal::ServerAsyncStreamingInterface
Definition: grpcpp/impl/codegen/service_type.h:39
grpc::ServerInterface::Wait
virtual void Wait()=0
grpc::ServerInterface::BaseAsyncRequest
Definition: grpcpp/impl/codegen/server_interface.h:167
grpc::ServerInterface::BaseAsyncRequest::delete_on_finalize_
const bool delete_on_finalize_
Definition: grpcpp/impl/codegen/server_interface.h:188
grpc::ServerInterface::BaseAsyncRequest::ContinueFinalizeResultAfterInterception
void ContinueFinalizeResultAfterInterception()
Definition: server_cc.cc:217
grpc::ServerInterface::NoPayloadAsyncRequest
Definition: grpcpp/impl/codegen/server_interface.h:225
server
Definition: examples/python/async_streaming/server.py:1
tests.unit._server_ssl_cert_config_test.Call
Call
Definition: _server_ssl_cert_config_test.py:70
grpc::ServerInterface::BaseAsyncRequest::server_
ServerInterface *const server_
Definition: grpcpp/impl/codegen/server_interface.h:182
port_platform.h
grpc::ServerInterface::server
virtual grpc_server * server()=0
grpc::ServerInterface::RegisterAsyncGenericService
virtual void RegisterAsyncGenericService(AsyncGenericService *service)=0
server_context.h
grpc::ServerInterface::BaseAsyncRequest::~BaseAsyncRequest
~BaseAsyncRequest() override
Definition: server_cc.cc:166
call_hook.h
grpc::ServerInterface::BaseAsyncRequest::BaseAsyncRequest
BaseAsyncRequest(ServerInterface *server, grpc::ServerContext *context, internal::ServerAsyncStreamingInterface *stream, grpc::CompletionQueue *call_cq, grpc::ServerCompletionQueue *notification_cq, void *tag, bool delete_on_finalize)
Definition: server_cc.cc:145
grpc::ServerInterface::GenericAsyncRequest::FinalizeResult
bool FinalizeResult(void **tag, bool *status) override
Definition: server_cc.cc:267
GPR_CODEGEN_ASSERT
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: grpcpp/impl/codegen/core_codegen_interface.h:151
grpc::ServerInterface::BaseAsyncRequest::call_cq_
grpc::CompletionQueue *const call_cq_
Definition: grpcpp/impl/codegen/server_interface.h:185
grpc::ServerInterface::BaseAsyncRequest::tag_
void *const tag_
Definition: grpcpp/impl/codegen/server_interface.h:187
GRPC_STATUS_INTERNAL
@ GRPC_STATUS_INTERNAL
Definition: include/grpc/impl/codegen/status.h:129
internal
Definition: benchmark/test/output_test_helper.cc:20
grpc::ServerInterface::PayloadAsyncRequest::PayloadAsyncRequest
PayloadAsyncRequest(internal::RpcServiceMethod *registered_method, ServerInterface *server, grpc::ServerContext *context, internal::ServerAsyncStreamingInterface *stream, grpc::CompletionQueue *call_cq, grpc::ServerCompletionQueue *notification_cq, void *tag, Message *request)
Definition: grpcpp/impl/codegen/server_interface.h:245
grpc::ServerInterface::RegisterService
virtual bool RegisterService(const std::string *host, Service *service)=0
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
grpc::ServerInterface::PayloadAsyncRequest
Definition: grpcpp/impl/codegen/server_interface.h:243
grpc::CompletionQueue
Definition: include/grpcpp/impl/codegen/completion_queue.h:104
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
grpc.beta.implementations.ServerCredentials
ServerCredentials
Definition: implementations.py:231
gpr_timespec
Definition: gpr_types.h:50
service
__attribute__((deprecated("Please use GRPCProtoMethod."))) @interface ProtoMethod NSString * service
Definition: ProtoMethod.h:25
grpc::internal::CompletionQueueTag
An interface allowing implementors to process and filter event tags.
Definition: grpcpp/impl/codegen/completion_queue_tag.h:28
grpc::ServerInterface::RequestAsyncCall
void RequestAsyncCall(internal::RpcServiceMethod *method, grpc::ServerContext *context, internal::ServerAsyncStreamingInterface *stream, grpc::CompletionQueue *call_cq, grpc::ServerCompletionQueue *notification_cq, void *tag, Message *message)
Definition: grpcpp/impl/codegen/server_interface.h:315
grpc::ServerInterface::Start
virtual void Start(grpc::ServerCompletionQueue **cqs, size_t num_cqs)=0
grpc::ServerInterface::RegisteredAsyncRequest::IssueRequest
void IssueRequest(void *registered_method, grpc_byte_buffer **payload, grpc::ServerCompletionQueue *notification_cq)
Definition: server_cc.cc:238
grpc::ServerInterface::PayloadAsyncRequest::registered_method_
internal::RpcServiceMethod *const registered_method_
Definition: grpcpp/impl/codegen/server_interface.h:295
method
NSString * method
Definition: ProtoMethod.h:28
grpc::ServerContextBase::set_server_rpc_info
grpc::experimental::ServerRpcInfo * set_server_rpc_info(const char *method, grpc::internal::RpcMethod::RpcType type, const std::vector< std::unique_ptr< grpc::experimental::ServerInterceptorFactoryInterface >> &creators)
Definition: grpcpp/impl/codegen/server_context.h:429
gen_server_registered_method_bad_client_test_body.payload
list payload
Definition: gen_server_registered_method_bad_client_test_body.py:40
ops
static grpc_op ops[6]
Definition: test/core/fling/client.cc:39
addr
struct sockaddr_in addr
Definition: libuv/docs/code/tcp-echo-server/main.c:10
grpc::CoreCodegenInterface::grpc_call_unref
virtual void grpc_call_unref(grpc_call *call)=0
grpc::ServerInterface::AddListeningPort
virtual int AddListeningPort(const std::string &addr, ServerCredentials *creds)=0
Message
Definition: protobuf/php/ext/google/protobuf/message.c:53
grpc::ByteBuffer::bbuf_ptr
ByteBufferPointer bbuf_ptr() const
Definition: include/grpcpp/impl/codegen/byte_buffer.h:219
grpc::ServerInterface::GenericAsyncRequest
Definition: grpcpp/impl/codegen/server_interface.h:300
call.h
grpc::ServerInterface::RegisteredAsyncRequest::FinalizeResult
bool FinalizeResult(void **tag, bool *status) override
Definition: grpcpp/impl/codegen/server_interface.h:206
grpc::ServerInterface::RegisteredAsyncRequest
RegisteredAsyncRequest is not part of the C++ API.
Definition: grpcpp/impl/codegen/server_interface.h:196
stream
voidpf stream
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:17