]> granicus.if.org Git - icinga2/commitdiff
Made IComponent::GetConfig() usable in IComponent::Start().
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 28 Sep 2012 08:39:28 +0000 (10:39 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 28 Sep 2012 08:40:12 +0000 (10:40 +0200)
Fixes #3200

lib/base/component.cpp
lib/base/component.h
lib/base/dynamicobject.cpp
lib/base/dynamicobject.h

index 70652aab97b79226974bd1f45bb6b28f41b5a3ec..e8c3950bed4e85559ec613d315b9f25c1b508be7 100644 (file)
@@ -94,8 +94,6 @@ Component::Component(const Dictionary::Ptr& properties)
                throw;
        }
 
-       impl->m_Config = this;
-       impl->Start();
        m_Impl = impl;
 }
 
@@ -108,6 +106,16 @@ Component::~Component(void)
                m_Impl->Stop();
 }
 
+/**
+ * Starts the component. Called when the DynamicObject is fully
+ * constructed/registered.
+ */
+void Component::Start(void)
+{
+       m_Impl->m_Config = GetSelf();
+       m_Impl->Start();
+}
+
 /**
  * Adds a directory to the component search path.
  *
@@ -129,7 +137,7 @@ void Component::AddSearchDir(const String& componentDirectory)
  */
 DynamicObject::Ptr IComponent::GetConfig(void) const
 {
-       return m_Config->GetSelf();
+       return m_Config.lock();
 }
 
 /**
index f1c92bf228eb62fe37a2596d258d454f099a59ca..377342ac3e36c98864d5f73e010eca41723bbb28 100644 (file)
@@ -41,7 +41,7 @@ protected:
        DynamicObject::Ptr GetConfig(void) const;
 
 private:
-       DynamicObject *m_Config; /**< The configuration object for this
+       DynamicObject::WeakPtr m_Config; /**< The configuration object for this
                                      component. */
 
        friend class Component;
@@ -62,6 +62,8 @@ public:
        Component(const Dictionary::Ptr& properties);
        ~Component(void);
 
+       virtual void Start(void);
+
        static void AddSearchDir(const String& componentDirectory);
 
 private:
index 2911a8e3cebe605e8149e6e1f5df5a071c7d7bfb..dde4510b2ae0a388cefe54ff8326500fa509f38f 100644 (file)
@@ -272,6 +272,13 @@ void DynamicObject::Register(void)
        ti.first->second.insert(make_pair(GetName(), GetSelf()));
 
        OnRegistered(GetSelf());
+
+       Start();
+}
+
+void DynamicObject::Start(void)
+{
+       /* Nothing to do here. */
 }
 
 void DynamicObject::Unregister(void)
index 3642105294ee0905253141d601e9e0eb6ab3d341..af22062f93ca684767a2dbf5cc5dd264d1b2f891 100644 (file)
@@ -119,6 +119,8 @@ public:
        void Register(void);
        void Unregister(void);
 
+       virtual void Start(void);
+
        static DynamicObject::Ptr GetObject(const String& type, const String& name);
        static pair<TypeMap::iterator, TypeMap::iterator> GetTypes(void);
        static pair<NameMap::iterator, NameMap::iterator> GetObjects(const String& type);