2012-03-31 15:18:09 +02:00
|
|
|
#include "i2-base.h"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
void ConfigObject::SetHive(const ConfigHive::WeakRefType& hive)
|
|
|
|
{
|
|
|
|
m_Hive = hive;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigHive::WeakRefType ConfigObject::GetHive(void) const
|
|
|
|
{
|
|
|
|
return m_Hive;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigObject::SetName(const string& name)
|
|
|
|
{
|
|
|
|
m_Name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
string ConfigObject::GetName(void) const
|
|
|
|
{
|
|
|
|
return m_Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigObject::SetType(const string& type)
|
|
|
|
{
|
|
|
|
m_Type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
string ConfigObject::GetType(void) const
|
|
|
|
{
|
|
|
|
return m_Type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigObject::SetProperty(const string& name, const string& value)
|
|
|
|
{
|
|
|
|
string oldValue = GetProperty(name);
|
|
|
|
|
|
|
|
Properties[name] = value;
|
|
|
|
|
|
|
|
ConfigHive::RefType hive = m_Hive.lock();
|
|
|
|
if (hive.get() != NULL) {
|
|
|
|
ConfigHiveEventArgs::RefType ea = new_object<ConfigHiveEventArgs>();
|
|
|
|
ea->Source = hive;
|
2012-04-01 09:48:52 +02:00
|
|
|
ea->Object = static_pointer_cast<ConfigObject>(shared_from_this());
|
2012-03-31 15:18:09 +02:00
|
|
|
ea->Property = name;
|
|
|
|
ea->OldValue = oldValue;
|
|
|
|
hive->OnPropertyChanged(ea);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-01 09:48:52 +02:00
|
|
|
string ConfigObject::GetProperty(const string& name, const string& defaultValue) const
|
2012-03-31 15:18:09 +02:00
|
|
|
{
|
|
|
|
map<string, string>::const_iterator vi = Properties.find(name);
|
|
|
|
if (vi == Properties.end())
|
2012-04-01 09:48:52 +02:00
|
|
|
return defaultValue;
|
2012-03-31 15:18:09 +02:00
|
|
|
return vi->second;
|
|
|
|
}
|
|
|
|
|
2012-04-01 09:48:52 +02:00
|
|
|
int ConfigObject::GetPropertyInteger(const string& name, int defaultValue) const
|
2012-03-31 15:18:09 +02:00
|
|
|
{
|
|
|
|
string value = GetProperty(name);
|
|
|
|
if (value == string())
|
2012-04-01 09:48:52 +02:00
|
|
|
return defaultValue;
|
2012-03-31 15:18:09 +02:00
|
|
|
return strtol(value.c_str(), NULL, 10);
|
|
|
|
}
|
|
|
|
|
2012-04-01 09:48:52 +02:00
|
|
|
double ConfigObject::GetPropertyDouble(const string& name, double defaultValue) const
|
2012-03-31 15:18:09 +02:00
|
|
|
{
|
|
|
|
string value = GetProperty(name);
|
|
|
|
if (value == string())
|
2012-04-01 09:48:52 +02:00
|
|
|
return defaultValue;
|
2012-03-31 15:18:09 +02:00
|
|
|
return strtod(value.c_str(), NULL);
|
|
|
|
}
|