2012-03-31 15:18:09 +02:00
|
|
|
#include "i2-base.h"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2012-04-02 20:50:35 +02:00
|
|
|
void ConfigObject::SetHive(const ConfigHive::WeakPtr& hive)
|
2012-03-31 15:18:09 +02:00
|
|
|
{
|
|
|
|
m_Hive = hive;
|
|
|
|
}
|
|
|
|
|
2012-04-02 20:50:35 +02:00
|
|
|
ConfigHive::WeakPtr ConfigObject::GetHive(void) const
|
2012-03-31 15:18:09 +02:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
Properties[name] = value;
|
|
|
|
|
2012-04-02 20:50:35 +02:00
|
|
|
ConfigHive::Ptr hive = m_Hive.lock();
|
2012-03-31 15:18:09 +02:00
|
|
|
if (hive.get() != NULL) {
|
2012-04-02 20:50:35 +02:00
|
|
|
ConfigHiveEventArgs::Ptr ea = new_object<ConfigHiveEventArgs>();
|
2012-03-31 15:18:09 +02:00
|
|
|
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;
|
2012-04-01 19:32:41 +02:00
|
|
|
|
|
|
|
string oldValue;
|
|
|
|
if (GetProperty(name, &oldValue))
|
|
|
|
ea->OldValue = oldValue;
|
|
|
|
|
2012-03-31 15:18:09 +02:00
|
|
|
hive->OnPropertyChanged(ea);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-01 19:32:41 +02:00
|
|
|
bool ConfigObject::GetProperty(const string& name, string *value) 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 19:32:41 +02:00
|
|
|
return false;
|
|
|
|
*value = vi->second;
|
|
|
|
return true;
|
2012-03-31 15:18:09 +02:00
|
|
|
}
|
|
|
|
|
2012-04-01 19:32:41 +02:00
|
|
|
bool ConfigObject::GetPropertyInteger(const string& name, int *value) const
|
2012-03-31 15:18:09 +02:00
|
|
|
{
|
2012-04-01 19:32:41 +02:00
|
|
|
string stringValue;
|
|
|
|
if (!GetProperty(name, &stringValue))
|
|
|
|
return false;
|
|
|
|
*value = strtol(stringValue.c_str(), NULL, 10);
|
|
|
|
return true;
|
2012-03-31 15:18:09 +02:00
|
|
|
}
|
|
|
|
|
2012-04-01 19:32:41 +02:00
|
|
|
bool ConfigObject::GetPropertyDouble(const string& name, double *value) const
|
2012-03-31 15:18:09 +02:00
|
|
|
{
|
2012-04-01 19:32:41 +02:00
|
|
|
string stringValue;
|
|
|
|
if (!GetProperty(name, &stringValue))
|
|
|
|
return false;
|
|
|
|
*value = strtod(stringValue.c_str(), NULL);
|
|
|
|
return true;
|
2012-03-31 15:18:09 +02:00
|
|
|
}
|