From 11710ef6830755ed063360c751f913ca53f0e2e8 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 11 Nov 2014 13:22:16 +0100 Subject: [PATCH] Fix static initializers refs #7634 --- lib/base/scriptfunction.cpp | 4 --- lib/base/scriptfunction.hpp | 19 +++++-------- lib/base/statsfunction.cpp | 6 ---- lib/base/statsfunction.hpp | 20 ++++++-------- lib/cli/clicommand.cpp | 9 ------ lib/cli/clicommand.hpp | 21 ++++++-------- lib/cli/nodeblackandwhitelistcommand.cpp | 19 ------------- lib/cli/nodeblackandwhitelistcommand.hpp | 35 ++++++++++++++---------- lib/cli/repositoryobjectcommand.cpp | 20 -------------- lib/cli/repositoryobjectcommand.hpp | 35 ++++++++++++++---------- lib/db_ido/dbtype.hpp | 30 ++++++-------------- lib/remote/apifunction.cpp | 6 ---- lib/remote/apifunction.hpp | 9 +++++- 13 files changed, 82 insertions(+), 151 deletions(-) diff --git a/lib/base/scriptfunction.cpp b/lib/base/scriptfunction.cpp index 584e49919..52a20b919 100644 --- a/lib/base/scriptfunction.cpp +++ b/lib/base/scriptfunction.cpp @@ -52,8 +52,4 @@ void ScriptFunction::Unregister(const String& name) ScriptVariable::Unregister(name); } -RegisterFunctionHelper::RegisterFunctionHelper(const String& name, const ScriptFunction::Callback& function) -{ - ScriptFunction::Register(name, new ScriptFunction(function)); -} diff --git a/lib/base/scriptfunction.hpp b/lib/base/scriptfunction.hpp index aa50d7f7c..442c9790c 100644 --- a/lib/base/scriptfunction.hpp +++ b/lib/base/scriptfunction.hpp @@ -53,19 +53,14 @@ private: Callback m_Callback; }; -/** - * Helper class for registering ScriptFunction implementation classes. - * - * @ingroup base - */ -class I2_BASE_API RegisterFunctionHelper -{ -public: - RegisterFunctionHelper(const String& name, const ScriptFunction::Callback& function); -}; - #define REGISTER_SCRIPTFUNCTION(name, callback) \ - I2_EXPORT icinga::RegisterFunctionHelper g_RegisterSF_ ## name(#name, WrapScriptFunction(callback)) + namespace { namespace UNIQUE_NAME(sf) { namespace sf ## name { \ + void RegisterFunction(void) { \ + ScriptFunction::Ptr sf = new icinga::ScriptFunction(WrapScriptFunction(callback)); \ + ScriptFunction::Register(#name, sf); \ + } \ + INITIALIZE_ONCE(RegisterFunction); \ + } } } } diff --git a/lib/base/statsfunction.cpp b/lib/base/statsfunction.cpp index e36c6f700..0d11e8082 100644 --- a/lib/base/statsfunction.cpp +++ b/lib/base/statsfunction.cpp @@ -32,12 +32,6 @@ Value StatsFunction::Invoke(Dictionary::Ptr& status, Array::Ptr& perfdata) return m_Callback(status, perfdata); } -RegisterStatsFunctionHelper::RegisterStatsFunctionHelper(const String& name, const StatsFunction::Callback& function) -{ - StatsFunction::Ptr func = new StatsFunction(function); - StatsFunctionRegistry::GetInstance()->Register(name, func); -} - StatsFunctionRegistry *StatsFunctionRegistry::GetInstance(void) { return Singleton::GetInstance(); diff --git a/lib/base/statsfunction.hpp b/lib/base/statsfunction.hpp index 3f08565de..8f52a3b24 100644 --- a/lib/base/statsfunction.hpp +++ b/lib/base/statsfunction.hpp @@ -61,19 +61,15 @@ public: static StatsFunctionRegistry *GetInstance(void); }; -/** - * Helper class for registering StatsFunction implementation classes. - * - * @ingroup base - */ -class I2_BASE_API RegisterStatsFunctionHelper -{ -public: - RegisterStatsFunctionHelper(const String& name, const StatsFunction::Callback& function); -}; - #define REGISTER_STATSFUNCTION(name, callback) \ - I2_EXPORT icinga::RegisterStatsFunctionHelper g_RegisterStF_ ## name(#name, callback) + namespace { namespace UNIQUE_NAME(stf) { namespace stf ## name { \ + void RegisterStatsFunction(void) \ + { \ + StatsFunction::Ptr stf = new StatsFunction(callback); \ + StatsFunctionRegistry::GetInstance()->Register(#name, stf); \ + } \ + INITIALIZE_ONCE(RegisterStatsFunction); \ + } } } } diff --git a/lib/cli/clicommand.cpp b/lib/cli/clicommand.cpp index 79bcf14da..31deb9958 100644 --- a/lib/cli/clicommand.cpp +++ b/lib/cli/clicommand.cpp @@ -21,10 +21,8 @@ #include "base/logger.hpp" #include "base/type.hpp" #include "base/serializer.hpp" -#include #include #include -#include #include #include #include @@ -139,13 +137,6 @@ void CLICommand::Unregister(const std::vector& name) GetRegistry().erase(name); } -RegisterCLICommandHelper::RegisterCLICommandHelper(const String& name, const CLICommand::Ptr& command) -{ - std::vector vname; - boost::algorithm::split(vname, name, boost::is_any_of("/")); - CLICommand::Register(vname, command); -} - std::vector CLICommand::GetArgumentSuggestions(const String& argument, const String& word) const { return std::vector(); diff --git a/lib/cli/clicommand.hpp b/lib/cli/clicommand.hpp index 6deb0495e..a00cee8ea 100644 --- a/lib/cli/clicommand.hpp +++ b/lib/cli/clicommand.hpp @@ -26,6 +26,8 @@ #include "base/type.hpp" #include #include +#include +#include namespace icinga { @@ -84,20 +86,15 @@ private: static std::map, CLICommand::Ptr>& GetRegistry(void); }; -/** - * Helper class for registering CLICommand implementation classes. - * - * @ingroup base - */ -class I2_CLI_API RegisterCLICommandHelper -{ -public: - RegisterCLICommandHelper(const String& name, const CLICommand::Ptr& command); -}; - #define REGISTER_CLICOMMAND(name, klass) \ namespace { namespace UNIQUE_NAME(cli) { \ - I2_EXPORT icinga::RegisterCLICommandHelper l_RegisterCLICommand(name, new klass()); \ + void RegisterCommand(void) \ + { \ + std::vector vname; \ + boost::algorithm::split(vname, name, boost::is_any_of("/")); \ + CLICommand::Register(vname, new klass()); \ + } \ + INITIALIZE_ONCE(RegisterCommand); \ } } } diff --git a/lib/cli/nodeblackandwhitelistcommand.cpp b/lib/cli/nodeblackandwhitelistcommand.cpp index f4954b67e..12a37955d 100644 --- a/lib/cli/nodeblackandwhitelistcommand.cpp +++ b/lib/cli/nodeblackandwhitelistcommand.cpp @@ -24,7 +24,6 @@ #include "base/objectlock.hpp" #include "base/json.hpp" #include -#include #include #include @@ -34,24 +33,6 @@ namespace po = boost::program_options; REGISTER_BLACKANDWHITELIST_CLICOMMAND(whitelist); REGISTER_BLACKANDWHITELIST_CLICOMMAND(blacklist); -RegisterBlackAndWhitelistCLICommandHelper::RegisterBlackAndWhitelistCLICommandHelper(const String& type) -{ - String ltype = type; - boost::algorithm::to_lower(ltype); - - std::vector name; - name.push_back("node"); - name.push_back(ltype); - name.push_back("add"); - CLICommand::Register(name, new BlackAndWhitelistCommand(type, BlackAndWhitelistCommandAdd)); - - name[2] = "remove"; - CLICommand::Register(name, new BlackAndWhitelistCommand(type, BlackAndWhitelistCommandRemove)); - - name[2] = "list"; - CLICommand::Register(name, new BlackAndWhitelistCommand(type, BlackAndWhitelistCommandList)); -} - BlackAndWhitelistCommand::BlackAndWhitelistCommand(const String& type, BlackAndWhitelistCommandType command) : m_Type(type), m_Command(command) { } diff --git a/lib/cli/nodeblackandwhitelistcommand.hpp b/lib/cli/nodeblackandwhitelistcommand.hpp index cd103660e..7ebc6e781 100644 --- a/lib/cli/nodeblackandwhitelistcommand.hpp +++ b/lib/cli/nodeblackandwhitelistcommand.hpp @@ -21,6 +21,7 @@ #define BLACKANDWHITELISTCOMMAND_H #include "cli/clicommand.hpp" +#include namespace icinga { @@ -55,21 +56,27 @@ private: BlackAndWhitelistCommandType m_Command; }; -/** - * Helper class for registering repository CLICommand implementation classes. - * - * @ingroup cli - */ -class I2_CLI_API RegisterBlackAndWhitelistCLICommandHelper -{ -public: - RegisterBlackAndWhitelistCLICommandHelper(const String& type); -}; - #define REGISTER_BLACKANDWHITELIST_CLICOMMAND(type) \ - namespace { namespace UNIQUE_NAME(blackandwhitelist) { \ - I2_EXPORT icinga::RegisterBlackAndWhitelistCLICommandHelper l_RegisterBlackAndWhitelistCLICommand_ ## type(#type); \ - } } + namespace { namespace UNIQUE_NAME(blackandwhitelist) { namespace blackandwhitelist ## type { \ + void RegisterCommand(void) \ + { \ + String ltype = #type; \ + boost::algorithm::to_lower(ltype); \ +\ + std::vector name; \ + name.push_back("node"); \ + name.push_back(ltype); \ + name.push_back("add"); \ + CLICommand::Register(name, new BlackAndWhitelistCommand(#type, BlackAndWhitelistCommandAdd)); \ +\ + name[2] = "remove"; \ + CLICommand::Register(name, new BlackAndWhitelistCommand(#type, BlackAndWhitelistCommandRemove)); \ +\ + name[2] = "list"; \ + CLICommand::Register(name, new BlackAndWhitelistCommand(#type, BlackAndWhitelistCommandList)); \ + } \ + INITIALIZE_ONCE(RegisterCommand); \ + } } } } diff --git a/lib/cli/repositoryobjectcommand.cpp b/lib/cli/repositoryobjectcommand.cpp index 35ab319e3..996015390 100644 --- a/lib/cli/repositoryobjectcommand.cpp +++ b/lib/cli/repositoryobjectcommand.cpp @@ -23,8 +23,6 @@ #include "base/application.hpp" #include "base/utility.hpp" #include -#include -#include #include #include @@ -36,24 +34,6 @@ REGISTER_REPOSITORY_CLICOMMAND(Service); REGISTER_REPOSITORY_CLICOMMAND(Zone); REGISTER_REPOSITORY_CLICOMMAND(Endpoint); -RegisterRepositoryCLICommandHelper::RegisterRepositoryCLICommandHelper(const String& type) -{ - String ltype = type; - boost::algorithm::to_lower(ltype); - - std::vector name; - name.push_back("repository"); - name.push_back(ltype); - name.push_back("add"); - CLICommand::Register(name, new RepositoryObjectCommand(type, RepositoryCommandAdd)); - - name[2] = "remove"; - CLICommand::Register(name, new RepositoryObjectCommand(type, RepositoryCommandRemove)); - - name[2] = "list"; - CLICommand::Register(name, new RepositoryObjectCommand(type, RepositoryCommandList)); -} - RepositoryObjectCommand::RepositoryObjectCommand(const String& type, RepositoryCommandType command) : m_Type(type), m_Command(command) { } diff --git a/lib/cli/repositoryobjectcommand.hpp b/lib/cli/repositoryobjectcommand.hpp index 9472f5e86..0d0152d13 100644 --- a/lib/cli/repositoryobjectcommand.hpp +++ b/lib/cli/repositoryobjectcommand.hpp @@ -21,6 +21,7 @@ #define REPOSITORYOBJECTCOMMAND_H #include "cli/clicommand.hpp" +#include namespace icinga { @@ -59,21 +60,27 @@ private: RepositoryCommandType m_Command; }; -/** - * Helper class for registering repository CLICommand implementation classes. - * - * @ingroup cli - */ -class I2_CLI_API RegisterRepositoryCLICommandHelper -{ -public: - RegisterRepositoryCLICommandHelper(const String& type); -}; - #define REGISTER_REPOSITORY_CLICOMMAND(type) \ - namespace { namespace UNIQUE_NAME(repositoryobject) { \ - I2_EXPORT icinga::RegisterRepositoryCLICommandHelper l_RegisterRepositoryCLICommand_ ## type(#type); \ - } } + namespace { namespace UNIQUE_NAME(repositoryobject) { namespace repositoryobject ## type { \ + void RegisterCommand(void) \ + { \ + String ltype = #type; \ + boost::algorithm::to_lower(ltype); \ +\ + std::vector name; \ + name.push_back("repository"); \ + name.push_back(ltype); \ + name.push_back("add"); \ + CLICommand::Register(name, new RepositoryObjectCommand(#type, RepositoryCommandAdd)); \ +\ + name[2] = "remove"; \ + CLICommand::Register(name, new RepositoryObjectCommand(#type, RepositoryCommandRemove)); \ +\ + name[2] = "list"; \ + CLICommand::Register(name, new RepositoryObjectCommand(#type, RepositoryCommandList)); \ + } \ + INITIALIZE_ONCE(RegisterCommand); \ + } } } } diff --git a/lib/db_ido/dbtype.hpp b/lib/db_ido/dbtype.hpp index 9f7544a2f..a0956c6e8 100644 --- a/lib/db_ido/dbtype.hpp +++ b/lib/db_ido/dbtype.hpp @@ -85,27 +85,6 @@ public: static DbTypeRegistry *GetInstance(void); }; -/** - * Helper class for registering DynamicObject implementation classes. - * - * @ingroup ido - */ -class RegisterDbTypeHelper -{ -public: - RegisterDbTypeHelper(const String& name, const String& table, long tid, const String& idcolumn, const DbType::ObjectFactory& factory) - { - DbType::Ptr dbtype; - - dbtype = DbType::GetByID(tid); - - if (!dbtype) - dbtype = new DbType(table, tid, idcolumn, factory); - - DbType::RegisterType(name, dbtype); - } -}; - /** * Factory function for DbObject-based classes. * @@ -118,7 +97,14 @@ intrusive_ptr DbObjectFactory(const DbType::Ptr& type, const String& name1, c } #define REGISTER_DBTYPE(name, table, tid, idcolumn, type) \ - I2_EXPORT icinga::RegisterDbTypeHelper g_RegisterDBT_ ## name(#name, table, tid, idcolumn, DbObjectFactory); + namespace { namespace UNIQUE_NAME(ido) { namespace ido ## name { \ + void RegisterDbType(void) \ + { \ + DbType::Ptr dbtype = new DbType(table, tid, idcolumn, DbObjectFactory); \ + DbType::RegisterType(#name, dbtype); \ + } \ + INITIALIZE_ONCE(RegisterDbType); \ + } } } } diff --git a/lib/remote/apifunction.cpp b/lib/remote/apifunction.cpp index 2e427df22..770c980ae 100644 --- a/lib/remote/apifunction.cpp +++ b/lib/remote/apifunction.cpp @@ -31,12 +31,6 @@ Value ApiFunction::Invoke(const MessageOrigin& origin, const Dictionary::Ptr& ar return m_Callback(origin, arguments); } -RegisterApiFunctionHelper::RegisterApiFunctionHelper(const String& name, const ApiFunction::Callback& function) -{ - ApiFunction::Ptr func = new ApiFunction(function); - ApiFunctionRegistry::GetInstance()->Register(name, func); -} - ApiFunction::Ptr ApiFunction::GetByName(const String& name) { return ApiFunctionRegistry::GetInstance()->GetItem(name); diff --git a/lib/remote/apifunction.hpp b/lib/remote/apifunction.hpp index 72da522d4..91282fd7b 100644 --- a/lib/remote/apifunction.hpp +++ b/lib/remote/apifunction.hpp @@ -78,7 +78,14 @@ public: }; #define REGISTER_APIFUNCTION(name, ns, callback) \ - I2_EXPORT icinga::RegisterApiFunctionHelper g_RegisterAF_ ## name(#ns "::" #name, callback) + namespace { namespace UNIQUE_NAME(apif) { namespace apif ## name { \ + void RegisterFunction(void) \ + { \ + ApiFunction::Ptr func = new ApiFunction(callback); \ + ApiFunctionRegistry::GetInstance()->Register(#ns "::" #name, func); \ + } \ + INITIALIZE_ONCE(RegisterFunction); \ + } } } } -- 2.40.0