mirror of https://github.com/Icinga/icinga2.git
Cleaned up component API.
This commit is contained in:
parent
0a435bf891
commit
1661a1b363
|
@ -172,6 +172,11 @@ Component::RefType Application::LoadComponent(string name)
|
||||||
Component::RefType component;
|
Component::RefType component;
|
||||||
Component *(*pCreateComponent)();
|
Component *(*pCreateComponent)();
|
||||||
|
|
||||||
|
component = GetComponent(name);
|
||||||
|
|
||||||
|
if (component.get() != NULL)
|
||||||
|
return component;
|
||||||
|
|
||||||
ConfigObject::RefType componentConfig = m_ConfigHive->GetObject("component", name);
|
ConfigObject::RefType componentConfig = m_ConfigHive->GetObject("component", name);
|
||||||
|
|
||||||
if (componentConfig.get() == NULL) {
|
if (componentConfig.get() == NULL) {
|
||||||
|
@ -200,13 +205,24 @@ Component::RefType Application::LoadComponent(string name)
|
||||||
|
|
||||||
component = Component::RefType(pCreateComponent());
|
component = Component::RefType(pCreateComponent());
|
||||||
component->SetApplication(static_pointer_cast<Application>(shared_from_this()));
|
component->SetApplication(static_pointer_cast<Application>(shared_from_this()));
|
||||||
|
component->SetConfig(componentConfig);
|
||||||
m_Components[component->GetName()] = component;
|
m_Components[component->GetName()] = component;
|
||||||
|
|
||||||
component->Start(componentConfig);
|
component->Start();
|
||||||
|
|
||||||
return component;
|
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)
|
void Application::UnloadComponent(string name)
|
||||||
{
|
{
|
||||||
map<string, Component::RefType>::iterator ci = m_Components.find(name);
|
map<string, Component::RefType>::iterator ci = m_Components.find(name);
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{9C92DA90-FD53-43A9-A244-90F2E8AF9677}</ProjectGuid>
|
<ProjectGuid>{9C92DA90-FD53-43A9-A244-90F2E8AF9677}</ProjectGuid>
|
||||||
<Keyword>Win32Proj</Keyword>
|
<Keyword>Win32Proj</Keyword>
|
||||||
<RootNamespace>i2base</RootNamespace>
|
<RootNamespace>icinga</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
void Component::SetApplication(Application::WeakRefType application)
|
void Component::SetApplication(const Application::WeakRefType& application)
|
||||||
{
|
{
|
||||||
m_Application = application;
|
m_Application = application;
|
||||||
}
|
}
|
||||||
|
@ -11,3 +11,13 @@ Application::RefType Component::GetApplication(void)
|
||||||
{
|
{
|
||||||
return m_Application.lock();
|
return m_Application.lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Component::SetConfig(ConfigObject::RefType componentConfig)
|
||||||
|
{
|
||||||
|
m_Config = componentConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigObject::RefType Component::GetConfig(void)
|
||||||
|
{
|
||||||
|
return m_Config;
|
||||||
|
}
|
||||||
|
|
|
@ -8,16 +8,20 @@ class Component : public Object
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Application::WeakRefType m_Application;
|
Application::WeakRefType m_Application;
|
||||||
|
ConfigObject::RefType m_Config;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef shared_ptr<Component> RefType;
|
typedef shared_ptr<Component> RefType;
|
||||||
typedef weak_ptr<Component> WeakRefType;
|
typedef weak_ptr<Component> WeakRefType;
|
||||||
|
|
||||||
void SetApplication(Application::WeakRefType application);
|
void SetApplication(const Application::WeakRefType& application);
|
||||||
Application::RefType GetApplication(void);
|
Application::RefType GetApplication(void);
|
||||||
|
|
||||||
|
void SetConfig(ConfigObject::RefType componentConfig);
|
||||||
|
ConfigObject::RefType GetConfig(void);
|
||||||
|
|
||||||
virtual string GetName(void) = 0;
|
virtual string GetName(void) = 0;
|
||||||
virtual void Start(ConfigObject::RefType componentConfig) = 0;
|
virtual void Start(void) = 0;
|
||||||
virtual void Stop(void) = 0;
|
virtual void Stop(void) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue