]> granicus.if.org Git - icinga2/commitdiff
Fix static initializers
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 11 Nov 2014 12:22:16 +0000 (13:22 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 11 Nov 2014 12:24:44 +0000 (13:24 +0100)
refs #7634

13 files changed:
lib/base/scriptfunction.cpp
lib/base/scriptfunction.hpp
lib/base/statsfunction.cpp
lib/base/statsfunction.hpp
lib/cli/clicommand.cpp
lib/cli/clicommand.hpp
lib/cli/nodeblackandwhitelistcommand.cpp
lib/cli/nodeblackandwhitelistcommand.hpp
lib/cli/repositoryobjectcommand.cpp
lib/cli/repositoryobjectcommand.hpp
lib/db_ido/dbtype.hpp
lib/remote/apifunction.cpp
lib/remote/apifunction.hpp

index 584e499194252063ae2a36867e935766d200993c..52a20b9195709e6f694c22ccaccd88dbdaf4f09e 100644 (file)
@@ -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));
-}
 
index aa50d7f7c804370e6c59e6dfedf98f3866a42eb0..442c9790ca3f44e1ae6ebabec67097cd8e929245 100644 (file)
@@ -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); \
+       } } }
 
 }
 
index e36c6f700f9adb9e121340a81c0c73b9675202ff..0d11e80826ac5f364f76d959242888bd9670071f 100644 (file)
@@ -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<StatsFunctionRegistry>::GetInstance();
index 3f08565deacda305d873785ac6d8c3423bad141c..8f52a3b24fc8f3d334707e2028abf0d4d00bb6af 100644 (file)
@@ -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); \
+       } } }
 
 }
 
index 79bcf14da792d89a6403060810c70628431cf598..31deb99586e0c444945f29f1ffc43f0b8211dad4 100644 (file)
 #include "base/logger.hpp"
 #include "base/type.hpp"
 #include "base/serializer.hpp"
-#include <boost/algorithm/string/split.hpp>
 #include <boost/algorithm/string/join.hpp>
 #include <boost/algorithm/string/trim.hpp>
-#include <boost/algorithm/string/classification.hpp>
 #include <boost/foreach.hpp>
 #include <boost/program_options.hpp>
 #include <algorithm>
@@ -139,13 +137,6 @@ void CLICommand::Unregister(const std::vector<String>& name)
        GetRegistry().erase(name);
 }
 
-RegisterCLICommandHelper::RegisterCLICommandHelper(const String& name, const CLICommand::Ptr& command)
-{
-       std::vector<String> vname;
-       boost::algorithm::split(vname, name, boost::is_any_of("/"));
-       CLICommand::Register(vname, command);
-}
-
 std::vector<String> CLICommand::GetArgumentSuggestions(const String& argument, const String& word) const
 {
        return std::vector<String>();
index 6deb0495e86a356019cbcac59c346cb37be59f8b..a00cee8ea1263c147c668147a6a1ec3b655858d3 100644 (file)
@@ -26,6 +26,8 @@
 #include "base/type.hpp"
 #include <vector>
 #include <boost/program_options.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string/classification.hpp>
 
 namespace icinga
 {
@@ -84,20 +86,15 @@ private:
        static std::map<std::vector<String>, 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<String> vname; \
+                       boost::algorithm::split(vname, name, boost::is_any_of("/")); \
+                       CLICommand::Register(vname, new klass()); \
+               } \
+               INITIALIZE_ONCE(RegisterCommand); \
        } }
 
 }
index f4954b67ee1ec7490c3adae52d38712a74a3d6bb..12a37955d1ba98de6ad21be1f4406cd40a40b730 100644 (file)
@@ -24,7 +24,6 @@
 #include "base/objectlock.hpp"
 #include "base/json.hpp"
 #include <boost/foreach.hpp>
-#include <boost/algorithm/string/case_conv.hpp>
 #include <iostream>
 #include <fstream>
 
@@ -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<String> 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)
 { }
index cd103660e25957eaef30eafcd0e959512c074490..7ebc6e7819396cda15a1eb6f5e101ae676c00697 100644 (file)
@@ -21,6 +21,7 @@
 #define BLACKANDWHITELISTCOMMAND_H
 
 #include "cli/clicommand.hpp"
+#include <boost/algorithm/string/case_conv.hpp>
 
 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<String> 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); \
+       } } }
 
 }
 
index 35ab319e3a204e644a8308a153b1bf940d5815f5..996015390d90522540399d4b532dfd07561741a8 100644 (file)
@@ -23,8 +23,6 @@
 #include "base/application.hpp"
 #include "base/utility.hpp"
 #include <boost/foreach.hpp>
-#include <boost/algorithm/string/join.hpp>
-#include <boost/algorithm/string/case_conv.hpp>
 #include <fstream>
 #include <iostream>
 
@@ -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<String> 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)
 { }
index 9472f5e8648b60882bf780e6230d31fc946f8ee1..0d0152d1309723b254b91c9013ce20d8b2c90de2 100644 (file)
@@ -21,6 +21,7 @@
 #define REPOSITORYOBJECTCOMMAND_H
 
 #include "cli/clicommand.hpp"
+#include <boost/algorithm/string/case_conv.hpp>
 
 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<String> 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); \
+       } } }
 
 }
 
index 9f7544a2fdc61e560c9d05a396c82ade1ff25110..a0956c6e89c3d769aa3700ffab1663940055e5f6 100644 (file)
@@ -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<T> 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<type>);
+       namespace { namespace UNIQUE_NAME(ido) { namespace ido ## name { \
+               void RegisterDbType(void) \
+               { \
+                       DbType::Ptr dbtype = new DbType(table, tid, idcolumn, DbObjectFactory<type>); \
+                       DbType::RegisterType(#name, dbtype); \
+               } \
+               INITIALIZE_ONCE(RegisterDbType); \
+       } } }
 
 }
 
index 2e427df229555168a3f9726e0d4ade2d32163410..770c980ae00a08145567717ecb4993c09af80a6f 100644 (file)
@@ -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);
index 72da522d4d26e2b5cfcfc047085188c2730e9ebd..91282fd7b5a0d9e41758375cce774d404b4d2dc5 100644 (file)
@@ -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); \
+       } } }
 
 }