2013-03-04 15:52:42 +01: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 *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
#include "base/attribute.h"
|
|
|
|
#include "base/utility.h"
|
2013-03-04 15:52:42 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2013-03-18 11:02:18 +01:00
|
|
|
static boost::mutex l_Mutex;
|
2013-03-04 15:52:42 +01:00
|
|
|
|
|
|
|
AttributeBase::AttributeBase(void)
|
|
|
|
: m_Value()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void AttributeBase::Set(const Value& value)
|
|
|
|
{
|
2013-03-18 11:02:18 +01:00
|
|
|
boost::mutex::scoped_lock lock(l_Mutex);
|
2013-03-04 15:52:42 +01:00
|
|
|
InternalSet(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value AttributeBase::Get(void) const
|
|
|
|
{
|
2013-03-18 11:02:18 +01:00
|
|
|
boost::mutex::scoped_lock lock(l_Mutex);
|
2013-03-04 15:52:42 +01:00
|
|
|
return InternalGet();
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributeBase::operator Value(void) const
|
|
|
|
{
|
2013-03-18 11:02:18 +01:00
|
|
|
boost::mutex::scoped_lock lock(l_Mutex);
|
2013-03-04 15:52:42 +01:00
|
|
|
return InternalGet();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AttributeBase::IsEmpty(void) const
|
|
|
|
{
|
2013-03-18 11:02:18 +01:00
|
|
|
boost::mutex::scoped_lock lock(l_Mutex);
|
2013-03-04 15:52:42 +01:00
|
|
|
return InternalGet().IsEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-03-22 12:02:20 +01:00
|
|
|
* Note: Caller must hold l_Mutex;
|
2013-03-04 15:52:42 +01:00
|
|
|
*/
|
|
|
|
void AttributeBase::InternalSet(const Value& value)
|
|
|
|
{
|
|
|
|
m_Value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-03-22 12:02:20 +01:00
|
|
|
* Note: Caller must hold l_Mutex.
|
2013-03-04 15:52:42 +01:00
|
|
|
*/
|
|
|
|
const Value& AttributeBase::InternalGet(void) const
|
|
|
|
{
|
|
|
|
return m_Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributeHolder::AttributeHolder(AttributeType type, AttributeBase *boundAttribute)
|
|
|
|
: m_Type(type), m_Tx(0)
|
|
|
|
{
|
|
|
|
if (boundAttribute) {
|
|
|
|
m_Attribute = boundAttribute;
|
|
|
|
m_OwnsAttribute = false;
|
|
|
|
} else {
|
|
|
|
m_Attribute = new Attribute<Value>();
|
|
|
|
m_OwnsAttribute = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributeHolder::AttributeHolder(const AttributeHolder& other)
|
|
|
|
{
|
|
|
|
m_Type = other.m_Type;
|
|
|
|
m_Tx = other.m_Tx;
|
|
|
|
m_OwnsAttribute = other.m_OwnsAttribute;
|
|
|
|
|
|
|
|
if (other.m_OwnsAttribute) {
|
|
|
|
m_Attribute = new Attribute<Value>();
|
|
|
|
m_Attribute->Set(other.m_Attribute->Get());
|
|
|
|
} else {
|
|
|
|
m_Attribute = other.m_Attribute;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributeHolder::~AttributeHolder(void)
|
|
|
|
{
|
|
|
|
if (m_OwnsAttribute)
|
|
|
|
delete m_Attribute;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeHolder::Bind(AttributeBase *boundAttribute)
|
|
|
|
{
|
2013-03-07 16:00:10 +01:00
|
|
|
ASSERT(m_OwnsAttribute);
|
2013-03-04 15:52:42 +01:00
|
|
|
boundAttribute->Set(m_Attribute->Get());
|
|
|
|
m_Attribute = boundAttribute;
|
|
|
|
m_OwnsAttribute = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeHolder::SetValue(double tx, const Value& value)
|
|
|
|
{
|
|
|
|
m_Tx = tx;
|
|
|
|
m_Attribute->Set(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value AttributeHolder::GetValue(void) const
|
|
|
|
{
|
|
|
|
return m_Attribute->Get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeHolder::SetType(AttributeType type)
|
|
|
|
{
|
|
|
|
m_Type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributeType AttributeHolder::GetType(void) const
|
|
|
|
{
|
|
|
|
return m_Type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeHolder::SetTx(double tx)
|
|
|
|
{
|
|
|
|
m_Tx = tx;
|
|
|
|
}
|
|
|
|
|
|
|
|
double AttributeHolder::GetTx(void) const
|
|
|
|
{
|
|
|
|
return m_Tx;
|
|
|
|
}
|