Make Channel ctor private

pull/3008/head
yang-g 10 years ago
parent ef00308e39
commit c317f07b56
  1. 4
      BUILD
  2. 2
      Makefile
  3. 2
      build.json
  4. 6
      include/grpc++/channel.h
  5. 2
      src/cpp/client/channel.cc
  6. 12
      src/cpp/client/create_channel.cc
  7. 46
      src/cpp/client/create_channel_internal.cc
  8. 51
      src/cpp/client/create_channel_internal.h
  9. 6
      src/cpp/client/insecure_credentials.cc
  10. 6
      src/cpp/client/secure_credentials.cc
  11. 2
      tools/doxygen/Doxyfile.c++.internal
  12. 6
      tools/run_tests/sources_and_headers.json
  13. 3
      vsprojects/grpc++/grpc++.vcxproj
  14. 6
      vsprojects/grpc++/grpc++.vcxproj.filters
  15. 3
      vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj
  16. 6
      vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj.filters

@ -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",

@ -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 \

@ -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",

@ -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);

@ -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) {}

@ -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

@ -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

@ -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

@ -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.

@ -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) {

@ -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 \

@ -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",

@ -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">

@ -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>

@ -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">

@ -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>

Loading…
Cancel
Save