Go to the documentation of this file.
19 #ifndef GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_IMPL_H
20 #define GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_IMPL_H
26 #include <type_traits>
55 template <
class W,
class R>
61 template <
class W,
class R>
69 template <
class ServiceType,
class RequestType,
class ResponseType>
71 template <
class RequestType,
class ResponseType>
72 class CallbackUnaryHandler;
73 template <
class RequestType,
class ResponseType>
74 class CallbackClientStreamingHandler;
75 template <
class RequestType,
class ResponseType>
76 class CallbackServerStreamingHandler;
77 template <
class RequestType,
class ResponseType>
78 class CallbackBidiHandler;
79 template <
class ServiceType,
class RequestType,
class ResponseType>
81 template <
class ServiceType,
class RequestType,
class ResponseType>
84 class FinishOnlyReactor;
85 template <
class W,
class R>
86 class ServerReaderWriterBody;
87 template <
class ServiceType,
class RequestType,
class ResponseType>
90 template <
class Streamer,
bool WriteNeeded>
92 template <::grpc::StatusCode code>
98 class GenericServerContext;
99 class ServerInterface;
101 #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
102 namespace experimental {
104 class GenericCallbackServerContext;
105 #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
113 class InteropServerContextInspector;
114 class ServerContextTestSpouse;
115 class DefaultReactorTestPeer;
128 std::chrono::system_clock::time_point
deadline()
const {
211 return *client_metadata_.
map();
216 return compression_level_;
223 compression_level_set_ =
true;
224 compression_level_ = level;
237 return compression_algorithm_;
251 if (auth_context_.get() ==
nullptr) {
254 return auth_context_;
277 has_notify_when_done_tag_ =
true;
278 async_notify_when_done_tag_ = tag;
286 return message_allocator_state_;
308 if (test_unary_ !=
nullptr) {
309 return reinterpret_cast<Reactor*>(&default_reactor_);
311 new (&default_reactor_) Reactor;
314 assert(default_reactor_used_.compare_exchange_strong(
315 old,
true, std::memory_order_relaxed));
317 default_reactor_used_.store(
true, std::memory_order_relaxed);
319 return reinterpret_cast<Reactor*>(&default_reactor_);
327 friend class ::grpc::testing::InteropServerContextInspector;
328 friend class ::grpc::testing::ServerContextTestSpouse;
329 friend class ::grpc::testing::DefaultReactorTestPeer;
330 friend class ::grpc::ServerInterface;
332 template <
class W,
class R>
338 template <
class W,
class R>
344 template <
class W,
class R>
345 friend class ::grpc_impl::internal::ServerReaderWriterBody;
346 template <
class ServiceType,
class RequestType,
class ResponseType>
348 template <
class ServiceType,
class RequestType,
class ResponseType>
350 template <
class ServiceType,
class RequestType,
class ResponseType>
352 template <
class Streamer,
bool WriteNeeded>
354 template <
class RequestType,
class ResponseType>
355 friend class ::grpc_impl::internal::CallbackUnaryHandler;
356 template <
class RequestType,
class ResponseType>
357 friend class ::grpc_impl::internal::CallbackClientStreamingHandler;
358 template <
class RequestType,
class ResponseType>
359 friend class ::grpc_impl::internal::CallbackServerStreamingHandler;
360 template <
class RequestType,
class ResponseType>
361 friend class ::grpc_impl::internal::CallbackBidiHandler;
362 template <::grpc::StatusCode code>
364 template <
class Base>
365 friend class ::grpc_impl::internal::FinishOnlyReactor;
367 friend class ::grpc::GenericServerContext;
368 #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL
369 friend class ::grpc::GenericCallbackServerContext;
371 friend class ::grpc::experimental::GenericCallbackServerContext;
380 void BeginCompletionOp(
386 void set_call(
grpc_call* call) { call_ = call; }
394 uint32_t initial_metadata_flags()
const {
return 0; }
398 const std::vector<std::unique_ptr<
400 if (creators.size() != 0) {
401 rpc_info_ = new ::grpc::experimental::ServerRpcInfo(
this, method, type);
402 rpc_info_->RegisterInterceptors(creators);
407 void set_message_allocator_state(
409 message_allocator_state_ = allocator_state;
412 CompletionOp* completion_op_;
413 bool has_notify_when_done_tag_;
414 void* async_notify_when_done_tag_;
420 bool sent_initial_metadata_;
421 mutable std::shared_ptr<const ::grpc::AuthContext> auth_context_;
422 mutable ::grpc::internal::MetadataMap client_metadata_;
423 std::multimap<grpc::string, grpc::string> initial_metadata_;
424 std::multimap<grpc::string, grpc::string> trailing_metadata_;
426 bool compression_level_set_;
433 bool has_pending_ops_;
440 void OnCancel()
override {}
441 void OnDone()
override {}
446 bool InternalInlineable()
override {
return true; }
449 void SetupTestDefaultReactor(std::function<
void(::
grpc::Status)> func) {
450 test_unary_.reset(
new TestServerCallbackUnary(
this, std::move(func)));
452 bool test_status_set()
const {
453 return (test_unary_ !=
nullptr) && test_unary_->status_set();
455 ::grpc::Status test_status()
const {
return test_unary_->status(); }
467 status_set_.store(
true, std::memory_order_release);
469 void SendInitialMetadata()
override {}
471 bool status_set()
const {
472 return status_set_.load(std::memory_order_acquire);
477 void CallOnDone()
override {}
483 std::atomic_bool status_set_{
false};
488 typename std::aligned_storage<
sizeof(Reactor),
alignof(Reactor)>::type
490 std::atomic_bool default_reactor_used_{
false};
491 std::unique_ptr<TestServerCallbackUnary> test_unary_;
591 "improper base class");
594 "improper base class");
602 #endif // GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_IMPL_H
void AddTrailingMetadata(const grpc::string &key, const grpc::string &value)
Add the (key, value) pair to the initial metadata associated with a server call.
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
grpc_compression_algorithm compression_algorithm() const
Return the compression algorithm the server call will request be used.
Definition: server_context_impl.h:236
void set_compression_level(grpc_compression_level level)
Set level to be the compression level used for the server call.
Definition: server_context_impl.h:222
::grpc_impl::internal::RpcMethodHandler< ServiceType, RequestType, ResponseType > RpcMethodHandler
Definition: method_handler.h:36
virtual ~ServerContextBase()
::grpc_impl::ServerUnaryReactor * DefaultReactor()
Get a library-owned default unary reactor for use in minimal reaction cases.
Definition: server_context_impl.h:305
::grpc_impl::internal::TemplatedBidiStreamingHandler< Streamer, WriteNeeded > TemplatedBidiStreamingHandler
Definition: method_handler.h:50
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
Primary implementation of CallOpSetInterface.
Definition: call_op_set.h:849
Definition: call_op_set.h:286
void BindReactor(Reactor *reactor)
Definition: server_callback_impl.h:201
::grpc_impl::ServerAsyncResponseWriter< W > ServerAsyncResponseWriter
Definition: async_unary_call.h:34
::grpc_impl::CompletionQueue CompletionQueue
Definition: completion_queue.h:26
grpc_compression_algorithm
The various compression algorithms supported by gRPC (not sorted by compression level)
Definition: compression_types.h:57
::grpc_impl::ServerAsyncReader< W, R > ServerAsyncReader
Definition: async_stream.h:63
Definition: server_callback_impl.h:693
Straightforward wrapping of the C call object.
Definition: call.h:38
std::shared_ptr< const ::grpc::AuthContext > auth_context() const
Return the authentication context for this server call.
Definition: server_context_impl.h:250
Base class of ServerContext. Experimental until callback API is final.
Definition: server_context_impl.h:123
void SetLoadReportingCosts(const std::vector< grpc::string > &cost_data)
Set the serialized load reporting costs in cost_data for the call.
Definition: server_context_impl.h:550
::grpc_impl::Server Server
Definition: server.h:26
Definition: message_allocator.h:29
ServerContextBase()
Constructors for use by derived classes.
::grpc_impl::ServerAsyncReaderWriter< W, R > ServerAsyncReaderWriter
Definition: async_stream.h:76
void TryCancel() const
Cancel the Call from the server.
::grpc_impl::ServerWriter< W > ServerWriter
Definition: sync_stream.h:81
Did it work? If it didn't, why?
Definition: status.h:31
A ServerContext or CallbackServerContext allows the code implementing a service handler to:
Definition: server_context_impl.h:510
::grpc_impl::internal::ServerStreamingHandler< ServiceType, RequestType, ResponseType > ServerStreamingHandler
Definition: method_handler.h:46
::grpc_impl::internal::BidiStreamingHandler< ServiceType, RequestType, ResponseType > BidiStreamingHandler
Definition: method_handler.h:31
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_impl.h:209
std::shared_ptr< const AuthContext > CreateAuthContext(grpc_call *call)
void AddInitialMetadata(const grpc::string &key, const grpc::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
::grpc_impl::ServerReader< R > ServerReader
Definition: sync_stream.h:75
bool IsCancelled() const
IsCancelled is always safe to call when using sync or callback API.
void set_compression_algorithm(grpc_compression_algorithm algorithm)
Set algorithm to be the compression algorithm used for the server call.
::grpc_impl::ServerUnaryReactor ServerUnaryReactor
Definition: server_callback.h:51
gpr_timespec raw_deadline() const
Return a gpr_timespec representation of the server call's deadline.
Definition: server_context_impl.h:133
RpcType
Definition: rpc_method.h:31
ServerRpcInfo represents the state of a particular RPC as it appears to an interceptor.
Definition: server_interceptor.h:60
An interface allowing implementors to process and filter event tags.
Definition: completion_queue_tag.h:26
The base class of ServerCallbackUnary etc.
Definition: server_callback_impl.h:72
Definition: server_callback_impl.h:48
Definition: server_interceptor.h:47
void AsyncNotifyWhenDone(void *tag)
Async only.
Definition: server_context_impl.h:276
grpc_compression_level compression_level() const
Return the compression algorithm to be used by the server call.
Definition: server_context_impl.h:215
Definition: server_callback_impl.h:191
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue_impl.h:103
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_impl.h:301
const struct census_context * census_context() const
Get the census context associated with this server call.
std::chrono::system_clock::time_point deadline() const
Return the deadline for the server call.
Definition: server_context_impl.h:128
std::string string
Definition: config.h:35
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm_impl.h:33
ServerContext()
Definition: server_context_impl.h:512
grpc_call * c_call()
Should be used for framework-level extensions only.
Definition: server_context_impl.h:268
::grpc_impl::ClientContext ClientContext
Definition: client_context.h:26
::grpc_impl::ServerAsyncWriter< W > ServerAsyncWriter
Definition: async_stream.h:69
Analogous to struct timespec.
Definition: gpr_types.h:47
::grpc_impl::internal::ErrorMethodHandler< code > ErrorMethodHandler
Definition: method_handler.h:62
::grpc::experimental::RpcAllocatorState * GetRpcAllocatorState()
NOTE: This is an API for advanced users who need custom allocators.
Definition: server_context_impl.h:285
grpc::string peer() const
Return the peer uri in a string.
::grpc_impl::internal::ClientStreamingHandler< ServiceType, RequestType, ResponseType > ClientStreamingHandler
Definition: method_handler.h:41
std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t)
CallbackServerContext()
Public constructors are for direct use only by mocking tests.
Definition: server_context_impl.h:554
bool compression_level_set() const
Return a bool indicating whether the compression level for this call has been set (either implicitly ...
Definition: server_context_impl.h:230