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>
52 template <
class W,
class R>
53 class ServerAsyncReader;
55 class ServerAsyncWriter;
57 class ServerAsyncResponseWriter;
58 template <
class W,
class R>
59 class ServerAsyncReaderWriter;
66 template <
class ServiceType,
class RequestType,
class ResponseType>
67 class BidiStreamingHandler;
68 template <
class RequestType,
class ResponseType>
69 class CallbackUnaryHandler;
70 template <
class RequestType,
class ResponseType>
71 class CallbackClientStreamingHandler;
72 template <
class RequestType,
class ResponseType>
73 class CallbackServerStreamingHandler;
74 template <
class RequestType,
class ResponseType>
75 class CallbackBidiHandler;
76 template <
class ServiceType,
class RequestType,
class ResponseType>
77 class ClientStreamingHandler;
78 template <
class ServiceType,
class RequestType,
class ResponseType>
79 class RpcMethodHandler;
81 class FinishOnlyReactor;
82 template <
class W,
class R>
83 class ServerReaderWriterBody;
84 template <
class ServiceType,
class RequestType,
class ResponseType>
85 class ServerStreamingHandler;
87 template <
class Streamer,
bool WriteNeeded>
88 class TemplatedBidiStreamingHandler;
89 template <::grpc::StatusCode code>
90 class ErrorMethodHandler;
94 class CompletionQueue;
95 class GenericServerContext;
97 class ServerInterface;
100 namespace experimental {
107 #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
108 namespace experimental {
110 class GenericCallbackServerContext;
111 #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
119 class InteropServerContextInspector;
120 class ServerContextTestSpouse;
121 class DefaultReactorTestPeer;
130 std::chrono::system_clock::time_point
deadline()
const {
223 return *client_metadata_.
map();
228 return compression_level_;
235 compression_level_set_ =
true;
236 compression_level_ = level;
249 return compression_algorithm_;
263 if (auth_context_.get() ==
nullptr) {
266 return auth_context_;
273 std::string
peer()
const;
289 has_notify_when_done_tag_ =
true;
290 async_notify_when_done_tag_ = tag;
298 return message_allocator_state_;
320 if (test_unary_ !=
nullptr) {
321 return reinterpret_cast<Reactor*
>(&default_reactor_);
323 new (&default_reactor_) Reactor;
326 assert(default_reactor_used_.compare_exchange_strong(
327 old,
true, std::memory_order_relaxed));
329 default_reactor_used_.store(
true, std::memory_order_relaxed);
331 return reinterpret_cast<Reactor*
>(&default_reactor_);
339 friend class ::grpc::testing::InteropServerContextInspector;
340 friend class ::grpc::testing::ServerContextTestSpouse;
341 friend class ::grpc::testing::DefaultReactorTestPeer;
342 friend class ::grpc::ServerInterface;
343 friend class ::grpc::Server;
344 template <
class W,
class R>
345 friend class ::grpc::ServerAsyncReader;
347 friend class ::grpc::ServerAsyncWriter;
349 friend class ::grpc::ServerAsyncResponseWriter;
350 template <
class W,
class R>
351 friend class ::grpc::ServerAsyncReaderWriter;
353 friend class ::grpc::ServerReader;
355 friend class ::grpc::ServerWriter;
356 template <
class W,
class R>
357 friend class ::grpc::internal::ServerReaderWriterBody;
358 template <
class ServiceType,
class RequestType,
class ResponseType>
359 friend class ::grpc::internal::RpcMethodHandler;
360 template <
class ServiceType,
class RequestType,
class ResponseType>
361 friend class ::grpc::internal::ClientStreamingHandler;
362 template <
class ServiceType,
class RequestType,
class ResponseType>
363 friend class ::grpc::internal::ServerStreamingHandler;
364 template <
class Streamer,
bool WriteNeeded>
365 friend class ::grpc::internal::TemplatedBidiStreamingHandler;
366 template <
class RequestType,
class ResponseType>
367 friend class ::grpc::internal::CallbackUnaryHandler;
368 template <
class RequestType,
class ResponseType>
369 friend class ::grpc::internal::CallbackClientStreamingHandler;
370 template <
class RequestType,
class ResponseType>
371 friend class ::grpc::internal::CallbackServerStreamingHandler;
372 template <
class RequestType,
class ResponseType>
373 friend class ::grpc::internal::CallbackBidiHandler;
374 template <::grpc::StatusCode code>
375 friend class ::grpc::internal::ErrorMethodHandler;
376 template <
class Base>
377 friend class ::grpc::internal::FinishOnlyReactor;
378 friend class ::grpc::ClientContext;
379 friend class ::grpc::GenericServerContext;
380 #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL
381 friend class ::grpc::GenericCallbackServerContext;
383 friend class ::grpc::experimental::GenericCallbackServerContext;
392 void BeginCompletionOp(
398 void set_call(
grpc_call* call) { call_.call = call; }
402 uint32_t initial_metadata_flags()
const {
return 0; }
406 const std::vector<std::unique_ptr<
408 if (creators.size() != 0) {
409 rpc_info_ = new ::grpc::experimental::ServerRpcInfo(
this, method, type);
410 rpc_info_->RegisterInterceptors(creators);
415 void set_message_allocator_state(
417 message_allocator_state_ = allocator_state;
432 CompletionOp* completion_op_ =
nullptr;
433 bool has_notify_when_done_tag_ =
false;
434 void* async_notify_when_done_tag_ =
nullptr;
439 bool sent_initial_metadata_ =
false;
440 mutable std::shared_ptr<const ::grpc::AuthContext> auth_context_;
441 mutable ::grpc::internal::MetadataMap client_metadata_;
442 std::multimap<std::string, std::string> initial_metadata_;
443 std::multimap<std::string, std::string> trailing_metadata_;
445 bool compression_level_set_ =
false;
452 bool has_pending_ops_ =
false;
459 void OnCancel()
override {}
460 void OnDone()
override {}
465 bool InternalInlineable()
override {
return true; }
468 void SetupTestDefaultReactor(std::function<
void(::
grpc::Status)> func) {
469 test_unary_.reset(
new TestServerCallbackUnary(
this, std::move(func)));
471 bool test_status_set()
const {
472 return (test_unary_ !=
nullptr) && test_unary_->status_set();
474 ::grpc::Status test_status()
const {
return test_unary_->status(); }
486 status_set_.store(
true, std::memory_order_release);
488 void SendInitialMetadata()
override {}
490 bool status_set()
const {
491 return status_set_.load(std::memory_order_acquire);
496 void CallOnDone()
override {}
500 std::atomic_bool status_set_{
false};
505 typename std::aligned_storage<
sizeof(Reactor),
alignof(Reactor)>::type
507 std::atomic_bool default_reactor_used_{
false};
508 std::unique_ptr<TestServerCallbackUnary> test_unary_;
554 friend class ::grpc::Server;
607 std::is_base_of<::grpc::ServerContextBase, ::grpc::ServerContext>::value,
608 "improper base class");
611 "improper base class");
619 #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:136
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:527
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:850
bool IsCancelled() const
Return whether this RPC failed before the server could provide its status back to the client.
Definition: server_context.h:567
Definition: call_op_set.h:287
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:125
void BindReactor(Reactor *reactor)
Definition: server_callback.h:201
ServerContextBase()
Constructors for use by derived classes.
::grpc::ServerContextBase ServerContextBase
Definition: server_context.h:102
Definition: message_allocator.h:29
::grpc::CallbackServerContext CallbackServerContext
Definition: server_context.h:103
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:130
gpr_timespec raw_deadline() const
Return a gpr_timespec representation of the server call's deadline.
Definition: server_context.h:135
std::shared_ptr< const ::grpc::AuthContext > auth_context() const
Return the authentication context for this server call.
Definition: server_context.h:262
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:242
::grpc::ServerUnaryReactor * DefaultReactor()
Get a library-owned default unary reactor for use in minimal reaction cases.
Definition: server_context.h:317
RpcType
Definition: rpc_method.h:31
CallbackServerContext()
Public constructors are for direct use only by mocking tests.
Definition: server_context.h:571
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
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:221
Definition: server_interceptor.h:43
virtual ~ServerContextBase()
void AsyncNotifyWhenDone(void *tag)
Async only.
Definition: server_context.h:288
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:301
std::string peer() const
Return the peer uri in a string.
Definition: server_callback.h:48
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue.h:96
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:297
ServerContext()
Definition: server_context.h:529
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:248
grpc_call * c_call()
Should be used for framework-level extensions only.
Definition: server_context.h:280
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:234
grpc_compression_level compression_level() const
Return the compression algorithm to be used by the server call.
Definition: server_context.h:227