Cleaned up component API.

This commit is contained in:
Gunnar Beutner 2012-03-31 16:03:42 +02:00
parent 0a435bf891
commit 1661a1b363
4 changed files with 35 additions and 5 deletions

View 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);

View 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">

View 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;
}

View 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;
};