Go to the documentation of this file.
19 #ifndef GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_H
20 #define GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_H
26 #include <type_traits>
53 template <
class W,
class R>
54 class ServerAsyncReader;
56 class ServerAsyncWriter;
58 class ServerAsyncResponseWriter;
59 template <
class W,
class R>
60 class ServerAsyncReaderWriter;
67 template <
class ServiceType,
class RequestType,
class ResponseType>
68 class BidiStreamingHandler;
69 template <
class RequestType,
class ResponseType>
70 class CallbackUnaryHandler;
71 template <
class RequestType,
class ResponseType>
72 class CallbackClientStreamingHandler;
73 template <
class RequestType,
class ResponseType>
74 class CallbackServerStreamingHandler;
75 template <
class RequestType,
class ResponseType>
76 class CallbackBidiHandler;
77 template <
class ServiceType,
class RequestType,
class ResponseType>
78 class ClientStreamingHandler;
79 template <
class ResponseType>
82 template <
class ServiceType,
class RequestType,
class ResponseType,
83 class BaseRequestType,
class BaseResponseType>
84 class RpcMethodHandler;
86 class FinishOnlyReactor;
87 template <
class W,
class R>
88 class ServerReaderWriterBody;
89 template <
class ServiceType,
class RequestType,
class ResponseType>
90 class ServerStreamingHandler;
92 template <
class Streamer,
bool WriteNeeded>
93 class TemplatedBidiStreamingHandler;
94 template <::grpc::StatusCode code>
95 class ErrorMethodHandler;
99 class CompletionQueue;
100 class GenericServerContext;
102 class ServerInterface;
103 class ContextAllocator;
106 namespace experimental {
113 #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
114 namespace experimental {
116 class GenericCallbackServerContext;
117 #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
125 class InteropServerContextInspector;
126 class ServerContextTestSpouse;
127 class DefaultReactorTestPeer;
136 std::chrono::system_clock::time_point
deadline()
const {
229 return *client_metadata_.
map();
234 return compression_level_;
241 compression_level_set_ =
true;
242 compression_level_ = level;
255 return compression_algorithm_;
269 if (auth_context_ ==
nullptr) {
272 return auth_context_;
279 std::string
peer()
const;
295 has_notify_when_done_tag_ =
true;
296 async_notify_when_done_tag_ = tag;
304 return message_allocator_state_;
326 if (test_unary_ !=
nullptr) {
327 return reinterpret_cast<Reactor*
>(&default_reactor_);
329 new (&default_reactor_) Reactor;
332 assert(default_reactor_used_.compare_exchange_strong(
333 old,
true, std::memory_order_relaxed));
335 default_reactor_used_.store(
true, std::memory_order_relaxed);
337 return reinterpret_cast<Reactor*
>(&default_reactor_);
351 friend class ::grpc::testing::InteropServerContextInspector;
352 friend class ::grpc::testing::ServerContextTestSpouse;
353 friend class ::grpc::testing::DefaultReactorTestPeer;
354 friend class ::grpc::ServerInterface;
355 friend class ::grpc::Server;
356 template <
class W,
class R>
357 friend class ::grpc::ServerAsyncReader;
359 friend class ::grpc::ServerAsyncWriter;
361 friend class ::grpc::ServerAsyncResponseWriter;
362 template <
class W,
class R>
363 friend class ::grpc::ServerAsyncReaderWriter;
365 friend class ::grpc::ServerReader;
367 friend class ::grpc::ServerWriter;
368 template <
class W,
class R>
369 friend class ::grpc::internal::ServerReaderWriterBody;
370 template <
class ResponseType>
374 template <
class ServiceType,
class RequestType,
class ResponseType,
375 class BaseRequestType,
class BaseResponseType>
376 friend class ::grpc::internal::RpcMethodHandler;
377 template <
class ServiceType,
class RequestType,
class ResponseType>
378 friend class ::grpc::internal::ClientStreamingHandler;
379 template <
class ServiceType,
class RequestType,
class ResponseType>
380 friend class ::grpc::internal::ServerStreamingHandler;
381 template <
class Streamer,
bool WriteNeeded>
382 friend class ::grpc::internal::TemplatedBidiStreamingHandler;
383 template <
class RequestType,
class ResponseType>
384 friend class ::grpc::internal::CallbackUnaryHandler;
385 template <
class RequestType,
class ResponseType>
386 friend class ::grpc::internal::CallbackClientStreamingHandler;
387 template <
class RequestType,
class ResponseType>
388 friend class ::grpc::internal::CallbackServerStreamingHandler;
389 template <
class RequestType,
class ResponseType>
390 friend class ::grpc::internal::CallbackBidiHandler;
391 template <::grpc::StatusCode code>
392 friend class ::grpc::internal::ErrorMethodHandler;
393 template <
class Base>
394 friend class ::grpc::internal::FinishOnlyReactor;
395 friend class ::grpc::ClientContext;
396 friend class ::grpc::GenericServerContext;
397 #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL
398 friend class ::grpc::GenericCallbackServerContext;
400 friend class ::grpc::experimental::GenericCallbackServerContext;
409 void BeginCompletionOp(
415 void set_call(
grpc_call* call) { call_.call = call; }
419 uint32_t initial_metadata_flags()
const {
return 0; }
423 const std::vector<std::unique_ptr<
425 if (!creators.empty()) {
426 rpc_info_ = new ::grpc::experimental::ServerRpcInfo(
this, method, type);
427 rpc_info_->RegisterInterceptors(creators);
432 void set_message_allocator_state(
434 message_allocator_state_ = allocator_state;
449 CompletionOp* completion_op_ =
nullptr;
450 bool has_notify_when_done_tag_ =
false;
451 void* async_notify_when_done_tag_ =
nullptr;
456 bool sent_initial_metadata_ =
false;
457 mutable std::shared_ptr<const ::grpc::AuthContext> auth_context_;
458 mutable ::grpc::internal::MetadataMap client_metadata_;
459 std::multimap<std::string, std::string> initial_metadata_;
460 std::multimap<std::string, std::string> trailing_metadata_;
462 bool compression_level_set_ =
false;
469 bool has_pending_ops_ =
false;
473 ContextAllocator* context_allocator_ =
nullptr;
477 void OnCancel()
override {}
478 void OnDone()
override {}
483 bool InternalInlineable()
override {
return true; }
486 void SetupTestDefaultReactor(std::function<
void(::
grpc::Status)> func) {
488 test_unary_.reset(
new TestServerCallbackUnary(
this, std::move(func)));
490 bool test_status_set()
const {
491 return (test_unary_ !=
nullptr) && test_unary_->status_set();
493 ::grpc::Status test_status()
const {
return test_unary_->status(); }
505 status_set_.store(
true, std::memory_order_release);
507 void SendInitialMetadata()
override {}
509 bool status_set()
const {
510 return status_set_.load(std::memory_order_acquire);
515 void CallOnDone()
override {}
519 std::atomic_bool status_set_{
false};
524 typename std::aligned_storage<
sizeof(Reactor),
alignof(Reactor)>::type
526 std::atomic_bool default_reactor_used_{
false};
527 std::unique_ptr<TestServerCallbackUnary> test_unary_;
573 friend class ::grpc::Server;
636 #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
649 #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
652 virtual void Release(GenericCallbackServerContext*) {}
659 std::is_base_of<::grpc::ServerContextBase, ::grpc::ServerContext>::value,
660 "improper base class");
663 "improper base class");
671 #endif // GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_H
CallbackWithSuccessTag can be reused multiple times, and will be used in this fashion for streaming o...
Definition: callback_common.h:137
struct census_context census_context
A Census Context is a handle used by Census to represent the current tracing and stats collection inf...
Definition: census.h:34
void set_compression_algorithm(grpc_compression_algorithm algorithm)
Set algorithm to be the compression algorithm used for the server call.
void SetLoadReportingCosts(const std::vector< std::string > &cost_data)
Set the serialized load reporting costs in cost_data for the call.
A ServerContext or CallbackServerContext allows the code implementing a service handler to:
Definition: server_context.h:546
const struct census_context * census_context() const
Get the census context associated with this server call.
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
Primary implementation of CallOpSetInterface.
Definition: call_op_set.h:852
bool IsCancelled() const
Return whether this RPC failed before the server could provide its status back to the client.
Definition: server_context.h:586
void set_context_allocator(ContextAllocator *context_allocator)
Definition: server_context.h:344
Definition: call_op_set.h:282
Definition: rpc_service_method.h:41
grpc_compression_algorithm
The various compression algorithms supported by gRPC (not sorted by compression level)
Definition: compression_types.h:57
Straightforward wrapping of the C call object.
Definition: call.h:35
Base class of ServerContext. Experimental until callback API is final.
Definition: server_context.h:131
ContextAllocator * context_allocator() const
Definition: server_context.h:348
void BindReactor(Reactor *reactor)
Definition: server_callback.h:201
ServerContextBase()
Constructors for use by derived classes.
::grpc::ServerContextBase ServerContextBase
Definition: server_context.h:108
Definition: message_allocator.h:29
::grpc::CallbackServerContext CallbackServerContext
Definition: server_context.h:109
Did it work? If it didn't, why?
Definition: status.h:31
virtual void Release(CallbackServerContext *)
Definition: server_context.h:647
Definition: async_generic_service.h:91
The base class of ServerCallbackUnary etc.
Definition: server_callback.h:72
std::shared_ptr< const AuthContext > CreateAuthContext(grpc_call *call)
std::chrono::system_clock::time_point deadline() const
Return the deadline for the server call.
Definition: server_context.h:136
gpr_timespec raw_deadline() const
Return a gpr_timespec representation of the server call's deadline.
Definition: server_context.h:141
std::shared_ptr< const ::grpc::AuthContext > auth_context() const
Return the authentication context for this server call.
Definition: server_context.h:268
void AddInitialMetadata(const std::string &key, const std::string &value)
Add the (key, value) pair to the initial metadata associated with a server call.
struct grpc_call grpc_call
A Call represents an RPC.
Definition: grpc_types.h:70
bool compression_level_set() const
Return a bool indicating whether the compression level for this call has been set (either implicitly ...
Definition: server_context.h:248
::grpc::ServerUnaryReactor * DefaultReactor()
Get a library-owned default unary reactor for use in minimal reaction cases.
Definition: server_context.h:323
virtual CallbackServerContext * NewCallbackServerContext()
Definition: server_context.h:634
RpcType
Definition: rpc_method.h:31
CallbackServerContext()
Public constructors are for direct use only by mocking tests.
Definition: server_context.h:590
void AddTrailingMetadata(const std::string &key, const std::string &value)
Add the (key, value) pair to the initial metadata associated with a server call.
ServerRpcInfo represents the state of a particular RPC as it appears to an interceptor.
Definition: server_interceptor.h:56
::google::protobuf::util::Status Status
Definition: config_protobuf.h:91
An interface allowing implementors to process and filter event tags.
Definition: completion_queue_tag.h:26
const std::multimap< grpc::string_ref, grpc::string_ref > & client_metadata() const
Return a collection of initial metadata key-value pairs sent from the client.
Definition: server_context.h:227
virtual void Release(experimental::GenericCallbackServerContext *)
Definition: server_context.h:650
Definition: server_interceptor.h:43
virtual ~ServerContextBase()
A CallbackServerContext allows users to use the contents of the CallbackServerContext or GenericCallb...
Definition: server_context.h:630
void AsyncNotifyWhenDone(void *tag)
Async only.
Definition: server_context.h:294
grpc_compression_level
Compression levels allow a party with knowledge of its peer's accepted encodings to request compressi...
Definition: compression_types.h:71
Definition: async_unary_call.h:398
std::string peer() const
Return the peer uri in a string.
void UnaryRunHandlerHelper(const MethodHandler::HandlerParameter &, ResponseType *, Status &)
Definition: server_callback.h:48
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue.h:102
void TryCancel() const
Cancel the Call from the server.
virtual ~ContextAllocator()
Definition: server_context.h:632
::grpc::experimental::RpcAllocatorState * GetRpcAllocatorState()
NOTE: This is an API for advanced users who need custom allocators.
Definition: server_context.h:303
void UnaryRunHandlerHelper(const ::grpc::internal::MethodHandler::HandlerParameter &, ResponseType *, ::grpc::Status &)
virtual experimental::GenericCallbackServerContext * NewGenericCallbackServerContext()
Definition: server_context.h:638
ServerContext()
Definition: server_context.h:548
Analogous to struct timespec.
Definition: gpr_types.h:47
Definition: server_callback.h:191
Definition: server_callback.h:688
grpc_compression_algorithm compression_algorithm() const
Return the compression algorithm the server call will request be used.
Definition: server_context.h:254
grpc_call * c_call()
Should be used for framework-level extensions only.
Definition: server_context.h:286
std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t)
void set_compression_level(grpc_compression_level level)
Set level to be the compression level used for the server call.
Definition: server_context.h:240
grpc_compression_level compression_level() const
Return the compression algorithm to be used by the server call.
Definition: server_context.h:233