From 7d099a5c907d9ab164416ea875ae07a3074adedb Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Fri, 6 May 2016 13:21:36 -0700 Subject: [PATCH] Fix naming and comment problems --- include/grpc++/impl/server_builder_plugin.h | 2 -- include/grpc++/server_builder.h | 1 + src/cpp/server/server_builder.cc | 10 ++++++---- test/cpp/end2end/server_builder_plugin_test.cc | 18 ++++++++---------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/include/grpc++/impl/server_builder_plugin.h b/include/grpc++/impl/server_builder_plugin.h index f792c4b321c..1e157efa111 100644 --- a/include/grpc++/impl/server_builder_plugin.h +++ b/include/grpc++/impl/server_builder_plugin.h @@ -64,6 +64,4 @@ class ServerBuilderPlugin { } // namespace grpc - - #endif // GRPCXX_IMPL_SERVER_BUILDER_PLUGIN_H diff --git a/include/grpc++/server_builder.h b/include/grpc++/server_builder.h index 52064b14349..ad629521cbe 100644 --- a/include/grpc++/server_builder.h +++ b/include/grpc++/server_builder.h @@ -113,6 +113,7 @@ class ServerBuilder { /// Return a running server which is ready for processing calls. std::unique_ptr BuildAndStart(); + /// For internal use only: Register a ServerBuilderPlugin factory function. static void InternalAddPluginFactory( std::unique_ptr (*CreatePlugin)()); diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc index b6e48efa8dd..9658a567455 100644 --- a/src/cpp/server/server_builder.cc +++ b/src/cpp/server/server_builder.cc @@ -41,18 +41,20 @@ namespace grpc { -static std::vector (*)()>* plugin_list; +static std::vector (*)()>* + g_plugin_factory_list; static gpr_once once_init_plugin_list = GPR_ONCE_INIT; static void do_plugin_list_init(void) { - plugin_list = new std::vector (*)()>(); + g_plugin_factory_list = + new std::vector (*)()>(); } ServerBuilder::ServerBuilder() : max_message_size_(-1), generic_service_(nullptr) { grpc_compression_options_init(&compression_options_); gpr_once_init(&once_init_plugin_list, do_plugin_list_init); - for (auto factory : (*plugin_list)) { + for (auto factory : (*g_plugin_factory_list)) { std::unique_ptr plugin = factory(); plugins_[plugin->name()] = std::move(plugin); } @@ -171,7 +173,7 @@ std::unique_ptr ServerBuilder::BuildAndStart() { void ServerBuilder::InternalAddPluginFactory( std::unique_ptr (*CreatePlugin)()) { gpr_once_init(&once_init_plugin_list, do_plugin_list_init); - (*plugin_list).push_back(CreatePlugin); + (*g_plugin_factory_list).push_back(CreatePlugin); } } // namespace grpc diff --git a/test/cpp/end2end/server_builder_plugin_test.cc b/test/cpp/end2end/server_builder_plugin_test.cc index 0d44999a08e..87e3709d7d2 100644 --- a/test/cpp/end2end/server_builder_plugin_test.cc +++ b/test/cpp/end2end/server_builder_plugin_test.cc @@ -115,10 +115,7 @@ class InsertPluginServerBuilderOption : public ServerBuilderOption { void UpdatePlugins( std::map>* plugins) GRPC_OVERRIDE { - auto it = plugins->begin(); - while (it != plugins->end()) { - plugins->erase(it++); - } + plugins->clear(); std::unique_ptr plugin( new TestServerBuilderPlugin()); @@ -136,7 +133,7 @@ std::unique_ptr CreateTestServerBuilderPlugin() { return std::unique_ptr(new TestServerBuilderPlugin()); } -void grpc_AddServerBuilderPlugin_reflection() { +void AddTestServerBuilderPlugin() { static bool already_here = false; if (already_here) return; already_here = true; @@ -145,12 +142,13 @@ void grpc_AddServerBuilderPlugin_reflection() { } // Force AddServerBuilderPlugin() to be called at static initialization time. -struct StaticPluginInitializer_reflection { - StaticPluginInitializer_reflection() { - grpc_AddServerBuilderPlugin_reflection(); - } -} static_plugin_initializer_reflection_; +struct StaticTestPluginInitializer { + StaticTestPluginInitializer() { AddTestServerBuilderPlugin(); } +} static_plugin_initializer_test_; +// When the param boolean is true, the ServerBuilder plugin will be added at the +// time of static initialization. When it's false, the ServerBuilder plugin will +// be added using ServerBuilder::SetOption(). class ServerBuilderPluginTest : public ::testing::TestWithParam { public: ServerBuilderPluginTest() {}