From 0fbc4a715ce4ed07fc15b88a40805dedd9dc5483 Mon Sep 17 00:00:00 2001 From: Cheng-Yu Chung Date: Mon, 17 Oct 2022 16:26:03 -0400 Subject: [PATCH] Remove `include/grpcpp/impl/codegen/service_type.h` (#31282) --- include/grpcpp/ext/orca_service.h | 2 +- include/grpcpp/impl/codegen/service_type.h | 217 +----------------- include/grpcpp/impl/service_type.h | 214 ++++++++++++++++- src/compiler/cpp_generator.cc | 4 +- .../fake_handshaker_server_main.cc | 2 +- .../alts_concurrent_connectivity_test.cc | 2 +- test/cpp/codegen/compiler_test_golden | 2 +- 7 files changed, 222 insertions(+), 221 deletions(-) diff --git a/include/grpcpp/ext/orca_service.h b/include/grpcpp/ext/orca_service.h index b18b94908cb..dcd02657725 100644 --- a/include/grpcpp/ext/orca_service.h +++ b/include/grpcpp/ext/orca_service.h @@ -23,8 +23,8 @@ #include "absl/time/time.h" #include "absl/types/optional.h" -#include #include +#include #include #include #include diff --git a/include/grpcpp/impl/codegen/service_type.h b/include/grpcpp/impl/codegen/service_type.h index 88bcb4a9e45..2db76e2af77 100644 --- a/include/grpcpp/impl/codegen/service_type.h +++ b/include/grpcpp/impl/codegen/service_type.h @@ -19,220 +19,9 @@ #ifndef GRPCPP_IMPL_CODEGEN_SERVICE_TYPE_H #define GRPCPP_IMPL_CODEGEN_SERVICE_TYPE_H -// IWYU pragma: private, include +// IWYU pragma: private -#include -#include -#include -#include -#include -#include - -namespace grpc { - -class CompletionQueue; -class ServerContext; -class ServerInterface; - -namespace internal { -class Call; -class ServerAsyncStreamingInterface { - public: - virtual ~ServerAsyncStreamingInterface() {} - - /// Request notification of the sending of initial metadata to the client. - /// Completion will be notified by \a tag on the associated completion - /// queue. This call is optional, but if it is used, it cannot be used - /// concurrently with or after the \a Finish method. - /// - /// \param[in] tag Tag identifying this request. - virtual void SendInitialMetadata(void* tag) = 0; - - private: - friend class grpc::ServerInterface; - virtual void BindCall(Call* call) = 0; -}; -} // namespace internal - -/// Desriptor of an RPC service and its various RPC methods -class Service { - public: - Service() : server_(nullptr) {} - virtual ~Service() {} - - bool has_async_methods() const { - for (const auto& method : methods_) { - if (method && method->handler() == nullptr) { - return true; - } - } - return false; - } - - bool has_synchronous_methods() const { - for (const auto& method : methods_) { - if (method && - method->api_type() == internal::RpcServiceMethod::ApiType::SYNC) { - return true; - } - } - return false; - } - - bool has_callback_methods() const { - for (const auto& method : methods_) { - if (method && (method->api_type() == - internal::RpcServiceMethod::ApiType::CALL_BACK || - method->api_type() == - internal::RpcServiceMethod::ApiType::RAW_CALL_BACK)) { - return true; - } - } - return false; - } - - bool has_generic_methods() const { - for (const auto& method : methods_) { - if (method == nullptr) { - return true; - } - } - return false; - } - - protected: - template - void RequestAsyncUnary(int index, grpc::ServerContext* context, - Message* request, - internal::ServerAsyncStreamingInterface* stream, - grpc::CompletionQueue* call_cq, - grpc::ServerCompletionQueue* notification_cq, - void* tag) { - // Typecast the index to size_t for indexing into a vector - // while preserving the API that existed before a compiler - // warning was first seen (grpc/grpc#11664) - size_t idx = static_cast(index); - server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, - notification_cq, tag, request); - } - void RequestAsyncClientStreaming( - int index, grpc::ServerContext* context, - internal::ServerAsyncStreamingInterface* stream, - grpc::CompletionQueue* call_cq, - grpc::ServerCompletionQueue* notification_cq, void* tag) { - size_t idx = static_cast(index); - server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, - notification_cq, tag); - } - template - void RequestAsyncServerStreaming( - int index, grpc::ServerContext* context, Message* request, - internal::ServerAsyncStreamingInterface* stream, - grpc::CompletionQueue* call_cq, - grpc::ServerCompletionQueue* notification_cq, void* tag) { - size_t idx = static_cast(index); - server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, - notification_cq, tag, request); - } - void RequestAsyncBidiStreaming( - int index, grpc::ServerContext* context, - internal::ServerAsyncStreamingInterface* stream, - grpc::CompletionQueue* call_cq, - grpc::ServerCompletionQueue* notification_cq, void* tag) { - size_t idx = static_cast(index); - server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, - notification_cq, tag); - } - - void AddMethod(internal::RpcServiceMethod* method) { - methods_.emplace_back(method); - } - - void MarkMethodAsync(int index) { - // This does not have to be a hard error, however no one has approached us - // with a use case yet. Please file an issue if you believe you have one. - size_t idx = static_cast(index); - GPR_CODEGEN_ASSERT( - methods_[idx].get() != nullptr && - "Cannot mark the method as 'async' because it has already been " - "marked as 'generic'."); - methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::ASYNC); - } - - void MarkMethodRaw(int index) { - // This does not have to be a hard error, however no one has approached us - // with a use case yet. Please file an issue if you believe you have one. - size_t idx = static_cast(index); - GPR_CODEGEN_ASSERT(methods_[idx].get() != nullptr && - "Cannot mark the method as 'raw' because it has already " - "been marked as 'generic'."); - methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::RAW); - } - - void MarkMethodGeneric(int index) { - // This does not have to be a hard error, however no one has approached us - // with a use case yet. Please file an issue if you believe you have one. - size_t idx = static_cast(index); - GPR_CODEGEN_ASSERT( - methods_[idx]->handler() != nullptr && - "Cannot mark the method as 'generic' because it has already been " - "marked as 'async' or 'raw'."); - methods_[idx].reset(); - } - - void MarkMethodStreamed(int index, internal::MethodHandler* streamed_method) { - // This does not have to be a hard error, however no one has approached us - // with a use case yet. Please file an issue if you believe you have one. - size_t idx = static_cast(index); - GPR_CODEGEN_ASSERT(methods_[idx] && methods_[idx]->handler() && - "Cannot mark an async or generic method Streamed"); - methods_[idx]->SetHandler(streamed_method); - - // From the server's point of view, streamed unary is a special - // case of BIDI_STREAMING that has 1 read and 1 write, in that order, - // and split server-side streaming is BIDI_STREAMING with 1 read and - // any number of writes, in that order. - methods_[idx]->SetMethodType(internal::RpcMethod::BIDI_STREAMING); - } - - void MarkMethodCallback(int index, internal::MethodHandler* handler) { - // This does not have to be a hard error, however no one has approached us - // with a use case yet. Please file an issue if you believe you have one. - size_t idx = static_cast(index); - GPR_CODEGEN_ASSERT( - methods_[idx].get() != nullptr && - "Cannot mark the method as 'callback' because it has already been " - "marked as 'generic'."); - methods_[idx]->SetHandler(handler); - methods_[idx]->SetServerApiType( - internal::RpcServiceMethod::ApiType::CALL_BACK); - } - - void MarkMethodRawCallback(int index, internal::MethodHandler* handler) { - // This does not have to be a hard error, however no one has approached us - // with a use case yet. Please file an issue if you believe you have one. - size_t idx = static_cast(index); - GPR_CODEGEN_ASSERT( - methods_[idx].get() != nullptr && - "Cannot mark the method as 'raw callback' because it has already " - "been marked as 'generic'."); - methods_[idx]->SetHandler(handler); - methods_[idx]->SetServerApiType( - internal::RpcServiceMethod::ApiType::RAW_CALL_BACK); - } - - internal::MethodHandler* GetHandler(int index) { - size_t idx = static_cast(index); - return methods_[idx]->handler(); - } - - private: - friend class Server; - friend class ServerInterface; - ServerInterface* server_; - std::vector> methods_; -}; - -} // namespace grpc +/// TODO(chengyuc): Remove this file after solving compatibility. +#include #endif // GRPCPP_IMPL_CODEGEN_SERVICE_TYPE_H diff --git a/include/grpcpp/impl/service_type.h b/include/grpcpp/impl/service_type.h index de45c4266a7..5c91f412c64 100644 --- a/include/grpcpp/impl/service_type.h +++ b/include/grpcpp/impl/service_type.h @@ -19,6 +19,218 @@ #ifndef GRPCPP_IMPL_SERVICE_TYPE_H #define GRPCPP_IMPL_SERVICE_TYPE_H -#include // IWYU pragma: export +#include +#include +#include +#include +#include +#include + +namespace grpc { + +class CompletionQueue; +class ServerContext; +class ServerInterface; + +namespace internal { +class Call; +class ServerAsyncStreamingInterface { + public: + virtual ~ServerAsyncStreamingInterface() {} + + /// Request notification of the sending of initial metadata to the client. + /// Completion will be notified by \a tag on the associated completion + /// queue. This call is optional, but if it is used, it cannot be used + /// concurrently with or after the \a Finish method. + /// + /// \param[in] tag Tag identifying this request. + virtual void SendInitialMetadata(void* tag) = 0; + + private: + friend class grpc::ServerInterface; + virtual void BindCall(Call* call) = 0; +}; +} // namespace internal + +/// Desriptor of an RPC service and its various RPC methods +class Service { + public: + Service() : server_(nullptr) {} + virtual ~Service() {} + + bool has_async_methods() const { + for (const auto& method : methods_) { + if (method && method->handler() == nullptr) { + return true; + } + } + return false; + } + + bool has_synchronous_methods() const { + for (const auto& method : methods_) { + if (method && + method->api_type() == internal::RpcServiceMethod::ApiType::SYNC) { + return true; + } + } + return false; + } + + bool has_callback_methods() const { + for (const auto& method : methods_) { + if (method && (method->api_type() == + internal::RpcServiceMethod::ApiType::CALL_BACK || + method->api_type() == + internal::RpcServiceMethod::ApiType::RAW_CALL_BACK)) { + return true; + } + } + return false; + } + + bool has_generic_methods() const { + for (const auto& method : methods_) { + if (method == nullptr) { + return true; + } + } + return false; + } + + protected: + template + void RequestAsyncUnary(int index, grpc::ServerContext* context, + Message* request, + internal::ServerAsyncStreamingInterface* stream, + grpc::CompletionQueue* call_cq, + grpc::ServerCompletionQueue* notification_cq, + void* tag) { + // Typecast the index to size_t for indexing into a vector + // while preserving the API that existed before a compiler + // warning was first seen (grpc/grpc#11664) + size_t idx = static_cast(index); + server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, + notification_cq, tag, request); + } + void RequestAsyncClientStreaming( + int index, grpc::ServerContext* context, + internal::ServerAsyncStreamingInterface* stream, + grpc::CompletionQueue* call_cq, + grpc::ServerCompletionQueue* notification_cq, void* tag) { + size_t idx = static_cast(index); + server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, + notification_cq, tag); + } + template + void RequestAsyncServerStreaming( + int index, grpc::ServerContext* context, Message* request, + internal::ServerAsyncStreamingInterface* stream, + grpc::CompletionQueue* call_cq, + grpc::ServerCompletionQueue* notification_cq, void* tag) { + size_t idx = static_cast(index); + server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, + notification_cq, tag, request); + } + void RequestAsyncBidiStreaming( + int index, grpc::ServerContext* context, + internal::ServerAsyncStreamingInterface* stream, + grpc::CompletionQueue* call_cq, + grpc::ServerCompletionQueue* notification_cq, void* tag) { + size_t idx = static_cast(index); + server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, + notification_cq, tag); + } + + void AddMethod(internal::RpcServiceMethod* method) { + methods_.emplace_back(method); + } + + void MarkMethodAsync(int index) { + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. + size_t idx = static_cast(index); + GPR_CODEGEN_ASSERT( + methods_[idx].get() != nullptr && + "Cannot mark the method as 'async' because it has already been " + "marked as 'generic'."); + methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::ASYNC); + } + + void MarkMethodRaw(int index) { + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. + size_t idx = static_cast(index); + GPR_CODEGEN_ASSERT(methods_[idx].get() != nullptr && + "Cannot mark the method as 'raw' because it has already " + "been marked as 'generic'."); + methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::RAW); + } + + void MarkMethodGeneric(int index) { + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. + size_t idx = static_cast(index); + GPR_CODEGEN_ASSERT( + methods_[idx]->handler() != nullptr && + "Cannot mark the method as 'generic' because it has already been " + "marked as 'async' or 'raw'."); + methods_[idx].reset(); + } + + void MarkMethodStreamed(int index, internal::MethodHandler* streamed_method) { + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. + size_t idx = static_cast(index); + GPR_CODEGEN_ASSERT(methods_[idx] && methods_[idx]->handler() && + "Cannot mark an async or generic method Streamed"); + methods_[idx]->SetHandler(streamed_method); + + // From the server's point of view, streamed unary is a special + // case of BIDI_STREAMING that has 1 read and 1 write, in that order, + // and split server-side streaming is BIDI_STREAMING with 1 read and + // any number of writes, in that order. + methods_[idx]->SetMethodType(internal::RpcMethod::BIDI_STREAMING); + } + + void MarkMethodCallback(int index, internal::MethodHandler* handler) { + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. + size_t idx = static_cast(index); + GPR_CODEGEN_ASSERT( + methods_[idx].get() != nullptr && + "Cannot mark the method as 'callback' because it has already been " + "marked as 'generic'."); + methods_[idx]->SetHandler(handler); + methods_[idx]->SetServerApiType( + internal::RpcServiceMethod::ApiType::CALL_BACK); + } + + void MarkMethodRawCallback(int index, internal::MethodHandler* handler) { + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. + size_t idx = static_cast(index); + GPR_CODEGEN_ASSERT( + methods_[idx].get() != nullptr && + "Cannot mark the method as 'raw callback' because it has already " + "been marked as 'generic'."); + methods_[idx]->SetHandler(handler); + methods_[idx]->SetServerApiType( + internal::RpcServiceMethod::ApiType::RAW_CALL_BACK); + } + + internal::MethodHandler* GetHandler(int index) { + size_t idx = static_cast(index); + return methods_[idx]->handler(); + } + + private: + friend class Server; + friend class ServerInterface; + ServerInterface* server_; + std::vector> methods_; +}; + +} // namespace grpc #endif // GRPCPP_IMPL_SERVICE_TYPE_H diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index 4249df6d3e7..104a628048e 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -150,7 +150,7 @@ std::string GetHeaderIncludes(grpc_generator::File* file, "grpcpp/support/server_callback.h", "grpcpp/impl/codegen/server_callback_handlers.h", "grpcpp/server_context.h", - "grpcpp/impl/codegen/service_type.h", + "grpcpp/impl/service_type.h", "grpcpp/impl/codegen/status.h", "grpcpp/impl/codegen/stub_options.h", "grpcpp/impl/codegen/sync_stream.h", @@ -1659,7 +1659,7 @@ std::string GetSourceIncludes(grpc_generator::File* file, "grpcpp/support/server_callback.h", "grpcpp/impl/codegen/server_callback_handlers.h", "grpcpp/server_context.h", - "grpcpp/impl/codegen/service_type.h", + "grpcpp/impl/service_type.h", "grpcpp/impl/codegen/sync_stream.h"}; std::vector headers(headers_strs, array_end(headers_strs)); PrintIncludes(printer.get(), headers, params.use_system_headers, diff --git a/test/core/tsi/alts/fake_handshaker/fake_handshaker_server_main.cc b/test/core/tsi/alts/fake_handshaker/fake_handshaker_server_main.cc index 352ca36e46a..6eb0ba7d2b9 100644 --- a/test/core/tsi/alts/fake_handshaker/fake_handshaker_server_main.cc +++ b/test/core/tsi/alts/fake_handshaker/fake_handshaker_server_main.cc @@ -20,7 +20,7 @@ #include "absl/flags/flag.h" #include -#include +#include #include #include "test/core/tsi/alts/fake_handshaker/fake_handshaker_server.h" diff --git a/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc b/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc index b4e1920b579..c9dbcf57eec 100644 --- a/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc +++ b/test/core/tsi/alts/handshaker/alts_concurrent_connectivity_test.cc @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include #include "src/core/lib/gpr/useful.h" diff --git a/test/cpp/codegen/compiler_test_golden b/test/cpp/codegen/compiler_test_golden index 20a695c3ff3..ea0ea26aa3a 100644 --- a/test/cpp/codegen/compiler_test_golden +++ b/test/cpp/codegen/compiler_test_golden @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include #include