diff options
author | David Garcia Quintas <dgq@google.com> | 2016-01-27 18:41:26 -0800 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2016-01-27 18:41:26 -0800 |
commit | e1300deb87b5fca2b4361a753d0bd4d19b078ea4 (patch) | |
tree | 62016bec7621d6f1650472c20d56fdbf713f077c /src/cpp | |
parent | 6a48405ed003a416bd574d3f480b20e3dee9e9df (diff) |
After GrpcLibrary refactoring. Compiles and passes. WIP still
Diffstat (limited to 'src/cpp')
-rw-r--r-- | src/cpp/client/channel.cc | 15 | ||||
-rw-r--r-- | src/cpp/client/create_channel.cc | 4 | ||||
-rw-r--r-- | src/cpp/client/credentials.cc | 7 | ||||
-rw-r--r-- | src/cpp/client/secure_credentials.cc | 12 | ||||
-rw-r--r-- | src/cpp/client/secure_credentials.h | 14 | ||||
-rw-r--r-- | src/cpp/codegen/grpc_library.cc | 40 | ||||
-rw-r--r-- | src/cpp/common/alarm.cc | 8 | ||||
-rw-r--r-- | src/cpp/common/completion_queue.cc | 6 | ||||
-rw-r--r-- | src/cpp/common/grpc_library_initializer.cc | 41 | ||||
-rw-r--r-- | src/cpp/server/server.cc | 12 |
10 files changed, 133 insertions, 26 deletions
diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc index f9bedbd0b5..9b87102f17 100644 --- a/src/cpp/client/channel.cc +++ b/src/cpp/client/channel.cc @@ -35,25 +35,28 @@ #include <memory> -#include <grpc/grpc.h> -#include <grpc/support/log.h> -#include <grpc/support/slice.h> #include <grpc++/client_context.h> #include <grpc++/completion_queue.h> -#include <grpc++/security/credentials.h> #include <grpc++/impl/call.h> -#include <grpc++/impl/rpc_method.h> #include <grpc++/impl/codegen/completion_queue_tag.h> +#include <grpc++/impl/grpc_library.h> +#include <grpc++/impl/rpc_method.h> +#include <grpc++/security/credentials.h> #include <grpc++/support/channel_arguments.h> #include <grpc++/support/config.h> #include <grpc++/support/status.h> #include <grpc++/support/time.h> +#include <grpc/grpc.h> +#include <grpc/support/log.h> +#include <grpc/support/slice.h> #include "src/core/profiling/timers.h" namespace grpc { Channel::Channel(const grpc::string& host, grpc_channel* channel) - : host_(host), c_channel_(channel) {} + : host_(host), c_channel_(channel) { + internal::g_gli_initializer.summon(); +} Channel::~Channel() { grpc_channel_destroy(c_channel_); } diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc index 3bbca807d3..a65e1e83d6 100644 --- a/src/cpp/client/create_channel.cc +++ b/src/cpp/client/create_channel.cc @@ -36,6 +36,7 @@ #include <grpc++/channel.h> #include <grpc++/create_channel.h> +#include <grpc++/impl/grpc_library.h> #include <grpc++/support/channel_arguments.h> #include "src/cpp/client/create_channel_internal.h" @@ -53,7 +54,8 @@ std::shared_ptr<Channel> CreateCustomChannel( const grpc::string& target, const std::shared_ptr<ChannelCredentials>& creds, const ChannelArguments& args) { - GrpcLibrary init_lib; // We need to call init in case of a bad creds. + internal::GrpcLibrary + init_lib; // We need to call init in case of a bad creds. ChannelArguments cp_args = args; std::ostringstream user_agent_prefix; user_agent_prefix << "grpc-c++/" << grpc_version_string(); diff --git a/src/cpp/client/credentials.cc b/src/cpp/client/credentials.cc index 0c08db11a9..7efe651e7a 100644 --- a/src/cpp/client/credentials.cc +++ b/src/cpp/client/credentials.cc @@ -31,12 +31,19 @@ * */ +#include <grpc++/impl/grpc_library.h> #include <grpc++/security/credentials.h> namespace grpc { +ChannelCredentials::ChannelCredentials() { + internal::g_gli_initializer.summon(); +} + ChannelCredentials::~ChannelCredentials() {} +CallCredentials::CallCredentials() { internal::g_gli_initializer.summon(); } + CallCredentials::~CallCredentials() {} } // namespace grpc diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 96ae25b761..0195a11527 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -41,6 +41,12 @@ namespace grpc { +SecureChannelCredentials::SecureChannelCredentials( + grpc_channel_credentials* c_creds) + : c_creds_(c_creds) { + internal::g_gli_initializer.summon(); +} + std::shared_ptr<grpc::Channel> SecureChannelCredentials::CreateChannel( const string& target, const grpc::ChannelArguments& args) { grpc_channel_args channel_args; @@ -51,6 +57,12 @@ std::shared_ptr<grpc::Channel> SecureChannelCredentials::CreateChannel( nullptr)); } +SecureCallCredentials::SecureCallCredentials(grpc_call_credentials* c_creds) + : c_creds_(c_creds) { + internal::GrpcLibraryInitializer gli_initializer; + gli_initializer.summon(); +} + bool SecureCallCredentials::ApplyToCall(grpc_call* call) { return grpc_call_set_credentials(call, c_creds_) == GRPC_CALL_OK; } diff --git a/src/cpp/client/secure_credentials.h b/src/cpp/client/secure_credentials.h index cef59292dd..ef61063d55 100644 --- a/src/cpp/client/secure_credentials.h +++ b/src/cpp/client/secure_credentials.h @@ -45,11 +45,8 @@ namespace grpc { class SecureChannelCredentials GRPC_FINAL : public ChannelCredentials { public: - explicit SecureChannelCredentials(grpc_channel_credentials* c_creds) - : c_creds_(c_creds) {} - ~SecureChannelCredentials() GRPC_OVERRIDE { - grpc_channel_credentials_release(c_creds_); - } + explicit SecureChannelCredentials(grpc_channel_credentials* c_creds); + ~SecureChannelCredentials() { grpc_channel_credentials_release(c_creds_); } grpc_channel_credentials* GetRawCreds() { return c_creds_; } std::shared_ptr<grpc::Channel> CreateChannel( @@ -62,11 +59,8 @@ class SecureChannelCredentials GRPC_FINAL : public ChannelCredentials { class SecureCallCredentials GRPC_FINAL : public CallCredentials { public: - explicit SecureCallCredentials(grpc_call_credentials* c_creds) - : c_creds_(c_creds) {} - ~SecureCallCredentials() GRPC_OVERRIDE { - grpc_call_credentials_release(c_creds_); - } + explicit SecureCallCredentials(grpc_call_credentials* c_creds); + ~SecureCallCredentials() { grpc_call_credentials_release(c_creds_); } grpc_call_credentials* GetRawCreds() { return c_creds_; } bool ApplyToCall(grpc_call* call) GRPC_OVERRIDE; diff --git a/src/cpp/codegen/grpc_library.cc b/src/cpp/codegen/grpc_library.cc new file mode 100644 index 0000000000..48acec3f3d --- /dev/null +++ b/src/cpp/codegen/grpc_library.cc @@ -0,0 +1,40 @@ +/* + * + * Copyright 2016, 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 <grpc++/impl/codegen/grpc_library.h> + +namespace grpc { + +GrpcLibraryInterface *g_glip = nullptr; + +} // namespace grpc diff --git a/src/cpp/common/alarm.cc b/src/cpp/common/alarm.cc index 1f0f04175e..79afe071fa 100644 --- a/src/cpp/common/alarm.cc +++ b/src/cpp/common/alarm.cc @@ -30,13 +30,17 @@ * */ -#include <grpc/grpc.h> #include <grpc++/alarm.h> +#include <grpc++/completion_queue.h> +#include <grpc++/impl/grpc_library.h> +#include <grpc/grpc.h> namespace grpc { Alarm::Alarm(CompletionQueue* cq, gpr_timespec deadline, void* tag) - : alarm_(grpc_alarm_create(cq->cq(), deadline, tag)) {} + : alarm_(grpc_alarm_create(cq->cq(), deadline, tag)) { + internal::g_gli_initializer.summon(); +} Alarm::~Alarm() { grpc_alarm_destroy(alarm_); } diff --git a/src/cpp/common/completion_queue.cc b/src/cpp/common/completion_queue.cc index 6ef77fcfff..0f7b6f63a3 100644 --- a/src/cpp/common/completion_queue.cc +++ b/src/cpp/common/completion_queue.cc @@ -34,14 +34,16 @@ #include <memory> +#include <grpc++/impl/codegen/completion_queue_tag.h> +#include <grpc++/impl/grpc_library.h> +#include <grpc++/support/time.h> #include <grpc/grpc.h> #include <grpc/support/log.h> -#include <grpc++/support/time.h> -#include <grpc++/impl/codegen/completion_queue_tag.h> namespace grpc { CompletionQueue::CompletionQueue() { + internal::g_gli_initializer.summon(); cq_ = grpc_completion_queue_create(nullptr); } diff --git a/src/cpp/common/grpc_library_initializer.cc b/src/cpp/common/grpc_library_initializer.cc new file mode 100644 index 0000000000..171efc9238 --- /dev/null +++ b/src/cpp/common/grpc_library_initializer.cc @@ -0,0 +1,41 @@ +/* + * Copyright 2016, 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 <grpc++/impl/grpc_library.h> + +namespace grpc { +namespace internal { + +GrpcLibraryInitializer g_gli_initializer; + +} // namespace internal +} // namespace grpc diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index 1a041133bd..fd6c4ae43e 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -35,18 +35,19 @@ #include <utility> -#include <grpc/grpc.h> -#include <grpc/support/alloc.h> -#include <grpc/support/log.h> #include <grpc++/completion_queue.h> #include <grpc++/generic/async_generic_service.h> +#include <grpc++/impl/codegen/completion_queue_tag.h> +#include <grpc++/impl/grpc_library.h> #include <grpc++/impl/method_handler_impl.h> #include <grpc++/impl/rpc_service_method.h> #include <grpc++/impl/service_type.h> -#include <grpc++/impl/codegen/completion_queue_tag.h> -#include <grpc++/server_context.h> #include <grpc++/security/server_credentials.h> +#include <grpc++/server_context.h> #include <grpc++/support/time.h> +#include <grpc/grpc.h> +#include <grpc/support/alloc.h> +#include <grpc/support/log.h> #include "src/core/profiling/timers.h" #include "src/cpp/server/thread_pool_interface.h" @@ -288,6 +289,7 @@ Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned, server_(CreateServer(args)), thread_pool_(thread_pool), thread_pool_owned_(thread_pool_owned) { + internal::g_gli_initializer.summon(); gpr_once_init(&g_once_init_callbacks, InitGlobalCallbacks); grpc_server_register_completion_queue(server_, cq_.cq(), nullptr); } |