34 #ifndef GRPCXX_SERVER_H
35 #define GRPCXX_SERVER_H
48 #include <grpc/compression.h>
54 class AsynchronousService;
55 class GenericServerContext;
56 class AsyncGenericService;
58 class RpcServiceMethod;
59 class ServerAsyncStreamingInterface;
61 class ThreadPoolInterface;
81 void Shutdown() { ShutdownInternal(gpr_inf_future(GPR_CLOCK_MONOTONIC)); }
113 class ShutdownRequest;
121 Server(ThreadPoolInterface* thread_pool,
bool thread_pool_owned,
160 void HandleQueueClosed();
166 void ScheduleCallback();
170 void ShutdownInternal(gpr_timespec deadline);
177 bool delete_on_finalize);
178 virtual ~BaseAsyncRequest();
188 const bool delete_on_finalize_;
190 grpc_metadata_array initial_metadata_array_;
193 class RegisteredAsyncRequest :
public BaseAsyncRequest {
202 void IssueRequest(
void* registered_method, grpc_byte_buffer** payload,
206 class NoPayloadAsyncRequest
GRPC_FINAL :
public RegisteredAsyncRequest {
208 NoPayloadAsyncRequest(
void* registered_method, Server* server,
209 ServerContext* context,
210 ServerAsyncStreamingInterface* stream,
211 CompletionQueue* call_cq,
212 ServerCompletionQueue* notification_cq,
void* tag)
213 : RegisteredAsyncRequest(server, context, stream, call_cq, tag) {
214 IssueRequest(registered_method,
nullptr, notification_cq);
220 template <
class Message>
221 class PayloadAsyncRequest
GRPC_FINAL :
public RegisteredAsyncRequest {
223 PayloadAsyncRequest(
void* registered_method, Server* server,
224 ServerContext* context,
225 ServerAsyncStreamingInterface* stream,
226 CompletionQueue* call_cq,
227 ServerCompletionQueue* notification_cq,
void* tag,
229 : RegisteredAsyncRequest(server, context, stream, call_cq, tag),
231 IssueRequest(registered_method, &payload_, notification_cq);
234 bool FinalizeResult(
void** tag,
bool* status)
GRPC_OVERRIDE {
235 bool serialization_status =
236 *status && payload_ &&
237 SerializationTraits<Message>::Deserialize(
238 payload_, request_, server_->max_message_size_).ok();
239 bool ret = RegisteredAsyncRequest::FinalizeResult(tag, status);
240 *status = serialization_status&&* status;
245 grpc_byte_buffer* payload_;
249 class GenericAsyncRequest :
public BaseAsyncRequest {
251 GenericAsyncRequest(Server* server, GenericServerContext* context,
252 ServerAsyncStreamingInterface* stream,
253 CompletionQueue* call_cq,
254 ServerCompletionQueue* notification_cq,
void* tag,
255 bool delete_on_finalize);
260 grpc_call_details call_details_;
263 class UnimplementedAsyncRequestContext;
264 class UnimplementedAsyncRequest;
265 class UnimplementedAsyncResponse;
267 template <
class Message>
268 void RequestAsyncCall(
void* registered_method, ServerContext* context,
269 ServerAsyncStreamingInterface* stream,
270 CompletionQueue* call_cq,
271 ServerCompletionQueue* notification_cq,
void* tag,
273 new PayloadAsyncRequest<Message>(registered_method,
this, context, stream,
274 call_cq, notification_cq, tag, message);
277 void RequestAsyncCall(
void* registered_method, ServerContext* context,
278 ServerAsyncStreamingInterface* stream,
279 CompletionQueue* call_cq,
280 ServerCompletionQueue* notification_cq,
void* tag) {
281 new NoPayloadAsyncRequest(registered_method,
this, context, stream, call_cq,
282 notification_cq, tag);
285 void RequestAsyncGenericCall(GenericServerContext* context,
286 ServerAsyncStreamingInterface* stream,
287 CompletionQueue* call_cq,
288 ServerCompletionQueue* notification_cq,
290 new GenericAsyncRequest(
this, context, stream, call_cq, notification_cq,
294 const int max_message_size_;
307 std::list<SyncRequest>* sync_methods_;
308 std::unique_ptr<RpcServiceMethod> unknown_method_;
309 bool has_generic_service_;
312 grpc_server*
const server_;
314 ThreadPoolInterface* thread_pool_;
316 bool thread_pool_owned_;
321 #endif // GRPCXX_SERVER_H
An interface allowing implementors to process and filter event tags.
Definition: completion_queue.h:192
void Shutdown()
Shutdown the server, waiting for all rpc processing to finish.
Definition: server.h:81
std::string string
Definition: config.h:112
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call.h:477
Definition: service_type.h:68
Options for channel creation.
Definition: channel_arguments.h:52
void Shutdown(const T &deadline)
Shutdown the server, blocking until all rpc processing finishes.
Definition: server.h:76
Definition: sync_no_cxx11.h:45
Definition: service_type.h:57
virtual ~GlobalCallbacks()
Definition: server.h:95
#define GRPC_FINAL
Definition: config.h:71
Definition: async_generic_service.h:59
static void SetGlobalCallbacks(GlobalCallbacks *callbacks)
Set the global callback object.
Definition: sync_no_cxx11.h:87
virtual void PreSynchronousRequest(ServerContext *context)=0
Called before application callback for each synchronous server request.
Definition: grpc_library.h:41
Definition: rpc_service_method.h:249
Definition: server_credentials.h:49
Models a gRPC server.
Definition: server.h:66
void Wait()
Block waiting for all work to complete.
Definition: server_context.h:89
A thin wrapper around grpc_completion_queue (see / src/core/surface/completion_queue.h).
Definition: completion_queue.h:81
Global Callbacks.
Definition: server.h:93
A specific type of completion queue used by the processing of notifications by servers.
Definition: completion_queue.h:204
virtual void PostSynchronousRequest(ServerContext *context)=0
Called after application callback for each synchronous server request.
#define GRPC_OVERRIDE
Definition: config.h:77
A builder class for the creation and startup of grpc::Server instances.
Definition: server_builder.h:57
::google::protobuf::Message Message
Definition: config_protobuf.h:60