2012-05-10 12:06:41 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
|
|
|
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
2012-05-11 13:33:57 +02:00
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
2012-05-10 12:06:41 +02:00
|
|
|
******************************************************************************/
|
|
|
|
|
2012-03-31 15:18:09 +02:00
|
|
|
#include "i2-base.h"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2012-04-24 14:02:15 +02:00
|
|
|
/**
|
|
|
|
* Constructor for the ConfigObject class.
|
|
|
|
*
|
|
|
|
* @param type The type of the object.
|
|
|
|
* @param name The name of the object.
|
|
|
|
*/
|
2012-04-04 10:04:38 +02:00
|
|
|
ConfigObject::ConfigObject(const string& type, const string& name)
|
|
|
|
{
|
|
|
|
m_Type = type;
|
|
|
|
m_Name = name;
|
2012-04-20 14:20:25 +02:00
|
|
|
m_Replicated = false;
|
2012-04-04 10:04:38 +02:00
|
|
|
}
|
|
|
|
|
2012-04-24 14:02:15 +02:00
|
|
|
/**
|
|
|
|
* Sets the hive this object belongs to.
|
|
|
|
*
|
|
|
|
* @param hive The hive.
|
|
|
|
*/
|
2012-04-02 20:50:35 +02:00
|
|
|
void ConfigObject::SetHive(const ConfigHive::WeakPtr& hive)
|
2012-03-31 15:18:09 +02:00
|
|
|
{
|
2012-04-20 13:49:04 +02:00
|
|
|
if (m_Hive.lock())
|
2012-04-30 08:22:30 +02:00
|
|
|
throw InvalidArgumentException("Config object already has a parent hive.");
|
2012-04-20 13:49:04 +02:00
|
|
|
|
2012-03-31 15:18:09 +02:00
|
|
|
m_Hive = hive;
|
|
|
|
}
|
|
|
|
|
2012-04-24 14:02:15 +02:00
|
|
|
/**
|
|
|
|
* Retrieves the hive this object belongs to.
|
|
|
|
*
|
|
|
|
* @returns The 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;
|
|
|
|
}
|
|
|
|
|
2012-04-24 14:02:15 +02:00
|
|
|
/**
|
|
|
|
* Sets the name of this object.
|
|
|
|
*
|
|
|
|
* @param name The name.
|
|
|
|
*/
|
2012-03-31 15:18:09 +02:00
|
|
|
void ConfigObject::SetName(const string& name)
|
|
|
|
{
|
|
|
|
m_Name = name;
|
|
|
|
}
|
|
|
|
|
2012-04-24 14:02:15 +02:00
|
|
|
/**
|
|
|
|
* Retrieves the name of this object.
|
|
|
|
*
|
|
|
|
* @returns The name.
|
|
|
|
*/
|
2012-03-31 15:18:09 +02:00
|
|
|
string ConfigObject::GetName(void) const
|
|
|
|
{
|
|
|
|
return m_Name;
|
|
|
|
}
|
|
|
|
|
2012-04-24 14:02:15 +02:00
|
|
|
/**
|
|
|
|
* Sets the type of this object.
|
|
|
|
*
|
|
|
|
* @param type The type.
|
|
|
|
*/
|
2012-03-31 15:18:09 +02:00
|
|
|
void ConfigObject::SetType(const string& type)
|
|
|
|
{
|
|
|
|
m_Type = type;
|
|
|
|
}
|
|
|
|
|
2012-04-24 14:02:15 +02:00
|
|
|
/**
|
|
|
|
* Retrieves the type of this object.
|
|
|
|
*
|
|
|
|
* @returns The type.
|
|
|
|
*/
|
2012-03-31 15:18:09 +02:00
|
|
|
string ConfigObject::GetType(void) const
|
|
|
|
{
|
|
|
|
return m_Type;
|
|
|
|
}
|
|
|
|
|
2012-04-24 14:02:15 +02:00
|
|
|
/**
|
|
|
|
* Sets whether this object was replicated.
|
|
|
|
*
|
|
|
|
* @param replicated Whether this object was replicated.
|
|
|
|
*/
|
2012-04-20 14:20:25 +02:00
|
|
|
void ConfigObject::SetReplicated(bool replicated)
|
|
|
|
{
|
|
|
|
m_Replicated = replicated;
|
|
|
|
}
|
|
|
|
|
2012-04-24 14:02:15 +02:00
|
|
|
/**
|
|
|
|
* Retrieves whether this object was replicated.
|
|
|
|
*
|
|
|
|
* @returns Whether this object was replicated.
|
|
|
|
*/
|
2012-04-20 14:20:25 +02:00
|
|
|
bool ConfigObject::GetReplicated(void) const
|
|
|
|
{
|
|
|
|
return m_Replicated;
|
|
|
|
}
|
|
|
|
|
2012-04-24 14:02:15 +02:00
|
|
|
/**
|
|
|
|
* Handles changed properties by propagating them to the hive
|
|
|
|
* and collection this object is contained in.
|
|
|
|
*
|
|
|
|
*/
|
2012-05-09 10:15:51 +02:00
|
|
|
void ConfigObject::Commit(void)
|
2012-03-31 15:18:09 +02:00
|
|
|
{
|
2012-04-02 20:50:35 +02:00
|
|
|
ConfigHive::Ptr hive = m_Hive.lock();
|
2012-04-04 10:04:38 +02:00
|
|
|
if (hive) {
|
2012-05-09 10:15:51 +02:00
|
|
|
EventArgs ea;
|
|
|
|
ea.Source = shared_from_this();
|
|
|
|
hive->GetCollection(m_Type)->OnObjectCommitted(ea);
|
|
|
|
hive->OnObjectCommitted(ea);
|
2012-03-31 15:18:09 +02:00
|
|
|
}
|
|
|
|
}
|