From f71801ffd6ce4218f32f53bf0f1b2c4e87c0f2e5 Mon Sep 17 00:00:00 2001 From: Karthik Ravi Shankar Date: Mon, 13 Jul 2020 14:45:33 -0700 Subject: [PATCH] Move GenericStub from ::grpc_impl to ::grpc Reverts: https://github.com/grpc/grpc/pull/18434 --- BUILD | 1 - BUILD.gn | 1 - CMakeLists.txt | 2 - Makefile | 2 - build_autogenerated.yaml | 2 - gRPC-C++.podspec | 1 - include/grpcpp/generic/generic_stub.h | 190 +++++++++++++++++- include/grpcpp/generic/generic_stub_impl.h | 216 --------------------- tools/doxygen/Doxyfile.c++ | 1 - tools/doxygen/Doxyfile.c++.internal | 1 - 10 files changed, 188 insertions(+), 229 deletions(-) delete mode 100644 include/grpcpp/generic/generic_stub_impl.h diff --git a/BUILD b/BUILD index 48fa1dfdb4a..016cf508bf5 100644 --- a/BUILD +++ b/BUILD @@ -230,7 +230,6 @@ GRPCXX_PUBLIC_HDRS = [ "include/grpcpp/ext/health_check_service_server_builder_option.h", "include/grpcpp/generic/async_generic_service.h", "include/grpcpp/generic/generic_stub.h", - "include/grpcpp/generic/generic_stub_impl.h", "include/grpcpp/grpcpp.h", "include/grpcpp/health_check_service_interface.h", "include/grpcpp/impl/call.h", diff --git a/BUILD.gn b/BUILD.gn index ea1e691aed5..a74787c60b4 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1231,7 +1231,6 @@ config("grpc_config") { "include/grpcpp/ext/health_check_service_server_builder_option.h", "include/grpcpp/generic/async_generic_service.h", "include/grpcpp/generic/generic_stub.h", - "include/grpcpp/generic/generic_stub_impl.h", "include/grpcpp/grpcpp.h", "include/grpcpp/health_check_service_interface.h", "include/grpcpp/impl/call.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 61842a31b40..b24b9ba51ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2812,7 +2812,6 @@ foreach(_hdr include/grpcpp/ext/health_check_service_server_builder_option.h include/grpcpp/generic/async_generic_service.h include/grpcpp/generic/generic_stub.h - include/grpcpp/generic/generic_stub_impl.h include/grpcpp/grpcpp.h include/grpcpp/health_check_service_interface.h include/grpcpp/impl/call.h @@ -3509,7 +3508,6 @@ foreach(_hdr include/grpcpp/ext/health_check_service_server_builder_option.h include/grpcpp/generic/async_generic_service.h include/grpcpp/generic/generic_stub.h - include/grpcpp/generic/generic_stub_impl.h include/grpcpp/grpcpp.h include/grpcpp/health_check_service_interface.h include/grpcpp/impl/call.h diff --git a/Makefile b/Makefile index 0cc937ebd15..c2295116b2e 100644 --- a/Makefile +++ b/Makefile @@ -5014,7 +5014,6 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/ext/health_check_service_server_builder_option.h \ include/grpcpp/generic/async_generic_service.h \ include/grpcpp/generic/generic_stub.h \ - include/grpcpp/generic/generic_stub_impl.h \ include/grpcpp/grpcpp.h \ include/grpcpp/health_check_service_interface.h \ include/grpcpp/impl/call.h \ @@ -5709,7 +5708,6 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/ext/health_check_service_server_builder_option.h \ include/grpcpp/generic/async_generic_service.h \ include/grpcpp/generic/generic_stub.h \ - include/grpcpp/generic/generic_stub_impl.h \ include/grpcpp/grpcpp.h \ include/grpcpp/health_check_service_interface.h \ include/grpcpp/impl/call.h \ diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 38dccf419a0..495c2ff0f2f 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -2339,7 +2339,6 @@ libs: - include/grpcpp/ext/health_check_service_server_builder_option.h - include/grpcpp/generic/async_generic_service.h - include/grpcpp/generic/generic_stub.h - - include/grpcpp/generic/generic_stub_impl.h - include/grpcpp/grpcpp.h - include/grpcpp/health_check_service_interface.h - include/grpcpp/impl/call.h @@ -2728,7 +2727,6 @@ libs: - include/grpcpp/ext/health_check_service_server_builder_option.h - include/grpcpp/generic/async_generic_service.h - include/grpcpp/generic/generic_stub.h - - include/grpcpp/generic/generic_stub_impl.h - include/grpcpp/grpcpp.h - include/grpcpp/health_check_service_interface.h - include/grpcpp/impl/call.h diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 7d0d152eff6..8c7e08e2207 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -89,7 +89,6 @@ Pod::Spec.new do |s| 'include/grpcpp/ext/health_check_service_server_builder_option.h', 'include/grpcpp/generic/async_generic_service.h', 'include/grpcpp/generic/generic_stub.h', - 'include/grpcpp/generic/generic_stub_impl.h', 'include/grpcpp/grpcpp.h', 'include/grpcpp/health_check_service_interface.h', 'include/grpcpp/impl/call.h', diff --git a/include/grpcpp/generic/generic_stub.h b/include/grpcpp/generic/generic_stub.h index f4c4664f53c..8610669a64a 100644 --- a/include/grpcpp/generic/generic_stub.h +++ b/include/grpcpp/generic/generic_stub.h @@ -19,11 +19,197 @@ #ifndef GRPCPP_GENERIC_GENERIC_STUB_H #define GRPCPP_GENERIC_GENERIC_STUB_H -#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace grpc_impl { +class CompletionQueue; +} // namespace grpc_impl namespace grpc { -typedef ::grpc_impl::GenericStub GenericStub; +typedef ::grpc_impl::ClientAsyncReaderWriter + GenericClientAsyncReaderWriter; +typedef ::grpc_impl::ClientAsyncResponseReader + GenericClientAsyncResponseReader; + +/// Generic stubs provide a type-unaware interface to call gRPC methods +/// by name. In practice, the Request and Response types should be basic +/// types like grpc::ByteBuffer or proto::MessageLite (the base protobuf). +template +class TemplatedGenericStub final { + public: + explicit TemplatedGenericStub(std::shared_ptr channel) + : channel_(channel) {} + + /// Setup a call to a named method \a method using \a context, but don't + /// start it. Let it be started explicitly with StartCall and a tag. + /// The return value only indicates whether or not registration of the call + /// succeeded (i.e. the call won't proceed if the return value is nullptr). + std::unique_ptr> + PrepareCall(ClientContext* context, const std::string& method, + CompletionQueue* cq) { + return CallInternal(channel_.get(), context, method, cq, false, nullptr); + } + + /// Setup a unary call to a named method \a method using \a context, and don't + /// start it. Let it be started explicitly with StartCall. + /// The return value only indicates whether or not registration of the call + /// succeeded (i.e. the call won't proceed if the return value is nullptr). + std::unique_ptr> PrepareUnaryCall( + ClientContext* context, const std::string& method, + const RequestType& request, CompletionQueue* cq) { + return std::unique_ptr>( + internal::ClientAsyncResponseReaderFactory::Create( + channel_.get(), cq, + grpc::internal::RpcMethod(method.c_str(), + grpc::internal::RpcMethod::NORMAL_RPC), + context, request, false)); + } + + /// DEPRECATED for multi-threaded use + /// Begin a call to a named method \a method using \a context. + /// A tag \a tag will be delivered to \a cq when the call has been started + /// (i.e, initial metadata has been sent). + /// The return value only indicates whether or not registration of the call + /// succeeded (i.e. the call won't proceed if the return value is nullptr). + std::unique_ptr> Call( + ClientContext* context, const std::string& method, CompletionQueue* cq, + void* tag) { + return CallInternal(channel_.get(), context, method, cq, true, tag); + } + +#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL + /// Setup and start a unary call to a named method \a method using + /// \a context and specifying the \a request and \a response buffers. + void UnaryCall(ClientContext* context, const std::string& method, + const RequestType* request, ResponseType* response, + std::function on_completion) { + UnaryCallInternal(context, method, request, response, + std::move(on_completion)); + } + + /// Setup a unary call to a named method \a method using + /// \a context and specifying the \a request and \a response buffers. + /// Like any other reactor-based RPC, it will not be activated until + /// StartCall is invoked on its reactor. + void PrepareUnaryCall(ClientContext* context, const std::string& method, + const RequestType* request, ResponseType* response, + ClientUnaryReactor* reactor) { + PrepareUnaryCallInternal(context, method, request, response, reactor); + } + + /// Setup a call to a named method \a method using \a context and tied to + /// \a reactor . Like any other bidi streaming RPC, it will not be activated + /// until StartCall is invoked on its reactor. + void PrepareBidiStreamingCall( + ClientContext* context, const std::string& method, + ClientBidiReactor* reactor) { + PrepareBidiStreamingCallInternal(context, method, reactor); + } +#endif + + /// NOTE: class experimental_type is not part of the public API of this class + /// TODO(vjpai): Move these contents to the public API of GenericStub when + /// they are no longer experimental + class experimental_type { + public: + explicit experimental_type(TemplatedGenericStub* stub) : stub_(stub) {} + + /// Setup and start a unary call to a named method \a method using + /// \a context and specifying the \a request and \a response buffers. + void UnaryCall(ClientContext* context, const std::string& method, + const RequestType* request, ResponseType* response, + std::function on_completion) { + stub_->UnaryCallInternal(context, method, request, response, + std::move(on_completion)); + } + + /// Setup a unary call to a named method \a method using + /// \a context and specifying the \a request and \a response buffers. + /// Like any other reactor-based RPC, it will not be activated until + /// StartCall is invoked on its reactor. + void PrepareUnaryCall(ClientContext* context, const std::string& method, + const RequestType* request, ResponseType* response, + ClientUnaryReactor* reactor) { + stub_->PrepareUnaryCallInternal(context, method, request, response, + reactor); + } + + /// Setup a call to a named method \a method using \a context and tied to + /// \a reactor . Like any other bidi streaming RPC, it will not be activated + /// until StartCall is invoked on its reactor. + void PrepareBidiStreamingCall( + ClientContext* context, const std::string& method, + ClientBidiReactor* reactor) { + stub_->PrepareBidiStreamingCallInternal(context, method, reactor); + } + + private: + TemplatedGenericStub* stub_; + }; + + /// NOTE: The function experimental() is not stable public API. It is a view + /// to the experimental components of this class. It may be changed or removed + /// at any time. + experimental_type experimental() { return experimental_type(this); } + + private: + std::shared_ptr channel_; + + void UnaryCallInternal(ClientContext* context, const std::string& method, + const RequestType* request, ResponseType* response, + std::function on_completion) { + internal::CallbackUnaryCall( + channel_.get(), + grpc::internal::RpcMethod(method.c_str(), + grpc::internal::RpcMethod::NORMAL_RPC), + context, request, response, std::move(on_completion)); + } + + void PrepareUnaryCallInternal(ClientContext* context, + const std::string& method, + const RequestType* request, + ResponseType* response, + ClientUnaryReactor* reactor) { + internal::ClientCallbackUnaryFactory::Create( + channel_.get(), + grpc::internal::RpcMethod(method.c_str(), + grpc::internal::RpcMethod::NORMAL_RPC), + context, request, response, reactor); + } + + void PrepareBidiStreamingCallInternal( + ClientContext* context, const std::string& method, + ClientBidiReactor* reactor) { + internal::ClientCallbackReaderWriterFactory:: + Create(channel_.get(), + grpc::internal::RpcMethod( + method.c_str(), grpc::internal::RpcMethod::BIDI_STREAMING), + context, reactor); + } + + std::unique_ptr> + CallInternal(grpc::ChannelInterface* channel, ClientContext* context, + const std::string& method, CompletionQueue* cq, bool start, + void* tag) { + return std::unique_ptr>( + internal::ClientAsyncReaderWriterFactory:: + Create( + channel, cq, + grpc::internal::RpcMethod( + method.c_str(), grpc::internal::RpcMethod::BIDI_STREAMING), + context, start, tag)); + } +}; + +typedef TemplatedGenericStub GenericStub; } // namespace grpc diff --git a/include/grpcpp/generic/generic_stub_impl.h b/include/grpcpp/generic/generic_stub_impl.h deleted file mode 100644 index 2573d7397c9..00000000000 --- a/include/grpcpp/generic/generic_stub_impl.h +++ /dev/null @@ -1,216 +0,0 @@ -/* - * - * Copyright 2015 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_GENERIC_GENERIC_STUB_IMPL_H -#define GRPCPP_GENERIC_GENERIC_STUB_IMPL_H - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace grpc { - -typedef ::grpc_impl::ClientAsyncReaderWriter - GenericClientAsyncReaderWriter; -typedef ::grpc_impl::ClientAsyncResponseReader - GenericClientAsyncResponseReader; -} // namespace grpc -namespace grpc_impl { -class CompletionQueue; - -/// Generic stubs provide a type-unaware interface to call gRPC methods -/// by name. In practice, the Request and Response types should be basic -/// types like grpc::ByteBuffer or proto::MessageLite (the base protobuf). -template -class TemplatedGenericStub final { - public: - explicit TemplatedGenericStub(std::shared_ptr channel) - : channel_(channel) {} - - /// Setup a call to a named method \a method using \a context, but don't - /// start it. Let it be started explicitly with StartCall and a tag. - /// The return value only indicates whether or not registration of the call - /// succeeded (i.e. the call won't proceed if the return value is nullptr). - std::unique_ptr> - PrepareCall(ClientContext* context, const std::string& method, - CompletionQueue* cq) { - return CallInternal(channel_.get(), context, method, cq, false, nullptr); - } - - /// Setup a unary call to a named method \a method using \a context, and don't - /// start it. Let it be started explicitly with StartCall. - /// The return value only indicates whether or not registration of the call - /// succeeded (i.e. the call won't proceed if the return value is nullptr). - std::unique_ptr> PrepareUnaryCall( - ClientContext* context, const std::string& method, - const RequestType& request, CompletionQueue* cq) { - return std::unique_ptr>( - internal::ClientAsyncResponseReaderFactory::Create( - channel_.get(), cq, - grpc::internal::RpcMethod(method.c_str(), - grpc::internal::RpcMethod::NORMAL_RPC), - context, request, false)); - } - - /// DEPRECATED for multi-threaded use - /// Begin a call to a named method \a method using \a context. - /// A tag \a tag will be delivered to \a cq when the call has been started - /// (i.e, initial metadata has been sent). - /// The return value only indicates whether or not registration of the call - /// succeeded (i.e. the call won't proceed if the return value is nullptr). - std::unique_ptr> Call( - ClientContext* context, const std::string& method, CompletionQueue* cq, - void* tag) { - return CallInternal(channel_.get(), context, method, cq, true, tag); - } - -#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - /// Setup and start a unary call to a named method \a method using - /// \a context and specifying the \a request and \a response buffers. - void UnaryCall(ClientContext* context, const std::string& method, - const RequestType* request, ResponseType* response, - std::function on_completion) { - UnaryCallInternal(context, method, request, response, - std::move(on_completion)); - } - - /// Setup a unary call to a named method \a method using - /// \a context and specifying the \a request and \a response buffers. - /// Like any other reactor-based RPC, it will not be activated until - /// StartCall is invoked on its reactor. - void PrepareUnaryCall(ClientContext* context, const std::string& method, - const RequestType* request, ResponseType* response, - ClientUnaryReactor* reactor) { - PrepareUnaryCallInternal(context, method, request, response, reactor); - } - - /// Setup a call to a named method \a method using \a context and tied to - /// \a reactor . Like any other bidi streaming RPC, it will not be activated - /// until StartCall is invoked on its reactor. - void PrepareBidiStreamingCall( - ClientContext* context, const std::string& method, - ClientBidiReactor* reactor) { - PrepareBidiStreamingCallInternal(context, method, reactor); - } -#endif - - /// NOTE: class experimental_type is not part of the public API of this class - /// TODO(vjpai): Move these contents to the public API of GenericStub when - /// they are no longer experimental - class experimental_type { - public: - explicit experimental_type(TemplatedGenericStub* stub) : stub_(stub) {} - - /// Setup and start a unary call to a named method \a method using - /// \a context and specifying the \a request and \a response buffers. - void UnaryCall(ClientContext* context, const std::string& method, - const RequestType* request, ResponseType* response, - std::function on_completion) { - stub_->UnaryCallInternal(context, method, request, response, - std::move(on_completion)); - } - - /// Setup a unary call to a named method \a method using - /// \a context and specifying the \a request and \a response buffers. - /// Like any other reactor-based RPC, it will not be activated until - /// StartCall is invoked on its reactor. - void PrepareUnaryCall(ClientContext* context, const std::string& method, - const RequestType* request, ResponseType* response, - ClientUnaryReactor* reactor) { - stub_->PrepareUnaryCallInternal(context, method, request, response, - reactor); - } - - /// Setup a call to a named method \a method using \a context and tied to - /// \a reactor . Like any other bidi streaming RPC, it will not be activated - /// until StartCall is invoked on its reactor. - void PrepareBidiStreamingCall( - ClientContext* context, const std::string& method, - ClientBidiReactor* reactor) { - stub_->PrepareBidiStreamingCallInternal(context, method, reactor); - } - - private: - TemplatedGenericStub* stub_; - }; - - /// NOTE: The function experimental() is not stable public API. It is a view - /// to the experimental components of this class. It may be changed or removed - /// at any time. - experimental_type experimental() { return experimental_type(this); } - - private: - std::shared_ptr channel_; - - void UnaryCallInternal(ClientContext* context, const std::string& method, - const RequestType* request, ResponseType* response, - std::function on_completion) { - internal::CallbackUnaryCall( - channel_.get(), - grpc::internal::RpcMethod(method.c_str(), - grpc::internal::RpcMethod::NORMAL_RPC), - context, request, response, std::move(on_completion)); - } - - void PrepareUnaryCallInternal(ClientContext* context, - const std::string& method, - const RequestType* request, - ResponseType* response, - ClientUnaryReactor* reactor) { - internal::ClientCallbackUnaryFactory::Create( - channel_.get(), - grpc::internal::RpcMethod(method.c_str(), - grpc::internal::RpcMethod::NORMAL_RPC), - context, request, response, reactor); - } - - void PrepareBidiStreamingCallInternal( - ClientContext* context, const std::string& method, - ClientBidiReactor* reactor) { - internal::ClientCallbackReaderWriterFactory:: - Create(channel_.get(), - grpc::internal::RpcMethod( - method.c_str(), grpc::internal::RpcMethod::BIDI_STREAMING), - context, reactor); - } - - std::unique_ptr> - CallInternal(grpc::ChannelInterface* channel, ClientContext* context, - const std::string& method, CompletionQueue* cq, bool start, - void* tag) { - return std::unique_ptr>( - internal::ClientAsyncReaderWriterFactory:: - Create( - channel, cq, - grpc::internal::RpcMethod( - method.c_str(), grpc::internal::RpcMethod::BIDI_STREAMING), - context, start, tag)); - } -}; - -typedef TemplatedGenericStub GenericStub; - -} // namespace grpc_impl - -#endif // GRPCPP_GENERIC_GENERIC_STUB_IMPL_H diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index fd62c5079da..79ce1688efa 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -945,7 +945,6 @@ include/grpcpp/create_channel_posix.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ include/grpcpp/generic/async_generic_service.h \ include/grpcpp/generic/generic_stub.h \ -include/grpcpp/generic/generic_stub_impl.h \ include/grpcpp/grpcpp.h \ include/grpcpp/health_check_service_interface.h \ include/grpcpp/impl/call.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 53ecaacce81..81f87fe5820 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -945,7 +945,6 @@ include/grpcpp/create_channel_posix.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ include/grpcpp/generic/async_generic_service.h \ include/grpcpp/generic/generic_stub.h \ -include/grpcpp/generic/generic_stub_impl.h \ include/grpcpp/grpcpp.h \ include/grpcpp/health_check_service_interface.h \ include/grpcpp/impl/call.h \