Merge pull request #19236 from mhaidrygoog/move_server_context

Move server context implementation to grpc_impl namespace and typedef…
pull/19324/head
Moiz Haidry 6 years ago committed by GitHub
commit 465eb2f8d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .gitignore
  2. 1
      BUILD
  3. 1
      BUILD.gn
  4. 5
      CMakeLists.txt
  5. 5
      Makefile
  6. 1
      build.yaml
  7. 1
      gRPC-C++.podspec
  8. 4
      include/grpcpp/impl/codegen/client_context_impl.h
  9. 4
      include/grpcpp/impl/codegen/completion_queue_impl.h
  10. 8
      include/grpcpp/impl/codegen/rpc_service_method.h
  11. 42
      include/grpcpp/impl/codegen/server_callback.h
  12. 355
      include/grpcpp/impl/codegen/server_context.h
  13. 376
      include/grpcpp/impl/codegen/server_context_impl.h
  14. 14
      include/grpcpp/impl/codegen/server_interceptor.h
  15. 22
      include/grpcpp/impl/codegen/server_interface.h
  16. 11
      include/grpcpp/impl/codegen/service_type.h
  17. 2
      include/grpcpp/opencensus.h
  18. 8
      include/grpcpp/opencensus_impl.h
  19. 6
      include/grpcpp/server_impl.h
  20. 2
      src/compiler/cpp_generator.cc
  21. 5
      src/cpp/ext/filters/census/grpc_plugin.h
  22. 38
      src/cpp/server/server_context.cc
  23. 2
      test/cpp/codegen/compiler_test_golden
  24. 1
      tools/doxygen/Doxyfile.c++
  25. 1
      tools/doxygen/Doxyfile.c++.internal
  26. 2
      tools/run_tests/generated/sources_and_headers.json

2
.gitignore vendored

@ -144,3 +144,5 @@ bm_*.json
!.vscode/launch.json !.vscode/launch.json
!.vscode/extensions.json !.vscode/extensions.json
# Clion artifacts
cmake-build-debug/

