2012-03-31 15:18:09 +02:00
|
|
|
#include "i2-base.h"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2012-04-03 11:39:26 +02:00
|
|
|
void ConfigHive::AddObject(const ConfigObject::Ptr& object)
|
2012-03-31 15:18:09 +02:00
|
|
|
{
|
|
|
|
string type = object->GetType();
|
|
|
|
TypeIterator ti = Objects.find(type);
|
|
|
|
|
|
|
|
if (ti == Objects.end()) {
|
2012-04-02 20:50:35 +02:00
|
|
|
Objects[type] = map<string, ConfigObject::Ptr>();
|
2012-03-31 15:18:09 +02:00
|
|
|
ti = Objects.find(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
object->SetHive(static_pointer_cast<ConfigHive>(shared_from_this()));
|
|
|
|
|
|
|
|
string name = object->GetName();
|
|
|
|
ti->second[name] = object;
|
|
|
|
|
2012-04-03 15:16:11 +02:00
|
|
|
ConfigHiveEventArgs::Ptr ea = make_shared<ConfigHiveEventArgs>();
|
2012-03-31 15:18:09 +02:00
|
|
|
ea->Source = shared_from_this();
|
2012-04-01 09:48:52 +02:00
|
|
|
ea->Object = object;
|
2012-03-31 15:18:09 +02:00
|
|
|
OnObjectCreated(ea);
|
|
|
|
}
|
|
|
|
|
2012-04-03 11:39:26 +02:00
|
|
|
void ConfigHive::RemoveObject(const ConfigObject::Ptr& object)
|
2012-03-31 15:18:09 +02:00
|
|
|
{
|
|
|
|
string type = object->GetType();
|
|
|
|
TypeIterator ti = Objects.find(type);
|
|
|
|
|
|
|
|
if (ti == Objects.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
ti->second.erase(object->GetName());
|
|
|
|
|
2012-04-03 15:16:11 +02:00
|
|
|
ConfigHiveEventArgs::Ptr ea = make_shared<ConfigHiveEventArgs>();
|
2012-03-31 15:18:09 +02:00
|
|
|
ea->Source = shared_from_this();
|
2012-04-01 09:48:52 +02:00
|
|
|
ea->Object = object;
|
2012-03-31 15:18:09 +02:00
|
|
|
OnObjectRemoved(ea);
|
|
|
|
}
|
|
|
|
|
2012-04-02 20:50:35 +02:00
|
|
|
ConfigObject::Ptr ConfigHive::GetObject(const string& type, const string& name)
|
2012-03-31 15:18:09 +02:00
|
|
|
{
|
|
|
|
ConfigHive::TypeIterator ti = Objects.find(type);
|
|
|
|
|
|
|
|
if (ti == Objects.end())
|
2012-04-02 20:50:35 +02:00
|
|
|
return ConfigObject::Ptr();
|
2012-03-31 15:18:09 +02:00
|
|
|
|
|
|
|
ConfigHive::ObjectIterator oi = ti->second.find(name);
|
|
|
|
|
|
|
|
if (oi == ti->second.end())
|
2012-04-02 20:50:35 +02:00
|
|
|
return ConfigObject::Ptr();
|
2012-03-31 15:18:09 +02:00
|
|
|
|
|
|
|
return oi->second;
|
|
|
|
}
|