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>
53 template <
class W,
class R>
59 template <
class W,
class R>
67 template <
class ServiceType,
class RequestType,
class ResponseType>
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>
79 template <
class ServiceType,
class RequestType,
class ResponseType>
82 class FinishOnlyReactor;
83 template <
class W,
class R>
84 class ServerReaderWriterBody;
85 template <
class ServiceType,
class RequestType,
class ResponseType>
88 template <
class Streamer,
bool WriteNeeded>
90 template <::grpc::StatusCode code>
97 class CompletionQueue;
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 {
221 return *client_metadata_.
map();
226 return compression_level_;
233 compression_level_set_ =
true;
234 compression_level_ = level;
247 return compression_algorithm_;
261 if (auth_context_.get() ==
nullptr) {
264 return auth_context_;
271 std::string
peer()
const;
287 has_notify_when_done_tag_ =
true;
288 async_notify_when_done_tag_ = tag;
296 return message_allocator_state_;
318 if (test_unary_ !=
nullptr) {
319 return reinterpret_cast<Reactor*
>(&default_reactor_);
321 new (&default_reactor_) Reactor;
324 assert(default_reactor_used_.compare_exchange_strong(
325 old,
true, std::memory_order_relaxed));
327 default_reactor_used_.store(
true, std::memory_order_relaxed);
329 return reinterpret_cast<Reactor*
>(&default_reactor_);
337 friend class ::grpc::testing::InteropServerContextInspector;
338 friend class ::grpc::testing::ServerContextTestSpouse;
339 friend class ::grpc::testing::DefaultReactorTestPeer;
340 friend class ::grpc::ServerInterface;
342 template <
class W,
class R>
348 template <
class W,
class R>
354 template <
class W,
class R>
355 friend class ::grpc_impl::internal::ServerReaderWriterBody;
356 template <
class ServiceType,
class RequestType,
class ResponseType>
358 template <
class ServiceType,
class RequestType,
class ResponseType>
360 template <
class ServiceType,
class RequestType,
class ResponseType>
362 template <
class Streamer,
bool WriteNeeded>
364 template <
class RequestType,
class ResponseType>
365 friend class ::grpc_impl::internal::CallbackUnaryHandler;
366 template <
class RequestType,
class ResponseType>
367 friend class ::grpc_impl::internal::CallbackClientStreamingHandler;
368 template <
class RequestType,
class ResponseType>
369 friend class ::grpc_impl::internal::CallbackServerStreamingHandler;
370 template <
class RequestType,
class ResponseType>
371 friend class ::grpc_impl::internal::CallbackBidiHandler;
372 template <::grpc::StatusCode code>
374 template <
class Base>
375 friend class ::grpc_impl::internal::FinishOnlyReactor;
376 friend class ::grpc::ClientContext;
377 friend class ::grpc::GenericServerContext;
378 #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL
379 friend class ::grpc::GenericCallbackServerContext;
381 friend class ::grpc::experimental::GenericCallbackServerContext;
390 void BeginCompletionOp(
396 void set_call(
grpc_call* call) { call_ = call; }
404 uint32_t initial_metadata_flags()
const {
return 0; }
408 const std::vector<std::unique_ptr<
410 if (creators.size() != 0) {
411 rpc_info_ = new ::grpc::experimental::ServerRpcInfo(
this, method, type);
412 rpc_info_->RegisterInterceptors(creators);
417 void set_message_allocator_state(
419 message_allocator_state_ = allocator_state;
422 CompletionOp* completion_op_;
423 bool has_notify_when_done_tag_;
424 void* async_notify_when_done_tag_;
430 bool sent_initial_metadata_;
431 mutable std::shared_ptr<const ::grpc::AuthContext> auth_context_;
432 mutable ::grpc::internal::MetadataMap client_metadata_;
433 std::multimap<std::string, std::string> initial_metadata_;
434 std::multimap<std::string, std::string> trailing_metadata_;
436 bool compression_level_set_;
443 bool has_pending_ops_;
450 void OnCancel()
override {}
451 void OnDone()
override {}
456 bool InternalInlineable()
override {
return true; }
459 void SetupTestDefaultReactor(std::function<
void(::
grpc::Status)> func) {
460 test_unary_.reset(
new TestServerCallbackUnary(
this, std::move(func)));
462 bool test_status_set()
const {
463 return (test_unary_ !=
nullptr) && test_unary_->status_set();
465 ::grpc::Status test_status()
const {
return test_unary_->status(); }
477 status_set_.store(
true, std::memory_order_release);
479 void SendInitialMetadata()
override {}
481 bool status_set()
const {
482 return status_set_.load(std::memory_order_acquire);
487 void CallOnDone()
override {}
493 std::atomic_bool status_set_{
false};
498 typename std::aligned_storage<
sizeof(Reactor),
alignof(Reactor)>::type
500 std::atomic_bool default_reactor_used_{
false};
501 std::unique_ptr<TestServerCallbackUnary> test_unary_;
601 "improper base class");
604 "improper base class");
612 #endif // GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_IMPL_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
std::string peer() const
Return the peer uri in a string.
grpc_compression_algorithm compression_algorithm() const
Return the compression algorithm the server call will request be used.
Definition: server_context_impl.h:246
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:232
::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:315
::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:850
Definition: call_op_set.h:287
void BindReactor(Reactor *reactor)
Definition: server_callback_impl.h:201
::grpc_impl::ServerAsyncResponseWriter< W > ServerAsyncResponseWriter
Definition: async_unary_call.h:34
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
void SetLoadReportingCosts(const std::vector< std::string > &cost_data)
Set the serialized load reporting costs in cost_data for the call.
Definition: server_callback_impl.h:693
Straightforward wrapping of the C call object.
Definition: call.h:35
std::shared_ptr< const ::grpc::AuthContext > auth_context() const
Return the authentication context for this server call.
Definition: server_context_impl.h:260
Base class of ServerContext. Experimental until callback API is final.
Definition: server_context_impl.h:123
Definition: server_context_impl.h:560
::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 AddTrailingMetadata(const std::string &key, const std::string &value)
Add the (key, value) pair to the initial metadata associated with a server call.
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:520
::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:219
std::shared_ptr< const AuthContext > CreateAuthContext(grpc_call *call)
struct grpc_call grpc_call
A Call represents an RPC.
Definition: grpc_types.h:70
void AddInitialMetadata(const std::string &key, const std::string &value)
Add the (key, value) pair to the initial metadata associated with a server call.
::grpc_impl::ServerReader< R > ServerReader
Definition: sync_stream.h:75
bool IsCancelled() const
Return whether this RPC failed before the server could provide its status back to the client.
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:286
grpc_compression_level compression_level() const
Return the compression algorithm to be used by the server call.
Definition: server_context_impl.h:225
Definition: server_callback_impl.h:191
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
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue.h:99
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:522
grpc_call * c_call()
Should be used for framework-level extensions only.
Definition: server_context_impl.h:278
::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:295
::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:564
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:240