@ -2186,6 +2186,7 @@ grpc_cc_library(
"include/grpcpp/impl/codegen/serialization_traits.h", "include/grpcpp/impl/codegen/serialization_traits.h",
"include/grpcpp/impl/codegen/server_callback.h", "include/grpcpp/impl/codegen/server_callback.h",
"include/grpcpp/impl/codegen/server_context.h", "include/grpcpp/impl/codegen/server_context.h",
"include/grpcpp/impl/codegen/server_context_impl.h",
"include/grpcpp/impl/codegen/server_interceptor.h", "include/grpcpp/impl/codegen/server_interceptor.h",
"include/grpcpp/impl/codegen/server_interface.h", "include/grpcpp/impl/codegen/server_interface.h",
"include/grpcpp/impl/codegen/service_type.h", "include/grpcpp/impl/codegen/service_type.h",

@ -1082,6 +1082,7 @@ config("grpc_config") {
"include/grpcpp/impl/codegen/serialization_traits.h", "include/grpcpp/impl/codegen/serialization_traits.h",
"include/grpcpp/impl/codegen/server_callback.h", "include/grpcpp/impl/codegen/server_callback.h",
"include/grpcpp/impl/codegen/server_context.h", "include/grpcpp/impl/codegen/server_context.h",
"include/grpcpp/impl/codegen/server_context_impl.h",
"include/grpcpp/impl/codegen/server_interceptor.h", "include/grpcpp/impl/codegen/server_interceptor.h",
"include/grpcpp/impl/codegen/server_interface.h", "include/grpcpp/impl/codegen/server_interface.h",
"include/grpcpp/impl/codegen/service_type.h", "include/grpcpp/impl/codegen/service_type.h",

@ -3337,6 +3337,7 @@ foreach(_hdr
include/grpcpp/impl/codegen/serialization_traits.h include/grpcpp/impl/codegen/serialization_traits.h
include/grpcpp/impl/codegen/server_callback.h include/grpcpp/impl/codegen/server_callback.h
include/grpcpp/impl/codegen/server_context.h include/grpcpp/impl/codegen/server_context.h
include/grpcpp/impl/codegen/server_context_impl.h
include/grpcpp/impl/codegen/server_interceptor.h include/grpcpp/impl/codegen/server_interceptor.h
include/grpcpp/impl/codegen/server_interface.h include/grpcpp/impl/codegen/server_interface.h
include/grpcpp/impl/codegen/service_type.h include/grpcpp/impl/codegen/service_type.h
@ -3957,6 +3958,7 @@ foreach(_hdr
include/grpcpp/impl/codegen/serialization_traits.h include/grpcpp/impl/codegen/serialization_traits.h
include/grpcpp/impl/codegen/server_callback.h include/grpcpp/impl/codegen/server_callback.h
include/grpcpp/impl/codegen/server_context.h include/grpcpp/impl/codegen/server_context.h
include/grpcpp/impl/codegen/server_context_impl.h
include/grpcpp/impl/codegen/server_interceptor.h include/grpcpp/impl/codegen/server_interceptor.h
include/grpcpp/impl/codegen/server_interface.h include/grpcpp/impl/codegen/server_interface.h
include/grpcpp/impl/codegen/service_type.h include/grpcpp/impl/codegen/service_type.h
@ -4393,6 +4395,7 @@ foreach(_hdr
include/grpcpp/impl/codegen/serialization_traits.h include/grpcpp/impl/codegen/serialization_traits.h
include/grpcpp/impl/codegen/server_callback.h include/grpcpp/impl/codegen/server_callback.h
include/grpcpp/impl/codegen/server_context.h include/grpcpp/impl/codegen/server_context.h
include/grpcpp/impl/codegen/server_context_impl.h
include/grpcpp/impl/codegen/server_interceptor.h include/grpcpp/impl/codegen/server_interceptor.h
include/grpcpp/impl/codegen/server_interface.h include/grpcpp/impl/codegen/server_interface.h
include/grpcpp/impl/codegen/service_type.h include/grpcpp/impl/codegen/service_type.h
@ -4593,6 +4596,7 @@ foreach(_hdr
include/grpcpp/impl/codegen/serialization_traits.h include/grpcpp/impl/codegen/serialization_traits.h
include/grpcpp/impl/codegen/server_callback.h include/grpcpp/impl/codegen/server_callback.h
include/grpcpp/impl/codegen/server_context.h include/grpcpp/impl/codegen/server_context.h
include/grpcpp/impl/codegen/server_context_impl.h
include/grpcpp/impl/codegen/server_interceptor.h include/grpcpp/impl/codegen/server_interceptor.h
include/grpcpp/impl/codegen/server_interface.h include/grpcpp/impl/codegen/server_interface.h
include/grpcpp/impl/codegen/service_type.h include/grpcpp/impl/codegen/service_type.h
@ -4953,6 +4957,7 @@ foreach(_hdr
include/grpcpp/impl/codegen/serialization_traits.h include/grpcpp/impl/codegen/serialization_traits.h
include/grpcpp/impl/codegen/server_callback.h include/grpcpp/impl/codegen/server_callback.h
include/grpcpp/impl/codegen/server_context.h include/grpcpp/impl/codegen/server_context.h
include/grpcpp/impl/codegen/server_context_impl.h
include/grpcpp/impl/codegen/server_interceptor.h include/grpcpp/impl/codegen/server_interceptor.h
include/grpcpp/impl/codegen/server_interface.h include/grpcpp/impl/codegen/server_interface.h
include/grpcpp/impl/codegen/service_type.h include/grpcpp/impl/codegen/service_type.h

@ -5692,6 +5692,7 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/impl/codegen/serialization_traits.h \ include/grpcpp/impl/codegen/serialization_traits.h \
include/grpcpp/impl/codegen/server_callback.h \ include/grpcpp/impl/codegen/server_callback.h \
include/grpcpp/impl/codegen/server_context.h \ include/grpcpp/impl/codegen/server_context.h \
include/grpcpp/impl/codegen/server_context_impl.h \
include/grpcpp/impl/codegen/server_interceptor.h \ include/grpcpp/impl/codegen/server_interceptor.h \
include/grpcpp/impl/codegen/server_interface.h \ include/grpcpp/impl/codegen/server_interface.h \
include/grpcpp/impl/codegen/service_type.h \ include/grpcpp/impl/codegen/service_type.h \
@ -6320,6 +6321,7 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/impl/codegen/serialization_traits.h \ include/grpcpp/impl/codegen/serialization_traits.h \
include/grpcpp/impl/codegen/server_callback.h \ include/grpcpp/impl/codegen/server_callback.h \
include/grpcpp/impl/codegen/server_context.h \ include/grpcpp/impl/codegen/server_context.h \
include/grpcpp/impl/codegen/server_context_impl.h \
include/grpcpp/impl/codegen/server_interceptor.h \ include/grpcpp/impl/codegen/server_interceptor.h \
include/grpcpp/impl/codegen/server_interface.h \ include/grpcpp/impl/codegen/server_interface.h \
include/grpcpp/impl/codegen/service_type.h \ include/grpcpp/impl/codegen/service_type.h \
@ -6728,6 +6730,7 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/impl/codegen/serialization_traits.h \ include/grpcpp/impl/codegen/serialization_traits.h \
include/grpcpp/impl/codegen/server_callback.h \ include/grpcpp/impl/codegen/server_callback.h \
include/grpcpp/impl/codegen/server_context.h \ include/grpcpp/impl/codegen/server_context.h \
include/grpcpp/impl/codegen/server_context_impl.h \
include/grpcpp/impl/codegen/server_interceptor.h \ include/grpcpp/impl/codegen/server_interceptor.h \
include/grpcpp/impl/codegen/server_interface.h \ include/grpcpp/impl/codegen/server_interface.h \
include/grpcpp/impl/codegen/service_type.h \ include/grpcpp/impl/codegen/service_type.h \
@ -6899,6 +6902,7 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/impl/codegen/serialization_traits.h \ include/grpcpp/impl/codegen/serialization_traits.h \
include/grpcpp/impl/codegen/server_callback.h \ include/grpcpp/impl/codegen/server_callback.h \
include/grpcpp/impl/codegen/server_context.h \ include/grpcpp/impl/codegen/server_context.h \
include/grpcpp/impl/codegen/server_context_impl.h \
include/grpcpp/impl/codegen/server_interceptor.h \ include/grpcpp/impl/codegen/server_interceptor.h \
include/grpcpp/impl/codegen/server_interface.h \ include/grpcpp/impl/codegen/server_interface.h \
include/grpcpp/impl/codegen/service_type.h \ include/grpcpp/impl/codegen/service_type.h \
@ -7265,6 +7269,7 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/impl/codegen/serialization_traits.h \ include/grpcpp/impl/codegen/serialization_traits.h \
include/grpcpp/impl/codegen/server_callback.h \ include/grpcpp/impl/codegen/server_callback.h \
include/grpcpp/impl/codegen/server_context.h \ include/grpcpp/impl/codegen/server_context.h \
include/grpcpp/impl/codegen/server_context_impl.h \
include/grpcpp/impl/codegen/server_interceptor.h \ include/grpcpp/impl/codegen/server_interceptor.h \
include/grpcpp/impl/codegen/server_interface.h \ include/grpcpp/impl/codegen/server_interface.h \
include/grpcpp/impl/codegen/service_type.h \ include/grpcpp/impl/codegen/service_type.h \

@ -1282,6 +1282,7 @@ filegroups:
- include/grpcpp/impl/codegen/serialization_traits.h - include/grpcpp/impl/codegen/serialization_traits.h
- include/grpcpp/impl/codegen/server_callback.h - include/grpcpp/impl/codegen/server_callback.h
- include/grpcpp/impl/codegen/server_context.h - include/grpcpp/impl/codegen/server_context.h
- include/grpcpp/impl/codegen/server_context_impl.h
- include/grpcpp/impl/codegen/server_interceptor.h - include/grpcpp/impl/codegen/server_interceptor.h
- include/grpcpp/impl/codegen/server_interface.h - include/grpcpp/impl/codegen/server_interface.h
- include/grpcpp/impl/codegen/service_type.h - include/grpcpp/impl/codegen/service_type.h

@ -183,6 +183,7 @@ Pod::Spec.new do |s|
'include/grpcpp/impl/codegen/serialization_traits.h', 'include/grpcpp/impl/codegen/serialization_traits.h',
'include/grpcpp/impl/codegen/server_callback.h', 'include/grpcpp/impl/codegen/server_callback.h',
'include/grpcpp/impl/codegen/server_context.h', 'include/grpcpp/impl/codegen/server_context.h',
'include/grpcpp/impl/codegen/server_context_impl.h',
'include/grpcpp/impl/codegen/server_interceptor.h', 'include/grpcpp/impl/codegen/server_interceptor.h',
'include/grpcpp/impl/codegen/server_interface.h', 'include/grpcpp/impl/codegen/server_interface.h',
'include/grpcpp/impl/codegen/service_type.h', 'include/grpcpp/impl/codegen/service_type.h',

@ -92,7 +92,6 @@ template <class W, class R>
class ClientAsyncReaderWriter; class ClientAsyncReaderWriter;
template <class R> template <class R>
class ClientAsyncResponseReader; class ClientAsyncResponseReader;
class ServerContext;
namespace testing { namespace testing {
class InteropClientContextInspector; class InteropClientContextInspector;
@ -103,6 +102,7 @@ namespace grpc_impl {
class CallCredentials; class CallCredentials;
class Channel; class Channel;
class CompletionQueue; class CompletionQueue;
class ServerContext;
/// Options for \a ClientContext::FromServerContext specifying which traits from /// Options for \a ClientContext::FromServerContext specifying which traits from
/// the \a ServerContext to propagate (copy) from it into a new \a /// the \a ServerContext to propagate (copy) from it into a new \a
@ -191,7 +191,7 @@ class ClientContext {
/// \return A newly constructed \a ClientContext instance based on \a /// \return A newly constructed \a ClientContext instance based on \a
/// server_context, with traits propagated (copied) according to \a options. /// server_context, with traits propagated (copied) according to \a options.
static std::unique_ptr<ClientContext> FromServerContext( static std::unique_ptr<ClientContext> FromServerContext(
const grpc::ServerContext& server_context, const grpc_impl::ServerContext& server_context,
PropagationOptions options = PropagationOptions()); PropagationOptions options = PropagationOptions());
/// Add the (\a meta_key, \a meta_value) pair to the metadata associated with /// Add the (\a meta_key, \a meta_value) pair to the metadata associated with

@ -46,6 +46,7 @@ namespace grpc_impl {
class Channel; class Channel;
class Server; class Server;
class ServerBuilder; class ServerBuilder;
class ServerContext;
} // namespace grpc_impl } // namespace grpc_impl
namespace grpc { namespace grpc {
@ -65,7 +66,6 @@ class ServerReaderWriterBody;
} // namespace internal } // namespace internal
class ChannelInterface; class ChannelInterface;
class ServerContext;
class ServerInterface; class ServerInterface;
namespace internal { namespace internal {
@ -277,7 +277,7 @@ class CompletionQueue : private ::grpc::GrpcLibraryCodegen {
template <::grpc::StatusCode code> template <::grpc::StatusCode code>
friend class ::grpc::internal::ErrorMethodHandler; friend class ::grpc::internal::ErrorMethodHandler;
friend class ::grpc_impl::Server; friend class ::grpc_impl::Server;
friend class ::grpc::ServerContext; friend class ::grpc_impl::ServerContext;
friend class ::grpc::ServerInterface; friend class ::grpc::ServerInterface;
template <class InputMessage, class OutputMessage> template <class InputMessage, class OutputMessage>
friend class ::grpc::internal::BlockingUnaryCallImpl; friend class ::grpc::internal::BlockingUnaryCallImpl;

@ -31,9 +31,11 @@
#include <grpcpp/impl/codegen/rpc_method.h> #include <grpcpp/impl/codegen/rpc_method.h>
#include <grpcpp/impl/codegen/status.h> #include <grpcpp/impl/codegen/status.h>
namespace grpc { namespace grpc_impl {
class ServerContext; class ServerContext;
}
namespace grpc {
namespace internal { namespace internal {
/// Base class for running an RPC handler. /// Base class for running an RPC handler.
class MethodHandler { class MethodHandler {
@ -50,7 +52,7 @@ class MethodHandler {
/// \param requester : used only by the callback API. It is a function /// \param requester : used only by the callback API. It is a function
/// called by the RPC Controller to request another RPC (and also /// called by the RPC Controller to request another RPC (and also
/// to set up the state required to make that request possible) /// to set up the state required to make that request possible)
HandlerParameter(Call* c, ServerContext* context, void* req, HandlerParameter(Call* c, ::grpc_impl::ServerContext* context, void* req,
Status req_status, void* handler_data, Status req_status, void* handler_data,
std::function<void()> requester) std::function<void()> requester)
: call(c), : call(c),
@ -61,7 +63,7 @@ class MethodHandler {
call_requester(std::move(requester)) {} call_requester(std::move(requester)) {}
~HandlerParameter() {} ~HandlerParameter() {}
Call* call; Call* call;
ServerContext* server_context; ::grpc_impl::ServerContext* server_context;
void* request; void* request;
Status status; Status status;
void* internal_data; void* internal_data;

@ -29,7 +29,7 @@
#include <grpcpp/impl/codegen/config.h> #include <grpcpp/impl/codegen/config.h>
#include <grpcpp/impl/codegen/core_codegen_interface.h> #include <grpcpp/impl/codegen/core_codegen_interface.h>
#include <grpcpp/impl/codegen/message_allocator.h> #include <grpcpp/impl/codegen/message_allocator.h>
#include <grpcpp/impl/codegen/server_context.h> #include <grpcpp/impl/codegen/server_context_impl.h>
#include <grpcpp/impl/codegen/server_interface.h> #include <grpcpp/impl/codegen/server_interface.h>
#include <grpcpp/impl/codegen/status.h> #include <grpcpp/impl/codegen/status.h>
@ -53,7 +53,7 @@ class ServerReactor {
virtual void OnCancel() = 0; virtual void OnCancel() = 0;
private: private:
friend class ::grpc::ServerContext; friend class ::grpc_impl::ServerContext;
template <class Request, class Response> template <class Request, class Response>
friend class CallbackClientStreamingHandler; friend class CallbackClientStreamingHandler;
template <class Request, class Response> template <class Request, class Response>
@ -313,7 +313,7 @@ class ServerBidiReactor : public internal::ServerReactor {
/// is a result of the client calling StartCall(). /// is a result of the client calling StartCall().
/// ///
/// \param[in] context The context object now associated with this RPC /// \param[in] context The context object now associated with this RPC
virtual void OnStarted(ServerContext* context) {} virtual void OnStarted(::grpc_impl::ServerContext* context) {}
/// Notifies the application that an explicit StartSendInitialMetadata /// Notifies the application that an explicit StartSendInitialMetadata
/// operation completed. Not used when the sending of initial metadata /// operation completed. Not used when the sending of initial metadata
@ -372,7 +372,7 @@ class ServerReadReactor : public internal::ServerReactor {
/// ///
/// \param[in] context The context object now associated with this RPC /// \param[in] context The context object now associated with this RPC
/// \param[in] resp The response object to be used by this RPC /// \param[in] resp The response object to be used by this RPC
virtual void OnStarted(ServerContext* context, Response* resp) {} virtual void OnStarted(::grpc_impl::ServerContext* context, Response* resp) {}
/// The following notifications are exactly like ServerBidiReactor. /// The following notifications are exactly like ServerBidiReactor.
virtual void OnSendInitialMetadataDone(bool ok) {} virtual void OnSendInitialMetadataDone(bool ok) {}
@ -413,7 +413,8 @@ class ServerWriteReactor : public internal::ServerReactor {
/// ///
/// \param[in] context The context object now associated with this RPC /// \param[in] context The context object now associated with this RPC
/// \param[in] req The request object sent by the client /// \param[in] req The request object sent by the client
virtual void OnStarted(ServerContext* context, const Request* req) {} virtual void OnStarted(::grpc_impl::ServerContext* context,
const Request* req) {}
/// The following notifications are exactly like ServerBidiReactor. /// The following notifications are exactly like ServerBidiReactor.
virtual void OnSendInitialMetadataDone(bool ok) {} virtual void OnSendInitialMetadataDone(bool ok) {}
@ -437,7 +438,7 @@ class UnimplementedReadReactor
: public experimental::ServerReadReactor<Request, Response> { : public experimental::ServerReadReactor<Request, Response> {
public: public:
void OnDone() override { delete this; } void OnDone() override { delete this; }
void OnStarted(ServerContext*, Response*) override { void OnStarted(::grpc_impl::ServerContext*, Response*) override {
this->Finish(Status(StatusCode::UNIMPLEMENTED, "")); this->Finish(Status(StatusCode::UNIMPLEMENTED, ""));
} }
}; };
@ -447,7 +448,7 @@ class UnimplementedWriteReactor
: public experimental::ServerWriteReactor<Request, Response> { : public experimental::ServerWriteReactor<Request, Response> {
public: public:
void OnDone() override { delete this; } void OnDone() override { delete this; }
void OnStarted(ServerContext*, const Request*) override { void OnStarted(::grpc_impl::ServerContext*, const Request*) override {
this->Finish(Status(StatusCode::UNIMPLEMENTED, "")); this->Finish(Status(StatusCode::UNIMPLEMENTED, ""));
} }
}; };
@ -457,7 +458,7 @@ class UnimplementedBidiReactor
: public experimental::ServerBidiReactor<Request, Response> { : public experimental::ServerBidiReactor<Request, Response> {
public: public:
void OnDone() override { delete this; } void OnDone() override { delete this; }
void OnStarted(ServerContext*) override { void OnStarted(::grpc_impl::ServerContext*) override {
this->Finish(Status(StatusCode::UNIMPLEMENTED, "")); this->Finish(Status(StatusCode::UNIMPLEMENTED, ""));
} }
}; };
@ -466,7 +467,8 @@ template <class RequestType, class ResponseType>
class CallbackUnaryHandler : public MethodHandler { class CallbackUnaryHandler : public MethodHandler {
public: public:
CallbackUnaryHandler( CallbackUnaryHandler(
std::function<void(ServerContext*, const RequestType*, ResponseType*, std::function<void(::grpc_impl::ServerContext*, const RequestType*,
ResponseType*,
experimental::ServerCallbackRpcController*)> experimental::ServerCallbackRpcController*)>
func) func)
: func_(func) {} : func_(func) {}
@ -525,8 +527,8 @@ class CallbackUnaryHandler : public MethodHandler {
} }
private: private:
std::function<void(ServerContext*, const RequestType*, ResponseType*, std::function<void(::grpc_impl::ServerContext*, const RequestType*,
experimental::ServerCallbackRpcController*)> ResponseType*, experimental::ServerCallbackRpcController*)>
func_; func_;
experimental::MessageAllocator<RequestType, ResponseType>* allocator_ = experimental::MessageAllocator<RequestType, ResponseType>* allocator_ =
nullptr; nullptr;
@ -597,7 +599,7 @@ class CallbackUnaryHandler : public MethodHandler {
friend class CallbackUnaryHandler<RequestType, ResponseType>; friend class CallbackUnaryHandler<RequestType, ResponseType>;
ServerCallbackRpcControllerImpl( ServerCallbackRpcControllerImpl(
ServerContext* ctx, Call* call, ::grpc_impl::ServerContext* ctx, Call* call,
experimental::MessageHolder<RequestType, ResponseType>* allocator_state, experimental::MessageHolder<RequestType, ResponseType>* allocator_state,
std::function<void()> call_requester) std::function<void()> call_requester)
: ctx_(ctx), : ctx_(ctx),
@ -628,7 +630,7 @@ class CallbackUnaryHandler : public MethodHandler {
finish_ops_; finish_ops_;
CallbackWithSuccessTag finish_tag_; CallbackWithSuccessTag finish_tag_;
ServerContext* ctx_; ::grpc_impl::ServerContext* ctx_;
Call call_; Call call_;
experimental::MessageHolder<RequestType, ResponseType>* const experimental::MessageHolder<RequestType, ResponseType>* const
allocator_state_; allocator_state_;
@ -732,7 +734,8 @@ class CallbackClientStreamingHandler : public MethodHandler {
friend class CallbackClientStreamingHandler<RequestType, ResponseType>; friend class CallbackClientStreamingHandler<RequestType, ResponseType>;
ServerCallbackReaderImpl( ServerCallbackReaderImpl(
ServerContext* ctx, Call* call, std::function<void()> call_requester, ::grpc_impl::ServerContext* ctx, Call* call,
std::function<void()> call_requester,
experimental::ServerReadReactor<RequestType, ResponseType>* reactor) experimental::ServerReadReactor<RequestType, ResponseType>* reactor)
: ctx_(ctx), : ctx_(ctx),
call_(*call), call_(*call),
@ -772,7 +775,7 @@ class CallbackClientStreamingHandler : public MethodHandler {
CallOpSet<CallOpRecvMessage<RequestType>> read_ops_; CallOpSet<CallOpRecvMessage<RequestType>> read_ops_;
CallbackWithSuccessTag read_tag_; CallbackWithSuccessTag read_tag_;
ServerContext* ctx_; ::grpc_impl::ServerContext* ctx_;
Call call_; Call call_;
ResponseType resp_; ResponseType resp_;
std::function<void()> call_requester_; std::function<void()> call_requester_;
@ -909,7 +912,7 @@ class CallbackServerStreamingHandler : public MethodHandler {
friend class CallbackServerStreamingHandler<RequestType, ResponseType>; friend class CallbackServerStreamingHandler<RequestType, ResponseType>;
ServerCallbackWriterImpl( ServerCallbackWriterImpl(
ServerContext* ctx, Call* call, const RequestType* req, ::grpc_impl::ServerContext* ctx, Call* call, const RequestType* req,
std::function<void()> call_requester, std::function<void()> call_requester,
experimental::ServerWriteReactor<RequestType, ResponseType>* reactor) experimental::ServerWriteReactor<RequestType, ResponseType>* reactor)
: ctx_(ctx), : ctx_(ctx),
@ -950,7 +953,7 @@ class CallbackServerStreamingHandler : public MethodHandler {
CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage> write_ops_; CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage> write_ops_;
CallbackWithSuccessTag write_tag_; CallbackWithSuccessTag write_tag_;
ServerContext* ctx_; ::grpc_impl::ServerContext* ctx_;
Call call_; Call call_;
const RequestType* req_; const RequestType* req_;
std::function<void()> call_requester_; std::function<void()> call_requester_;
@ -1078,7 +1081,8 @@ class CallbackBidiHandler : public MethodHandler {
friend class CallbackBidiHandler<RequestType, ResponseType>; friend class CallbackBidiHandler<RequestType, ResponseType>;
ServerCallbackReaderWriterImpl( ServerCallbackReaderWriterImpl(
ServerContext* ctx, Call* call, std::function<void()> call_requester, ::grpc_impl::ServerContext* ctx, Call* call,
std::function<void()> call_requester,
experimental::ServerBidiReactor<RequestType, ResponseType>* reactor) experimental::ServerBidiReactor<RequestType, ResponseType>* reactor)
: ctx_(ctx), : ctx_(ctx),
call_(*call), call_(*call),
@ -1124,7 +1128,7 @@ class CallbackBidiHandler : public MethodHandler {
CallOpSet<CallOpRecvMessage<RequestType>> read_ops_; CallOpSet<CallOpRecvMessage<RequestType>> read_ops_;
CallbackWithSuccessTag read_tag_; CallbackWithSuccessTag read_tag_;
ServerContext* ctx_; ::grpc_impl::ServerContext* ctx_;
Call call_; Call call_;
std::function<void()> call_requester_; std::function<void()> call_requester_;
experimental::ServerBidiReactor<RequestType, ResponseType>* reactor_; experimental::ServerBidiReactor<RequestType, ResponseType>* reactor_;

@ -19,361 +19,10 @@
#ifndef GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_H #ifndef GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_H
#define GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_H #define GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_H
#include <map> #include <grpcpp/impl/codegen/server_context_impl.h>
#include <memory>
#include <vector>
#include <grpc/impl/codegen/compression_types.h>
#include <grpcpp/impl/codegen/call.h>
#include <grpcpp/impl/codegen/call_op_set.h>
#include <grpcpp/impl/codegen/callback_common.h>
#include <grpcpp/impl/codegen/completion_queue_tag.h>
#include <grpcpp/impl/codegen/config.h>
#include <grpcpp/impl/codegen/create_auth_context.h>
#include <grpcpp/impl/codegen/metadata_map.h>
#include <grpcpp/impl/codegen/security/auth_context.h>
#include <grpcpp/impl/codegen/server_interceptor.h>
#include <grpcpp/impl/codegen/string_ref.h>
#include <grpcpp/impl/codegen/time.h>
struct grpc_metadata;
struct grpc_call;
struct census_context;
namespace grpc_impl {
class ClientContext;
class CompletionQueue;
class Server;
} // namespace grpc_impl
namespace grpc { namespace grpc {
class GenericServerContext; typedef ::grpc_impl::ServerContext ServerContext;
class ServerInterface;
template <class W, class R>
class ServerAsyncReader;
template <class W>
class ServerAsyncWriter;
template <class W>
class ServerAsyncResponseWriter;
template <class W, class R>
class ServerAsyncReaderWriter;
template <class R>
class ServerReader;
template <class W>
class ServerWriter;
namespace internal {
template <class W, class R>
class ServerReaderWriterBody;
template <class ServiceType, class RequestType, class ResponseType>
class RpcMethodHandler;
template <class ServiceType, class RequestType, class ResponseType>
class ClientStreamingHandler;
template <class ServiceType, class RequestType, class ResponseType>
class ServerStreamingHandler;
template <class ServiceType, class RequestType, class ResponseType>
class BidiStreamingHandler;
template <class RequestType, class ResponseType>
class CallbackUnaryHandler;
template <class RequestType, class ResponseType>
class CallbackClientStreamingHandler;
template <class RequestType, class ResponseType>
class CallbackServerStreamingHandler;
template <class RequestType, class ResponseType>
class CallbackBidiHandler;
template <class Streamer, bool WriteNeeded>
class TemplatedBidiStreamingHandler;
template <StatusCode code>
class ErrorMethodHandler;
class Call;
class ServerReactor;
} // namespace internal
class ServerInterface;
namespace testing {
class InteropServerContextInspector;
class ServerContextTestSpouse;
} // namespace testing
/// A ServerContext allows the person implementing a service handler to:
///
/// - Add custom initial and trailing metadata key-value pairs that will
/// propagated to the client side.
/// - Control call settings such as compression and authentication.
/// - Access metadata coming from the client.
/// - Get performance metrics (ie, census).
///
/// Context settings are only relevant to the call handler they are supplied to,
/// that is to say, they aren't sticky across multiple calls. Some of these
/// settings, such as the compression options, can be made persistent at server
/// construction time by specifying the appropriate \a ChannelArguments
/// to a \a grpc::ServerBuilder, via \a ServerBuilder::AddChannelArgument.
///
/// \warning ServerContext instances should \em not be reused across rpcs.
class ServerContext {
public:
ServerContext(); // for async calls
~ServerContext();
/// Return the deadline for the server call.
std::chrono::system_clock::time_point deadline() const {
return Timespec2Timepoint(deadline_);
}
/// Return a \a gpr_timespec representation of the server call's deadline.
gpr_timespec raw_deadline() const { return deadline_; }
/// Add the (\a key, \a value) pair to the initial metadata
/// associated with a server call. These are made available at the client side
/// by the \a grpc::ClientContext::GetServerInitialMetadata() method.
///
/// \warning This method should only be called before sending initial metadata
/// to the client (which can happen explicitly, or implicitly when sending a
/// a response message or status to the client).
///
/// \param key The metadata key. If \a value is binary data, it must
/// end in "-bin".
/// \param value The metadata value. If its value is binary, the key name
/// must end in "-bin".
///
/// Metadata must conform to the following format:
/// Custom-Metadata -> Binary-Header / ASCII-Header
/// Binary-Header -> {Header-Name "-bin" } {binary value}
/// ASCII-Header -> Header-Name ASCII-Value
/// Header-Name -> 1*( %x30-39 / %x61-7A / "_" / "-" / ".") ; 0-9 a-z _ - .
/// ASCII-Value -> 1*( %x20-%x7E ) ; space and printable ASCII
void AddInitialMetadata(const grpc::string& key, const grpc::string& value);
/// Add the (\a key, \a value) pair to the initial metadata
/// associated with a server call. These are made available at the client
/// side by the \a grpc::ClientContext::GetServerTrailingMetadata() method.
///
/// \warning This method should only be called before sending trailing
/// metadata to the client (which happens when the call is finished and a
/// status is sent to the client).
///
/// \param key The metadata key. If \a value is binary data,
/// it must end in "-bin".
/// \param value The metadata value. If its value is binary, the key name
/// must end in "-bin".
///
/// Metadata must conform to the following format:
/// Custom-Metadata -> Binary-Header / ASCII-Header
/// Binary-Header -> {Header-Name "-bin" } {binary value}
/// ASCII-Header -> Header-Name ASCII-Value
/// Header-Name -> 1*( %x30-39 / %x61-7A / "_" / "-" / ".") ; 0-9 a-z _ - .
/// ASCII-Value -> 1*( %x20-%x7E ) ; space and printable ASCII
void AddTrailingMetadata(const grpc::string& key, const grpc::string& value);
/// IsCancelled is always safe to call when using sync or callback API.
/// When using async API, it is only safe to call IsCancelled after
/// the AsyncNotifyWhenDone tag has been delivered.
bool IsCancelled() const;
/// Cancel the Call from the server. This is a best-effort API and
/// depending on when it is called, the RPC may still appear successful to
/// the client.
/// For example, if TryCancel() is called on a separate thread, it might race
/// with the server handler which might return success to the client before
/// TryCancel() was even started by the thread.
///
/// It is the caller's responsibility to prevent such races and ensure that if
/// TryCancel() is called, the serverhandler must return Status::CANCELLED.
/// The only exception is that if the serverhandler is already returning an
/// error status code, it is ok to not return Status::CANCELLED even if
/// TryCancel() was called.
///
/// Note that TryCancel() does not change any of the tags that are pending
/// on the completion queue. All pending tags will still be delivered
/// (though their ok result may reflect the effect of cancellation).
void TryCancel() const;
/// Return a collection of initial metadata key-value pairs sent from the
/// client. Note that keys may happen more than
/// once (ie, a \a std::multimap is returned).
///
/// It is safe to use this method after initial metadata has been received,
/// Calls always begin with the client sending initial metadata, so this is
/// safe to access as soon as the call has begun on the server side.
///
/// \return A multimap of initial metadata key-value pairs from the server.
const std::multimap<grpc::string_ref, grpc::string_ref>& client_metadata()
const {
return *client_metadata_.map();
}
/// Return the compression algorithm to be used by the server call.
grpc_compression_level compression_level() const {
return compression_level_;
}
/// Set \a level to be the compression level used for the server call.
///
/// \param level The compression level used for the server call.
void set_compression_level(grpc_compression_level level) {
compression_level_set_ = true;
compression_level_ = level;
}
/// Return a bool indicating whether the compression level for this call
/// has been set (either implicitly or through a previous call to
/// \a set_compression_level.
bool compression_level_set() const { return compression_level_set_; }
/// Return the compression algorithm the server call will request be used.
/// Note that the gRPC runtime may decide to ignore this request, for example,
/// due to resource constraints, or if the server is aware the client doesn't
/// support the requested algorithm.
grpc_compression_algorithm compression_algorithm() const {
return compression_algorithm_;
}
/// Set \a algorithm to be the compression algorithm used for the server call.
///
/// \param algorithm The compression algorithm used for the server call.
void set_compression_algorithm(grpc_compression_algorithm algorithm);
/// Set the serialized load reporting costs in \a cost_data for the call.
void SetLoadReportingCosts(const std::vector<grpc::string>& cost_data);
/// Return the authentication context for this server call.
///
/// \see grpc::AuthContext.
std::shared_ptr<const AuthContext> auth_context() const {
if (auth_context_.get() == nullptr) {
auth_context_ = CreateAuthContext(call_);
}
return auth_context_;
}
/// Return the peer uri in a string.
/// WARNING: this value is never authenticated or subject to any security
/// related code. It must not be used for any authentication related
/// functionality. Instead, use auth_context.
grpc::string peer() const;
/// Get the census context associated with this server call.
const struct census_context* census_context() const;
/// Async only. Has to be called before the rpc starts.
/// Returns the tag in completion queue when the rpc finishes.
/// IsCancelled() can then be called to check whether the rpc was cancelled.
/// TODO(vjpai): Fix this so that the tag is returned even if the call never
/// starts (https://github.com/grpc/grpc/issues/10136).
void AsyncNotifyWhenDone(void* tag) {
has_notify_when_done_tag_ = true;
async_notify_when_done_tag_ = tag;
}
/// Should be used for framework-level extensions only.
/// Applications never need to call this method.
grpc_call* c_call() { return call_; }
private:
friend class ::grpc::testing::InteropServerContextInspector;
friend class ::grpc::testing::ServerContextTestSpouse;
friend class ::grpc::ServerInterface;
friend class ::grpc_impl::Server;
template <class W, class R>
friend class ::grpc::ServerAsyncReader;
template <class W>
friend class ::grpc::ServerAsyncWriter;
template <class W>
friend class ::grpc::ServerAsyncResponseWriter;
template <class W, class R>
friend class ::grpc::ServerAsyncReaderWriter;
template <class R>
friend class ::grpc::ServerReader;
template <class W>
friend class ::grpc::ServerWriter;
template <class W, class R>
friend class ::grpc::internal::ServerReaderWriterBody;
template <class ServiceType, class RequestType, class ResponseType>
friend class ::grpc::internal::RpcMethodHandler;
template <class ServiceType, class RequestType, class ResponseType>
friend class ::grpc::internal::ClientStreamingHandler;
template <class ServiceType, class RequestType, class ResponseType>
friend class ::grpc::internal::ServerStreamingHandler;
template <class Streamer, bool WriteNeeded>
friend class ::grpc::internal::TemplatedBidiStreamingHandler;
template <class RequestType, class ResponseType>
friend class ::grpc::internal::CallbackUnaryHandler;
template <class RequestType, class ResponseType>
friend class ::grpc::internal::CallbackClientStreamingHandler;
template <class RequestType, class ResponseType>
friend class ::grpc::internal::CallbackServerStreamingHandler;
template <class RequestType, class ResponseType>
friend class ::grpc::internal::CallbackBidiHandler;
template <StatusCode code>
friend class internal::ErrorMethodHandler;
friend class ::grpc_impl::ClientContext;
friend class ::grpc::GenericServerContext;
/// Prevent copying.
ServerContext(const ServerContext&);
ServerContext& operator=(const ServerContext&);
class CompletionOp;
void BeginCompletionOp(internal::Call* call,
std::function<void(bool)> callback,
internal::ServerReactor* reactor);
/// Return the tag queued by BeginCompletionOp()
internal::CompletionQueueTag* GetCompletionOpTag();
ServerContext(gpr_timespec deadline, grpc_metadata_array* arr);
void set_call(grpc_call* call) { call_ = call; }
void BindDeadlineAndMetadata(gpr_timespec deadline, grpc_metadata_array* arr);
void Clear();
void Setup(gpr_timespec deadline);
uint32_t initial_metadata_flags() const { return 0; }
void SetCancelCallback(std::function<void()> callback);
void ClearCancelCallback();
experimental::ServerRpcInfo* set_server_rpc_info(
const char* method, internal::RpcMethod::RpcType type,
const std::vector<
std::unique_ptr<experimental::ServerInterceptorFactoryInterface>>&
creators) {
if (creators.size() != 0) {
rpc_info_ = new experimental::ServerRpcInfo(this, method, type);
rpc_info_->RegisterInterceptors(creators);
}
return rpc_info_;
}
CompletionOp* completion_op_;
bool has_notify_when_done_tag_;
void* async_notify_when_done_tag_;
internal::CallbackWithSuccessTag completion_tag_;
gpr_timespec deadline_;
grpc_call* call_;
::grpc_impl::CompletionQueue* cq_;
bool sent_initial_metadata_;
mutable std::shared_ptr<const AuthContext> auth_context_;
mutable internal::MetadataMap client_metadata_;
std::multimap<grpc::string, grpc::string> initial_metadata_;
std::multimap<grpc::string, grpc::string> trailing_metadata_;
bool compression_level_set_;
grpc_compression_level compression_level_;
grpc_compression_algorithm compression_algorithm_;
internal::CallOpSet<internal::CallOpSendInitialMetadata,
internal::CallOpSendMessage>
pending_ops_;
bool has_pending_ops_;
experimental::ServerRpcInfo* rpc_info_;
};
} // namespace grpc } // namespace grpc
#endif // GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_H #endif // GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_H

@ -0,0 +1,376 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_IMPL_H
#define GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_IMPL_H
#include <map>
#include <memory>
#include <vector>
#include <grpc/impl/codegen/compression_types.h>
#include <grpcpp/impl/codegen/call.h>
#include <grpcpp/impl/codegen/call_op_set.h>
#include <grpcpp/impl/codegen/callback_common.h>
#include <grpcpp/impl/codegen/completion_queue_tag.h>
#include <grpcpp/impl/codegen/config.h>
#include <grpcpp/impl/codegen/create_auth_context.h>
#include <grpcpp/impl/codegen/metadata_map.h>
#include <grpcpp/impl/codegen/security/auth_context.h>
#include <grpcpp/impl/codegen/server_interceptor.h>
#include <grpcpp/impl/codegen/string_ref.h>
#include <grpcpp/impl/codegen/time.h>
struct grpc_metadata;
struct grpc_call;
struct census_context;
namespace grpc_impl {
class ClientContext;
class CompletionQueue;
class Server;
} // namespace grpc_impl
namespace grpc {
class GenericServerContext;
class ServerInterface;
template <class W, class R>
class ServerAsyncReader;
template <class W>
class ServerAsyncWriter;
template <class W>
class ServerAsyncResponseWriter;
template <class W, class R>
class ServerAsyncReaderWriter;
template <class R>
class ServerReader;
template <class W>
class ServerWriter;
namespace internal {
template <class W, class R>
class ServerReaderWriterBody;
template <class ServiceType, class RequestType, class ResponseType>
class RpcMethodHandler;
template <class ServiceType, class RequestType, class ResponseType>
class ClientStreamingHandler;
template <class ServiceType, class RequestType, class ResponseType>
class ServerStreamingHandler;
template <class ServiceType, class RequestType, class ResponseType>
class BidiStreamingHandler;
template <class RequestType, class ResponseType>
class CallbackUnaryHandler;
template <class RequestType, class ResponseType>
class CallbackClientStreamingHandler;
template <class RequestType, class ResponseType>
class CallbackServerStreamingHandler;
template <class RequestType, class ResponseType>
class CallbackBidiHandler;
template <class Streamer, bool WriteNeeded>
class TemplatedBidiStreamingHandler;
template <StatusCode code>
class ErrorMethodHandler;
class Call;
class ServerReactor;
} // namespace internal
class ServerInterface;
namespace testing {
class InteropServerContextInspector;
class ServerContextTestSpouse;
} // namespace testing
} // namespace grpc
namespace grpc_impl {
/// A ServerContext allows the person implementing a service handler to:
///
/// - Add custom initial and trailing metadata key-value pairs that will
/// propagated to the client side.
/// - Control call settings such as compression and authentication.
/// - Access metadata coming from the client.
/// - Get performance metrics (ie, census).
///
/// Context settings are only relevant to the call handler they are supplied to,
/// that is to say, they aren't sticky across multiple calls. Some of these
/// settings, such as the compression options, can be made persistent at server
/// construction time by specifying the appropriate \a ChannelArguments
/// to a \a grpc::ServerBuilder, via \a ServerBuilder::AddChannelArgument.
///
/// \warning ServerContext instances should \em not be reused across rpcs.
class ServerContext {
public:
ServerContext(); // for async calls
~ServerContext();
/// Return the deadline for the server call.
std::chrono::system_clock::time_point deadline() const {
return ::grpc::Timespec2Timepoint(deadline_);
}
/// Return a \a gpr_timespec representation of the server call's deadline.
gpr_timespec raw_deadline() const { return deadline_; }
/// Add the (\a key, \a value) pair to the initial metadata
/// associated with a server call. These are made available at the client side
/// by the \a grpc::ClientContext::GetServerInitialMetadata() method.
///
/// \warning This method should only be called before sending initial metadata
/// to the client (which can happen explicitly, or implicitly when sending a
/// a response message or status to the client).
///
/// \param key The metadata key. If \a value is binary data, it must
/// end in "-bin".
/// \param value The metadata value. If its value is binary, the key name
/// must end in "-bin".
///
/// Metadata must conform to the following format:
/// Custom-Metadata -> Binary-Header / ASCII-Header
/// Binary-Header -> {Header-Name "-bin" } {binary value}
/// ASCII-Header -> Header-Name ASCII-Value
/// Header-Name -> 1*( %x30-39 / %x61-7A / "_" / "-" / ".") ; 0-9 a-z _ - .
/// ASCII-Value -> 1*( %x20-%x7E ) ; space and printable ASCII
void AddInitialMetadata(const grpc::string& key, const grpc::string& value);
/// Add the (\a key, \a value) pair to the initial metadata
/// associated with a server call. These are made available at the client
/// side by the \a grpc::ClientContext::GetServerTrailingMetadata() method.
///
/// \warning This method should only be called before sending trailing
/// metadata to the client (which happens when the call is finished and a
/// status is sent to the client).
///
/// \param key The metadata key. If \a value is binary data,
/// it must end in "-bin".
/// \param value The metadata value. If its value is binary, the key name
/// must end in "-bin".
///
/// Metadata must conform to the following format:
/// Custom-Metadata -> Binary-Header / ASCII-Header
/// Binary-Header -> {Header-Name "-bin" } {binary value}
/// ASCII-Header -> Header-Name ASCII-Value
/// Header-Name -> 1*( %x30-39 / %x61-7A / "_" / "-" / ".") ; 0-9 a-z _ - .
/// ASCII-Value -> 1*( %x20-%x7E ) ; space and printable ASCII
void AddTrailingMetadata(const grpc::string& key, const grpc::string& value);
/// IsCancelled is always safe to call when using sync or callback API.
/// When using async API, it is only safe to call IsCancelled after
/// the AsyncNotifyWhenDone tag has been delivered.
bool IsCancelled() const;
/// Cancel the Call from the server. This is a best-effort API and
/// depending on when it is called, the RPC may still appear successful to
/// the client.
/// For example, if TryCancel() is called on a separate thread, it might race
/// with the server handler which might return success to the client before
/// TryCancel() was even started by the thread.
///
/// It is the caller's responsibility to prevent such races and ensure that if
/// TryCancel() is called, the serverhandler must return Status::CANCELLED.
/// The only exception is that if the serverhandler is already returning an
/// error status code, it is ok to not return Status::CANCELLED even if
/// TryCancel() was called.
///
/// Note that TryCancel() does not change any of the tags that are pending
/// on the completion queue. All pending tags will still be delivered
/// (though their ok result may reflect the effect of cancellation).
void TryCancel() const;
/// Return a collection of initial metadata key-value pairs sent from the
/// client. Note that keys may happen more than
/// once (ie, a \a std::multimap is returned).
///
/// It is safe to use this method after initial metadata has been received,
/// Calls always begin with the client sending initial metadata, so this is
/// safe to access as soon as the call has begun on the server side.
///
/// \return A multimap of initial metadata key-value pairs from the server.
const std::multimap<grpc::string_ref, grpc::string_ref>& client_metadata()
const {
return *client_metadata_.map();
}
/// Return the compression algorithm to be used by the server call.
grpc_compression_level compression_level() const {
return compression_level_;
}
/// Set \a level to be the compression level used for the server call.
///
/// \param level The compression level used for the server call.
void set_compression_level(grpc_compression_level level) {
compression_level_set_ = true;
compression_level_ = level;
}
/// Return a bool indicating whether the compression level for this call
/// has been set (either implicitly or through a previous call to
/// \a set_compression_level.
bool compression_level_set() const { return compression_level_set_; }
/// Return the compression algorithm the server call will request be used.
/// Note that the gRPC runtime may decide to ignore this request, for example,
/// due to resource constraints, or if the server is aware the client doesn't
/// support the requested algorithm.
grpc_compression_algorithm compression_algorithm() const {
return compression_algorithm_;
}
/// Set \a algorithm to be the compression algorithm used for the server call.
///
/// \param algorithm The compression algorithm used for the server call.
void set_compression_algorithm(grpc_compression_algorithm algorithm);
/// Set the serialized load reporting costs in \a cost_data for the call.
void SetLoadReportingCosts(const std::vector<grpc::string>& cost_data);
/// Return the authentication context for this server call.
///
/// \see grpc::AuthContext.
std::shared_ptr<const ::grpc::AuthContext> auth_context() const {
if (auth_context_.get() == nullptr) {
auth_context_ = ::grpc::CreateAuthContext(call_);
}
return auth_context_;
}
/// Return the peer uri in a string.
/// WARNING: this value is never authenticated or subject to any security
/// related code. It must not be used for any authentication related
/// functionality. Instead, use auth_context.
grpc::string peer() const;
/// Get the census context associated with this server call.
const struct census_context* census_context() const;
/// Async only. Has to be called before the rpc starts.
/// Returns the tag in completion queue when the rpc finishes.
/// IsCancelled() can then be called to check whether the rpc was cancelled.
/// TODO(vjpai): Fix this so that the tag is returned even if the call never
/// starts (https://github.com/grpc/grpc/issues/10136).
void AsyncNotifyWhenDone(void* tag) {
has_notify_when_done_tag_ = true;
async_notify_when_done_tag_ = tag;
}
/// Should be used for framework-level extensions only.
/// Applications never need to call this method.
grpc_call* c_call() { return call_; }
private:
friend class ::grpc::testing::InteropServerContextInspector;
friend class ::grpc::testing::ServerContextTestSpouse;
friend class ::grpc::ServerInterface;
friend class ::grpc_impl::Server;
template <class W, class R>
friend class ::grpc::ServerAsyncReader;
template <class W>
friend class ::grpc::ServerAsyncWriter;
template <class W>
friend class ::grpc::ServerAsyncResponseWriter;
template <class W, class R>
friend class ::grpc::ServerAsyncReaderWriter;
template <class R>
friend class ::grpc::ServerReader;
template <class W>
friend class ::grpc::ServerWriter;
template <class W, class R>
friend class ::grpc::internal::ServerReaderWriterBody;
template <class ServiceType, class RequestType, class ResponseType>
friend class ::grpc::internal::RpcMethodHandler;
template <class ServiceType, class RequestType, class ResponseType>
friend class ::grpc::internal::ClientStreamingHandler;
template <class ServiceType, class RequestType, class ResponseType>
friend class ::grpc::internal::ServerStreamingHandler;
template <class Streamer, bool WriteNeeded>
friend class ::grpc::internal::TemplatedBidiStreamingHandler;
template <class RequestType, class ResponseType>
friend class ::grpc::internal::CallbackUnaryHandler;
template <class RequestType, class ResponseType>
friend class ::grpc::internal::CallbackClientStreamingHandler;
template <class RequestType, class ResponseType>
friend class ::grpc::internal::CallbackServerStreamingHandler;
template <class RequestType, class ResponseType>
friend class ::grpc::internal::CallbackBidiHandler;
template <::grpc::StatusCode code>
friend class ::grpc::internal::ErrorMethodHandler;
friend class ::grpc_impl::ClientContext;
friend class ::grpc::GenericServerContext;
/// Prevent copying.
ServerContext(const ServerContext&);
ServerContext& operator=(const ServerContext&);
class CompletionOp;
void BeginCompletionOp(::grpc::internal::Call* call,
std::function<void(bool)> callback,
::grpc::internal::ServerReactor* reactor);
/// Return the tag queued by BeginCompletionOp()
::grpc::internal::CompletionQueueTag* GetCompletionOpTag();
ServerContext(gpr_timespec deadline, grpc_metadata_array* arr);
void set_call(grpc_call* call) { call_ = call; }
void BindDeadlineAndMetadata(gpr_timespec deadline, grpc_metadata_array* arr);
void Clear();
void Setup(gpr_timespec deadline);
uint32_t initial_metadata_flags() const { return 0; }
void SetCancelCallback(std::function<void()> callback);
void ClearCancelCallback();
::grpc::experimental::ServerRpcInfo* set_server_rpc_info(
const char* method, ::grpc::internal::RpcMethod::RpcType type,
const std::vector<std::unique_ptr<
::grpc::experimental::ServerInterceptorFactoryInterface>>& creators) {
if (creators.size() != 0) {
rpc_info_ = new ::grpc::experimental::ServerRpcInfo(this, method, type);
rpc_info_->RegisterInterceptors(creators);
}
return rpc_info_;
}
CompletionOp* completion_op_;
bool has_notify_when_done_tag_;
void* async_notify_when_done_tag_;
::grpc::internal::CallbackWithSuccessTag completion_tag_;
gpr_timespec deadline_;
grpc_call* call_;
::grpc_impl::CompletionQueue* cq_;
bool sent_initial_metadata_;
mutable std::shared_ptr<const ::grpc::AuthContext> auth_context_;
mutable ::grpc::internal::MetadataMap client_metadata_;
std::multimap<grpc::string, grpc::string> initial_metadata_;
std::multimap<grpc::string, grpc::string> trailing_metadata_;
bool compression_level_set_;
grpc_compression_level compression_level_;
grpc_compression_algorithm compression_algorithm_;
::grpc::internal::CallOpSet<::grpc::internal::CallOpSendInitialMetadata,
::grpc::internal::CallOpSendMessage>
pending_ops_;
bool has_pending_ops_;
::grpc::experimental::ServerRpcInfo* rpc_info_;
};
} // namespace grpc_impl
#endif // GRPCPP_IMPL_CODEGEN_SERVER_CONTEXT_IMPL_H

@ -26,9 +26,11 @@
#include <grpcpp/impl/codegen/rpc_method.h> #include <grpcpp/impl/codegen/rpc_method.h>
#include <grpcpp/impl/codegen/string_ref.h> #include <grpcpp/impl/codegen/string_ref.h>
namespace grpc { namespace grpc_impl {
class ServerContext; class ServerContext;
}
namespace grpc {
namespace internal { namespace internal {
class InterceptorBatchMethodsImpl; class InterceptorBatchMethodsImpl;
@ -78,7 +80,7 @@ class ServerRpcInfo {
/// Return a pointer to the underlying ServerContext structure associated /// Return a pointer to the underlying ServerContext structure associated
/// with the RPC to support features that apply to it /// with the RPC to support features that apply to it
grpc::ServerContext* server_context() { return ctx_; } grpc_impl::ServerContext* server_context() { return ctx_; }
private: private:
static_assert(Type::UNARY == static_assert(Type::UNARY ==
@ -94,7 +96,7 @@ class ServerRpcInfo {
static_cast<Type>(internal::RpcMethod::BIDI_STREAMING), static_cast<Type>(internal::RpcMethod::BIDI_STREAMING),
"violated expectation about Type enum"); "violated expectation about Type enum");
ServerRpcInfo(grpc::ServerContext* ctx, const char* method, ServerRpcInfo(grpc_impl::ServerContext* ctx, const char* method,
internal::RpcMethod::RpcType type) internal::RpcMethod::RpcType type)
: ctx_(ctx), method_(method), type_(static_cast<Type>(type)) { : ctx_(ctx), method_(method), type_(static_cast<Type>(type)) {
ref_.store(1); ref_.store(1);
@ -127,14 +129,14 @@ class ServerRpcInfo {
} }
} }
grpc::ServerContext* ctx_ = nullptr; grpc_impl::ServerContext* ctx_ = nullptr;
const char* method_ = nullptr; const char* method_ = nullptr;
const Type type_; const Type type_;
std::atomic_int ref_; std::atomic_int ref_;
std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_; std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_;
friend class internal::InterceptorBatchMethodsImpl; friend class internal::InterceptorBatchMethodsImpl;
friend class grpc::ServerContext; friend class grpc_impl::ServerContext;
}; };
} // namespace experimental } // namespace experimental

@ -34,12 +34,12 @@ class Channel;
class CompletionQueue; class CompletionQueue;
class ServerCompletionQueue; class ServerCompletionQueue;
class ServerCredentials; class ServerCredentials;
class ServerContext;
} // namespace grpc_impl } // namespace grpc_impl
namespace grpc { namespace grpc {
class AsyncGenericService; class AsyncGenericService;
class GenericServerContext; class GenericServerContext;
class ServerContext;
class Service; class Service;
extern CoreCodegenInterface* g_core_codegen_interface; extern CoreCodegenInterface* g_core_codegen_interface;
@ -176,7 +176,8 @@ class ServerInterface : public internal::CallHook {
class BaseAsyncRequest : public internal::CompletionQueueTag { class BaseAsyncRequest : public internal::CompletionQueueTag {
public: public:
BaseAsyncRequest(ServerInterface* server, ServerContext* context, BaseAsyncRequest(ServerInterface* server,
::grpc_impl::ServerContext* context,
internal::ServerAsyncStreamingInterface* stream, internal::ServerAsyncStreamingInterface* stream,
::grpc_impl::CompletionQueue* call_cq, ::grpc_impl::CompletionQueue* call_cq,
::grpc_impl::ServerCompletionQueue* notification_cq, ::grpc_impl::ServerCompletionQueue* notification_cq,
@ -190,7 +191,7 @@ class ServerInterface : public internal::CallHook {
protected: protected:
ServerInterface* const server_; ServerInterface* const server_;
ServerContext* const context_; ::grpc_impl::ServerContext* const context_;
internal::ServerAsyncStreamingInterface* const stream_; internal::ServerAsyncStreamingInterface* const stream_;
::grpc_impl::CompletionQueue* const call_cq_; ::grpc_impl::CompletionQueue* const call_cq_;
::grpc_impl::ServerCompletionQueue* const notification_cq_; ::grpc_impl::ServerCompletionQueue* const notification_cq_;
@ -205,7 +206,8 @@ class ServerInterface : public internal::CallHook {
/// RegisteredAsyncRequest is not part of the C++ API /// RegisteredAsyncRequest is not part of the C++ API
class RegisteredAsyncRequest : public BaseAsyncRequest { class RegisteredAsyncRequest : public BaseAsyncRequest {
public: public:
RegisteredAsyncRequest(ServerInterface* server, ServerContext* context, RegisteredAsyncRequest(ServerInterface* server,
::grpc_impl::ServerContext* context,
internal::ServerAsyncStreamingInterface* stream, internal::ServerAsyncStreamingInterface* stream,
::grpc_impl::CompletionQueue* call_cq, ::grpc_impl::CompletionQueue* call_cq,
::grpc_impl::ServerCompletionQueue* notification_cq, ::grpc_impl::ServerCompletionQueue* notification_cq,
@ -234,7 +236,8 @@ class ServerInterface : public internal::CallHook {
class NoPayloadAsyncRequest final : public RegisteredAsyncRequest { class NoPayloadAsyncRequest final : public RegisteredAsyncRequest {
public: public:
NoPayloadAsyncRequest(internal::RpcServiceMethod* registered_method, NoPayloadAsyncRequest(internal::RpcServiceMethod* registered_method,
ServerInterface* server, ServerContext* context, ServerInterface* server,
::grpc_impl::ServerContext* context,
internal::ServerAsyncStreamingInterface* stream, internal::ServerAsyncStreamingInterface* stream,
::grpc_impl::CompletionQueue* call_cq, ::grpc_impl::CompletionQueue* call_cq,
::grpc_impl::ServerCompletionQueue* notification_cq, ::grpc_impl::ServerCompletionQueue* notification_cq,
@ -252,7 +255,8 @@ class ServerInterface : public internal::CallHook {
class PayloadAsyncRequest final : public RegisteredAsyncRequest { class PayloadAsyncRequest final : public RegisteredAsyncRequest {
public: public:
PayloadAsyncRequest(internal::RpcServiceMethod* registered_method, PayloadAsyncRequest(internal::RpcServiceMethod* registered_method,
ServerInterface* server, ServerContext* context, ServerInterface* server,
::grpc_impl::ServerContext* context,
internal::ServerAsyncStreamingInterface* stream, internal::ServerAsyncStreamingInterface* stream,
::grpc_impl::CompletionQueue* call_cq, ::grpc_impl::CompletionQueue* call_cq,
::grpc_impl::ServerCompletionQueue* notification_cq, ::grpc_impl::ServerCompletionQueue* notification_cq,
@ -309,7 +313,7 @@ class ServerInterface : public internal::CallHook {
private: private:
internal::RpcServiceMethod* const registered_method_; internal::RpcServiceMethod* const registered_method_;
ServerInterface* const server_; ServerInterface* const server_;
ServerContext* const context_; ::grpc_impl::ServerContext* const context_;
internal::ServerAsyncStreamingInterface* const stream_; internal::ServerAsyncStreamingInterface* const stream_;
::grpc_impl::CompletionQueue* const call_cq_; ::grpc_impl::CompletionQueue* const call_cq_;
@ -335,7 +339,7 @@ class ServerInterface : public internal::CallHook {
template <class Message> template <class Message>
void RequestAsyncCall(internal::RpcServiceMethod* method, void RequestAsyncCall(internal::RpcServiceMethod* method,
ServerContext* context, ::grpc_impl::ServerContext* context,
internal::ServerAsyncStreamingInterface* stream, internal::ServerAsyncStreamingInterface* stream,
::grpc_impl::CompletionQueue* call_cq, ::grpc_impl::CompletionQueue* call_cq,
::grpc_impl::ServerCompletionQueue* notification_cq, ::grpc_impl::ServerCompletionQueue* notification_cq,
@ -346,7 +350,7 @@ class ServerInterface : public internal::CallHook {
} }
void RequestAsyncCall(internal::RpcServiceMethod* method, void RequestAsyncCall(internal::RpcServiceMethod* method,
ServerContext* context, ::grpc_impl::ServerContext* context,
internal::ServerAsyncStreamingInterface* stream, internal::ServerAsyncStreamingInterface* stream,
::grpc_impl::CompletionQueue* call_cq, ::grpc_impl::CompletionQueue* call_cq,
::grpc_impl::ServerCompletionQueue* notification_cq, ::grpc_impl::ServerCompletionQueue* notification_cq,

@ -30,11 +30,11 @@ namespace grpc_impl {
class Server; class Server;
class CompletionQueue; class CompletionQueue;
class ServerContext;
} // namespace grpc_impl } // namespace grpc_impl
namespace grpc { namespace grpc {
class ServerInterface; class ServerInterface;
class ServerContext;
namespace internal { namespace internal {
class Call; class Call;
@ -146,7 +146,8 @@ class Service {
experimental_type experimental() { return experimental_type(this); } experimental_type experimental() { return experimental_type(this); }
template <class Message> template <class Message>
void RequestAsyncUnary(int index, ServerContext* context, Message* request, void RequestAsyncUnary(int index, ::grpc_impl::ServerContext* context,
Message* request,
internal::ServerAsyncStreamingInterface* stream, internal::ServerAsyncStreamingInterface* stream,
CompletionQueue* call_cq, CompletionQueue* call_cq,
ServerCompletionQueue* notification_cq, void* tag) { ServerCompletionQueue* notification_cq, void* tag) {
@ -158,7 +159,7 @@ class Service {
notification_cq, tag, request); notification_cq, tag, request);
} }
void RequestAsyncClientStreaming( void RequestAsyncClientStreaming(
int index, ServerContext* context, int index, ::grpc_impl::ServerContext* context,
internal::ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, internal::ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq,
ServerCompletionQueue* notification_cq, void* tag) { ServerCompletionQueue* notification_cq, void* tag) {
size_t idx = static_cast<size_t>(index); size_t idx = static_cast<size_t>(index);
@ -167,7 +168,7 @@ class Service {
} }
template <class Message> template <class Message>
void RequestAsyncServerStreaming( void RequestAsyncServerStreaming(
int index, ServerContext* context, Message* request, int index, ::grpc_impl::ServerContext* context, Message* request,
internal::ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, internal::ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq,
ServerCompletionQueue* notification_cq, void* tag) { ServerCompletionQueue* notification_cq, void* tag) {
size_t idx = static_cast<size_t>(index); size_t idx = static_cast<size_t>(index);
@ -175,7 +176,7 @@ class Service {
notification_cq, tag, request); notification_cq, tag, request);
} }
void RequestAsyncBidiStreaming( void RequestAsyncBidiStreaming(
int index, ServerContext* context, int index, ::grpc_impl::ServerContext* context,
internal::ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, internal::ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq,
ServerCompletionQueue* notification_cq, void* tag) { ServerCompletionQueue* notification_cq, void* tag) {
size_t idx = static_cast<size_t>(index); size_t idx = static_cast<size_t>(index);

@ -30,7 +30,7 @@ static inline void RegisterOpenCensusViewsForExport() {
::grpc_impl::RegisterOpenCensusViewsForExport(); ::grpc_impl::RegisterOpenCensusViewsForExport();
} }
static inline ::opencensus::trace::Span GetSpanFromServerContext( static inline ::opencensus::trace::Span GetSpanFromServerContext(
ServerContext* context) { ::grpc_impl::ServerContext* context) {
return ::grpc_impl::GetSpanFromServerContext(context); return ::grpc_impl::GetSpanFromServerContext(context);
} }

@ -21,11 +21,8 @@
#include "opencensus/trace/span.h" #include "opencensus/trace/span.h"
namespace grpc {
class ServerContext;
}
namespace grpc_impl { namespace grpc_impl {
class ServerContext;
// These symbols in this file will not be included in the binary unless // These symbols in this file will not be included in the binary unless
// grpc_opencensus_plugin build target was added as a dependency. At the moment // grpc_opencensus_plugin build target was added as a dependency. At the moment
// it is only setup to be built with Bazel. // it is only setup to be built with Bazel.
@ -43,8 +40,7 @@ void RegisterOpenCensusPlugin();
void RegisterOpenCensusViewsForExport(); void RegisterOpenCensusViewsForExport();
// Returns the tracing Span for the current RPC. // Returns the tracing Span for the current RPC.
::opencensus::trace::Span GetSpanFromServerContext( ::opencensus::trace::Span GetSpanFromServerContext(ServerContext* context);
grpc::ServerContext* context);
} // namespace grpc_impl } // namespace grpc_impl

@ -44,7 +44,6 @@ struct grpc_server;
namespace grpc { namespace grpc {
class AsyncGenericService; class AsyncGenericService;
class ServerContext;
namespace internal { namespace internal {
class ExternalConnectionAcceptorImpl; class ExternalConnectionAcceptorImpl;
@ -54,6 +53,7 @@ class ExternalConnectionAcceptorImpl;
namespace grpc_impl { namespace grpc_impl {
class HealthCheckServiceInterface; class HealthCheckServiceInterface;
class ServerContext;
class ServerInitializer; class ServerInitializer;
/// Represents a gRPC server. /// Represents a gRPC server.
@ -82,9 +82,9 @@ class Server : public grpc::ServerInterface, private grpc::GrpcLibraryCodegen {
/// Called before server is created. /// Called before server is created.
virtual void UpdateArguments(grpc::ChannelArguments* args) {} virtual void UpdateArguments(grpc::ChannelArguments* args) {}
/// Called before application callback for each synchronous server request /// Called before application callback for each synchronous server request
virtual void PreSynchronousRequest(grpc::ServerContext* context) = 0; virtual void PreSynchronousRequest(grpc_impl::ServerContext* context) = 0;
/// Called after application callback for each synchronous server request /// Called after application callback for each synchronous server request
virtual void PostSynchronousRequest(grpc::ServerContext* context) = 0; virtual void PostSynchronousRequest(grpc_impl::ServerContext* context) = 0;
/// Called before server is started. /// Called before server is started.
virtual void PreServerStart(Server* server) {} virtual void PreServerStart(Server* server) {}
/// Called after a server port is added. /// Called after a server port is added.

@ -157,13 +157,13 @@ grpc::string GetHeaderIncludes(grpc_generator::File* file,
printer->Print(vars, "namespace grpc_impl {\n"); printer->Print(vars, "namespace grpc_impl {\n");
printer->Print(vars, "class CompletionQueue;\n"); printer->Print(vars, "class CompletionQueue;\n");
printer->Print(vars, "class ServerCompletionQueue;\n"); printer->Print(vars, "class ServerCompletionQueue;\n");
printer->Print(vars, "class ServerContext;\n");
printer->Print(vars, "} // namespace grpc_impl\n\n"); printer->Print(vars, "} // namespace grpc_impl\n\n");
printer->Print(vars, "namespace grpc {\n"); printer->Print(vars, "namespace grpc {\n");
printer->Print(vars, "namespace experimental {\n"); printer->Print(vars, "namespace experimental {\n");
printer->Print(vars, "template <typename RequestT, typename ResponseT>\n"); printer->Print(vars, "template <typename RequestT, typename ResponseT>\n");
printer->Print(vars, "class MessageAllocator;\n"); printer->Print(vars, "class MessageAllocator;\n");
printer->Print(vars, "} // namespace experimental\n"); printer->Print(vars, "} // namespace experimental\n");
printer->Print(vars, "class ServerContext;\n");
printer->Print(vars, "} // namespace grpc\n\n"); printer->Print(vars, "} // namespace grpc\n\n");
vars["message_header_ext"] = params.message_header_extension.empty() vars["message_header_ext"] = params.message_header_extension.empty()

@ -25,8 +25,11 @@
#include "include/grpcpp/opencensus.h" #include "include/grpcpp/opencensus.h"
#include "opencensus/stats/stats.h" #include "opencensus/stats/stats.h"
namespace grpc { namespace grpc_impl {
class ServerContext; class ServerContext;
}
namespace grpc {
// The tag keys set when recording RPC stats. // The tag keys set when recording RPC stats.
::opencensus::stats::TagKey ClientMethodTagKey(); ::opencensus::stats::TagKey ClientMethodTagKey();

@ -16,7 +16,7 @@
* *
*/ */
#include <grpcpp/server_context.h> #include <grpcpp/impl/codegen/server_context_impl.h>
#include <grpcpp/support/server_callback.h> #include <grpcpp/support/server_callback.h>
#include <algorithm> #include <algorithm>
@ -28,23 +28,25 @@
#include <grpc/load_reporting.h> #include <grpc/load_reporting.h>
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpcpp/completion_queue.h>
#include <grpcpp/impl/call.h> #include <grpcpp/impl/call.h>
#include <grpcpp/impl/codegen/completion_queue_impl.h>
#include <grpcpp/support/time.h> #include <grpcpp/support/time.h>
#include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/gprpp/ref_counted.h"
#include "src/core/lib/gprpp/sync.h" #include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/surface/call.h" #include "src/core/lib/surface/call.h"
namespace grpc { namespace grpc_impl {
// CompletionOp // CompletionOp
class ServerContext::CompletionOp final : public internal::CallOpSetInterface { class ServerContext::CompletionOp final
: public ::grpc::internal::CallOpSetInterface {
public: public:
// initial refs: one in the server context, one in the cq // initial refs: one in the server context, one in the cq
// must ref the call before calling constructor and after deleting this // must ref the call before calling constructor and after deleting this
CompletionOp(internal::Call* call, internal::ServerReactor* reactor) CompletionOp(::grpc::internal::Call* call,
::grpc::internal::ServerReactor* reactor)
: call_(*call), : call_(*call),
reactor_(reactor), reactor_(reactor),
has_tag_(false), has_tag_(false),
@ -67,7 +69,7 @@ class ServerContext::CompletionOp final : public internal::CallOpSetInterface {
} }
} }
void FillOps(internal::Call* call) override; void FillOps(::grpc::internal::Call* call) override;
// This should always be arena allocated in the call, so override delete. // This should always be arena allocated in the call, so override delete.
// But this class is not trivially destructible, so must actually call delete // But this class is not trivially destructible, so must actually call delete
@ -149,8 +151,8 @@ class ServerContext::CompletionOp final : public internal::CallOpSetInterface {
return finalized_ ? (cancelled_ != 0) : false; return finalized_ ? (cancelled_ != 0) : false;
} }
internal::Call call_; ::grpc::internal::Call call_;
internal::ServerReactor* const reactor_; ::grpc::internal::ServerReactor* const reactor_;
bool has_tag_; bool has_tag_;
void* tag_; void* tag_;
void* core_cq_tag_; void* core_cq_tag_;
@ -160,7 +162,7 @@ class ServerContext::CompletionOp final : public internal::CallOpSetInterface {
int cancelled_; // This is an int (not bool) because it is passed to core int cancelled_; // This is an int (not bool) because it is passed to core
std::function<void()> cancel_callback_; std::function<void()> cancel_callback_;
bool done_intercepting_; bool done_intercepting_;
internal::InterceptorBatchMethodsImpl interceptor_methods_; ::grpc::internal::InterceptorBatchMethodsImpl interceptor_methods_;
}; };
void ServerContext::CompletionOp::Unref() { void ServerContext::CompletionOp::Unref() {
@ -171,7 +173,7 @@ void ServerContext::CompletionOp::Unref() {
} }
} }
void ServerContext::CompletionOp::FillOps(internal::Call* call) { void ServerContext::CompletionOp::FillOps(::grpc::internal::Call* call) {
grpc_op ops; grpc_op ops;
ops.op = GRPC_OP_RECV_CLOSE_ON_SERVER; ops.op = GRPC_OP_RECV_CLOSE_ON_SERVER;
ops.data.recv_close_on_server.cancelled = &cancelled_; ops.data.recv_close_on_server.cancelled = &cancelled_;
@ -227,7 +229,7 @@ bool ServerContext::CompletionOp::FinalizeResult(void** tag, bool* status) {
} }
/* Add interception point and run through interceptors */ /* Add interception point and run through interceptors */
interceptor_methods_.AddInterceptionHookPoint( interceptor_methods_.AddInterceptionHookPoint(
experimental::InterceptionHookPoints::POST_RECV_CLOSE); ::grpc::experimental::InterceptionHookPoints::POST_RECV_CLOSE);
if (interceptor_methods_.RunInterceptors()) { if (interceptor_methods_.RunInterceptors()) {
/* No interceptors were run */ /* No interceptors were run */
if (has_tag_) { if (has_tag_) {
@ -292,9 +294,9 @@ void ServerContext::Clear() {
} }
} }
void ServerContext::BeginCompletionOp(internal::Call* call, void ServerContext::BeginCompletionOp(
std::function<void(bool)> callback, ::grpc::internal::Call* call, std::function<void(bool)> callback,
internal::ServerReactor* reactor) { ::grpc::internal::ServerReactor* reactor) {
GPR_ASSERT(!completion_op_); GPR_ASSERT(!completion_op_);
if (rpc_info_) { if (rpc_info_) {
rpc_info_->Ref(); rpc_info_->Ref();
@ -313,8 +315,8 @@ void ServerContext::BeginCompletionOp(internal::Call* call,
call->PerformOps(completion_op_); call->PerformOps(completion_op_);
} }
internal::CompletionQueueTag* ServerContext::GetCompletionOpTag() { ::grpc::internal::CompletionQueueTag* ServerContext::GetCompletionOpTag() {
return static_cast<internal::CompletionQueueTag*>(completion_op_); return static_cast<::grpc::internal::CompletionQueueTag*>(completion_op_);
} }
void ServerContext::AddInitialMetadata(const grpc::string& key, void ServerContext::AddInitialMetadata(const grpc::string& key,
@ -328,7 +330,7 @@ void ServerContext::AddTrailingMetadata(const grpc::string& key,
} }
void ServerContext::TryCancel() const { void ServerContext::TryCancel() const {
internal::CancelInterceptorBatchMethods cancel_methods; ::grpc::internal::CancelInterceptorBatchMethods cancel_methods;
if (rpc_info_) { if (rpc_info_) {
for (size_t i = 0; i < rpc_info_->interceptors_.size(); i++) { for (size_t i = 0; i < rpc_info_->interceptors_.size(); i++) {
rpc_info_->RunInterceptor(&cancel_methods, i); rpc_info_->RunInterceptor(&cancel_methods, i);
@ -398,4 +400,4 @@ void ServerContext::SetLoadReportingCosts(
} }
} }
} // namespace grpc } // namespace grpc_impl

@ -43,6 +43,7 @@
namespace grpc_impl { namespace grpc_impl {
class CompletionQueue; class CompletionQueue;
class ServerCompletionQueue; class ServerCompletionQueue;
class ServerContext;
} // namespace grpc_impl } // namespace grpc_impl
namespace grpc { namespace grpc {
@ -50,7 +51,6 @@ namespace experimental {
template <typename RequestT, typename ResponseT> template <typename RequestT, typename ResponseT>
class MessageAllocator; class MessageAllocator;
} // namespace experimental } // namespace experimental
class ServerContext;
} // namespace grpc } // namespace grpc
namespace grpc { namespace grpc {

@ -983,6 +983,7 @@ include/grpcpp/impl/codegen/security/auth_context.h \
include/grpcpp/impl/codegen/serialization_traits.h \ include/grpcpp/impl/codegen/serialization_traits.h \
include/grpcpp/impl/codegen/server_callback.h \ include/grpcpp/impl/codegen/server_callback.h \
include/grpcpp/impl/codegen/server_context.h \ include/grpcpp/impl/codegen/server_context.h \
include/grpcpp/impl/codegen/server_context_impl.h \
include/grpcpp/impl/codegen/server_interceptor.h \ include/grpcpp/impl/codegen/server_interceptor.h \
include/grpcpp/impl/codegen/server_interface.h \ include/grpcpp/impl/codegen/server_interface.h \
include/grpcpp/impl/codegen/service_type.h \ include/grpcpp/impl/codegen/service_type.h \

@ -985,6 +985,7 @@ include/grpcpp/impl/codegen/security/auth_context.h \
include/grpcpp/impl/codegen/serialization_traits.h \ include/grpcpp/impl/codegen/serialization_traits.h \
include/grpcpp/impl/codegen/server_callback.h \ include/grpcpp/impl/codegen/server_callback.h \
include/grpcpp/impl/codegen/server_context.h \ include/grpcpp/impl/codegen/server_context.h \
include/grpcpp/impl/codegen/server_context_impl.h \
include/grpcpp/impl/codegen/server_interceptor.h \ include/grpcpp/impl/codegen/server_interceptor.h \
include/grpcpp/impl/codegen/server_interface.h \ include/grpcpp/impl/codegen/server_interface.h \
include/grpcpp/impl/codegen/service_type.h \ include/grpcpp/impl/codegen/service_type.h \

@ -10152,6 +10152,7 @@
"include/grpcpp/impl/codegen/serialization_traits.h", "include/grpcpp/impl/codegen/serialization_traits.h",
"include/grpcpp/impl/codegen/server_callback.h", "include/grpcpp/impl/codegen/server_callback.h",
"include/grpcpp/impl/codegen/server_context.h", "include/grpcpp/impl/codegen/server_context.h",
"include/grpcpp/impl/codegen/server_context_impl.h",
"include/grpcpp/impl/codegen/server_interceptor.h", "include/grpcpp/impl/codegen/server_interceptor.h",
"include/grpcpp/impl/codegen/server_interface.h", "include/grpcpp/impl/codegen/server_interface.h",
"include/grpcpp/impl/codegen/service_type.h", "include/grpcpp/impl/codegen/service_type.h",
@ -10231,6 +10232,7 @@
"include/grpcpp/impl/codegen/serialization_traits.h", "include/grpcpp/impl/codegen/serialization_traits.h",
"include/grpcpp/impl/codegen/server_callback.h", "include/grpcpp/impl/codegen/server_callback.h",
"include/grpcpp/impl/codegen/server_context.h", "include/grpcpp/impl/codegen/server_context.h",
"include/grpcpp/impl/codegen/server_context_impl.h",
"include/grpcpp/impl/codegen/server_interceptor.h", "include/grpcpp/impl/codegen/server_interceptor.h",
"include/grpcpp/impl/codegen/server_interface.h", "include/grpcpp/impl/codegen/server_interface.h",
"include/grpcpp/impl/codegen/service_type.h", "include/grpcpp/impl/codegen/service_type.h",

Loading…
Cancel
Save