]> granicus.if.org Git - icinga2/commitdiff
Cleaned up component API.
authorGunnar Beutner <gunnar.beutner@netways.de>
Sat, 31 Mar 2012 14:03:42 +0000 (16:03 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sat, 31 Mar 2012 14:03:42 +0000 (16:03 +0200)
base/application.cpp
base/base.vcxproj
base/component.cpp
base/component.h

index fa96db0012b903b725887d103f07948b41b55811..838b74fbcd4d907c23dc9adc1ed5f947d421a88e 100644 (file)
@@ -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<Application>(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<string, Component::RefType>::iterator ci = m_Components.find(name);
+
+       if (ci == m_Components.end())
+               return Component::RefType();
+
+       return ci->second;
+}
+
 void Application::UnloadComponent(string name)
 {
        map<string, Component::RefType>::iterator ci = m_Components.find(name);
index e78a762b6a728da86658bbae3554262fa9a7b026..943a18abb2e1cc8ad88a4022609e199dfa6e76af 100644 (file)
@@ -54,7 +54,7 @@
   <PropertyGroup Label="Globals">
     <ProjectGuid>{9C92DA90-FD53-43A9-A244-90F2E8AF9677}</ProjectGuid>
     <Keyword>Win32Proj</Keyword>
-    <RootNamespace>i2base</RootNamespace>
+    <RootNamespace>icinga</RootNamespace>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
index d18d9a26a5570495987d8ecde324c3fb4dbb0aca..8388ace5b9e53930bd6422c92474002eaf0ac282 100644 (file)
@@ -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;
+}
index 9b979e9974d00b50ddb31b941c70493e16c4d162..d7d3c93b271819bbdf98ce4821d338352046d3bb 100644 (file)
@@ -8,16 +8,20 @@ class Component : public Object
 {
 private:
        Application::WeakRefType m_Application;
+       ConfigObject::RefType m_Config;
 
 public:
        typedef shared_ptr<Component> RefType;
        typedef weak_ptr<Component> 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;
 };