Go to the documentation of this file.
19 #ifndef GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_H
20 #define GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_H
30 #include <type_traits>
55 template <
class W,
class R>
61 template <
class W,
class R>
71 template <
class ServiceType,
class RequestType,
class ResponseType>
72 class BidiStreamingHandler;
73 template <
class RequestType,
class ResponseType>
74 class CallbackUnaryHandler;
75 template <
class RequestType,
class ResponseType>
76 class CallbackClientStreamingHandler;
77 template <
class RequestType,
class ResponseType>
78 class CallbackServerStreamingHandler;
79 template <
class RequestType,
class ResponseType>
80 class CallbackBidiHandler;
81 template <
class ServiceType,
class RequestType,
class ResponseType>
82 class ClientStreamingHandler;
83 template <
class ResponseType>
86 template <
class ServiceType,
class RequestType,
class ResponseType,
87 class BaseRequestType,
class BaseResponseType>
88 class RpcMethodHandler;
90 class FinishOnlyReactor;
91 template <
class W,
class R>
92 class ServerReaderWriterBody;
93 template <
class ServiceType,
class RequestType,
class ResponseType>
94 class ServerStreamingHandler;
96 template <
class Streamer,
bool WriteNeeded>
97 class TemplatedBidiStreamingHandler;
98 template <grpc::StatusCode code>
99 class ErrorMethodHandler;
115 class InteropServerContextInspector;
116 class ServerContextTestSpouse;
117 class DefaultReactorTestPeer;
120 namespace experimental {
121 class OrcaServerInterceptor;
122 class CallMetricRecorder;
131 std::chrono::system_clock::time_point
deadline()
const {
232 return *client_metadata_.
map();
237 return compression_level_;
244 compression_level_set_ =
true;
245 compression_level_ = level;
258 return compression_algorithm_;
272 if (auth_context_ ==
nullptr) {
275 return auth_context_;
282 std::string
peer()
const;
297 return call_metric_recorder_;
311 has_notify_when_done_tag_ =
true;
312 async_notify_when_done_tag_ = tag;
337 if (test_unary_ !=
nullptr) {
338 return reinterpret_cast<Reactor*
>(&default_reactor_);
340 new (&default_reactor_) Reactor;
343 assert(default_reactor_used_.compare_exchange_strong(
344 old,
true, std::memory_order_relaxed));
346 default_reactor_used_.store(
true, std::memory_order_relaxed);
348 return reinterpret_cast<Reactor*
>(&default_reactor_);
367 template <
class W,
class R>
373 template <
class W,
class R>
379 template <
class W,
class R>
381 template <
class ResponseType>
385 template <
class ServiceType,
class RequestType,
class ResponseType,
386 class BaseRequestType,
class BaseResponseType>
388 template <
class ServiceType,
class RequestType,
class ResponseType>
390 template <
class ServiceType,
class RequestType,
class ResponseType>
392 template <
class Streamer,
bool WriteNeeded>
394 template <
class RequestType,
class ResponseType>
396 template <
class RequestType,
class ResponseType>
398 template <
class RequestType,
class ResponseType>
400 template <
class RequestType,
class ResponseType>
402 template <grpc::StatusCode code>
404 template <
class Base>
417 void BeginCompletionOp(
423 void set_call(
grpc_call* call) { call_.call = call; }
427 uint32_t initial_metadata_flags()
const {
return 0; }
431 const std::vector<std::unique_ptr<
433 if (!creators.empty()) {
435 rpc_info_->RegisterInterceptors(creators);
440 void set_message_allocator_state(RpcAllocatorState* allocator_state) {
441 message_allocator_state_ = allocator_state;
444 void MaybeMarkCancelledOnRead() {
447 marked_cancelled_.store(
true, std::memory_order_release);
451 void CreateCallMetricRecorder();
465 CompletionOp* completion_op_ =
nullptr;
466 bool has_notify_when_done_tag_ =
false;
467 void* async_notify_when_done_tag_ =
nullptr;
472 bool sent_initial_metadata_ =
false;
473 mutable std::shared_ptr<const grpc::AuthContext> auth_context_;
475 std::multimap<std::string, std::string> initial_metadata_;
476 std::multimap<std::string, std::string> trailing_metadata_;
478 bool compression_level_set_ =
false;
485 bool has_pending_ops_ =
false;
488 RpcAllocatorState* message_allocator_state_ =
nullptr;
489 ContextAllocator* context_allocator_ =
nullptr;
490 experimental::CallMetricRecorder* call_metric_recorder_ =
nullptr;
494 void OnCancel()
override {}
495 void OnDone()
override {}
500 bool InternalInlineable()
override {
return true; }
503 void SetupTestDefaultReactor(std::function<
void(
grpc::Status)> func) {
505 test_unary_.reset(
new TestServerCallbackUnary(
this, std::move(func)));
507 bool test_status_set()
const {
508 return (test_unary_ !=
nullptr) && test_unary_->status_set();
510 grpc::Status test_status()
const {
return test_unary_->status(); }
522 status_set_.store(
true, std::memory_order_release);
524 void SendInitialMetadata()
override {}
526 bool status_set()
const {
527 return status_set_.load(std::memory_order_acquire);
532 void CallOnDone()
override {}
536 std::atomic_bool status_set_{
false};
541 typename std::aligned_storage<
sizeof(Reactor),
alignof(Reactor)>::type
543 std::atomic_bool default_reactor_used_{
false};
545 std::atomic_bool marked_cancelled_{
false};
547 std::unique_ptr<TestServerCallbackUnary> test_unary_;
668 std::is_base_of<grpc::ServerContextBase, grpc::ServerContext>::value,
669 "improper base class");
672 "improper base class");
679 #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
This class is a non owning reference to a string.
Definition: string_ref.h:43
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.
virtual GenericCallbackServerContext * NewGenericCallbackServerContext()
Definition: server_context.h:656
A ServerContext or CallbackServerContext allows the code implementing a service handler to:
Definition: server_context.h:566
Represents a gRPC server.
Definition: server.h:59
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:859
bool IsCancelled() const
Return whether this RPC failed before the server could provide its status back to the client.
Definition: server_context.h:606
void set_context_allocator(ContextAllocator *context_allocator)
Definition: server_context.h:355
Definition: call_op_set.h:289
Definition: message_allocator.h:28
Async server-side API for doing server streaming RPCs, where the outgoing message stream from the ser...
Definition: server_context.h:58
General method handler class for errors that prevent real method use e.g., handle unknown method by r...
Definition: completion_queue.h:79
Definition: rpc_service_method.h:43
A wrapper class of an application provided rpc method handler.
Definition: completion_queue.h:71
Synchronous (blocking) server-side API for doing for doing a server-streaming RPCs,...
Definition: completion_queue.h:60
grpc_compression_algorithm
The various compression algorithms supported by gRPC (not sorted by compression level)
Definition: compression_types.h:60
friend class grpc::experimental::OrcaServerInterceptor
Definition: server_context.h:409
grpc::ServerUnaryReactor * DefaultReactor()
Get a library-owned default unary reactor for use in minimal reaction cases.
Definition: server_context.h:334
Straightforward wrapping of the C call object.
Definition: call.h:36
Base class of ServerContext.
Definition: server_context.h:126
ContextAllocator * context_allocator() const
Definition: server_context.h:359
void BindReactor(Reactor *reactor)
Definition: server_callback.h:203
ServerContextBase()
Constructors for use by derived classes.
Definition: completion_queue.h:63
friend class grpc::testing::DefaultReactorTestPeer
Definition: server_context.h:364
friend class grpc::testing::ServerContextTestSpouse
Definition: server_context.h:363
Did it work? If it didn't, why?
Definition: status.h:35
virtual void Release(CallbackServerContext *)
Definition: server_context.h:660
Records call metrics for the purpose of load balancing.
Definition: call_metric_recorder.h:52
experimental::CallMetricRecorder * ExperimentalGetCallMetricRecorder()
Get the CallMetricRecorder object for the current RPC.
Definition: server_context.h:296
The base class of ServerCallbackUnary etc.
Definition: server_callback.h:75
std::shared_ptr< const AuthContext > CreateAuthContext(grpc_call *call)
Synchronous (blocking) server-side API for doing client-streaming RPCs, where the incoming message st...
Definition: completion_queue.h:58
std::chrono::system_clock::time_point deadline() const
Return the deadline for the server call.
Definition: server_context.h:131
gpr_timespec raw_deadline() const
Return a gpr_timespec representation of the server call's deadline.
Definition: server_context.h:136
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:195
RpcAllocatorState * GetRpcAllocatorState()
NOTE: This is an API for advanced users who need custom allocators.
Definition: server_context.h:318
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
Definition: server_callback.h:43
std::shared_ptr< const grpc::AuthContext > auth_context() const
Return the authentication context for this server call.
Definition: server_context.h:271
Definition: server_callback.h:47
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:251
virtual int grpc_call_failed_before_recv_message(const grpc_call *c)=0
virtual CallbackServerContext * NewCallbackServerContext()
Definition: server_context.h:654
RpcType
Definition: rpc_method.h:33
CallbackServerContext()
Public constructors are for direct use only by mocking tests.
Definition: server_context.h:610
Definition: async_generic_service.h:39
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:58
Definition: server_callback.h:770
An interface allowing implementors to process and filter event tags.
Definition: completion_queue_tag.h:28
Interface between the codegen library and the minimal subset of core features required by the generat...
Definition: core_codegen_interface.h:40
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:230
Definition: server_interceptor.h:45
virtual ~ServerContextBase()
A wrapper class of an application provided server streaming handler.
Definition: completion_queue.h:75
Async server-side API for handling unary calls, where the single response message sent to the client ...
Definition: server_context.h:60
Definition: server_callback.h:49
A CallbackServerContext allows users to use the contents of the CallbackServerContext or GenericCallb...
Definition: server_context.h:650
A wrapper class of an application provided client streaming handler.
Definition: completion_queue.h:73
void AsyncNotifyWhenDone(void *tag)
Async only.
Definition: server_context.h:310
A wrapper class of an application provided bidi-streaming handler.
Definition: completion_queue.h:77
grpc_compression_level
Compression levels allow a party with knowledge of its peer's accepted encodings to request compressi...
Definition: compression_types.h:72
Definition: async_unary_call.h:407
friend class grpc::testing::InteropServerContextInspector
Definition: server_context.h:362
Definition: async_generic_service.h:87
std::string peer() const
Return the peer uri in a string.
Definition: server_callback.h:51
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue.h:104
grpc::string_ref ExperimentalGetAuthority() const
EXPERIMENTAL API Returns the call's authority.
Definition: server_callback.h:45
void TryCancel() const
Cancel the Call from the server.
CoreCodegenInterface * g_core_codegen_interface
Definition: completion_queue.h:98
virtual ~ContextAllocator()
Definition: server_context.h:652
Async server-side API for doing client-streaming RPCs, where the incoming message stream from the cli...
Definition: server_context.h:56
Async server-side API for doing bidirectional streaming RPCs, where the incoming message stream comin...
Definition: server_context.h:62
Definition: server_interface.h:61
ServerContext()
Definition: server_context.h:568
Analogous to struct timespec.
Definition: gpr_types.h:50
void UnaryRunHandlerHelper(const grpc::internal::MethodHandler::HandlerParameter &, ResponseType *, grpc::Status &)
A helper function with reduced templating to do the common work needed to actually send the server re...
Definition: method_handler.h:59
Definition: server_callback.h:193
Definition: server_callback.h:699
grpc_compression_algorithm compression_algorithm() const
Return the compression algorithm the server call will request be used.
Definition: server_context.h:257
grpc_call * c_call()
Should be used for framework-level extensions only.
Definition: server_context.h:289
std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t)
virtual void Release(GenericCallbackServerContext *)
Definition: server_context.h:662
void set_compression_level(grpc_compression_level level)
Set level to be the compression level used for the server call.
Definition: server_context.h:243
grpc_compression_level compression_level() const
Return the compression algorithm to be used by the server call.
Definition: server_context.h:236