From 18e8d4a976801a26dd1882335507ec73851aefb6 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 26 Nov 2012 08:30:52 +0100 Subject: [PATCH] Refactored IcingaApplication::Get*(). Fixes #3209, #3277 --- lib/icinga/icingaapplication.cpp | 55 +++++++++++--------------------- lib/icinga/icingaapplication.h | 7 ---- 2 files changed, 19 insertions(+), 43 deletions(-) diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index bc616f856..a6500b4b9 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -90,32 +90,6 @@ int IcingaApplication::Main(const vector& args) } } - m_CertificateFile = Get("cert_path"); - m_CAFile = Get("ca_path"); - m_Node = Get("node"); - m_Service = Get("service"); - - m_PidPath = Get("pid_path"); - if (m_PidPath.IsEmpty()) - m_PidPath = DefaultPidPath; - - m_StatePath = Get("state_path"); - if (m_StatePath.IsEmpty()) - m_StatePath = DefaultStatePath; - - m_Macros = Get("macros"); - - String logpath = Get("log_path"); - if (!logpath.IsEmpty()) { - ConfigItemBuilder::Ptr fileLogConfig = boost::make_shared(); - fileLogConfig->SetType("Logger"); - fileLogConfig->SetName("main"); - fileLogConfig->SetLocal(true); - fileLogConfig->AddExpression("type", OperatorSet, "file"); - fileLogConfig->AddExpression("path", OperatorSet, logpath); - fileLogConfig->Compile()->Commit(); - } - UpdatePidFile(GetPidPath()); if (!GetCertificateFile().IsEmpty() && !GetCAFile().IsEmpty()) { @@ -131,9 +105,8 @@ int IcingaApplication::Main(const vector& args) } /* create the primary RPC listener */ - String service = GetService(); - if (!service.IsEmpty()) - EndpointManager::GetInstance()->AddListener(service); + if (!GetService().IsEmpty()) + EndpointManager::GetInstance()->AddListener(GetService()); if (daemonize) { Logger::Write(LogInformation, "icinga", "Daemonizing."); @@ -171,37 +144,47 @@ IcingaApplication::Ptr IcingaApplication::GetInstance(void) String IcingaApplication::GetCertificateFile(void) const { - return m_CertificateFile; + return Get("cert_path"); } String IcingaApplication::GetCAFile(void) const { - return m_CAFile; + return Get("ca_path"); } String IcingaApplication::GetNode(void) const { - return m_Node; + return Get("node"); } String IcingaApplication::GetService(void) const { - return m_Service; + return Get("service"); } String IcingaApplication::GetPidPath(void) const { - return m_PidPath; + Value pidPath = Get("pid_path"); + + if (pidPath.IsEmpty()) + pidPath = DefaultPidPath; + + return pidPath; } String IcingaApplication::GetStatePath(void) const { - return m_StatePath; + Value statePath = Get("state_path"); + + if (statePath.IsEmpty()) + statePath = DefaultStatePath; + + return statePath; } Dictionary::Ptr IcingaApplication::GetMacros(void) const { - return m_Macros; + return Get("macros"); } double IcingaApplication::GetStartTime(void) const diff --git a/lib/icinga/icingaapplication.h b/lib/icinga/icingaapplication.h index d1175758b..e238fa6ae 100644 --- a/lib/icinga/icingaapplication.h +++ b/lib/icinga/icingaapplication.h @@ -55,13 +55,6 @@ public: static const String DefaultStatePath; private: - String m_CertificateFile; - String m_CAFile; - String m_Node; - String m_Service; - String m_PidPath; - String m_StatePath; - Dictionary::Ptr m_Macros; shared_ptr m_SSLContext; double m_StartTime;