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;
105 namespace experimental {
112 #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
113 namespace experimental {
115 class GenericCallbackServerContext;
116 #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
124 class InteropServerContextInspector;
125 class ServerContextTestSpouse;
126 class DefaultReactorTestPeer;
135 std::chrono::system_clock::time_point
deadline()
const {
228 return *client_metadata_.
map();
233 return compression_level_;
240 compression_level_set_ =
true;
241 compression_level_ = level;
254 return compression_algorithm_;
268 if (auth_context_ ==
nullptr) {
271 return auth_context_;
278 std::string
peer()
const;
294 has_notify_when_done_tag_ =
true;
295 async_notify_when_done_tag_ = tag;
303 return message_allocator_state_;
325 if (test_unary_ !=
nullptr) {
326 return reinterpret_cast<Reactor*
>(&default_reactor_);
328 new (&default_reactor_) Reactor;
331 assert(default_reactor_used_.compare_exchange_strong(
332 old,
true, std::memory_order_relaxed));
334 default_reactor_used_.store(
true, std::memory_order_relaxed);
336 return reinterpret_cast<Reactor*
>(&default_reactor_);
344 friend class ::grpc::testing::InteropServerContextInspector;
345 friend class ::grpc::testing::ServerContextTestSpouse;
346 friend class ::grpc::testing::DefaultReactorTestPeer;
347 friend class ::grpc::ServerInterface;
348 friend class ::grpc::Server;
349 template <
class W,
class R>
350 friend class ::grpc::ServerAsyncReader;
352 friend class ::grpc::ServerAsyncWriter;
354 friend class ::grpc::ServerAsyncResponseWriter;
355 template <
class W,
class R>
356 friend class ::grpc::ServerAsyncReaderWriter;
358 friend class ::grpc::ServerReader;
360 friend class ::grpc::ServerWriter;
361 template <
class W,
class R>
362 friend class ::grpc::internal::ServerReaderWriterBody;
363 template <
class ResponseType>
367 template <
class ServiceType,
class RequestType,
class ResponseType,
368 class BaseRequestType,
class BaseResponseType>
369 friend class ::grpc::internal::RpcMethodHandler;
370 template <
class ServiceType,
class RequestType,
class ResponseType>
371 friend class ::grpc::internal::ClientStreamingHandler;
372 template <
class ServiceType,
class RequestType,
class ResponseType>
373 friend class ::grpc::internal::ServerStreamingHandler;
374 template <
class Streamer,
bool WriteNeeded>
375 friend class ::grpc::internal::TemplatedBidiStreamingHandler;
376 template <
class RequestType,
class ResponseType>
377 friend class ::grpc::internal::CallbackUnaryHandler;
378 template <
class RequestType,
class ResponseType>
379 friend class ::grpc::internal::CallbackClientStreamingHandler;
380 template <
class RequestType,
class ResponseType>
381 friend class ::grpc::internal::CallbackServerStreamingHandler;
382 template <
class RequestType,
class ResponseType>
383 friend class ::grpc::internal::CallbackBidiHandler;
384 template <::grpc::StatusCode code>
385 friend class ::grpc::internal::ErrorMethodHandler;
386 template <
class Base>
387 friend class ::grpc::internal::FinishOnlyReactor;
388 friend class ::grpc::ClientContext;
389 friend class ::grpc::GenericServerContext;
390 #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL
391 friend class ::grpc::GenericCallbackServerContext;
393 friend class ::grpc::experimental::GenericCallbackServerContext;
402 void BeginCompletionOp(
408 void set_call(
grpc_call* call) { call_.call = call; }
412 uint32_t initial_metadata_flags()
const {
return 0; }
416 const std::vector<std::unique_ptr<
418 if (!creators.empty()) {
419 rpc_info_ = new ::grpc::experimental::ServerRpcInfo(
this, method, type);
420 rpc_info_->RegisterInterceptors(creators);
425 void set_message_allocator_state(
427 message_allocator_state_ = allocator_state;
442 CompletionOp* completion_op_ =
nullptr;
443 bool has_notify_when_done_tag_ =
false;
444 void* async_notify_when_done_tag_ =
nullptr;
449 bool sent_initial_metadata_ =
false;
450 mutable std::shared_ptr<const ::grpc::AuthContext> auth_context_;
451 mutable ::grpc::internal::MetadataMap client_metadata_;
452 std::multimap<std::string, std::string> initial_metadata_;
453 std::multimap<std::string, std::string> trailing_metadata_;
455 bool compression_level_set_ =
false;
462 bool has_pending_ops_ =
false;
469 void OnCancel()
override {}
470 void OnDone()
override {}
475 bool InternalInlineable()
override {
return true; }
478 void SetupTestDefaultReactor(std::function<
void(::
grpc::Status)> func) {
480 test_unary_.reset(
new TestServerCallbackUnary(
this, std::move(func)));
482 bool test_status_set()
const {
483 return (test_unary_ !=
nullptr) && test_unary_->status_set();
485 ::grpc::Status test_status()
const {
return test_unary_->status(); }
497 status_set_.store(
true, std::memory_order_release);
499 void SendInitialMetadata()
override {}
501 bool status_set()
const {
502 return status_set_.load(std::memory_order_acquire);
507 void CallOnDone()
override {}
511 std::atomic_bool status_set_{
false};
516 typename std::aligned_storage<
sizeof(Reactor),
alignof(Reactor)>::type
518 std::atomic_bool default_reactor_used_{
false};
519 std::unique_ptr<TestServerCallbackUnary> test_unary_;
565 friend class ::grpc::Server;
618 std::is_base_of<::grpc::ServerContextBase, ::grpc::ServerContext>::value,
619 "improper base class");
622 "improper base class");
630 #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:538
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:578
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:130
void BindReactor(Reactor *reactor)
Definition: server_callback.h:201
ServerContextBase()
Constructors for use by derived classes.
::grpc::ServerContextBase ServerContextBase
Definition: server_context.h:107
Definition: message_allocator.h:29
::grpc::CallbackServerContext CallbackServerContext
Definition: server_context.h:108
Did it work? If it didn't, why?
Definition: status.h:31
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:135
gpr_timespec raw_deadline() const
Return a gpr_timespec representation of the server call's deadline.
Definition: server_context.h:140
std::shared_ptr< const ::grpc::AuthContext > auth_context() const
Return the authentication context for this server call.
Definition: server_context.h:267
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:247
::grpc::ServerUnaryReactor * DefaultReactor()
Get a library-owned default unary reactor for use in minimal reaction cases.
Definition: server_context.h:322
RpcType
Definition: rpc_method.h:31
CallbackServerContext()
Public constructors are for direct use only by mocking tests.
Definition: server_context.h:582
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:226
Definition: server_interceptor.h:43
virtual ~ServerContextBase()
void AsyncNotifyWhenDone(void *tag)
Async only.
Definition: server_context.h:293
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.
::grpc::experimental::RpcAllocatorState * GetRpcAllocatorState()
NOTE: This is an API for advanced users who need custom allocators.
Definition: server_context.h:302
void UnaryRunHandlerHelper(const ::grpc::internal::MethodHandler::HandlerParameter &, ResponseType *, ::grpc::Status &)
ServerContext()
Definition: server_context.h:540
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:253
grpc_call * c_call()
Should be used for framework-level extensions only.
Definition: server_context.h:285
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:239
grpc_compression_level compression_level() const
Return the compression algorithm to be used by the server call.
Definition: server_context.h:232