From 152f46b5f649f96cebf68ac44cb476f22f235476 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 4 Feb 2020 23:39:14 -0800 Subject: [PATCH 1/2] Move generic stub implementation to header (prepare for templates) --- BUILD | 1 - BUILD.gn | 1 - CMakeLists.txt | 2 - Makefile | 2 - build.yaml | 1 - gRPC-C++.podspec | 1 - grpc.gyp | 2 - include/grpcpp/generic/generic_stub_impl.h | 86 ++++++++++++----- src/cpp/client/generic_stub.cc | 106 --------------------- tools/doxygen/Doxyfile.c++.internal | 1 - 10 files changed, 63 insertions(+), 140 deletions(-) delete mode 100644 src/cpp/client/generic_stub.cc diff --git a/BUILD b/BUILD index eef85e95e46..4f1210e8ae6 100644 --- a/BUILD +++ b/BUILD @@ -134,7 +134,6 @@ GRPCXX_SRCS = [ "src/cpp/client/create_channel_internal.cc", "src/cpp/client/create_channel_posix.cc", "src/cpp/client/credentials_cc.cc", - "src/cpp/client/generic_stub.cc", "src/cpp/common/alarm.cc", "src/cpp/common/channel_arguments.cc", "src/cpp/common/channel_filter.cc", diff --git a/BUILD.gn b/BUILD.gn index 97c849363eb..b7529a98788 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1399,7 +1399,6 @@ config("grpc_config") { "src/cpp/client/create_channel_internal.h", "src/cpp/client/create_channel_posix.cc", "src/cpp/client/credentials_cc.cc", - "src/cpp/client/generic_stub.cc", "src/cpp/client/insecure_credentials.cc", "src/cpp/client/secure_credentials.cc", "src/cpp/client/secure_credentials.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 38f530b7f80..05a450fb070 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3696,7 +3696,6 @@ add_library(grpc++ src/cpp/client/create_channel_internal.cc src/cpp/client/create_channel_posix.cc src/cpp/client/credentials_cc.cc - src/cpp/client/generic_stub.cc src/cpp/common/alarm.cc src/cpp/common/channel_arguments.cc src/cpp/common/channel_filter.cc @@ -4830,7 +4829,6 @@ add_library(grpc++_unsecure src/cpp/client/create_channel_internal.cc src/cpp/client/create_channel_posix.cc src/cpp/client/credentials_cc.cc - src/cpp/client/generic_stub.cc src/cpp/common/alarm.cc src/cpp/common/channel_arguments.cc src/cpp/common/channel_filter.cc diff --git a/Makefile b/Makefile index 481e73477a0..764706879ba 100644 --- a/Makefile +++ b/Makefile @@ -6084,7 +6084,6 @@ LIBGRPC++_SRC = \ src/cpp/client/create_channel_internal.cc \ src/cpp/client/create_channel_posix.cc \ src/cpp/client/credentials_cc.cc \ - src/cpp/client/generic_stub.cc \ src/cpp/common/alarm.cc \ src/cpp/common/channel_arguments.cc \ src/cpp/common/channel_filter.cc \ @@ -7192,7 +7191,6 @@ LIBGRPC++_UNSECURE_SRC = \ src/cpp/client/create_channel_internal.cc \ src/cpp/client/create_channel_posix.cc \ src/cpp/client/credentials_cc.cc \ - src/cpp/client/generic_stub.cc \ src/cpp/common/alarm.cc \ src/cpp/common/channel_arguments.cc \ src/cpp/common/channel_filter.cc \ diff --git a/build.yaml b/build.yaml index e0a38b7f287..ec7733837b9 100644 --- a/build.yaml +++ b/build.yaml @@ -595,7 +595,6 @@ filegroups: - src/cpp/client/create_channel_internal.cc - src/cpp/client/create_channel_posix.cc - src/cpp/client/credentials_cc.cc - - src/cpp/client/generic_stub.cc - src/cpp/common/alarm.cc - src/cpp/common/channel_arguments.cc - src/cpp/common/channel_filter.cc diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index c70c1ab5b78..44a59f601cb 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -591,7 +591,6 @@ Pod::Spec.new do |s| 'src/cpp/client/create_channel_internal.h', 'src/cpp/client/create_channel_posix.cc', 'src/cpp/client/credentials_cc.cc', - 'src/cpp/client/generic_stub.cc', 'src/cpp/client/insecure_credentials.cc', 'src/cpp/client/secure_credentials.cc', 'src/cpp/client/secure_credentials.h', diff --git a/grpc.gyp b/grpc.gyp index 81615b79d59..f137833dfd6 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -1820,7 +1820,6 @@ 'src/cpp/client/create_channel_internal.cc', 'src/cpp/client/create_channel_posix.cc', 'src/cpp/client/credentials_cc.cc', - 'src/cpp/client/generic_stub.cc', 'src/cpp/common/alarm.cc', 'src/cpp/common/channel_arguments.cc', 'src/cpp/common/channel_filter.cc', @@ -1992,7 +1991,6 @@ 'src/cpp/client/create_channel_internal.cc', 'src/cpp/client/create_channel_posix.cc', 'src/cpp/client/credentials_cc.cc', - 'src/cpp/client/generic_stub.cc', 'src/cpp/common/alarm.cc', 'src/cpp/common/channel_arguments.cc', 'src/cpp/common/channel_filter.cc', diff --git a/include/grpcpp/generic/generic_stub_impl.h b/include/grpcpp/generic/generic_stub_impl.h index 4aca1cd5393..344c8710a8f 100644 --- a/include/grpcpp/generic/generic_stub_impl.h +++ b/include/grpcpp/generic/generic_stub_impl.h @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -50,16 +51,24 @@ class GenericStub final { /// 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( - grpc::ClientContext* context, const grpc::string& method, - CompletionQueue* cq); + ClientContext* context, const grpc::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( - grpc_impl::ClientContext* context, const grpc::string& method, - const grpc::ByteBuffer& request, CompletionQueue* cq); + ClientContext* context, const grpc::string& method, + const grpc::ByteBuffer& 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. @@ -68,13 +77,15 @@ class GenericStub final { /// 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( - grpc_impl::ClientContext* context, const grpc::string& method, - CompletionQueue* cq, void* tag); + ClientContext* context, const grpc::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(grpc_impl::ClientContext* context, const grpc::string& method, + void UnaryCall(ClientContext* context, const grpc::string& method, const grpc::ByteBuffer* request, grpc::ByteBuffer* response, std::function on_completion) { UnaryCallInternal(context, method, request, response, @@ -85,8 +96,7 @@ class GenericStub final { /// \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(grpc_impl::ClientContext* context, - const grpc::string& method, + void PrepareUnaryCall(ClientContext* context, const grpc::string& method, const grpc::ByteBuffer* request, grpc::ByteBuffer* response, grpc_impl::ClientUnaryReactor* reactor) { @@ -97,7 +107,7 @@ class GenericStub final { /// \a reactor . Like any other bidi streaming RPC, it will not be activated /// until StartCall is invoked on its reactor. void PrepareBidiStreamingCall( - grpc_impl::ClientContext* context, const grpc::string& method, + ClientContext* context, const grpc::string& method, grpc_impl::ClientBidiReactor* reactor) { PrepareBidiStreamingCallInternal(context, method, reactor); @@ -113,9 +123,8 @@ class GenericStub final { /// 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(grpc_impl::ClientContext* context, - const grpc::string& method, const grpc::ByteBuffer* request, - grpc::ByteBuffer* response, + void UnaryCall(ClientContext* context, const grpc::string& method, + const grpc::ByteBuffer* request, grpc::ByteBuffer* response, std::function on_completion) { stub_->UnaryCallInternal(context, method, request, response, std::move(on_completion)); @@ -125,8 +134,7 @@ class GenericStub final { /// \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(grpc_impl::ClientContext* context, - const grpc::string& method, + void PrepareUnaryCall(ClientContext* context, const grpc::string& method, const grpc::ByteBuffer* request, grpc::ByteBuffer* response, grpc_impl::ClientUnaryReactor* reactor) { @@ -138,7 +146,7 @@ class GenericStub final { /// \a reactor . Like any other bidi streaming RPC, it will not be activated /// until StartCall is invoked on its reactor. void PrepareBidiStreamingCall( - grpc_impl::ClientContext* context, const grpc::string& method, + ClientContext* context, const grpc::string& method, grpc_impl::ClientBidiReactor* reactor) { stub_->PrepareBidiStreamingCallInternal(context, method, reactor); @@ -156,22 +164,54 @@ class GenericStub final { private: std::shared_ptr channel_; - void UnaryCallInternal(grpc_impl::ClientContext* context, - const grpc::string& method, + void UnaryCallInternal(ClientContext* context, const grpc::string& method, const grpc::ByteBuffer* request, grpc::ByteBuffer* response, - std::function on_completion); + 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(grpc_impl::ClientContext* context, + void PrepareUnaryCallInternal(ClientContext* context, const grpc::string& method, const grpc::ByteBuffer* request, grpc::ByteBuffer* response, - grpc_impl::ClientUnaryReactor* reactor); + grpc_impl::ClientUnaryReactor* reactor) { + internal::ClientCallbackUnaryFactory::Create( + channel_.get(), + grpc::internal::RpcMethod(method.c_str(), + grpc::internal::RpcMethod::NORMAL_RPC), + context, request, response, reactor); + } void PrepareBidiStreamingCallInternal( - grpc_impl::ClientContext* context, const grpc::string& method, + ClientContext* context, const grpc::string& method, grpc_impl::ClientBidiReactor* - reactor); + 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 grpc::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)); + } }; } // namespace grpc_impl diff --git a/src/cpp/client/generic_stub.cc b/src/cpp/client/generic_stub.cc deleted file mode 100644 index aa28226f506..00000000000 --- a/src/cpp/client/generic_stub.cc +++ /dev/null @@ -1,106 +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. - * - */ - -#include - -#include -#include -#include - -namespace grpc_impl { - -namespace { -std::unique_ptr CallInternal( - grpc::ChannelInterface* channel, grpc::ClientContext* context, - const grpc::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)); -} - -} // namespace - -// begin a call to a named method -std::unique_ptr GenericStub::Call( - grpc::ClientContext* context, const grpc::string& method, - CompletionQueue* cq, void* tag) { - return CallInternal(channel_.get(), context, method, cq, true, tag); -} - -// setup a call to a named method -std::unique_ptr GenericStub::PrepareCall( - grpc::ClientContext* context, const grpc::string& method, - CompletionQueue* cq) { - return CallInternal(channel_.get(), context, method, cq, false, nullptr); -} - -// setup a unary call to a named method -std::unique_ptr -GenericStub::PrepareUnaryCall(grpc::ClientContext* context, - const grpc::string& method, - const grpc::ByteBuffer& 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)); -} - -void GenericStub::UnaryCallInternal( - grpc::ClientContext* context, const grpc::string& method, - const grpc::ByteBuffer* request, grpc::ByteBuffer* 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 GenericStub::PrepareBidiStreamingCallInternal( - grpc::ClientContext* context, const grpc::string& method, - ClientBidiReactor* reactor) { - internal::ClientCallbackReaderWriterFactory< - grpc::ByteBuffer, - grpc::ByteBuffer>::Create(channel_.get(), - grpc::internal::RpcMethod( - method.c_str(), - grpc::internal::RpcMethod::BIDI_STREAMING), - context, reactor); -} - -void GenericStub::PrepareUnaryCallInternal(grpc::ClientContext* context, - const grpc::string& method, - const grpc::ByteBuffer* request, - grpc::ByteBuffer* response, - ClientUnaryReactor* reactor) { - internal::ClientCallbackUnaryFactory::Create( - channel_.get(), - grpc::internal::RpcMethod(method.c_str(), - grpc::internal::RpcMethod::NORMAL_RPC), - context, request, response, reactor); -} - -} // namespace grpc_impl diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 6891c5cc35a..4408ada7f66 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1247,7 +1247,6 @@ src/cpp/client/create_channel_internal.cc \ src/cpp/client/create_channel_internal.h \ src/cpp/client/create_channel_posix.cc \ src/cpp/client/credentials_cc.cc \ -src/cpp/client/generic_stub.cc \ src/cpp/client/insecure_credentials.cc \ src/cpp/client/secure_credentials.cc \ src/cpp/client/secure_credentials.h \ From 7aaacb4bd9becd4a42fcd0983519645907c73ac1 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Thu, 6 Feb 2020 22:49:04 -0800 Subject: [PATCH 2/2] Remove some grpc_impl:: --- include/grpcpp/generic/generic_stub_impl.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/include/grpcpp/generic/generic_stub_impl.h b/include/grpcpp/generic/generic_stub_impl.h index 344c8710a8f..e272e73c8ec 100644 --- a/include/grpcpp/generic/generic_stub_impl.h +++ b/include/grpcpp/generic/generic_stub_impl.h @@ -99,7 +99,7 @@ class GenericStub final { void PrepareUnaryCall(ClientContext* context, const grpc::string& method, const grpc::ByteBuffer* request, grpc::ByteBuffer* response, - grpc_impl::ClientUnaryReactor* reactor) { + ClientUnaryReactor* reactor) { PrepareUnaryCallInternal(context, method, request, response, reactor); } @@ -108,8 +108,7 @@ class GenericStub final { /// until StartCall is invoked on its reactor. void PrepareBidiStreamingCall( ClientContext* context, const grpc::string& method, - grpc_impl::ClientBidiReactor* - reactor) { + ClientBidiReactor* reactor) { PrepareBidiStreamingCallInternal(context, method, reactor); } #endif @@ -137,7 +136,7 @@ class GenericStub final { void PrepareUnaryCall(ClientContext* context, const grpc::string& method, const grpc::ByteBuffer* request, grpc::ByteBuffer* response, - grpc_impl::ClientUnaryReactor* reactor) { + ClientUnaryReactor* reactor) { stub_->PrepareUnaryCallInternal(context, method, request, response, reactor); } @@ -147,8 +146,7 @@ class GenericStub final { /// until StartCall is invoked on its reactor. void PrepareBidiStreamingCall( ClientContext* context, const grpc::string& method, - grpc_impl::ClientBidiReactor* - reactor) { + ClientBidiReactor* reactor) { stub_->PrepareBidiStreamingCallInternal(context, method, reactor); } @@ -179,7 +177,7 @@ class GenericStub final { const grpc::string& method, const grpc::ByteBuffer* request, grpc::ByteBuffer* response, - grpc_impl::ClientUnaryReactor* reactor) { + ClientUnaryReactor* reactor) { internal::ClientCallbackUnaryFactory::Create( channel_.get(), @@ -190,8 +188,7 @@ class GenericStub final { void PrepareBidiStreamingCallInternal( ClientContext* context, const grpc::string& method, - grpc_impl::ClientBidiReactor* - reactor) { + ClientBidiReactor* reactor) { internal::ClientCallbackReaderWriterFactory:: Create(channel_.get(),