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>
87 template <
class W,
class R>
89 template <
class ServiceType,
class RequestType,
class ResponseType>
92 template <
class Streamer,
bool WriteNeeded>
94 template <::grpc::StatusCode code>
106 namespace experimental {
120 class InteropServerContextInspector;
121 class ServerContextTestSpouse;
122 class DefaultReactorTestPeer;
131 std::chrono::system_clock::time_point
deadline()
const {
224 return *client_metadata_.
map();
229 return compression_level_;
236 compression_level_set_ =
true;
237 compression_level_ = level;
250 return compression_algorithm_;
264 if (auth_context_ ==
nullptr) {
267 return auth_context_;
290 has_notify_when_done_tag_ =
true;
291 async_notify_when_done_tag_ = tag;
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_);
343 friend class ::grpc::testing::InteropServerContextInspector;
344 friend class ::grpc::testing::ServerContextTestSpouse;
345 friend class ::grpc::testing::DefaultReactorTestPeer;
346 friend class ::grpc::ServerInterface;
347 friend class ::grpc::Server;
348 template <
class W,
class R>
349 friend class ::grpc::ServerAsyncReader;
351 friend class ::grpc::ServerAsyncWriter;
353 friend class ::grpc::ServerAsyncResponseWriter;
354 template <
class W,
class R>
355 friend class ::grpc::ServerAsyncReaderWriter;
357 friend class ::grpc::ServerReader;
359 friend class ::grpc::ServerWriter;
360 template <
class W,
class R>
361 friend class ::grpc::internal::ServerReaderWriterBody;
362 template <
class ResponseType>
366 template <
class ServiceType,
class RequestType,
class ResponseType,
367 class BaseRequestType,
class BaseResponseType>
368 friend class ::grpc::internal::RpcMethodHandler;
369 template <
class ServiceType,
class RequestType,
class ResponseType>
370 friend class ::grpc::internal::ClientStreamingHandler;
371 template <
class ServiceType,
class RequestType,
class ResponseType>
372 friend class ::grpc::internal::ServerStreamingHandler;
373 template <
class Streamer,
bool WriteNeeded>
374 friend class ::grpc::internal::TemplatedBidiStreamingHandler;
375 template <
class RequestType,
class ResponseType>
376 friend class ::grpc::internal::CallbackUnaryHandler;
377 template <
class RequestType,
class ResponseType>
378 friend class ::grpc::internal::CallbackClientStreamingHandler;
379 template <
class RequestType,
class ResponseType>
380 friend class ::grpc::internal::CallbackServerStreamingHandler;
381 template <
class RequestType,
class ResponseType>
382 friend class ::grpc::internal::CallbackBidiHandler;
383 template <::grpc::StatusCode code>
384 friend class ::grpc::internal::ErrorMethodHandler;
385 template <
class Base>
386 friend class ::grpc::internal::FinishOnlyReactor;
387 friend class ::grpc::ClientContext;
388 friend class ::grpc::GenericServerContext;
389 friend class ::grpc::GenericCallbackServerContext;
397 void BeginCompletionOp(
403 void set_call(
grpc_call* call) { call_.call = call; }
407 uint32_t initial_metadata_flags()
const {
return 0; }
411 const std::vector<std::unique_ptr<
413 if (!creators.empty()) {
414 rpc_info_ = new ::grpc::experimental::ServerRpcInfo(
this, method, type);
415 rpc_info_->RegisterInterceptors(creators);
420 void set_message_allocator_state(RpcAllocatorState* allocator_state) {
421 message_allocator_state_ = allocator_state;
424 void MaybeMarkCancelledOnRead();
438 CompletionOp* completion_op_ =
nullptr;
439 bool has_notify_when_done_tag_ =
false;
440 void* async_notify_when_done_tag_ =
nullptr;
445 bool sent_initial_metadata_ =
false;
446 mutable std::shared_ptr<const ::grpc::AuthContext> auth_context_;
447 mutable ::grpc::internal::MetadataMap client_metadata_;
448 std::multimap<std::string, std::string> initial_metadata_;
449 std::multimap<std::string, std::string> trailing_metadata_;
451 bool compression_level_set_ =
false;
458 bool has_pending_ops_ =
false;
461 RpcAllocatorState* message_allocator_state_ =
nullptr;
462 ContextAllocator* context_allocator_ =
nullptr;
466 void OnCancel()
override {}
467 void OnDone()
override {}
472 bool InternalInlineable()
override {
return true; }
475 void SetupTestDefaultReactor(std::function<
void(::
grpc::Status)> func) {
477 test_unary_.reset(
new TestServerCallbackUnary(
this, std::move(func)));
479 bool test_status_set()
const {
480 return (test_unary_ !=
nullptr) && test_unary_->status_set();
482 ::grpc::Status test_status()
const {
return test_unary_->status(); }
494 status_set_.store(
true, std::memory_order_release);
496 void SendInitialMetadata()
override {}
498 bool status_set()
const {
499 return status_set_.load(std::memory_order_acquire);
504 void CallOnDone()
override {}
508 std::atomic_bool status_set_{
false};
513 typename std::aligned_storage<
sizeof(Reactor),
alignof(Reactor)>::type
515 std::atomic_bool default_reactor_used_{
false};
517 std::atomic_bool marked_cancelled_{
false};
519 std::unique_ptr<TestServerCallbackUnary> test_unary_;
565 friend class ::grpc::Server;
640 std::is_base_of<::grpc::ServerContextBase, ::grpc::ServerContext>::value,
641 "improper base class");
644 "improper base class");
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
Definition: server_context.h:578
CallbackServerContext()
Public constructors are for direct use only by mocking tests.
Definition: server_context.h:582
A ClientContext allows the person implementing a service client to:
Definition: client_context.h:193
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue.h:102
A CallbackServerContext allows users to use the contents of the CallbackServerContext or GenericCallb...
Definition: server_context.h:622
virtual void Release(GenericCallbackServerContext *)
Definition: server_context.h:634
virtual ~ContextAllocator()
Definition: server_context.h:624
virtual void Release(CallbackServerContext *)
Definition: server_context.h:632
virtual CallbackServerContext * NewCallbackServerContext()
Definition: server_context.h:626
virtual GenericCallbackServerContext * NewGenericCallbackServerContext()
Definition: server_context.h:628
Definition: async_generic_service.h:87
Definition: async_generic_service.h:39
Definition: message_allocator.h:26
Definition: server_callback.h:191
void BindReactor(Reactor *reactor)
Definition: server_callback.h:201
Base class of ServerContext. Experimental until callback API is final.
Definition: server_context.h:126
void set_context_allocator(ContextAllocator *context_allocator)
Definition: server_context.h:336
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:222
std::shared_ptr< const ::grpc::AuthContext > auth_context() const
Return the authentication context for this server call.
Definition: server_context.h:263
void set_compression_algorithm(grpc_compression_algorithm algorithm)
Set algorithm to be the compression algorithm used for the server call.
::grpc::ServerUnaryReactor * DefaultReactor()
Get a library-owned default unary reactor for use in minimal reaction cases.
Definition: server_context.h:315
void set_compression_level(grpc_compression_level level)
Set level to be the compression level used for the server call.
Definition: server_context.h:235
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.h:249
void TryCancel() const
Cancel the Call from the server.
void SetLoadReportingCosts(const std::vector< std::string > &cost_data)
Set the serialized load reporting costs in cost_data for the call.
ServerContextBase()
Constructors for use by derived classes.
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:243
std::chrono::system_clock::time_point deadline() const
Return the deadline for the server call.
Definition: server_context.h:131
const struct census_context * census_context() const
Get the census context associated with this server call.
void AddInitialMetadata(const std::string &key, const std::string &value)
Add the (key, value) pair to the initial metadata associated with a server call.
RpcAllocatorState * GetRpcAllocatorState()
NOTE: This is an API for advanced users who need custom allocators.
Definition: server_context.h:297
virtual ~ServerContextBase()
gpr_timespec raw_deadline() const
Return a gpr_timespec representation of the server call's deadline.
Definition: server_context.h:136
grpc_call * c_call()
Should be used for framework-level extensions only.
Definition: server_context.h:281
grpc_compression_level compression_level() const
Return the compression algorithm to be used by the server call.
Definition: server_context.h:228
void AsyncNotifyWhenDone(void *tag)
Async only.
Definition: server_context.h:289
ContextAllocator * context_allocator() const
Definition: server_context.h:340
void AddTrailingMetadata(const std::string &key, const std::string &value)
Add the (key, value) pair to the initial metadata associated with a server call.
bool IsCancelled() const
Return whether this RPC failed before the server could provide its status back to the client.
ServerContextBase(gpr_timespec deadline, grpc_metadata_array *arr)
A ServerContext or CallbackServerContext allows the code implementing a service handler to:
Definition: server_context.h:538
ServerContext()
Definition: server_context.h:540
std::chrono::system_clock::time_point deadline() const
Return the deadline for the server call.
Definition: server_context.h:131
Represents a gRPC server.
Definition: server.h:59
Definition: server_interface.h:59
Definition: server_callback.h:697
Did it work? If it didn't, why?
Definition: status.h:31
Definition: server_interceptor.h:43
ServerRpcInfo represents the state of a particular RPC as it appears to an interceptor.
Definition: server_interceptor.h:56
Straightforward wrapping of the C call object.
Definition: call.h:35
Definition: call_op_set.h:282
Primary implementation of CallOpSetInterface.
Definition: call_op_set.h:867
CallbackWithSuccessTag can be reused multiple times, and will be used in this fashion for streaming o...
Definition: callback_common.h:135
An interface allowing implementors to process and filter event tags.
Definition: completion_queue_tag.h:26
General method handler class for errors that prevent real method use e.g., handle unknown method by r...
Definition: method_handler.h:358
Definition: server_callback.h:768
A wrapper class of an application provided rpc method handler.
Definition: method_handler.h:98
RpcType
Definition: rpc_method.h:31
The base class of ServerCallbackUnary etc.
Definition: server_callback.h:73
Definition: server_callback.h:49
Definition: sync_stream.h:708
A wrapper class of an application provided server streaming handler.
Definition: method_handler.h:189
A wrapper class of an application provided bidi-streaming handler.
Definition: method_handler.h:262
grpc_compression_level
Compression levels allow a party with knowledge of its peer's accepted encodings to request compressi...
Definition: compression_types.h:71
grpc_compression_algorithm
The various compression algorithms supported by gRPC (not sorted by compression level)
Definition: compression_types.h:57
struct grpc_call grpc_call
A Call represents an RPC.
Definition: grpc_types.h:70
::grpc::ServerContextBase ServerContextBase
Definition: server_context.h:108
::grpc::CallbackServerContext CallbackServerContext
Definition: server_context.h:109
void UnaryRunHandlerHelper(const MethodHandler::HandlerParameter &, ResponseType *, Status &)
void UnaryRunHandlerHelper(const ::grpc::internal::MethodHandler::HandlerParameter &, ResponseType *, ::grpc::Status &)
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t)
std::shared_ptr< const AuthContext > CreateAuthContext(grpc_call *call)
Definition: async_unary_call.h:398
Analogous to struct timespec.
Definition: gpr_types.h:47
Definition: rpc_service_method.h:41