Renamed ConfigObject to DynamicObject.

This commit is contained in:
Gunnar Beutner 2012-07-30 10:17:29 +02:00
parent 24a5a10e00
commit 8c185a38b0
30 changed files with 167 additions and 167 deletions

View File

@ -10,10 +10,10 @@ libbase_la_SOURCES = \
asynctask.h \ asynctask.h \
component.cpp \ component.cpp \
component.h \ component.h \
configobject.cpp \
configobject.h \
dictionary.cpp \ dictionary.cpp \
dictionary.h \ dictionary.h \
dynamicobject.cpp \
dynamicobject.h \
event.cpp \ event.cpp \
event.h \ event.h \
exception.cpp \ exception.cpp \

View File

@ -13,7 +13,7 @@
<ItemGroup> <ItemGroup>
<ClCompile Include="application.cpp" /> <ClCompile Include="application.cpp" />
<ClCompile Include="component.cpp" /> <ClCompile Include="component.cpp" />
<ClCompile Include="configobject.cpp" /> <ClCompile Include="dynamicobject.cpp" />
<ClCompile Include="dictionary.cpp" /> <ClCompile Include="dictionary.cpp" />
<ClCompile Include="event.cpp" /> <ClCompile Include="event.cpp" />
<ClCompile Include="exception.cpp" /> <ClCompile Include="exception.cpp" />
@ -47,7 +47,7 @@
<ClInclude Include="application.h" /> <ClInclude Include="application.h" />
<ClInclude Include="asynctask.h" /> <ClInclude Include="asynctask.h" />
<ClInclude Include="component.h" /> <ClInclude Include="component.h" />
<ClInclude Include="configobject.h" /> <ClInclude Include="dynamicobject.h" />
<ClInclude Include="dictionary.h" /> <ClInclude Include="dictionary.h" />
<ClInclude Include="event.h" /> <ClInclude Include="event.h" />
<ClInclude Include="fifo.h" /> <ClInclude Include="fifo.h" />

View File

@ -7,9 +7,6 @@
<ClCompile Include="component.cpp"> <ClCompile Include="component.cpp">
<Filter>Quelldateien</Filter> <Filter>Quelldateien</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="configobject.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="dictionary.cpp"> <ClCompile Include="dictionary.cpp">
<Filter>Quelldateien</Filter> <Filter>Quelldateien</Filter>
</ClCompile> </ClCompile>
@ -85,6 +82,9 @@
<ClCompile Include="netstring.cpp"> <ClCompile Include="netstring.cpp">
<Filter>Quelldateien</Filter> <Filter>Quelldateien</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="dynamicobject.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="application.h"> <ClInclude Include="application.h">
@ -96,9 +96,6 @@
<ClInclude Include="component.h"> <ClInclude Include="component.h">
<Filter>Headerdateien</Filter> <Filter>Headerdateien</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="configobject.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="dictionary.h"> <ClInclude Include="dictionary.h">
<Filter>Headerdateien</Filter> <Filter>Headerdateien</Filter>
</ClInclude> </ClInclude>
@ -177,6 +174,9 @@
<ClInclude Include="netstring.h"> <ClInclude Include="netstring.h">
<Filter>Headerdateien</Filter> <Filter>Headerdateien</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="dynamicobject.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="Quelldateien"> <Filter Include="Quelldateien">

View File

