icinga2/base/configobject.cpp

139 lines
2.2 KiB
C++
Raw Normal View History

#include "i2-base.h"
using namespace icinga;
2012-04-24 14:02:15 +02:00
/**
* ConfigObject
*
* Constructor for the ConfigObject class.
*
* @param type The type of the object.
* @param name The name of the object.
*/
ConfigObject::ConfigObject(const string& type, const string& name)
{
m_Type = type;
m_Name = name;
m_Replicated = false;
}
2012-04-24 14:02:15 +02:00
/**
* SetHive
*
* Sets the hive this object belongs to.
*
* @param hive The hive.
*/
void ConfigObject::SetHive(const ConfigHive::WeakPtr& hive)
{
2012-04-20 13:49:04 +02:00
if (m_Hive.lock())
throw InvalidArgumentException();
m_Hive = hive;
2012-04-20 13:49:04 +02:00
OnPropertyChanged += bind_weak(&ConfigObject::PropertyChangedHandler, shared_from_this());
}
2012-04-24 14:02:15 +02:00
/**
* GetHive
*
* Retrieves the hive this object belongs to.
*
* @returns The hive.
*/
ConfigHive::WeakPtr ConfigObject::GetHive(void) const
{
return m_Hive;
}
2012-04-24 14:02:15 +02:00
/**
* SetName
*
* Sets the name of this object.
*
* @param name The name.
*/
void ConfigObject::SetName(const string& name)
{
m_Name = name;
}
2012-04-24 14:02:15 +02:00
/**
* GetName
*
* Retrieves the name of this object.
*
* @returns The name.
*/
string ConfigObject::GetName(void) const
{
return m_Name;
}
2012-04-24 14:02:15 +02:00
/**
* SetType
*
* Sets the type of this object.
*
* @param type The type.
*/
void ConfigObject::SetType(const string& type)
{
m_Type = type;
}
2012-04-24 14:02:15 +02:00
/**
* GetType
*
* Retrieves the type of this object.
*
* @returns The type.
*/
string ConfigObject::GetType(void) const
{
return m_Type;
}
2012-04-24 14:02:15 +02:00
/**
* SetReplicated
*
* Sets whether this object was replicated.
*
* @param replicated Whether this object was replicated.
*/
void ConfigObject::SetReplicated(bool replicated)
{
m_Replicated = replicated;
}
2012-04-24 14:02:15 +02:00
/**
* GetReplicated
*
* Retrieves whether this object was replicated.
*
* @returns Whether this object was replicated.
*/
bool ConfigObject::GetReplicated(void) const
{
return m_Replicated;
}
2012-04-24 14:02:15 +02:00
/**
* PropertyChangedHandler
*
* Handles changed properties by propagating them to the hive
* and collection this object is contained in.
*
* @param dpcea The event arguments.
* @returns 0.
*/
2012-04-22 16:45:31 +02:00
int ConfigObject::PropertyChangedHandler(const PropertyChangedEventArgs& dpcea)
{
ConfigHive::Ptr hive = m_Hive.lock();
if (hive) {
2012-04-20 13:49:04 +02:00
hive->GetCollection(m_Type)->OnPropertyChanged(dpcea);
hive->OnPropertyChanged(dpcea);
}
2012-04-20 13:49:04 +02:00
return 0;
}