19 #ifndef GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_IMPL_H 20 #define GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_IMPL_H 46 struct census_context;
52 template <
class W,
class R>
58 template <
class W,
class R>
66 template <
class ServiceType,
class RequestType,
class ResponseType>
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>
78 template <
class ServiceType,
class RequestType,
class ResponseType>
81 class FinishOnlyReactor;
82 template <
class W,
class R>
83 class ServerReaderWriterBody;
84 template <
class ServiceType,
class RequestType,
class ResponseType>
87 template <
class Streamer,
bool WriteNeeded>
89 template <::grpc::StatusCode code>
95 class GenericServerContext;
96 class ServerInterface;
98 namespace experimental {
99 class GenericCallbackServerContext;
107 class InteropServerContextInspector;
108 class ServerContextTestSpouse;
109 class DefaultReactorTestPeer;
122 std::chrono::system_clock::time_point
deadline()
const {
205 return *client_metadata_.
map();
210 return compression_level_;
217 compression_level_set_ =
true;
218 compression_level_ = level;
231 return compression_algorithm_;
245 if (auth_context_.get() ==
nullptr) {
248 return auth_context_;
271 has_notify_when_done_tag_ =
true;
272 async_notify_when_done_tag_ = tag;
280 return message_allocator_state_;
300 auto reactor = &default_reactor_;
301 default_reactor_used_.store(
true, std::memory_order_relaxed);
310 friend class ::grpc::testing::InteropServerContextInspector;
311 friend class ::grpc::testing::ServerContextTestSpouse;
312 friend class ::grpc::testing::DefaultReactorTestPeer;
313 friend class ::grpc::ServerInterface;
315 template <
class W,
class R>
321 template <
class W,
class R>
327 template <
class W,
class R>
328 friend class ::grpc_impl::internal::ServerReaderWriterBody;
329 template <
class ServiceType,
class RequestType,
class ResponseType>
331 template <
class ServiceType,
class RequestType,
class ResponseType>
333 template <
class ServiceType,
class RequestType,
class ResponseType>
335 template <
class Streamer,
bool WriteNeeded>
337 template <
class RequestType,
class ResponseType>
338 friend class ::grpc_impl::internal::CallbackUnaryHandler;
339 template <
class RequestType,
class ResponseType>
340 friend class ::grpc_impl::internal::CallbackClientStreamingHandler;
341 template <
class RequestType,
class ResponseType>
342 friend class ::grpc_impl::internal::CallbackServerStreamingHandler;
343 template <
class RequestType,
class ResponseType>
344 friend class ::grpc_impl::internal::CallbackBidiHandler;
345 template <::grpc::StatusCode code>
347 template <
class Base>
348 friend class ::grpc_impl::internal::FinishOnlyReactor;
350 friend class ::grpc::GenericServerContext;
351 friend class ::grpc::experimental::GenericCallbackServerContext;
359 void BeginCompletionOp(
365 void set_call(
grpc_call* call) { call_ = call; }
373 uint32_t initial_metadata_flags()
const {
return 0; }
377 const std::vector<std::unique_ptr<
379 if (creators.size() != 0) {
380 rpc_info_ = new ::grpc::experimental::ServerRpcInfo(
this, method, type);
381 rpc_info_->RegisterInterceptors(creators);
386 void set_message_allocator_state(
388 message_allocator_state_ = allocator_state;
391 CompletionOp* completion_op_;
392 bool has_notify_when_done_tag_;
393 void* async_notify_when_done_tag_;
399 bool sent_initial_metadata_;
400 mutable std::shared_ptr<const ::grpc::AuthContext> auth_context_;
401 mutable ::grpc::internal::MetadataMap client_metadata_;
402 std::multimap<grpc::string, grpc::string> initial_metadata_;
403 std::multimap<grpc::string, grpc::string> trailing_metadata_;
405 bool compression_level_set_;
412 bool has_pending_ops_;
419 void OnCancel()
override {}
420 void OnDone()
override {}
425 bool InternalInlineable()
override {
return true; }
428 void SetupTestDefaultReactor(std::function<
void(::
grpc::Status)> func) {
429 test_unary_.reset(
new TestServerCallbackUnary(
this, std::move(func)));
431 bool test_status_set()
const {
432 return (test_unary_ !=
nullptr) && test_unary_->status_set();
434 ::grpc::Status test_status()
const {
return test_unary_->status(); }
440 : reactor_(&ctx->default_reactor_), func_(
std::move(func)) {
446 status_set_.store(
true, std::memory_order_release);
448 void SendInitialMetadata()
override {}
450 bool status_set()
const {
451 return status_set_.load(std::memory_order_acquire);
456 void MaybeDone()
override {}
462 std::atomic_bool status_set_{
false};
464 const std::function<void(::grpc::Status s)> func_;
467 Reactor default_reactor_;
468 std::atomic_bool default_reactor_used_{
false};
469 std::unique_ptr<TestServerCallbackUnary> test_unary_;
569 "improper base class");
572 "improper base class");
580 #endif // GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_IMPL_H
struct grpc_call grpc_call
A Call represents an RPC.
Definition: grpc_types.h:70
Definition: server_context_impl.h:528
::grpc_impl::ClientContext ClientContext
Definition: client_context.h:26
::grpc_impl::internal::ErrorMethodHandler< code > ErrorMethodHandler
Definition: method_handler.h:62
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:203
bool IsCancelled() const
IsCancelled is always safe to call when using sync or callback API.
Definition: server_context.cc:332
void AddInitialMetadata(const grpc::string &key, const grpc::string &value)
Add the (key, value) pair to the initial metadata associated with a server call.
Definition: server_context.cc:308
std::string string
Definition: config.h:35
::grpc_impl::internal::ClientStreamingHandler< ServiceType, RequestType, ResponseType > ClientStreamingHandler
Definition: method_handler.h:41
void AsyncNotifyWhenDone(void *tag)
Async only.
Definition: server_context_impl.h:270
grpc_compression_level compression_level() const
Return the compression algorithm to be used by the server call.
Definition: server_context_impl.h:209
gpr_timespec raw_deadline() const
Return a gpr_timespec representation of the server call's deadline.
Definition: server_context_impl.h:127
An interface allowing implementors to process and filter event tags.
Definition: completion_queue_tag.h:26
::grpc_impl::internal::TemplatedBidiStreamingHandler< Streamer, WriteNeeded > TemplatedBidiStreamingHandler
Definition: method_handler.h:50
::grpc_impl::Server Server
Definition: server.h:26
Definition: server_callback_impl.h:151
Primary implementation of CallOpSetInterface.
Definition: call_op_set.h:824
CallbackServerContext()
Public constructors are for direct use only by mocking tests.
Definition: server_context_impl.h:532
::grpc_impl::internal::BidiStreamingHandler< ServiceType, RequestType, ResponseType > BidiStreamingHandler
Definition: method_handler.h:31
::grpc_impl::ServerAsyncResponseWriter< W > ServerAsyncResponseWriter
Definition: async_unary_call.h:34
Definition: async_unary_call_impl.h:301
const struct census_context * census_context() const
Get the census context associated with this server call.
Definition: server_context.cc:369
::grpc_impl::ServerAsyncWriter< W > ServerAsyncWriter
Definition: async_stream.h:69
grpc_compression_level
Compression levels allow a party with knowledge of its peer's accepted encodings to request compressi...
Definition: compression_types.h:71
RpcType
Definition: rpc_method.h:31
std::shared_ptr< const AuthContext > CreateAuthContext(grpc_call *call)
Definition: secure_create_auth_context.cc:28
A ServerContext or CallbackServerContext allows the code implementing a service handler to: ...
Definition: server_context_impl.h:488
::grpc::experimental::RpcAllocatorState * GetRpcAllocatorState()
NOTE: This is an API for advanced users who need custom allocators.
Definition: server_context_impl.h:279
Definition: server_interceptor.h:47
The base class of ServerCallbackUnary etc.
Definition: server_callback_impl.h:72
std::chrono::system_clock::time_point deadline() const
Return the deadline for the server call.
Definition: server_context_impl.h:122
grpc::string peer() const
Return the peer uri in a string.
Definition: server_context.cc:359
Base class of ServerContext. Experimental until callback API is final.
Definition: server_context_impl.h:117
::grpc_impl::ServerReader< R > ServerReader
Definition: sync_stream.h:75
::grpc_impl::CompletionQueue CompletionQueue
Definition: completion_queue.h:26
::grpc_impl::ServerUnaryReactor * DefaultReactor()
Get a library-owned default unary reactor for use in minimal reaction cases.
Definition: server_context_impl.h:299
grpc_compression_algorithm compression_algorithm() const
Return the compression algorithm the server call will request be used.
Definition: server_context_impl.h:230
grpc_call * c_call()
Should be used for framework-level extensions only.
Definition: server_context_impl.h:262
void BindReactor(Reactor *reactor)
Definition: server_callback_impl.h:161
Definition: call_op_set.h:286
Definition: server_context.cc:42
grpc_compression_algorithm
The various compression algorithms supported by gRPC (not sorted by compression level) ...
Definition: compression_types.h:57
ServerRpcInfo represents the state of a particular RPC as it appears to an interceptor.
Definition: server_interceptor.h:60
::grpc_impl::ServerUnaryReactor ServerUnaryReactor
Definition: server_callback.h:35
std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t)
Definition: time_cc.cc:63
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
void AddTrailingMetadata(const grpc::string &key, const grpc::string &value)
Add the (key, value) pair to the initial metadata associated with a server call.
Definition: server_context.cc:313
::grpc_impl::internal::RpcMethodHandler< ServiceType, RequestType, ResponseType > RpcMethodHandler
Definition: method_handler.h:36
void SetLoadReportingCosts(const std::vector< grpc::string > &cost_data)
Set the serialized load reporting costs in cost_data for the call.
Definition: server_context.cc:373
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:224
::grpc_impl::internal::ServerStreamingHandler< ServiceType, RequestType, ResponseType > ServerStreamingHandler
Definition: method_handler.h:46
Definition: server_callback_impl.h:660
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:216
ServerContext()
Definition: server_context_impl.h:490
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm_impl.h:33
::grpc_impl::ServerAsyncReaderWriter< W, R > ServerAsyncReaderWriter
Definition: async_stream.h:76
CallbackWithSuccessTag can be reused multiple times, and will be used in this fashion for streaming o...
Definition: callback_common.h:136
::grpc_impl::ServerAsyncReader< W, R > ServerAsyncReader
Definition: async_stream.h:63
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue_impl.h:100
Did it work? If it didn't, why?
Definition: status.h:31
Analogous to struct timespec.
Definition: gpr_types.h:47
virtual ~ServerContextBase()
Definition: server_context.cc:253
Definition: message_allocator.h:27
::grpc_impl::ServerWriter< W > ServerWriter
Definition: sync_stream.h:81
void set_compression_algorithm(grpc_compression_algorithm algorithm)
Set algorithm to be the compression algorithm used for the server call.
Definition: server_context.cc:346
std::shared_ptr< const ::grpc::AuthContext > auth_context() const
Return the authentication context for this server call.
Definition: server_context_impl.h:244
Definition: server_callback_impl.h:48
ServerContextBase()
Constructors for use by derived classes.
Definition: server_context.cc:224
void TryCancel() const
Cancel the Call from the server.
Definition: server_context.cc:318
Straightforward wrapping of the C call object.
Definition: call.h:38