@ -27,7 +27,7 @@ REGISTER_CLASS(Component);
* Constructor for the component class. * Constructor for the component class.
*/ */
Component::Component(const Dictionary::Ptr& properties) Component::Component(const Dictionary::Ptr& properties)
: ConfigObject(properties) : DynamicObject(properties)
{ {
assert(Application::IsMainThread()); assert(Application::IsMainThread());
@ -136,7 +136,7 @@ void Component::AddSearchDir(const string& componentDirectory)
* *
* @returns The configuration. * @returns The configuration.
*/ */
ConfigObject::Ptr IComponent::GetConfig(void) const DynamicObject::Ptr IComponent::GetConfig(void) const
{ {
return m_Config->GetSelf(); return m_Config->GetSelf();
} }

View File

@ -33,10 +33,10 @@ public:
virtual void Stop(void); virtual void Stop(void);
protected: protected:
ConfigObject::Ptr GetConfig(void) const; DynamicObject::Ptr GetConfig(void) const;
private: private:
ConfigObject *m_Config; DynamicObject *m_Config;
friend class Component; friend class Component;
}; };
@ -47,7 +47,7 @@ private:
* *
* @ingroup base * @ingroup base
*/ */
class I2_BASE_API Component : public ConfigObject class I2_BASE_API Component : public DynamicObject
{ {
public: public:
typedef shared_ptr<Component> Ptr; typedef shared_ptr<Component> Ptr;

View File

@ -21,11 +21,11 @@
using namespace icinga; using namespace icinga;
map<pair<string, string>, Dictionary::Ptr> ConfigObject::m_PersistentTags; map<pair<string, string>, Dictionary::Ptr> DynamicObject::m_PersistentTags;
boost::signal<void (const ConfigObject::Ptr&)> ConfigObject::OnCommitted; boost::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnCommitted;
boost::signal<void (const ConfigObject::Ptr&)> ConfigObject::OnRemoved; boost::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnRemoved;
ConfigObject::ConfigObject(const Dictionary::Ptr& properties) DynamicObject::DynamicObject(const Dictionary::Ptr& properties)
: m_Properties(properties), m_Tags(boost::make_shared<Dictionary>()) : m_Properties(properties), m_Tags(boost::make_shared<Dictionary>())
{ {
/* restore the object's tags */ /* restore the object's tags */
@ -37,88 +37,88 @@ ConfigObject::ConfigObject(const Dictionary::Ptr& properties)
} }
} }
void ConfigObject::SetProperties(const Dictionary::Ptr& properties) void DynamicObject::SetProperties(const Dictionary::Ptr& properties)
{ {
m_Properties = properties; m_Properties = properties;
} }
Dictionary::Ptr ConfigObject::GetProperties(void) const Dictionary::Ptr DynamicObject::GetProperties(void) const
{ {
return m_Properties; return m_Properties;
} }
void ConfigObject::SetTags(const Dictionary::Ptr& tags) void DynamicObject::SetTags(const Dictionary::Ptr& tags)
{ {
m_Tags = tags; m_Tags = tags;
} }
Dictionary::Ptr ConfigObject::GetTags(void) const Dictionary::Ptr DynamicObject::GetTags(void) const
{ {
return m_Tags; return m_Tags;
} }
string ConfigObject::GetType(void) const string DynamicObject::GetType(void) const
{ {
string type; string type;
GetProperties()->Get("__type", &type); GetProperties()->Get("__type", &type);
return type; return type;
} }
string ConfigObject::GetName(void) const string DynamicObject::GetName(void) const
{ {
string name; string name;
GetProperties()->Get("__name", &name); GetProperties()->Get("__name", &name);
return name; return name;
} }
bool ConfigObject::IsLocal(void) const bool DynamicObject::IsLocal(void) const
{ {
bool value = false; bool value = false;
GetProperties()->Get("__local", &value); GetProperties()->Get("__local", &value);
return value; return value;
} }
bool ConfigObject::IsAbstract(void) const bool DynamicObject::IsAbstract(void) const
{ {
bool value = false; bool value = false;
GetProperties()->Get("__abstract", &value); GetProperties()->Get("__abstract", &value);
return value; return value;
} }
void ConfigObject::SetSource(const string& value) void DynamicObject::SetSource(const string& value)
{ {
GetProperties()->Set("__source", value); GetProperties()->Set("__source", value);
} }
string ConfigObject::GetSource(void) const string DynamicObject::GetSource(void) const
{ {
string value; string value;
GetProperties()->Get("__source", &value); GetProperties()->Get("__source", &value);
return value; return value;
} }
void ConfigObject::SetCommitTimestamp(double ts) void DynamicObject::SetCommitTimestamp(double ts)
{ {
GetProperties()->Set("__tx", ts); GetProperties()->Set("__tx", ts);
} }
double ConfigObject::GetCommitTimestamp(void) const double DynamicObject::GetCommitTimestamp(void) const
{ {
double value = 0; double value = 0;
GetProperties()->Get("__tx", &value); GetProperties()->Get("__tx", &value);
return value; return value;
} }
void ConfigObject::Commit(void) void DynamicObject::Commit(void)
{ {
assert(Application::IsMainThread()); assert(Application::IsMainThread());
ConfigObject::Ptr dobj = GetObject(GetType(), GetName()); DynamicObject::Ptr dobj = GetObject(GetType(), GetName());
ConfigObject::Ptr self = GetSelf(); DynamicObject::Ptr self = GetSelf();
assert(!dobj || dobj == self); assert(!dobj || dobj == self);
pair<ConfigObject::TypeMap::iterator, bool> ti; pair<DynamicObject::TypeMap::iterator, bool> ti;
ti = GetAllObjects().insert(make_pair(GetType(), ConfigObject::NameMap())); ti = GetAllObjects().insert(make_pair(GetType(), DynamicObject::NameMap()));
ti.first->second.insert(make_pair(GetName(), GetSelf())); ti.first->second.insert(make_pair(GetName(), GetSelf()));
SetCommitTimestamp(Utility::GetTime()); SetCommitTimestamp(Utility::GetTime());
@ -126,17 +126,17 @@ void ConfigObject::Commit(void)
OnCommitted(GetSelf()); OnCommitted(GetSelf());
} }
void ConfigObject::Unregister(void) void DynamicObject::Unregister(void)
{ {
assert(Application::IsMainThread()); assert(Application::IsMainThread());
ConfigObject::TypeMap::iterator tt; DynamicObject::TypeMap::iterator tt;
tt = GetAllObjects().find(GetType()); tt = GetAllObjects().find(GetType());
if (tt == GetAllObjects().end()) if (tt == GetAllObjects().end())
return; return;
ConfigObject::NameMap::iterator nt = tt->second.find(GetName()); DynamicObject::NameMap::iterator nt = tt->second.find(GetName());
if (nt == tt->second.end()) if (nt == tt->second.end())
return; return;
@ -146,41 +146,41 @@ void ConfigObject::Unregister(void)
OnRemoved(GetSelf()); OnRemoved(GetSelf());
} }
ConfigObject::Ptr ConfigObject::GetObject(const string& type, const string& name) DynamicObject::Ptr DynamicObject::GetObject(const string& type, const string& name)
{ {
ConfigObject::TypeMap::iterator tt; DynamicObject::TypeMap::iterator tt;
tt = GetAllObjects().find(type); tt = GetAllObjects().find(type);
if (tt == GetAllObjects().end()) if (tt == GetAllObjects().end())
return ConfigObject::Ptr(); return DynamicObject::Ptr();
ConfigObject::NameMap::iterator nt = tt->second.find(name); DynamicObject::NameMap::iterator nt = tt->second.find(name);
if (nt == tt->second.end()) if (nt == tt->second.end())
return ConfigObject::Ptr(); return DynamicObject::Ptr();
return nt->second; return nt->second;
} }
pair<ConfigObject::TypeMap::iterator, ConfigObject::TypeMap::iterator> ConfigObject::GetTypes(void) pair<DynamicObject::TypeMap::iterator, DynamicObject::TypeMap::iterator> DynamicObject::GetTypes(void)
{ {
return make_pair(GetAllObjects().begin(), GetAllObjects().end()); return make_pair(GetAllObjects().begin(), GetAllObjects().end());
} }
pair<ConfigObject::NameMap::iterator, ConfigObject::NameMap::iterator> ConfigObject::GetObjects(const string& type) pair<DynamicObject::NameMap::iterator, DynamicObject::NameMap::iterator> DynamicObject::GetObjects(const string& type)
{ {
pair<ConfigObject::TypeMap::iterator, bool> ti; pair<DynamicObject::TypeMap::iterator, bool> ti;
ti = GetAllObjects().insert(make_pair(type, ConfigObject::NameMap())); ti = GetAllObjects().insert(make_pair(type, DynamicObject::NameMap()));
return make_pair(ti.first->second.begin(), ti.first->second.end()); return make_pair(ti.first->second.begin(), ti.first->second.end());
} }
void ConfigObject::RemoveTag(const string& key) void DynamicObject::RemoveTag(const string& key)
{ {
GetTags()->Remove(key); GetTags()->Remove(key);
} }
ScriptTask::Ptr ConfigObject::InvokeMethod(const string& method, ScriptTask::Ptr DynamicObject::InvokeMethod(const string& method,
const vector<Variant>& arguments, ScriptTask::CompletionCallback callback) const vector<Variant>& arguments, ScriptTask::CompletionCallback callback)
{ {
Dictionary::Ptr methods; Dictionary::Ptr methods;
@ -199,7 +199,7 @@ ScriptTask::Ptr ConfigObject::InvokeMethod(const string& method,
return task; return task;
} }
void ConfigObject::DumpObjects(const string& filename) void DynamicObject::DumpObjects(const string& filename)
{ {
Logger::Write(LogInformation, "base", "Dumping program state to file '" + filename + "'"); Logger::Write(LogInformation, "base", "Dumping program state to file '" + filename + "'");
@ -211,11 +211,11 @@ void ConfigObject::DumpObjects(const string& filename)
FIFO::Ptr fifo = boost::make_shared<FIFO>(); FIFO::Ptr fifo = boost::make_shared<FIFO>();
ConfigObject::TypeMap::iterator tt; DynamicObject::TypeMap::iterator tt;
for (tt = GetAllObjects().begin(); tt != GetAllObjects().end(); tt++) { for (tt = GetAllObjects().begin(); tt != GetAllObjects().end(); tt++) {
ConfigObject::NameMap::iterator nt; DynamicObject::NameMap::iterator nt;
for (nt = tt->second.begin(); nt != tt->second.end(); nt++) { for (nt = tt->second.begin(); nt != tt->second.end(); nt++) {
ConfigObject::Ptr object = nt->second; DynamicObject::Ptr object = nt->second;
Dictionary::Ptr persistentObject = boost::make_shared<Dictionary>(); Dictionary::Ptr persistentObject = boost::make_shared<Dictionary>();
@ -249,10 +249,8 @@ void ConfigObject::DumpObjects(const string& filename)
} }
} }
void ConfigObject::RestoreObjects(const string& filename) void DynamicObject::RestoreObjects(const string& filename)
{ {
assert(GetAllObjects().empty());
Logger::Write(LogInformation, "base", "Restoring program state from file '" + filename + "'"); Logger::Write(LogInformation, "base", "Restoring program state from file '" + filename + "'");
std::ifstream fp; std::ifstream fp;
@ -290,7 +288,7 @@ void ConfigObject::RestoreObjects(const string& filename)
Dictionary::Ptr properties; Dictionary::Ptr properties;
if (persistentObject->Get("properties", &properties)) { if (persistentObject->Get("properties", &properties)) {
ConfigObject::Ptr object = Create(type, properties); DynamicObject::Ptr object = Create(type, properties);
object->SetTags(tags); object->SetTags(tags);
object->Commit(); object->Commit();
} else { } else {
@ -301,33 +299,34 @@ void ConfigObject::RestoreObjects(const string& filename)
} }
} }
ConfigObject::TypeMap& ConfigObject::GetAllObjects(void) DynamicObject::TypeMap& DynamicObject::GetAllObjects(void)
{ {
static TypeMap objects; static TypeMap objects;
return objects; return objects;
} }
ConfigObject::ClassMap& ConfigObject::GetClasses(void) DynamicObject::ClassMap& DynamicObject::GetClasses(void)
{ {
static ClassMap classes; static ClassMap classes;
return classes; return classes;
} }
void ConfigObject::RegisterClass(const string& type, ConfigObject::Factory factory) void DynamicObject::RegisterClass(const string& type, DynamicObject::Factory factory)
{ {
GetClasses()[type] = factory; if (GetObjects(type).first != GetObjects(type).second)
throw_exception(runtime_error("Cannot register class for type '" +
type + "': Objects of this type already exist."));
/* TODO: upgrade existing objects */ GetClasses()[type] = factory;
} }
ConfigObject::Ptr ConfigObject::Create(const string& type, const Dictionary::Ptr& properties) DynamicObject::Ptr DynamicObject::Create(const string& type, const Dictionary::Ptr& properties)
{ {
ConfigObject::ClassMap::iterator it; DynamicObject::ClassMap::iterator it;
it = GetClasses().find(type); it = GetClasses().find(type);
if (it != GetClasses().end()) if (it != GetClasses().end())
return it->second(properties); return it->second(properties);
else else
return boost::make_shared<ConfigObject>(properties); return boost::make_shared<DynamicObject>(properties);
} }

View File

@ -17,30 +17,30 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/ ******************************************************************************/
#ifndef CONFIGOBJECT_H #ifndef DYNAMICOBJECT_H
#define CONFIGOBJECT_H #define DYNAMICOBJECT_H
namespace icinga namespace icinga
{ {
/** /**
* A configuration object. * A dynamic object that can be instantiated from the configuration file.
* *
* @ingroup base * @ingroup base
*/ */
class I2_BASE_API ConfigObject : public Object class I2_BASE_API DynamicObject : public Object
{ {
public: public:
typedef shared_ptr<ConfigObject> Ptr; typedef shared_ptr<DynamicObject> Ptr;
typedef weak_ptr<ConfigObject> WeakPtr; typedef weak_ptr<DynamicObject> WeakPtr;
typedef function<ConfigObject::Ptr (const Dictionary::Ptr&)> Factory; typedef function<DynamicObject::Ptr (const Dictionary::Ptr&)> Factory;
typedef map<string, Factory> ClassMap; typedef map<string, Factory> ClassMap;
typedef map<string, ConfigObject::Ptr> NameMap; typedef map<string, DynamicObject::Ptr> NameMap;
typedef map<string, NameMap> TypeMap; typedef map<string, NameMap> TypeMap;
ConfigObject(const Dictionary::Ptr& properties); DynamicObject(const Dictionary::Ptr& properties);
void SetProperties(const Dictionary::Ptr& config); void SetProperties(const Dictionary::Ptr& config);
Dictionary::Ptr GetProperties(void) const; Dictionary::Ptr GetProperties(void) const;
@ -68,7 +68,7 @@ public:
void RemoveTag(const string& key); void RemoveTag(const string& key);
ScriptTask::Ptr InvokeMethod(const string& hook, ScriptTask::Ptr InvokeMethod(const string& method,
const vector<Variant>& arguments, ScriptTask::CompletionCallback callback); const vector<Variant>& arguments, ScriptTask::CompletionCallback callback);
string GetType(void) const; string GetType(void) const;
@ -85,7 +85,7 @@ public:
void Commit(void); void Commit(void);
void Unregister(void); void Unregister(void);
static ConfigObject::Ptr GetObject(const string& type, const string& name); static DynamicObject::Ptr GetObject(const string& type, const string& name);
static pair<TypeMap::iterator, TypeMap::iterator> GetTypes(void); static pair<TypeMap::iterator, TypeMap::iterator> GetTypes(void);
static pair<NameMap::iterator, NameMap::iterator> GetObjects(const string& type); static pair<NameMap::iterator, NameMap::iterator> GetObjects(const string& type);
@ -93,10 +93,10 @@ public:
static void RestoreObjects(const string& filename); static void RestoreObjects(const string& filename);
static void RegisterClass(const string& type, Factory factory); static void RegisterClass(const string& type, Factory factory);
static ConfigObject::Ptr Create(const string& type, const Dictionary::Ptr& properties); static DynamicObject::Ptr Create(const string& type, const Dictionary::Ptr& properties);
static boost::signal<void (const ConfigObject::Ptr&)> OnCommitted; static boost::signal<void (const DynamicObject::Ptr&)> OnCommitted;
static boost::signal<void (const ConfigObject::Ptr&)> OnRemoved; static boost::signal<void (const DynamicObject::Ptr&)> OnRemoved;
private: private:
static ClassMap& GetClasses(void); static ClassMap& GetClasses(void);
@ -113,9 +113,9 @@ private:
class RegisterClassHelper class RegisterClassHelper
{ {
public: public:
RegisterClassHelper(const string& name, ConfigObject::Factory factory) RegisterClassHelper(const string& name, DynamicObject::Factory factory)
{ {
ConfigObject::RegisterClass(name, factory); DynamicObject::RegisterClass(name, factory);
} }
}; };
@ -124,4 +124,4 @@ public:
} }
#endif /* CONFIGOBJECT_H */ #endif /* DYNAMICOBJECT_H */

View File

@ -184,7 +184,7 @@ namespace tuples = boost::tuples;
#include "process.h" #include "process.h"
#include "scriptfunction.h" #include "scriptfunction.h"
#include "scripttask.h" #include "scripttask.h"
#include "configobject.h" #include "dynamicobject.h"
#include "logger.h" #include "logger.h"
#include "application.h" #include "application.h"
#include "component.h" #include "component.h"

View File

@ -30,7 +30,7 @@ REGISTER_CLASS(Logger);
* to this logger. * to this logger.
*/ */
Logger::Logger(const Dictionary::Ptr& properties) Logger::Logger(const Dictionary::Ptr& properties)
: ConfigObject(properties) : DynamicObject(properties)
{ {
if (!IsLocal()) if (!IsLocal())
throw_exception(runtime_error("Logger objects must be local.")); throw_exception(runtime_error("Logger objects must be local."));
@ -107,8 +107,8 @@ LogSeverity Logger::GetMinSeverity(void) const
*/ */
void Logger::ForwardLogEntry(const LogEntry& entry) void Logger::ForwardLogEntry(const LogEntry& entry)
{ {
ConfigObject::Ptr object; DynamicObject::Ptr object;
BOOST_FOREACH(tie(tuples::ignore, object), ConfigObject::GetObjects("Logger")) { BOOST_FOREACH(tie(tuples::ignore, object), DynamicObject::GetObjects("Logger")) {
Logger::Ptr logger = dynamic_pointer_cast<Logger>(object); Logger::Ptr logger = dynamic_pointer_cast<Logger>(object);
if (entry.Severity >= logger->GetMinSeverity()) if (entry.Severity >= logger->GetMinSeverity())

View File

@ -60,15 +60,15 @@ public:
virtual void ProcessLogEntry(const LogEntry& entry) = 0; virtual void ProcessLogEntry(const LogEntry& entry) = 0;
protected: protected:
ConfigObject::Ptr GetConfig(void) const; DynamicObject::Ptr GetConfig(void) const;
private: private:
ConfigObject *m_Config; DynamicObject *m_Config;
friend class Logger; friend class Logger;
}; };
class I2_BASE_API Logger : public ConfigObject class I2_BASE_API Logger : public DynamicObject
{ {
public: public:
typedef shared_ptr<Logger> Ptr; typedef shared_ptr<Logger> Ptr;

View File

@ -35,12 +35,12 @@ string Host::GetAlias(void) const
bool Host::Exists(const string& name) bool Host::Exists(const string& name)
{ {
return (ConfigObject::GetObject("Host", name)); return (DynamicObject::GetObject("Host", name));
} }
Host::Ptr Host::GetByName(const string& name) Host::Ptr Host::GetByName(const string& name)
{ {
ConfigObject::Ptr configObject = ConfigObject::GetObject("Host", name); DynamicObject::Ptr configObject = DynamicObject::GetObject("Host", name);
if (!configObject) if (!configObject)
throw_exception(invalid_argument("Host '" + name + "' does not exist.")); throw_exception(invalid_argument("Host '" + name + "' does not exist."));

View File

@ -23,14 +23,14 @@
namespace icinga namespace icinga
{ {
class I2_CIB_API Host : public ConfigObject class I2_CIB_API Host : public DynamicObject
{ {
public: public:
typedef shared_ptr<Host> Ptr; typedef shared_ptr<Host> Ptr;
typedef weak_ptr<Host> WeakPtr; typedef weak_ptr<Host> WeakPtr;
Host(const Dictionary::Ptr& properties) Host(const Dictionary::Ptr& properties)
: ConfigObject(properties) : DynamicObject(properties)
{ } { }
static bool Exists(const string& name); static bool Exists(const string& name);

View File

@ -49,12 +49,12 @@ string HostGroup::GetActionUrl(void) const
bool HostGroup::Exists(const string& name) bool HostGroup::Exists(const string& name)
{ {
return (ConfigObject::GetObject("HostGroup", name)); return (DynamicObject::GetObject("HostGroup", name));
} }
HostGroup::Ptr HostGroup::GetByName(const string& name) HostGroup::Ptr HostGroup::GetByName(const string& name)
{ {
ConfigObject::Ptr configObject = ConfigObject::GetObject("HostGroup", name); DynamicObject::Ptr configObject = DynamicObject::GetObject("HostGroup", name);
if (!configObject) if (!configObject)
throw_exception(invalid_argument("HostGroup '" + name + "' does not exist.")); throw_exception(invalid_argument("HostGroup '" + name + "' does not exist."));

View File

@ -23,14 +23,14 @@
namespace icinga namespace icinga
{ {
class I2_CIB_API HostGroup : public ConfigObject class I2_CIB_API HostGroup : public DynamicObject
{ {
public: public:
typedef shared_ptr<HostGroup> Ptr; typedef shared_ptr<HostGroup> Ptr;
typedef weak_ptr<HostGroup> WeakPtr; typedef weak_ptr<HostGroup> WeakPtr;
HostGroup(const Dictionary::Ptr& properties) HostGroup(const Dictionary::Ptr& properties)
: ConfigObject(properties) : DynamicObject(properties)
{ } { }
static bool Exists(const string& name); static bool Exists(const string& name);

View File

@ -31,7 +31,7 @@ void NagiosCheckTask::ScriptFunc(const ScriptTask::Ptr& task, const vector<Varia
throw_exception(invalid_argument("Missing argument: Service must be specified.")); throw_exception(invalid_argument("Missing argument: Service must be specified."));
Variant vservice = arguments[0]; Variant vservice = arguments[0];
if (!vservice.IsObjectType<ConfigObject>()) if (!vservice.IsObjectType<DynamicObject>())
throw_exception(invalid_argument("Argument must be a config object.")); throw_exception(invalid_argument("Argument must be a config object."));
Service::Ptr service = static_cast<Service::Ptr>(vservice); Service::Ptr service = static_cast<Service::Ptr>(vservice);

View File

@ -37,12 +37,12 @@ string Service::GetAlias(void) const
bool Service::Exists(const string& name) bool Service::Exists(const string& name)
{ {
return (ConfigObject::GetObject("Service", name)); return (DynamicObject::GetObject("Service", name));
} }
Service::Ptr Service::GetByName(const string& name) Service::Ptr Service::GetByName(const string& name)
{ {
ConfigObject::Ptr configObject = ConfigObject::GetObject("Service", name); DynamicObject::Ptr configObject = DynamicObject::GetObject("Service", name);
if (!configObject) if (!configObject)
throw_exception(invalid_argument("Service '" + name + "' does not exist.")); throw_exception(invalid_argument("Service '" + name + "' does not exist."));

View File

@ -42,14 +42,14 @@ class CheckResult;
class CheckResultMessage; class CheckResultMessage;
class ServiceStatusMessage; class ServiceStatusMessage;
class I2_CIB_API Service : public ConfigObject class I2_CIB_API Service : public DynamicObject
{ {
public: public:
typedef shared_ptr<Service> Ptr; typedef shared_ptr<Service> Ptr;
typedef weak_ptr<Service> WeakPtr; typedef weak_ptr<Service> WeakPtr;
Service(const Dictionary::Ptr& properties) Service(const Dictionary::Ptr& properties)
: ConfigObject(properties) : DynamicObject(properties)
{ } { }
static bool Exists(const string& name); static bool Exists(const string& name);

View File

@ -49,12 +49,12 @@ string ServiceGroup::GetActionUrl(void) const
bool ServiceGroup::Exists(const string& name) bool ServiceGroup::Exists(const string& name)
{ {
return (ConfigObject::GetObject("ServiceGroup", name)); return (DynamicObject::GetObject("ServiceGroup", name));
} }
ServiceGroup::Ptr ServiceGroup::GetByName(const string& name) ServiceGroup::Ptr ServiceGroup::GetByName(const string& name)
{ {
ConfigObject::Ptr configObject = ConfigObject::GetObject("ServiceGroup", name); DynamicObject::Ptr configObject = DynamicObject::GetObject("ServiceGroup", name);
if (!configObject) if (!configObject)
throw_exception(invalid_argument("ServiceGroup '" + name + "' does not exist.")); throw_exception(invalid_argument("ServiceGroup '" + name + "' does not exist."));

View File

@ -23,14 +23,14 @@
namespace icinga namespace icinga
{ {
class I2_CIB_API ServiceGroup : public ConfigObject class I2_CIB_API ServiceGroup : public DynamicObject
{ {
public: public:
typedef shared_ptr<ServiceGroup> Ptr; typedef shared_ptr<ServiceGroup> Ptr;
typedef weak_ptr<ServiceGroup> WeakPtr; typedef weak_ptr<ServiceGroup> WeakPtr;
ServiceGroup(const Dictionary::Ptr& properties) ServiceGroup(const Dictionary::Ptr& properties)
: ConfigObject(properties) : DynamicObject(properties)
{ } { }
static bool Exists(const string& name); static bool Exists(const string& name);

View File

@ -76,7 +76,7 @@ void CheckerComponent::CheckTimerHandler(void)
arguments.push_back(service); arguments.push_back(service);
ScriptTask::Ptr task; ScriptTask::Ptr task;
task = service->InvokeMethod("check", arguments, boost::bind(&CheckerComponent::CheckCompletedHandler, this, service, _1)); task = service->InvokeMethod("check", arguments, boost::bind(&CheckerComponent::CheckCompletedHandler, this, service, _1));
assert(task); /* TODO: gracefully handle missing hooks */ assert(task); /* TODO: gracefully handle missing methods */
service->SetTag("current_task", task); service->SetTag("current_task", task);

View File

@ -34,8 +34,8 @@ void CIBSyncComponent::Start(void)
m_Endpoint->RegisterTopicHandler("config::FetchObjects", m_Endpoint->RegisterTopicHandler("config::FetchObjects",
boost::bind(&CIBSyncComponent::FetchObjectsHandler, this, _2)); boost::bind(&CIBSyncComponent::FetchObjectsHandler, this, _2));
ConfigObject::OnCommitted.connect(boost::bind(&CIBSyncComponent::LocalObjectCommittedHandler, this, _1)); DynamicObject::OnCommitted.connect(boost::bind(&CIBSyncComponent::LocalObjectCommittedHandler, this, _1));
ConfigObject::OnRemoved.connect(boost::bind(&CIBSyncComponent::LocalObjectRemovedHandler, this, _1)); DynamicObject::OnRemoved.connect(boost::bind(&CIBSyncComponent::LocalObjectRemovedHandler, this, _1));
m_Endpoint->RegisterPublication("config::ObjectCommitted"); m_Endpoint->RegisterPublication("config::ObjectCommitted");
m_Endpoint->RegisterPublication("config::ObjectRemoved"); m_Endpoint->RegisterPublication("config::ObjectRemoved");
@ -106,7 +106,7 @@ void CIBSyncComponent::SessionEstablishedHandler(const Endpoint::Ptr& endpoint)
EndpointManager::GetInstance()->SendUnicastMessage(m_Endpoint, endpoint, request); EndpointManager::GetInstance()->SendUnicastMessage(m_Endpoint, endpoint, request);
} }
RequestMessage CIBSyncComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties) RequestMessage CIBSyncComponent::MakeObjectMessage(const DynamicObject::Ptr& object, string method, bool includeProperties)
{ {
RequestMessage msg; RequestMessage msg;
msg.SetMethod(method); msg.SetMethod(method);
@ -123,17 +123,17 @@ RequestMessage CIBSyncComponent::MakeObjectMessage(const ConfigObject::Ptr& obje
return msg; return msg;
} }
bool CIBSyncComponent::ShouldReplicateObject(const ConfigObject::Ptr& object) bool CIBSyncComponent::ShouldReplicateObject(const DynamicObject::Ptr& object)
{ {
return (!object->IsLocal()); return (!object->IsLocal());
} }
void CIBSyncComponent::FetchObjectsHandler(const Endpoint::Ptr& sender) void CIBSyncComponent::FetchObjectsHandler(const Endpoint::Ptr& sender)
{ {
pair<ConfigObject::TypeMap::iterator, ConfigObject::TypeMap::iterator> trange; pair<DynamicObject::TypeMap::iterator, DynamicObject::TypeMap::iterator> trange;
ConfigObject::TypeMap::iterator tt; DynamicObject::TypeMap::iterator tt;
for (tt = trange.first; tt != trange.second; tt++) { for (tt = trange.first; tt != trange.second; tt++) {
ConfigObject::Ptr object; DynamicObject::Ptr object;
BOOST_FOREACH(tie(tuples::ignore, object), tt->second) { BOOST_FOREACH(tie(tuples::ignore, object), tt->second) {
if (!ShouldReplicateObject(object)) if (!ShouldReplicateObject(object))
continue; continue;
@ -145,7 +145,7 @@ void CIBSyncComponent::FetchObjectsHandler(const Endpoint::Ptr& sender)
} }
} }
void CIBSyncComponent::LocalObjectCommittedHandler(const ConfigObject::Ptr& object) void CIBSyncComponent::LocalObjectCommittedHandler(const DynamicObject::Ptr& object)
{ {
/* don't send messages when we're currently processing a remote update */ /* don't send messages when we're currently processing a remote update */
if (m_SyncingConfig) if (m_SyncingConfig)
@ -158,7 +158,7 @@ void CIBSyncComponent::LocalObjectCommittedHandler(const ConfigObject::Ptr& obje
MakeObjectMessage(object, "config::ObjectCommitted", true)); MakeObjectMessage(object, "config::ObjectCommitted", true));
} }
void CIBSyncComponent::LocalObjectRemovedHandler(const ConfigObject::Ptr& object) void CIBSyncComponent::LocalObjectRemovedHandler(const DynamicObject::Ptr& object)
{ {
/* don't send messages when we're currently processing a remote update */ /* don't send messages when we're currently processing a remote update */
if (m_SyncingConfig) if (m_SyncingConfig)
@ -189,10 +189,10 @@ void CIBSyncComponent::RemoteObjectCommittedHandler(const Endpoint::Ptr& sender,
if (!params.Get("properties", &properties)) if (!params.Get("properties", &properties))
return; return;
ConfigObject::Ptr object = ConfigObject::GetObject(type, name); DynamicObject::Ptr object = DynamicObject::GetObject(type, name);
if (!object) { if (!object) {
object = boost::make_shared<ConfigObject>(properties.GetDictionary()); object = boost::make_shared<DynamicObject>(properties.GetDictionary());
if (object->GetSource() == EndpointManager::GetInstance()->GetIdentity()) { if (object->GetSource() == EndpointManager::GetInstance()->GetIdentity()) {
/* the peer sent us an object that was originally created by us - /* the peer sent us an object that was originally created by us -
@ -204,7 +204,7 @@ void CIBSyncComponent::RemoteObjectCommittedHandler(const Endpoint::Ptr& sender,
return; return;
} }
} else { } else {
ConfigObject::Ptr remoteObject = boost::make_shared<ConfigObject>(properties.GetDictionary()); DynamicObject::Ptr remoteObject = boost::make_shared<DynamicObject>(properties.GetDictionary());
if (object->GetCommitTimestamp() >= remoteObject->GetCommitTimestamp()) if (object->GetCommitTimestamp() >= remoteObject->GetCommitTimestamp())
return; return;
@ -245,7 +245,7 @@ void CIBSyncComponent::RemoteObjectRemovedHandler(const RequestMessage& request)
if (!params.Get("type", &type)) if (!params.Get("type", &type))
return; return;
ConfigObject::Ptr object = ConfigObject::GetObject(type, name); DynamicObject::Ptr object = DynamicObject::GetObject(type, name);
if (!object) if (!object)
return; return;

View File

@ -41,17 +41,17 @@ private:
void NewEndpointHandler(const Endpoint::Ptr& endpoint); void NewEndpointHandler(const Endpoint::Ptr& endpoint);
void SessionEstablishedHandler(const Endpoint::Ptr& endpoint); void SessionEstablishedHandler(const Endpoint::Ptr& endpoint);
void LocalObjectCommittedHandler(const ConfigObject::Ptr& object); void LocalObjectCommittedHandler(const DynamicObject::Ptr& object);
void LocalObjectRemovedHandler(const ConfigObject::Ptr& object); void LocalObjectRemovedHandler(const DynamicObject::Ptr& object);
void FetchObjectsHandler(const Endpoint::Ptr& sender); void FetchObjectsHandler(const Endpoint::Ptr& sender);
void RemoteObjectCommittedHandler(const Endpoint::Ptr& sender, const RequestMessage& request); void RemoteObjectCommittedHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
void RemoteObjectRemovedHandler(const RequestMessage& request); void RemoteObjectRemovedHandler(const RequestMessage& request);
static RequestMessage MakeObjectMessage(const ConfigObject::Ptr& object, static RequestMessage MakeObjectMessage(const DynamicObject::Ptr& object,
string method, bool includeProperties); string method, bool includeProperties);
static bool ShouldReplicateObject(const ConfigObject::Ptr& object); static bool ShouldReplicateObject(const DynamicObject::Ptr& object);
}; };
} }

View File

@ -222,8 +222,8 @@ void CompatComponent::StatusTimerHandler(void)
map<string, vector<string> > hostgroups; map<string, vector<string> > hostgroups;
ConfigObject::Ptr object; DynamicObject::Ptr object;
BOOST_FOREACH(tie(tuples::ignore, object), ConfigObject::GetObjects("Host")) { BOOST_FOREACH(tie(tuples::ignore, object), DynamicObject::GetObjects("Host")) {
const Host::Ptr& host = static_pointer_cast<Host>(object); const Host::Ptr& host = static_pointer_cast<Host>(object);
Dictionary::Ptr dict; Dictionary::Ptr dict;
@ -265,7 +265,7 @@ void CompatComponent::StatusTimerHandler(void)
map<string, vector<Service::Ptr> > servicegroups; map<string, vector<Service::Ptr> > servicegroups;
BOOST_FOREACH(tie(tuples::ignore, object), ConfigObject::GetObjects("Service")) { BOOST_FOREACH(tie(tuples::ignore, object), DynamicObject::GetObjects("Service")) {
Service::Ptr service = static_pointer_cast<Service>(object); Service::Ptr service = static_pointer_cast<Service>(object);
Dictionary::Ptr dict; Dictionary::Ptr dict;

View File

@ -144,7 +144,7 @@ void ConvenienceComponent::HostRemovedHandler(const ConfigItem::Ptr& item)
if (item->GetType() != "host") if (item->GetType() != "host")
return; return;
ConfigObject::Ptr host = item->GetConfigObject(); DynamicObject::Ptr host = item->GetDynamicObject();
if (!host) if (!host)
return; return;

View File

@ -24,8 +24,8 @@ using namespace icinga;
void DelegationComponent::Start(void) void DelegationComponent::Start(void)
{ {
ConfigObject::OnCommitted.connect(boost::bind(&DelegationComponent::ServiceCommittedHandler, this, _1)); DynamicObject::OnCommitted.connect(boost::bind(&DelegationComponent::ServiceCommittedHandler, this, _1));
ConfigObject::OnRemoved.connect(boost::bind(&DelegationComponent::ServiceRemovedHandler, this, _1)); DynamicObject::OnRemoved.connect(boost::bind(&DelegationComponent::ServiceRemovedHandler, this, _1));
m_DelegationTimer = boost::make_shared<Timer>(); m_DelegationTimer = boost::make_shared<Timer>();
m_DelegationTimer->SetInterval(30); m_DelegationTimer->SetInterval(30);
@ -50,7 +50,7 @@ void DelegationComponent::Stop(void)
mgr->UnregisterEndpoint(m_Endpoint); mgr->UnregisterEndpoint(m_Endpoint);
} }
void DelegationComponent::ServiceCommittedHandler(const ConfigObject::Ptr& object) void DelegationComponent::ServiceCommittedHandler(const DynamicObject::Ptr& object)
{ {
Service::Ptr service = dynamic_pointer_cast<Service>(object); Service::Ptr service = dynamic_pointer_cast<Service>(object);
@ -71,7 +71,7 @@ void DelegationComponent::ServiceCommittedHandler(const ConfigObject::Ptr& objec
} }
} }
void DelegationComponent::ServiceRemovedHandler(const ConfigObject::Ptr& object) void DelegationComponent::ServiceRemovedHandler(const DynamicObject::Ptr& object)
{ {
Service::Ptr service = dynamic_pointer_cast<Service>(object); Service::Ptr service = dynamic_pointer_cast<Service>(object);
@ -160,8 +160,8 @@ void DelegationComponent::SessionEstablishedHandler(const Endpoint::Ptr& endpoin
return; return;
/* locally clear checker for all services that previously belonged to this endpoint */ /* locally clear checker for all services that previously belonged to this endpoint */
ConfigObject::Ptr object; DynamicObject::Ptr object;
BOOST_FOREACH(tie(tuples::ignore, object), ConfigObject::GetObjects("Service")) { BOOST_FOREACH(tie(tuples::ignore, object), DynamicObject::GetObjects("Service")) {
Service::Ptr service = dynamic_pointer_cast<Service>(object); Service::Ptr service = dynamic_pointer_cast<Service>(object);
if (!service) if (!service)
@ -186,8 +186,8 @@ void DelegationComponent::DelegationTimerHandler(void)
vector<Service::Ptr> services; vector<Service::Ptr> services;
/* build "checker -> service count" histogram */ /* build "checker -> service count" histogram */
ConfigObject::Ptr object; DynamicObject::Ptr object;
BOOST_FOREACH(tie(tuples::ignore, object), ConfigObject::GetObjects("Service")) { BOOST_FOREACH(tie(tuples::ignore, object), DynamicObject::GetObjects("Service")) {
Service::Ptr service = dynamic_pointer_cast<Service>(object); Service::Ptr service = dynamic_pointer_cast<Service>(object);
if (!service) if (!service)

View File

@ -39,8 +39,8 @@ private:
void NewEndpointHandler(const Endpoint::Ptr& endpoint); void NewEndpointHandler(const Endpoint::Ptr& endpoint);
void SessionEstablishedHandler(const Endpoint::Ptr& endpoint); void SessionEstablishedHandler(const Endpoint::Ptr& endpoint);
void ServiceCommittedHandler(const ConfigObject::Ptr& object); void ServiceCommittedHandler(const DynamicObject::Ptr& object);
void ServiceRemovedHandler(const ConfigObject::Ptr& object); void ServiceRemovedHandler(const DynamicObject::Ptr& object);
void DelegationTimerHandler(void); void DelegationTimerHandler(void);
vector<Endpoint::Ptr> GetCheckerCandidates(const Service::Ptr& service) const; vector<Endpoint::Ptr> GetCheckerCandidates(const Service::Ptr& service) const;

View File

@ -313,8 +313,8 @@ bool DiscoveryComponent::HasMessagePermission(const Dictionary::Ptr& roles, cons
if (!roles) if (!roles)
return false; return false;
ConfigObject::Ptr role; DynamicObject::Ptr role;
BOOST_FOREACH(tie(tuples::ignore, role), ConfigObject::GetObjects("Role")) { BOOST_FOREACH(tie(tuples::ignore, role), DynamicObject::GetObjects("Role")) {
Dictionary::Ptr permissions; Dictionary::Ptr permissions;
if (!role->GetProperty(messageType, &permissions)) if (!role->GetProperty(messageType, &permissions))
continue; continue;
@ -355,7 +355,7 @@ void DiscoveryComponent::ProcessDiscoveryMessage(const string& identity, const D
if (message.GetService(&service) && !service.empty()) if (message.GetService(&service) && !service.empty())
info->Service = service; info->Service = service;
ConfigObject::Ptr endpointConfig = ConfigObject::GetObject("endpoint", identity); DynamicObject::Ptr endpointConfig = DynamicObject::GetObject("endpoint", identity);
Dictionary::Ptr roles; Dictionary::Ptr roles;
if (endpointConfig) if (endpointConfig)
endpointConfig->GetProperty("roles", &roles); endpointConfig->GetProperty("roles", &roles);
@ -442,8 +442,8 @@ void DiscoveryComponent::DiscoveryTimerHandler(void)
double now = Utility::GetTime(); double now = Utility::GetTime();
/* check whether we have to reconnect to one of our upstream endpoints */ /* check whether we have to reconnect to one of our upstream endpoints */
ConfigObject::Ptr object; DynamicObject::Ptr object;
BOOST_FOREACH(tie(tuples::ignore, object), ConfigObject::GetObjects("Endpoint")) { BOOST_FOREACH(tie(tuples::ignore, object), DynamicObject::GetObjects("Endpoint")) {
/* Check if we're already connected to this endpoint. */ /* Check if we're already connected to this endpoint. */
if (endpointManager->GetEndpointByIdentity(object->GetName())) if (endpointManager->GetEndpointByIdentity(object->GetName()))
continue; continue;
@ -470,7 +470,7 @@ void DiscoveryComponent::DiscoveryTimerHandler(void)
/* for explicitly-configured upstream endpoints /* for explicitly-configured upstream endpoints
* we prefer to use the node/service from the * we prefer to use the node/service from the
* config object - which is what the for loop above does */ * config object - which is what the for loop above does */
if (ConfigObject::GetObject("endpoint", identity)) if (DynamicObject::GetObject("endpoint", identity))
continue; continue;
if (info->LastSeen < now - DiscoveryComponent::RegistrationTTL) { if (info->LastSeen < now - DiscoveryComponent::RegistrationTTL) {

View File

@ -75,22 +75,22 @@ void ConfigItem::CalculateProperties(Dictionary::Ptr dictionary) const
m_ExpressionList->Execute(dictionary); m_ExpressionList->Execute(dictionary);
} }
ConfigObject::Ptr ConfigItem::Commit(void) DynamicObject::Ptr ConfigItem::Commit(void)
{ {
ConfigObject::Ptr dobj = m_ConfigObject.lock(); DynamicObject::Ptr dobj = m_DynamicObject.lock();
Dictionary::Ptr properties = boost::make_shared<Dictionary>(); Dictionary::Ptr properties = boost::make_shared<Dictionary>();
CalculateProperties(properties); CalculateProperties(properties);
if (!dobj) if (!dobj)
dobj = ConfigObject::GetObject(GetType(), GetName()); dobj = DynamicObject::GetObject(GetType(), GetName());
if (!dobj) if (!dobj)
dobj = ConfigObject::Create(GetType(), properties); dobj = DynamicObject::Create(GetType(), properties);
else else
dobj->SetProperties(properties); dobj->SetProperties(properties);
m_ConfigObject = dobj; m_DynamicObject = dobj;
if (dobj->IsAbstract()) if (dobj->IsAbstract())
dobj->Unregister(); dobj->Unregister();
@ -109,7 +109,7 @@ ConfigObject::Ptr ConfigItem::Commit(void)
void ConfigItem::Unregister(void) void ConfigItem::Unregister(void)
{ {
ConfigObject::Ptr dobj = m_ConfigObject.lock(); DynamicObject::Ptr dobj = m_DynamicObject.lock();
if (dobj) if (dobj)
dobj->Unregister(); dobj->Unregister();
@ -123,9 +123,9 @@ void ConfigItem::Unregister(void)
OnRemoved(GetSelf()); OnRemoved(GetSelf());
} }
ConfigObject::Ptr ConfigItem::GetConfigObject(void) const DynamicObject::Ptr ConfigItem::GetDynamicObject(void) const
{ {
return m_ConfigObject.lock(); return m_DynamicObject.lock();
} }
ConfigItem::Ptr ConfigItem::GetObject(const string& type, const string& name) ConfigItem::Ptr ConfigItem::GetObject(const string& type, const string& name)

View File

@ -41,10 +41,10 @@ public:
void CalculateProperties(Dictionary::Ptr dictionary) const; void CalculateProperties(Dictionary::Ptr dictionary) const;
ConfigObject::Ptr Commit(void); DynamicObject::Ptr Commit(void);
void Unregister(void); void Unregister(void);
ConfigObject::Ptr GetConfigObject(void) const; DynamicObject::Ptr GetDynamicObject(void) const;
DebugInfo GetDebugInfo(void) const; DebugInfo GetDebugInfo(void) const;
@ -61,7 +61,7 @@ private:
vector<string> m_Parents; vector<string> m_Parents;
DebugInfo m_DebugInfo; DebugInfo m_DebugInfo;
ConfigObject::WeakPtr m_ConfigObject; DynamicObject::WeakPtr m_DynamicObject;
typedef map<pair<string, string>, ConfigItem::Ptr> ItemMap; typedef map<pair<string, string>, ConfigItem::Ptr> ItemMap;
static ItemMap m_Items; static ItemMap m_Items;

View File

@ -42,14 +42,6 @@ IcingaApplication::IcingaApplication(void)
*/ */
int IcingaApplication::Main(const vector<string>& args) int IcingaApplication::Main(const vector<string>& args)
{ {
/* restore the previous program state */
ConfigObject::RestoreObjects("retention.dat");
m_RetentionTimer = boost::make_shared<Timer>();
m_RetentionTimer->SetInterval(60);
m_RetentionTimer->OnTimerExpired.connect(boost::bind(&IcingaApplication::DumpProgramState, this));
m_RetentionTimer->Start();
/* create console logger */ /* create console logger */
ConfigItemBuilder::Ptr consoleLogConfig = boost::make_shared<ConfigItemBuilder>(); ConfigItemBuilder::Ptr consoleLogConfig = boost::make_shared<ConfigItemBuilder>();
consoleLogConfig->SetType("Logger"); consoleLogConfig->SetType("Logger");
@ -58,6 +50,15 @@ int IcingaApplication::Main(const vector<string>& args)
consoleLogConfig->AddExpression("type", OperatorSet, "console"); consoleLogConfig->AddExpression("type", OperatorSet, "console");
consoleLogConfig->Compile()->Commit(); consoleLogConfig->Compile()->Commit();
/* restore the previous program state */
DynamicObject::RestoreObjects("retention.dat");
/* periodically dump the program state */
m_RetentionTimer = boost::make_shared<Timer>();
m_RetentionTimer->SetInterval(60);
m_RetentionTimer->OnTimerExpired.connect(boost::bind(&IcingaApplication::DumpProgramState, this));
m_RetentionTimer->Start();
#ifdef _WIN32 #ifdef _WIN32
Logger::Write(LogInformation, "icinga", "Icinga component loader"); Logger::Write(LogInformation, "icinga", "Icinga component loader");
#else /* _WIN32 */ #else /* _WIN32 */
@ -135,7 +136,7 @@ int IcingaApplication::Main(const vector<string>& args)
item->Commit(); item->Commit();
} }
ConfigObject::Ptr icingaConfig = ConfigObject::GetObject("Application", "icinga"); DynamicObject::Ptr icingaConfig = DynamicObject::GetObject("Application", "icinga");
if (!icingaConfig) if (!icingaConfig)
throw_exception(runtime_error("Configuration must contain an 'Application' object named 'icinga'.")); throw_exception(runtime_error("Configuration must contain an 'Application' object named 'icinga'."));
@ -196,7 +197,7 @@ int IcingaApplication::Main(const vector<string>& args)
} }
void IcingaApplication::DumpProgramState(void) { void IcingaApplication::DumpProgramState(void) {
ConfigObject::DumpObjects("retention.dat.tmp"); DynamicObject::DumpObjects("retention.dat.tmp");
rename("retention.dat.tmp", "retention.dat"); rename("retention.dat.tmp", "retention.dat");
} }