From: Gunnar Beutner Date: Sat, 31 Mar 2012 14:03:42 +0000 (+0200) Subject: Cleaned up component API. X-Git-Tag: v0.0.1~683 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1661a1b363a42d0a472728e7801733ca10d33d0a;p=icinga2 Cleaned up component API. --- diff --git a/base/application.cpp b/base/application.cpp index fa96db001..838b74fbc 100644 --- a/base/application.cpp +++ b/base/application.cpp @@ -172,6 +172,11 @@ Component::RefType Application::LoadComponent(string name) Component::RefType component; Component *(*pCreateComponent)(); + component = GetComponent(name); + + if (component.get() != NULL) + return component; + ConfigObject::RefType componentConfig = m_ConfigHive->GetObject("component", name); if (componentConfig.get() == NULL) { @@ -200,13 +205,24 @@ Component::RefType Application::LoadComponent(string name) component = Component::RefType(pCreateComponent()); component->SetApplication(static_pointer_cast(shared_from_this())); + component->SetConfig(componentConfig); m_Components[component->GetName()] = component; - component->Start(componentConfig); + component->Start(); return component; } +Component::RefType Application::GetComponent(string name) +{ + map::iterator ci = m_Components.find(name); + + if (ci == m_Components.end()) + return Component::RefType(); + + return ci->second; +} + void Application::UnloadComponent(string name) { map::iterator ci = m_Components.find(name); diff --git a/base/base.vcxproj b/base/base.vcxproj index e78a762b6..943a18abb 100644 --- a/base/base.vcxproj +++ b/base/base.vcxproj @@ -54,7 +54,7 @@ {9C92DA90-FD53-43A9-A244-90F2E8AF9677} Win32Proj - i2base + icinga diff --git a/base/component.cpp b/base/component.cpp index d18d9a26a..8388ace5b 100644 --- a/base/component.cpp +++ b/base/component.cpp @@ -2,7 +2,7 @@ using namespace icinga; -void Component::SetApplication(Application::WeakRefType application) +void Component::SetApplication(const Application::WeakRefType& application) { m_Application = application; } @@ -11,3 +11,13 @@ Application::RefType Component::GetApplication(void) { return m_Application.lock(); } + +void Component::SetConfig(ConfigObject::RefType componentConfig) +{ + m_Config = componentConfig; +} + +ConfigObject::RefType Component::GetConfig(void) +{ + return m_Config; +} diff --git a/base/component.h b/base/component.h index 9b979e997..d7d3c93b2 100644 --- a/base/component.h +++ b/base/component.h @@ -8,16 +8,20 @@ class Component : public Object { private: Application::WeakRefType m_Application; + ConfigObject::RefType m_Config; public: typedef shared_ptr RefType; typedef weak_ptr WeakRefType; - void SetApplication(Application::WeakRefType application); + void SetApplication(const Application::WeakRefType& application); Application::RefType GetApplication(void); + void SetConfig(ConfigObject::RefType componentConfig); + ConfigObject::RefType GetConfig(void); + virtual string GetName(void) = 0; - virtual void Start(ConfigObject::RefType componentConfig) = 0; + virtual void Start(void) = 0; virtual void Stop(void) = 0; };