Go to the documentation of this file.
19 #ifndef GRPCPP_SERVER_H
20 #define GRPCPP_SERVER_H
47 class AsyncGenericService;
49 class ServerInitializer;
52 class ExternalConnectionAcceptorImpl;
103 return health_check_service_.get();
121 std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
122 interceptor_creators);
177 std::shared_ptr<std::vector<std::unique_ptr<ServerCompletionQueue>>>
179 int min_pollers,
int max_pollers,
int sync_cq_timeout_msec,
180 std::vector<std::shared_ptr<internal::ExternalConnectionAcceptorImpl>>
184 std::unique_ptr<experimental::ServerInterceptorFactoryInterface>>
185 interceptor_creators = std::vector<std::unique_ptr<
201 std::unique_ptr<HealthCheckServiceInterface> service) {
202 health_check_service_ = std::move(service);
207 return health_check_service_disabled_;
211 std::vector<std::unique_ptr<experimental::ServerInterceptorFactoryInterface>>*
212 interceptor_creators()
override {
213 return &interceptor_creators_;
221 class CallbackRequestBase;
222 template <
class ServerContextType>
223 class CallbackRequest;
224 class UnimplementedAsyncRequest;
225 class UnimplementedAsyncResponse;
231 class SyncRequestThreadManager;
237 #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL
238 void RegisterCallbackGenericService(CallbackGenericService* service)
override;
243 class experimental_registration_type final
251 void RegisterCallbackGenericService(
253 server_->RegisterCallbackGenericService(service);
261 void RegisterCallbackGenericService(
262 experimental::CallbackGenericService* service);
267 experimental_registration_interface* experimental_registration()
override {
268 return &experimental_registration_;
272 void PerformOpsOnCall(internal::CallOpSetInterface* ops,
273 internal::Call* call)
override;
277 int max_receive_message_size()
const override {
278 return max_receive_message_size_;
281 CompletionQueue* CallbackCQ()
override;
289 void UnrefWithPossibleNotify() ;
290 void UnrefAndWaitLocked() ;
292 std::vector<std::shared_ptr<internal::ExternalConnectionAcceptorImpl>>
300 std::vector<std::unique_ptr<experimental::ServerInterceptorFactoryInterface>>
301 interceptor_creators_;
303 int max_receive_message_size_;
308 std::shared_ptr<std::vector<std::unique_ptr<ServerCompletionQueue>>>
313 std::vector<std::unique_ptr<SyncRequestThreadManager>> sync_req_mgrs_;
315 #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
318 experimental_registration_type experimental_registration_{
this};
325 bool shutdown_notified_;
326 internal::CondVar shutdown_done_cv_;
327 bool shutdown_done_ =
false;
328 std::atomic_int shutdown_refs_outstanding_{1};
330 internal::CondVar shutdown_cv_;
332 std::shared_ptr<GlobalCallbacks> global_callbacks_;
334 std::vector<std::string> services_;
335 bool has_async_generic_service_ =
false;
336 bool has_callback_generic_service_ =
false;
337 bool has_callback_methods_ =
false;
342 std::unique_ptr<ServerInitializer> server_initializer_;
344 std::unique_ptr<HealthCheckServiceInterface> health_check_service_;
345 bool health_check_service_disabled_;
349 #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL
350 std::unique_ptr<CallbackGenericService> unimplemented_service_;
352 std::unique_ptr<experimental::CallbackGenericService> unimplemented_service_;
356 std::unique_ptr<internal::MethodHandler> resource_exhausted_handler_;
359 std::unique_ptr<internal::MethodHandler> generic_handler_;
365 CompletionQueue* callback_cq_ =
nullptr;
370 std::vector<CompletionQueue*> cq_list_;
375 #endif // GRPCPP_SERVER_H
Classes that require gRPC to be initialized should inherit from this class.
Definition: grpc_library.h:38
std::shared_ptr< Channel > InProcessChannel(const ChannelArguments &args)
Establish a channel for in-process communication.
A ServerContext or CallbackServerContext allows the code implementing a service handler to:
Definition: server_context.h:527
Represents a gRPC server.
Definition: server.h:59
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
struct grpc_resource_quota grpc_resource_quota
Definition: grpc_types.h:691
bool health_check_service_disabled() const
NOTE: This method is not part of the public API for this class.
Definition: server.h:206
Definition: server_initializer.h:31
virtual void PostSynchronousRequest(ServerContext *context)=0
Called after application callback for each synchronous server request.
The gRPC server uses this interface to expose the health checking service without depending on protob...
Definition: health_check_service_interface.h:31
Wrapper around grpc_server_credentials, a way to authenticate a server.
Definition: server_credentials.h:62
experimental_type(Server *server)
Definition: server.h:114
virtual void PreSynchronousRequest(ServerContext *context)=0
Called before application callback for each synchronous server request.
void Start(ServerCompletionQueue **cqs, size_t num_cqs) override
Start the server.
Desriptor of an RPC service and its various RPC methods.
Definition: service_type.h:56
void Wait() override
Block until the server shuts down.
virtual void AddPort(Server *, const std::string &, ServerCredentials *, int)
Called after a server port is added.
Definition: server.h:87
virtual ~GlobalCallbacks()
Definition: server.h:77
Options for channel creation.
Definition: channel_arguments.h:39
friend class ServerInitializer
Definition: server.h:218
bool RegisterService(const std::string *host, Service *service) override
Register a service.
int AddListeningPort(const std::string &addr, ServerCredentials *creds) override
Try binding the server to the given addr endpoint (port, and optionally including IP address to bind ...
NOTE: class experimental_registration_interface is not part of the public API of this class TODO(vjpa...
Definition: server_interface.h:144
struct grpc_server grpc_server
A server listens to some port and responds to request calls.
Definition: grpc_types.h:65
grpc_server * server() override
Definition: server.h:196
virtual void UpdateArguments(ChannelArguments *)
Called before server is created.
Definition: server.h:79
CallbackGenericService is the base class for generic services implemented using the callback API and ...
Definition: async_generic_service.h:106
virtual void PreServerStart(Server *)
Called before server is started.
Definition: server.h:85
Definition: async_generic_service.h:68
NOTE: class experimental_type is not part of the public API of this class.
Definition: server.h:112
Definition: server_interceptor.h:43
HealthCheckServiceInterface * GetHealthCheckService() const
Returns the health check service.
Definition: server.h:102
std::shared_ptr< Channel > InProcessChannelWithInterceptors(const ChannelArguments &args, std::vector< std::unique_ptr< experimental::ClientInterceptorFactoryInterface >> interceptor_creators)
Establish a channel for in-process communication with client interceptors.
Server(ChannelArguments *args, std::shared_ptr< std::vector< std::unique_ptr< ServerCompletionQueue >>> sync_server_cqs, int min_pollers, int max_pollers, int sync_cq_timeout_msec, std::vector< std::shared_ptr< internal::ExternalConnectionAcceptorImpl >> acceptors, grpc_resource_quota *server_rq=nullptr, std::vector< std::unique_ptr< experimental::ServerInterceptorFactoryInterface >> interceptor_creators=std::vector< std::unique_ptr< experimental::ServerInterceptorFactoryInterface >>())
NOTE: This is NOT a public API.
A specific type of completion queue used by the processing of notifications by servers.
Definition: completion_queue.h:418
static void SetGlobalCallbacks(GlobalCallbacks *callbacks)
Set the global callback object.
grpc_server * c_server()
Returns a raw pointer to the underlying grpc_server instance.
void set_health_check_service(std::unique_ptr< HealthCheckServiceInterface > service)
NOTE: This method is not part of the public API for this class.
Definition: server.h:200
A builder class for the creation and startup of grpc::Server instances.
Definition: server_builder.h:90
Definition: server_interface.h:65
Analogous to struct timespec.
Definition: gpr_types.h:47
Global callbacks are a set of hooks that are called when server events occur.
Definition: server.h:75
experimental_type experimental()
NOTE: The function experimental() is not stable public API.
Definition: server.h:131