]> granicus.if.org Git - icinga2/commitdiff
Get rid of INITIALIZE_ONCE for the ExternalCommandProcessor
authorGunnar Beutner <gunnar.beutner@icinga.com>
Thu, 23 Nov 2017 08:31:39 +0000 (09:31 +0100)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Thu, 30 Nov 2017 16:47:09 +0000 (17:47 +0100)
lib/icinga/externalcommandprocessor.cpp
lib/icinga/externalcommandprocessor.hpp

index 3ea5afe7119754c0180354aff79a53a48afabd0e..d1c9f73e0400b2b0f2115f5ae09df07e1d303a39 100644 (file)
 
 using namespace icinga;
 
-INITIALIZE_ONCE(&ExternalCommandProcessor::StaticInitialize);
-
-typedef std::function<void (double, const std::vector<String>& arguments)> ExternalCommandCallback;
-
-struct ExternalCommandInfo
-{
-       ExternalCommandCallback Callback;
-       size_t MinArgs;
-       size_t MaxArgs;
-};
-
-static boost::mutex& GetMutex(void)
-{
-       static boost::mutex mtx;
-       return mtx;
-}
-static std::map<String, ExternalCommandInfo>& GetCommands(void)
-{
-       static std::map<String, ExternalCommandInfo> commands;
-       return commands;
-}
-
-boost::signals2::signal<void (double, const String&, const std::vector<String>&)> ExternalCommandProcessor::OnNewExternalCommand;
-
-static void RegisterCommand(const String& command, const ExternalCommandCallback& callback, size_t minArgs = 0, size_t maxArgs = UINT_MAX)
-{
-       boost::mutex::scoped_lock lock(GetMutex());
-       ExternalCommandInfo eci;
-       eci.Callback = callback;
-       eci.MinArgs = minArgs;
-       eci.MaxArgs = (maxArgs == UINT_MAX) ? minArgs : maxArgs;
-       GetCommands()[command] = eci;
-}
+boost::signals2::signal<void(double, const String&, const std::vector<String>&)> ExternalCommandProcessor::OnNewExternalCommand;
 
 void ExternalCommandProcessor::Execute(const String& line)
 {
@@ -156,7 +124,17 @@ void ExternalCommandProcessor::Execute(double time, const String& command, const
        eci.Callback(time, realArguments);
 }
 
-void ExternalCommandProcessor::StaticInitialize(void)
+void ExternalCommandProcessor::RegisterCommand(const String& command, const ExternalCommandCallback& callback, size_t minArgs, size_t maxArgs)
+{
+       boost::mutex::scoped_lock lock(GetMutex());
+       ExternalCommandInfo eci;
+       eci.Callback = callback;
+       eci.MinArgs = minArgs;
+       eci.MaxArgs = (maxArgs == UINT_MAX) ? minArgs : maxArgs;
+       GetCommands()[command] = eci;
+}
+
+void ExternalCommandProcessor::RegisterCommands(void)
 {
        RegisterCommand("PROCESS_HOST_CHECK_RESULT", &ExternalCommandProcessor::ProcessHostCheckResult, 3);
        RegisterCommand("PROCESS_SERVICE_CHECK_RESULT", &ExternalCommandProcessor::ProcessServiceCheckResult, 4);
@@ -2254,3 +2232,16 @@ void ExternalCommandProcessor::DisableServicegroupSvcNotifications(double, const
                service->ModifyAttribute("enable_notifications", false);
        }
 }
+
+boost::mutex& ExternalCommandProcessor::GetMutex(void)
+{
+       static boost::mutex mtx;
+       return mtx;
+}
+
+std::map<String, ExternalCommandInfo>& ExternalCommandProcessor::GetCommands(void)
+{
+       static std::map<String, ExternalCommandInfo> commands;
+       return commands;
+}
+
index 07fbfa5125f2a96c34ac9267cf38c3f173a18a70..51cf2d29179e25e140e13a06d5298c4316422d9a 100644 (file)
 namespace icinga
 {
 
+typedef std::function<void (double, const std::vector<String>& arguments)> ExternalCommandCallback;
+
+struct ExternalCommandInfo
+{
+       ExternalCommandCallback Callback;
+       size_t MinArgs;
+       size_t MaxArgs;
+};
+
 class I2_ICINGA_API ExternalCommandProcessor {
 public:
        static void Execute(const String& line);
        static void Execute(double time, const String& command, const std::vector<String>& arguments);
 
-       static void StaticInitialize(void);
-
        static boost::signals2::signal<void(double, const String&, const std::vector<String>&)> OnNewExternalCommand;
 
 private:
@@ -165,6 +172,13 @@ private:
 
 private:
        static void ChangeCustomCommandVarInternal(const Command::Ptr& command, const String& name, const Value& value);
+
+       static void RegisterCommand(const String& command, const ExternalCommandCallback& callback, size_t minArgs = 0, size_t maxArgs = UINT_MAX);
+       static void RegisterCommands(void);
+
+       static boost::mutex& GetMutex(void);
+       static std::map<String, ExternalCommandInfo>& GetCommands(void);
+
 };
 
 }