From e1300deb87b5fca2b4361a753d0bd4d19b078ea4 Mon Sep 17 00:00:00 2001
From: David Garcia Quintas
Date: Wed, 27 Jan 2016 18:41:26 -0800
Subject: [PATCH] After GrpcLibrary refactoring. Compiles and passes. WIP still
---
BUILD | 11 +
Makefile | 11 +
build.yaml | 6 +-
include/grpc++/alarm.h | 9 +-
include/grpc++/channel.h | 10 +-
include/grpc++/completion_queue.h | 10 +-
include/grpc++/impl/client_unary_call.h | 6 +-
include/grpc++/impl/codegen/grpc_library.h | 67 ++++
include/grpc++/impl/grpc_library.h | 24 +-
include/grpc++/security/credentials.h | 15 +-
include/grpc++/server.h | 6 +-
include/grpc++/support/sync_stream.h | 62 ++--
src/cpp/client/channel.cc | 15 +-
src/cpp/client/create_channel.cc | 4 +-
src/cpp/client/credentials.cc | 7 +
src/cpp/client/secure_credentials.cc | 12 +
src/cpp/client/secure_credentials.h | 14 +-
src/cpp/codegen/grpc_library.cc | 40 +++
src/cpp/common/alarm.cc | 8 +-
src/cpp/common/completion_queue.cc | 6 +-
src/cpp/common/grpc_library_initializer.cc | 41 +++
src/cpp/server/server.cc | 12 +-
tools/doxygen/Doxyfile.c++ | 310 +++++++++---------
tools/doxygen/Doxyfile.c++.internal | 6 +-
tools/run_tests/sources_and_headers.json | 19 +-
vsprojects/vcxproj/grpc++/grpc++.vcxproj | 6 +
.../vcxproj/grpc++/grpc++.vcxproj.filters | 15 +
.../grpc++_unsecure/grpc++_unsecure.vcxproj | 6 +
.../grpc++_unsecure.vcxproj.filters | 15 +
.../grpc_plugin_support.vcxproj | 4 +
.../grpc_plugin_support.vcxproj.filters | 15 +
31 files changed, 544 insertions(+), 248 deletions(-)
create mode 100644 include/grpc++/impl/codegen/grpc_library.h
create mode 100644 src/cpp/codegen/grpc_library.cc
create mode 100644 src/cpp/common/grpc_library_initializer.cc
diff --git a/BUILD b/BUILD
index 59e4c4447064f..0b8ee0702d4cd 100644
--- a/BUILD
+++ b/BUILD
@@ -785,6 +785,7 @@ cc_library(
"src/cpp/common/call.cc",
"src/cpp/common/channel_arguments.cc",
"src/cpp/common/completion_queue.cc",
+ "src/cpp/common/grpc_library_initializer.cc",
"src/cpp/common/rpc_method.cc",
"src/cpp/proto/proto_utils.cc",
"src/cpp/server/async_generic_service.cc",
@@ -801,6 +802,7 @@ cc_library(
"src/cpp/util/status.cc",
"src/cpp/util/string_ref.cc",
"src/cpp/util/time.cc",
+ "src/cpp/codegen/grpc_library.cc",
],
hdrs = [
"include/grpc++/channel.h",
@@ -854,6 +856,7 @@ cc_library(
"include/grpc++/impl/codegen/completion_queue_tag.h",
"include/grpc++/impl/codegen/config.h",
"include/grpc++/impl/codegen/config_protobuf.h",
+ "include/grpc++/impl/codegen/grpc_library.h",
"include/grpc++/impl/codegen/proto_utils.h",
"include/grpc++/impl/codegen/security/auth_context.h",
"include/grpc++/impl/codegen/serialization_traits.h",
@@ -863,6 +866,7 @@ cc_library(
"include/grpc++/impl/codegen/status.h",
"include/grpc++/impl/codegen/status_code_enum.h",
"include/grpc++/impl/codegen/string_ref.h",
+ "include/grpc++/impl/codegen/stub_options.h",
"include/grpc++/impl/codegen/sync.h",
"include/grpc++/impl/codegen/sync_cxx11.h",
"include/grpc++/impl/codegen/sync_no_cxx11.h",
@@ -900,6 +904,7 @@ cc_library(
"src/cpp/common/call.cc",
"src/cpp/common/channel_arguments.cc",
"src/cpp/common/completion_queue.cc",
+ "src/cpp/common/grpc_library_initializer.cc",
"src/cpp/common/rpc_method.cc",
"src/cpp/proto/proto_utils.cc",
"src/cpp/server/async_generic_service.cc",
@@ -916,6 +921,7 @@ cc_library(
"src/cpp/util/status.cc",
"src/cpp/util/string_ref.cc",
"src/cpp/util/time.cc",
+ "src/cpp/codegen/grpc_library.cc",
],
hdrs = [
"include/grpc++/channel.h",
@@ -969,6 +975,7 @@ cc_library(
"include/grpc++/impl/codegen/completion_queue_tag.h",
"include/grpc++/impl/codegen/config.h",
"include/grpc++/impl/codegen/config_protobuf.h",
+ "include/grpc++/impl/codegen/grpc_library.h",
"include/grpc++/impl/codegen/proto_utils.h",
"include/grpc++/impl/codegen/security/auth_context.h",
"include/grpc++/impl/codegen/serialization_traits.h",
@@ -978,6 +985,7 @@ cc_library(
"include/grpc++/impl/codegen/status.h",
"include/grpc++/impl/codegen/status_code_enum.h",
"include/grpc++/impl/codegen/string_ref.h",
+ "include/grpc++/impl/codegen/stub_options.h",
"include/grpc++/impl/codegen/sync.h",
"include/grpc++/impl/codegen/sync_cxx11.h",
"include/grpc++/impl/codegen/sync_no_cxx11.h",
@@ -1018,6 +1026,7 @@ cc_library(
"src/compiler/objective_c_generator.cc",
"src/compiler/python_generator.cc",
"src/compiler/ruby_generator.cc",
+ "src/cpp/codegen/grpc_library.cc",
],
hdrs = [
"include/grpc++/impl/codegen/async_stream.h",
@@ -1028,6 +1037,7 @@ cc_library(
"include/grpc++/impl/codegen/completion_queue_tag.h",
"include/grpc++/impl/codegen/config.h",
"include/grpc++/impl/codegen/config_protobuf.h",
+ "include/grpc++/impl/codegen/grpc_library.h",
"include/grpc++/impl/codegen/proto_utils.h",
"include/grpc++/impl/codegen/security/auth_context.h",
"include/grpc++/impl/codegen/serialization_traits.h",
@@ -1037,6 +1047,7 @@ cc_library(
"include/grpc++/impl/codegen/status.h",
"include/grpc++/impl/codegen/status_code_enum.h",
"include/grpc++/impl/codegen/string_ref.h",
+ "include/grpc++/impl/codegen/stub_options.h",
"include/grpc++/impl/codegen/sync.h",
"include/grpc++/impl/codegen/sync_cxx11.h",
"include/grpc++/impl/codegen/sync_no_cxx11.h",
diff --git a/Makefile b/Makefile
index 5a5434675f484..da993f5aa17ad 100644
--- a/Makefile
+++ b/Makefile
@@ -3010,6 +3010,7 @@ LIBGRPC++_SRC = \
src/cpp/common/call.cc \
src/cpp/common/channel_arguments.cc \
src/cpp/common/completion_queue.cc \
+ src/cpp/common/grpc_library_initializer.cc \
src/cpp/common/rpc_method.cc \
src/cpp/proto/proto_utils.cc \
src/cpp/server/async_generic_service.cc \
@@ -3026,6 +3027,7 @@ LIBGRPC++_SRC = \
src/cpp/util/status.cc \
src/cpp/util/string_ref.cc \
src/cpp/util/time.cc \
+ src/cpp/codegen/grpc_library.cc \
PUBLIC_HEADERS_CXX += \
include/grpc++/channel.h \
@@ -3079,6 +3081,7 @@ PUBLIC_HEADERS_CXX += \
include/grpc++/impl/codegen/completion_queue_tag.h \
include/grpc++/impl/codegen/config.h \
include/grpc++/impl/codegen/config_protobuf.h \
+ include/grpc++/impl/codegen/grpc_library.h \
include/grpc++/impl/codegen/proto_utils.h \
include/grpc++/impl/codegen/security/auth_context.h \
include/grpc++/impl/codegen/serialization_traits.h \
@@ -3088,6 +3091,7 @@ PUBLIC_HEADERS_CXX += \
include/grpc++/impl/codegen/status.h \
include/grpc++/impl/codegen/status_code_enum.h \
include/grpc++/impl/codegen/string_ref.h \
+ include/grpc++/impl/codegen/stub_options.h \
include/grpc++/impl/codegen/sync.h \
include/grpc++/impl/codegen/sync_cxx11.h \
include/grpc++/impl/codegen/sync_no_cxx11.h \
@@ -3301,6 +3305,7 @@ LIBGRPC++_UNSECURE_SRC = \
src/cpp/common/call.cc \
src/cpp/common/channel_arguments.cc \
src/cpp/common/completion_queue.cc \
+ src/cpp/common/grpc_library_initializer.cc \
src/cpp/common/rpc_method.cc \
src/cpp/proto/proto_utils.cc \
src/cpp/server/async_generic_service.cc \
@@ -3317,6 +3322,7 @@ LIBGRPC++_UNSECURE_SRC = \
src/cpp/util/status.cc \
src/cpp/util/string_ref.cc \
src/cpp/util/time.cc \
+ src/cpp/codegen/grpc_library.cc \
PUBLIC_HEADERS_CXX += \
include/grpc++/channel.h \
@@ -3370,6 +3376,7 @@ PUBLIC_HEADERS_CXX += \
include/grpc++/impl/codegen/completion_queue_tag.h \
include/grpc++/impl/codegen/config.h \
include/grpc++/impl/codegen/config_protobuf.h \
+ include/grpc++/impl/codegen/grpc_library.h \
include/grpc++/impl/codegen/proto_utils.h \
include/grpc++/impl/codegen/security/auth_context.h \
include/grpc++/impl/codegen/serialization_traits.h \
@@ -3379,6 +3386,7 @@ PUBLIC_HEADERS_CXX += \
include/grpc++/impl/codegen/status.h \
include/grpc++/impl/codegen/status_code_enum.h \
include/grpc++/impl/codegen/string_ref.h \
+ include/grpc++/impl/codegen/stub_options.h \
include/grpc++/impl/codegen/sync.h \
include/grpc++/impl/codegen/sync_cxx11.h \
include/grpc++/impl/codegen/sync_no_cxx11.h \
@@ -3458,6 +3466,7 @@ LIBGRPC_PLUGIN_SUPPORT_SRC = \
src/compiler/objective_c_generator.cc \
src/compiler/python_generator.cc \
src/compiler/ruby_generator.cc \
+ src/cpp/codegen/grpc_library.cc \
PUBLIC_HEADERS_CXX += \
include/grpc++/impl/codegen/async_stream.h \
@@ -3468,6 +3477,7 @@ PUBLIC_HEADERS_CXX += \
include/grpc++/impl/codegen/completion_queue_tag.h \
include/grpc++/impl/codegen/config.h \
include/grpc++/impl/codegen/config_protobuf.h \
+ include/grpc++/impl/codegen/grpc_library.h \
include/grpc++/impl/codegen/proto_utils.h \
include/grpc++/impl/codegen/security/auth_context.h \
include/grpc++/impl/codegen/serialization_traits.h \
@@ -3477,6 +3487,7 @@ PUBLIC_HEADERS_CXX += \
include/grpc++/impl/codegen/status.h \
include/grpc++/impl/codegen/status_code_enum.h \
include/grpc++/impl/codegen/string_ref.h \
+ include/grpc++/impl/codegen/stub_options.h \
include/grpc++/impl/codegen/sync.h \
include/grpc++/impl/codegen/sync_cxx11.h \
include/grpc++/impl/codegen/sync_no_cxx11.h \
diff --git a/build.yaml b/build.yaml
index 4df69762a353d..f63e033aa8aa4 100644
--- a/build.yaml
+++ b/build.yaml
@@ -84,6 +84,7 @@ filegroups:
- src/cpp/common/call.cc
- src/cpp/common/channel_arguments.cc
- src/cpp/common/completion_queue.cc
+ - src/cpp/common/grpc_library_initializer.cc
- src/cpp/common/rpc_method.cc
- src/cpp/proto/proto_utils.cc
- src/cpp/server/async_generic_service.cc
@@ -107,10 +108,10 @@ filegroups:
- include/grpc++/impl/codegen/call_hook.h
- include/grpc++/impl/codegen/channel_interface.h
- include/grpc++/impl/codegen/client_context.h
- - include/grpc++/impl/codegen/stub_options.h
- include/grpc++/impl/codegen/completion_queue_tag.h
- include/grpc++/impl/codegen/config.h
- include/grpc++/impl/codegen/config_protobuf.h
+ - include/grpc++/impl/codegen/grpc_library.h
- include/grpc++/impl/codegen/proto_utils.h
- include/grpc++/impl/codegen/security/auth_context.h
- include/grpc++/impl/codegen/serialization_traits.h
@@ -120,10 +121,13 @@ filegroups:
- include/grpc++/impl/codegen/status.h
- include/grpc++/impl/codegen/status_code_enum.h
- include/grpc++/impl/codegen/string_ref.h
+ - include/grpc++/impl/codegen/stub_options.h
- include/grpc++/impl/codegen/sync.h
- include/grpc++/impl/codegen/sync_cxx11.h
- include/grpc++/impl/codegen/sync_no_cxx11.h
- include/grpc++/impl/codegen/time.h
+ src:
+ - src/cpp/codegen/grpc_library.cc
- name: grpc_base
public_headers:
- include/grpc/byte_buffer.h
diff --git a/include/grpc++/alarm.h b/include/grpc++/alarm.h
index 957d11c5000ce..381e8c7698dde 100644
--- a/include/grpc++/alarm.h
+++ b/include/grpc++/alarm.h
@@ -36,14 +36,15 @@
#ifndef GRPCXX_ALARM_H
#define GRPCXX_ALARM_H
-#include
-#include
-#include
+#include
+#include
namespace grpc {
+class CompletionQueue;
+
/// A thin wrapper around \a grpc_alarm (see / \a / src/core/surface/alarm.h).
-class Alarm : public GrpcLibrary {
+class Alarm : private GrpcLibrary {
public:
/// Create a completion queue alarm instance associated to \a cq.
///
diff --git a/include/grpc++/channel.h b/include/grpc++/channel.h
index d6f55a8bf674e..80547f7ab8abb 100644
--- a/include/grpc++/channel.h
+++ b/include/grpc++/channel.h
@@ -36,20 +36,20 @@
#include
-#include
#include
#include
-#include
-#include
+#include
+#include
+#include
struct grpc_channel;
namespace grpc {
/// Channels represent a connection to an endpoint. Created by \a CreateChannel.
class Channel GRPC_FINAL : public ChannelInterface,
- public GrpcLibrary,
public CallHook,
- public std::enable_shared_from_this {
+ public std::enable_shared_from_this,
+ private GrpcLibrary {
public:
~Channel();
diff --git a/include/grpc++/completion_queue.h b/include/grpc++/completion_queue.h
index 7ed8f590089fb..911d7919e1e2d 100644
--- a/include/grpc++/completion_queue.h
+++ b/include/grpc++/completion_queue.h
@@ -36,9 +36,9 @@
#ifndef GRPCXX_COMPLETION_QUEUE_H
#define GRPCXX_COMPLETION_QUEUE_H
-#include
-#include
-#include
+#include
+#include
+#include
struct grpc_completion_queue;
@@ -78,7 +78,7 @@ class ServerContext;
/// A thin wrapper around \a grpc_completion_queue (see / \a
/// src/core/surface/completion_queue.h).
-class CompletionQueue : public GrpcLibrary {
+class CompletionQueue : private GrpcLibrary {
public:
/// Default constructor. Implicitly creates a \a grpc_completion_queue
/// instance.
@@ -90,7 +90,7 @@ class CompletionQueue : public GrpcLibrary {
explicit CompletionQueue(grpc_completion_queue* take);
/// Destructor. Destroys the owned wrapped completion queue / instance.
- ~CompletionQueue() GRPC_OVERRIDE;
+ ~CompletionQueue();
/// Tri-state return for AsyncNext: SHUTDOWN, GOT_EVENT, TIMEOUT.
enum NextStatus {
diff --git a/include/grpc++/impl/client_unary_call.h b/include/grpc++/impl/client_unary_call.h
index 6033fb7cc2861..9017bf5e3544f 100644
--- a/include/grpc++/impl/client_unary_call.h
+++ b/include/grpc++/impl/client_unary_call.h
@@ -34,10 +34,10 @@
#ifndef GRPCXX_IMPL_CLIENT_UNARY_CALL_H
#define GRPCXX_IMPL_CLIENT_UNARY_CALL_H
-#include
+#include
#include
-#include
-#include
+#include
+#include
namespace grpc {
diff --git a/include/grpc++/impl/codegen/grpc_library.h b/include/grpc++/impl/codegen/grpc_library.h
new file mode 100644
index 0000000000000..eb7152a2c60af
--- /dev/null
+++ b/include/grpc++/impl/codegen/grpc_library.h
@@ -0,0 +1,67 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#ifndef GRPCXX_IMPL_CODEGEN_GRPC_LIBRARY_H
+#define GRPCXX_IMPL_CODEGEN_GRPC_LIBRARY_H
+
+#include
+
+namespace grpc {
+
+class GrpcLibraryInterface {
+ public:
+ virtual void init() = 0;
+ virtual void shutdown() = 0;
+};
+
+extern GrpcLibraryInterface* g_glip;
+
+class GrpcLibrary {
+ public:
+ GrpcLibrary() {
+ GPR_ASSERT(g_glip &&
+ "gRPC library not initialized. See "
+ "grpc::internal::GrpcLibraryInitializer.");
+ g_glip->init();
+ }
+ virtual ~GrpcLibrary() {
+ GPR_ASSERT(g_glip &&
+ "gRPC library not initialized. See "
+ "grpc::internal::GrpcLibraryInitializer.");
+ g_glip->shutdown();
+ }
+};
+
+} // namespace grpc
+
+#endif // GRPCXX_IMPL_GRPC_LIBRARY_H
diff --git a/include/grpc++/impl/grpc_library.h b/include/grpc++/impl/grpc_library.h
index ce4211418dda6..041a88f2b6398 100644
--- a/include/grpc++/impl/grpc_library.h
+++ b/include/grpc++/impl/grpc_library.h
@@ -34,16 +34,34 @@
#ifndef GRPCXX_IMPL_GRPC_LIBRARY_H
#define GRPCXX_IMPL_GRPC_LIBRARY_H
+#include
+#include
#include
namespace grpc {
-class GrpcLibrary {
+namespace internal {
+class GrpcLibrary GRPC_FINAL : public GrpcLibraryInterface {
public:
- GrpcLibrary() { grpc_init(); }
- virtual ~GrpcLibrary() { grpc_shutdown(); }
+ void init() GRPC_OVERRIDE { grpc_init(); }
+
+ void shutdown() GRPC_OVERRIDE { grpc_shutdown(); }
};
+static GrpcLibrary g_gli;
+
+class GrpcLibraryInitializer GRPC_FINAL {
+ public:
+ GrpcLibraryInitializer() { grpc::g_glip = &g_gli; }
+
+ /// A no-op method to force the linker to reference this class, which will
+ /// take care of initializing and shutting down the gRPC runtime.
+ inline void summon() {}
+};
+
+extern GrpcLibraryInitializer g_gli_initializer;
+
+} // namespace internal
} // namespace grpc
#endif // GRPCXX_IMPL_GRPC_LIBRARY_H
diff --git a/include/grpc++/security/credentials.h b/include/grpc++/security/credentials.h
index 75945fd8e81e1..4d64b5e227318 100644
--- a/include/grpc++/security/credentials.h
+++ b/include/grpc++/security/credentials.h
@@ -37,12 +37,13 @@
#include