From e55aa712b5e84300395c82a05e29139a6629caba Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 28 Sep 2012 10:39:28 +0200 Subject: [PATCH] Made IComponent::GetConfig() usable in IComponent::Start(). Fixes #3200 --- lib/base/component.cpp | 14 +++++++++++--- lib/base/component.h | 4 +++- lib/base/dynamicobject.cpp | 7 +++++++ lib/base/dynamicobject.h | 2 ++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/base/component.cpp b/lib/base/component.cpp index 70652aab9..e8c3950be 100644 --- a/lib/base/component.cpp +++ b/lib/base/component.cpp @@ -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(); } /** diff --git a/lib/base/component.h b/lib/base/component.h index f1c92bf22..377342ac3 100644 --- a/lib/base/component.h +++ b/lib/base/component.h @@ -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: diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index 2911a8e3c..dde4510b2 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -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) diff --git a/lib/base/dynamicobject.h b/lib/base/dynamicobject.h index 364210529..af22062f9 100644 --- a/lib/base/dynamicobject.h +++ b/lib/base/dynamicobject.h @@ -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 GetTypes(void); static pair GetObjects(const String& type);