diff --git a/BUILD b/BUILD index 514b6621011498eb466f627c1090e8a3e6445922..d712053a3d4c94ebfe4ec3108fe74d8419e47cd1 100644 --- a/BUILD +++ b/BUILD @@ -675,6 +675,7 @@ cc_library( "src/cpp/client/secure_credentials.h", "src/cpp/common/secure_auth_context.h", "src/cpp/server/secure_server_credentials.h", + "src/cpp/client/create_channel_internal.h", "src/cpp/common/create_auth_context.h", "src/cpp/client/secure_channel_arguments.cc", "src/cpp/client/secure_credentials.cc", @@ -686,6 +687,7 @@ cc_library( "src/cpp/client/channel_arguments.cc", "src/cpp/client/client_context.cc", "src/cpp/client/create_channel.cc", + "src/cpp/client/create_channel_internal.cc", "src/cpp/client/credentials.cc", "src/cpp/client/generic_stub.cc", "src/cpp/client/insecure_credentials.cc", @@ -764,12 +766,14 @@ cc_library( cc_library( name = "grpc++_unsecure", srcs = [ + "src/cpp/client/create_channel_internal.h", "src/cpp/common/create_auth_context.h", "src/cpp/common/insecure_create_auth_context.cc", "src/cpp/client/channel.cc", "src/cpp/client/channel_arguments.cc", "src/cpp/client/client_context.cc", "src/cpp/client/create_channel.cc", + "src/cpp/client/create_channel_internal.cc", "src/cpp/client/credentials.cc", "src/cpp/client/generic_stub.cc", "src/cpp/client/insecure_credentials.cc", diff --git a/Makefile b/Makefile index ce6406112ea4502ff0b1ed175d84616377c92c35..c74c720b7bf15c87537195d984a8310290846844 100644 --- a/Makefile +++ b/Makefile @@ -4603,6 +4603,7 @@ LIBGRPC++_SRC = \ src/cpp/client/channel_arguments.cc \ src/cpp/client/client_context.cc \ src/cpp/client/create_channel.cc \ + src/cpp/client/create_channel_internal.cc \ src/cpp/client/credentials.cc \ src/cpp/client/generic_stub.cc \ src/cpp/client/insecure_credentials.cc \ @@ -4844,6 +4845,7 @@ LIBGRPC++_UNSECURE_SRC = \ src/cpp/client/channel_arguments.cc \ src/cpp/client/client_context.cc \ src/cpp/client/create_channel.cc \ + src/cpp/client/create_channel_internal.cc \ src/cpp/client/credentials.cc \ src/cpp/client/generic_stub.cc \ src/cpp/client/insecure_credentials.cc \ diff --git a/build.json b/build.json index d49b953d8aa2639d1c0c60f41bbdc08f316b82a5..64558a60282de3161768ae9534512d39c8a39ee3 100644 --- a/build.json +++ b/build.json @@ -72,6 +72,7 @@ "include/grpc++/time.h" ], "headers": [ + "src/cpp/client/create_channel_internal.h", "src/cpp/common/create_auth_context.h" ], "src": [ @@ -79,6 +80,7 @@ "src/cpp/client/channel_arguments.cc", "src/cpp/client/client_context.cc", "src/cpp/client/create_channel.cc", + "src/cpp/client/create_channel_internal.cc", "src/cpp/client/credentials.cc", "src/cpp/client/generic_stub.cc", "src/cpp/client/insecure_credentials.cc", diff --git a/include/grpc++/channel.h b/include/grpc++/channel.h index ceb921eff8ecd30c6cbff0e73f23eac264d29528..7d6216e9c49c95c98a88961df8a5f5b7e6b28351 100644 --- a/include/grpc++/channel.h +++ b/include/grpc++/channel.h @@ -69,8 +69,6 @@ class Channel GRPC_FINAL : public GrpcLibrary, public CallHook, public std::enable_shared_from_this<Channel> { public: - explicit Channel(grpc_channel* c_channel); - Channel(const grpc::string& host, grpc_channel* c_channel); ~Channel(); // Get the current channel state. If the channel is in IDLE and try_to_connect @@ -115,6 +113,10 @@ class Channel GRPC_FINAL : public GrpcLibrary, const InputMessage& request, OutputMessage* result); friend class ::grpc::RpcMethod; + friend std::shared_ptr<Channel> CreateChannelInternal( + const grpc::string& host, grpc_channel* c_channel); + + Channel(const grpc::string& host, grpc_channel* c_channel); Call CreateCall(const RpcMethod& method, ClientContext* context, CompletionQueue* cq); diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc index d9ffdc30cd1b39aa737e0d55288e7697d1a60358..90fc776d4a20431b68462fa22906bba3a05d8d45 100644 --- a/src/cpp/client/channel.cc +++ b/src/cpp/client/channel.cc @@ -52,8 +52,6 @@ namespace grpc { -Channel::Channel(grpc_channel* channel) : c_channel_(channel) {} - Channel::Channel(const grpc::string& host, grpc_channel* channel) : host_(host), c_channel_(channel) {} diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc index 704470693e6d74a3443a206b2f36a399006ddf4e..70ea7e0e275ede1bbdf27e52cfc7e48316f8d9ee 100644 --- a/src/cpp/client/create_channel.cc +++ b/src/cpp/client/create_channel.cc @@ -38,6 +38,8 @@ #include <grpc++/channel_arguments.h> #include <grpc++/create_channel.h> +#include "src/cpp/client/create_channel_internal.h" + namespace grpc { class ChannelArguments; @@ -49,10 +51,10 @@ std::shared_ptr<Channel> CreateChannel( user_agent_prefix << "grpc-c++/" << grpc_version_string(); cp_args.SetString(GRPC_ARG_PRIMARY_USER_AGENT_STRING, user_agent_prefix.str()); - return creds ? creds->CreateChannel(target, cp_args) - : std::shared_ptr<Channel>( - new Channel(grpc_lame_client_channel_create( - NULL, GRPC_STATUS_INVALID_ARGUMENT, - "Invalid credentials."))); + return creds + ? creds->CreateChannel(target, cp_args) + : CreateChannelInternal("", grpc_lame_client_channel_create( + NULL, GRPC_STATUS_INVALID_ARGUMENT, + "Invalid credentials.")); } } // namespace grpc diff --git a/src/cpp/client/create_channel_internal.cc b/src/cpp/client/create_channel_internal.cc new file mode 100644 index 0000000000000000000000000000000000000000..9c5ab038cf1db5a5e09d6e6f1e623f7e83000cdc --- /dev/null +++ b/src/cpp/client/create_channel_internal.cc @@ -0,0 +1,46 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <memory> + +#include <grpc++/channel.h> + +struct grpc_channel; + +namespace grpc { + +std::shared_ptr<Channel> CreateChannelInternal(const grpc::string& host, + grpc_channel* c_channel) { + return std::shared_ptr<Channel>(new Channel(host, c_channel)); +} +} // namespace grpc diff --git a/src/cpp/client/create_channel_internal.h b/src/cpp/client/create_channel_internal.h new file mode 100644 index 0000000000000000000000000000000000000000..16924719909f1fd2aee331ffad46f276fb2dfe7c --- /dev/null +++ b/src/cpp/client/create_channel_internal.h @@ -0,0 +1,51 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_INTERNAL_CPP_CLIENT_CREATE_CHANNEL_INTERNAL_H +#define GRPC_INTERNAL_CPP_CLIENT_CREATE_CHANNEL_INTERNAL_H + +#include <memory> + +#include <grpc++/config.h> + +struct grpc_channel; + +namespace grpc { +class Channel; + +std::shared_ptr<Channel> CreateChannelInternal(const grpc::string& host, + grpc_channel* c_channel); + +} // namespace grpc + +#endif // GRPC_INTERNAL_CPP_CLIENT_CREATE_CHANNEL_INTERNAL_H diff --git a/src/cpp/client/insecure_credentials.cc b/src/cpp/client/insecure_credentials.cc index 70ce17dc6dadc0e48c2d04d7a7b59657c5178cb5..97931406af38e5c09e74da45e5da0e7fc2db5e9c 100644 --- a/src/cpp/client/insecure_credentials.cc +++ b/src/cpp/client/insecure_credentials.cc @@ -38,6 +38,7 @@ #include <grpc++/channel_arguments.h> #include <grpc++/config.h> #include <grpc++/credentials.h> +#include "src/cpp/client/create_channel_internal.h" namespace grpc { @@ -48,8 +49,9 @@ class InsecureCredentialsImpl GRPC_FINAL : public Credentials { const string& target, const grpc::ChannelArguments& args) GRPC_OVERRIDE { grpc_channel_args channel_args; args.SetChannelArgs(&channel_args); - return std::shared_ptr<Channel>(new Channel( - grpc_insecure_channel_create(target.c_str(), &channel_args, nullptr))); + return CreateChannelInternal( + "", + grpc_insecure_channel_create(target.c_str(), &channel_args, nullptr)); } // InsecureCredentials should not be applied to a call. diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index b32f783fa337713dc4fd26f6aae00aaaa0e5d472..1e912c6beba8ff631e62b6397c6b97b9f802b2a7 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -32,10 +32,10 @@ */ #include <grpc/support/log.h> - #include <grpc++/channel.h> #include <grpc++/channel_arguments.h> #include <grpc++/impl/grpc_library.h> +#include "src/cpp/client/create_channel_internal.h" #include "src/cpp/client/secure_credentials.h" namespace grpc { @@ -44,9 +44,9 @@ std::shared_ptr<grpc::Channel> SecureCredentials::CreateChannel( const string& target, const grpc::ChannelArguments& args) { grpc_channel_args channel_args; args.SetChannelArgs(&channel_args); - return std::shared_ptr<Channel>(new Channel( + return CreateChannelInternal( args.GetSslTargetNameOverride(), - grpc_secure_channel_create(c_creds_, target.c_str(), &channel_args))); + grpc_secure_channel_create(c_creds_, target.c_str(), &channel_args)); } bool SecureCredentials::ApplyToCall(grpc_call* call) { diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index b8f04cbcd38094f229baf7b3fa27a09eb749e61b..23ff05fb8627023bd218efc32c641764db158bd5 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -803,6 +803,7 @@ include/grpc++/time.h \ src/cpp/client/secure_credentials.h \ src/cpp/common/secure_auth_context.h \ src/cpp/server/secure_server_credentials.h \ +src/cpp/client/create_channel_internal.h \ src/cpp/common/create_auth_context.h \ src/cpp/client/secure_channel_arguments.cc \ src/cpp/client/secure_credentials.cc \ @@ -814,6 +815,7 @@ src/cpp/client/channel.cc \ src/cpp/client/channel_arguments.cc \ src/cpp/client/client_context.cc \ src/cpp/client/create_channel.cc \ +src/cpp/client/create_channel_internal.cc \ src/cpp/client/credentials.cc \ src/cpp/client/generic_stub.cc \ src/cpp/client/insecure_credentials.cc \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 5c515d1ba4774146a8f1824fe952806848629965..863c9f802ec9e9752446efb2f55a4bbc9258d7f5 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -13141,6 +13141,7 @@ "include/grpc++/stub_options.h", "include/grpc++/thread_pool_interface.h", "include/grpc++/time.h", + "src/cpp/client/create_channel_internal.h", "src/cpp/client/secure_credentials.h", "src/cpp/common/create_auth_context.h", "src/cpp/common/secure_auth_context.h", @@ -13193,6 +13194,8 @@ "src/cpp/client/channel_arguments.cc", "src/cpp/client/client_context.cc", "src/cpp/client/create_channel.cc", + "src/cpp/client/create_channel_internal.cc", + "src/cpp/client/create_channel_internal.h", "src/cpp/client/credentials.cc", "src/cpp/client/generic_stub.cc", "src/cpp/client/insecure_credentials.cc", @@ -13310,6 +13313,7 @@ "include/grpc++/stub_options.h", "include/grpc++/thread_pool_interface.h", "include/grpc++/time.h", + "src/cpp/client/create_channel_internal.h", "src/cpp/common/create_auth_context.h" ], "language": "c++", @@ -13359,6 +13363,8 @@ "src/cpp/client/channel_arguments.cc", "src/cpp/client/client_context.cc", "src/cpp/client/create_channel.cc", + "src/cpp/client/create_channel_internal.cc", + "src/cpp/client/create_channel_internal.h", "src/cpp/client/credentials.cc", "src/cpp/client/generic_stub.cc", "src/cpp/client/insecure_credentials.cc", diff --git a/vsprojects/grpc++/grpc++.vcxproj b/vsprojects/grpc++/grpc++.vcxproj index dbbb7c12cdd7492f75b74b578b7ae1adb0359d8f..e2e17d41770613a13a4b890b5397f908a7f4b32e 100644 --- a/vsprojects/grpc++/grpc++.vcxproj +++ b/vsprojects/grpc++/grpc++.vcxproj @@ -258,6 +258,7 @@ <ClInclude Include="..\..\src\cpp\client\secure_credentials.h" /> <ClInclude Include="..\..\src\cpp\common\secure_auth_context.h" /> <ClInclude Include="..\..\src\cpp\server\secure_server_credentials.h" /> + <ClInclude Include="..\..\src\cpp\client\create_channel_internal.h" /> <ClInclude Include="..\..\src\cpp\common\create_auth_context.h" /> </ItemGroup> <ItemGroup> @@ -281,6 +282,8 @@ </ClCompile> <ClCompile Include="..\..\src\cpp\client\create_channel.cc"> </ClCompile> + <ClCompile Include="..\..\src\cpp\client\create_channel_internal.cc"> + </ClCompile> <ClCompile Include="..\..\src\cpp\client\credentials.cc"> </ClCompile> <ClCompile Include="..\..\src\cpp\client\generic_stub.cc"> diff --git a/vsprojects/grpc++/grpc++.vcxproj.filters b/vsprojects/grpc++/grpc++.vcxproj.filters index 7c982e910ac6894bacc6c0f38df415748b6b6da1..6f308d1d02545b614bd68e50f5b3de9a2b2af00a 100644 --- a/vsprojects/grpc++/grpc++.vcxproj.filters +++ b/vsprojects/grpc++/grpc++.vcxproj.filters @@ -31,6 +31,9 @@ <ClCompile Include="..\..\src\cpp\client\create_channel.cc"> <Filter>src\cpp\client</Filter> </ClCompile> + <ClCompile Include="..\..\src\cpp\client\create_channel_internal.cc"> + <Filter>src\cpp\client</Filter> + </ClCompile> <ClCompile Include="..\..\src\cpp\client\credentials.cc"> <Filter>src\cpp\client</Filter> </ClCompile> @@ -224,6 +227,9 @@ <ClInclude Include="..\..\src\cpp\server\secure_server_credentials.h"> <Filter>src\cpp\server</Filter> </ClInclude> + <ClInclude Include="..\..\src\cpp\client\create_channel_internal.h"> + <Filter>src\cpp\client</Filter> + </ClInclude> <ClInclude Include="..\..\src\cpp\common\create_auth_context.h"> <Filter>src\cpp\common</Filter> </ClInclude> diff --git a/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj b/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj index 98d15cd98dcab3811cfbba564662999e2929a1f8..4be468cb62b5548bcfb5430da9fdb4cb82c9f881 100644 --- a/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj +++ b/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj @@ -255,6 +255,7 @@ <ClInclude Include="..\..\include\grpc++\time.h" /> </ItemGroup> <ItemGroup> + <ClInclude Include="..\..\src\cpp\client\create_channel_internal.h" /> <ClInclude Include="..\..\src\cpp\common\create_auth_context.h" /> </ItemGroup> <ItemGroup> @@ -268,6 +269,8 @@ </ClCompile> <ClCompile Include="..\..\src\cpp\client\create_channel.cc"> </ClCompile> + <ClCompile Include="..\..\src\cpp\client\create_channel_internal.cc"> + </ClCompile> <ClCompile Include="..\..\src\cpp\client\credentials.cc"> </ClCompile> <ClCompile Include="..\..\src\cpp\client\generic_stub.cc"> diff --git a/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj.filters b/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj.filters index 99734c8953f85f1533b002abe2618c9aa1dd2467..bd51d1fa0b1eb4311d9c09d6b0421b4a461a535d 100644 --- a/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj.filters +++ b/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj.filters @@ -16,6 +16,9 @@ <ClCompile Include="..\..\src\cpp\client\create_channel.cc"> <Filter>src\cpp\client</Filter> </ClCompile> + <ClCompile Include="..\..\src\cpp\client\create_channel_internal.cc"> + <Filter>src\cpp\client</Filter> + </ClCompile> <ClCompile Include="..\..\src\cpp\client\credentials.cc"> <Filter>src\cpp\client</Filter> </ClCompile> @@ -200,6 +203,9 @@ </ClInclude> </ItemGroup> <ItemGroup> + <ClInclude Include="..\..\src\cpp\client\create_channel_internal.h"> + <Filter>src\cpp\client</Filter> + </ClInclude> <ClInclude Include="..\..\src\cpp\common\create_auth_context.h"> <Filter>src\cpp\common</Filter> </ClInclude>