2012-05-10 06:06:41 -04:00
|
|
|
/******************************************************************************
|
|
|
|
|
* Icinga 2 *
|
2014-03-18 20:02:29 -04:00
|
|
|
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
2012-05-10 06:06:41 -04:00
|
|
|
* *
|
|
|
|
|
* 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 07:33:57 -04:00
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
2012-05-10 06:06:41 -04:00
|
|
|
******************************************************************************/
|
|
|
|
|
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "base/object.hpp"
|
|
|
|
|
#include "base/value.hpp"
|
2014-11-03 01:07:54 -05:00
|
|
|
#include "base/primitivetype.hpp"
|
2014-12-08 03:12:40 -05:00
|
|
|
#include "base/utility.hpp"
|
2012-03-28 07:24:49 -04:00
|
|
|
|
|
|
|
|
using namespace icinga;
|
2012-05-14 13:14:23 -04:00
|
|
|
|
2014-11-02 18:44:04 -05:00
|
|
|
REGISTER_PRIMITIVE_TYPE(Object);
|
|
|
|
|
|
2012-05-14 13:14:23 -04:00
|
|
|
/**
|
|
|
|
|
* Default constructor for the Object class.
|
|
|
|
|
*/
|
|
|
|
|
Object::Object(void)
|
2014-11-08 15:17:16 -05:00
|
|
|
: m_References(0)
|
2013-03-04 09:52:42 -05:00
|
|
|
#ifdef _DEBUG
|
2014-11-12 06:32:14 -05:00
|
|
|
, m_LockOwner(0)
|
2013-03-04 09:52:42 -05:00
|
|
|
#endif /* _DEBUG */
|
2013-02-17 13:14:34 -05:00
|
|
|
{ }
|
2012-05-14 13:14:23 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destructor for the Object class.
|
|
|
|
|
*/
|
|
|
|
|
Object::~Object(void)
|
2013-02-17 13:14:34 -05:00
|
|
|
{ }
|
2012-06-14 09:16:41 -04:00
|
|
|
|
2014-12-08 03:12:40 -05:00
|
|
|
/**
|
|
|
|
|
* Returns a string representation for the object.
|
|
|
|
|
*/
|
|
|
|
|
String Object::ToString(void) const
|
|
|
|
|
{
|
|
|
|
|
return "Object of type '" + Utility::GetTypeName(typeid(*this)) + "'";
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-02 03:07:47 -05:00
|
|
|
#ifdef _DEBUG
|
2012-09-14 08:41:17 -04:00
|
|
|
/**
|
2013-03-04 09:52:42 -05:00
|
|
|
* Checks if the calling thread owns the lock on this object.
|
2012-09-14 08:41:17 -04:00
|
|
|
*
|
2013-03-01 06:07:52 -05:00
|
|
|
* @returns True if the calling thread owns the lock, false otherwise.
|
2012-09-14 08:41:17 -04:00
|
|
|
*/
|
2013-03-01 06:07:52 -05:00
|
|
|
bool Object::OwnsLock(void) const
|
2012-08-03 07:19:55 -04:00
|
|
|
{
|
2014-11-12 06:32:14 -05:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
DWORD tid = InterlockedExchangeAdd(&m_LockOwner, 0);
|
|
|
|
|
|
|
|
|
|
return (tid == GetCurrentThreadId());
|
|
|
|
|
#else /* _WIN32 */
|
|
|
|
|
pthread_t tid = __sync_fetch_and_add(&m_LockOwner, 0);
|
|
|
|
|
|
|
|
|
|
return (tid == pthread_self());
|
|
|
|
|
#endif /* _WIN32 */
|
2012-08-03 07:19:55 -04:00
|
|
|
}
|
2013-03-02 03:07:47 -05:00
|
|
|
#endif /* _DEBUG */
|
2013-06-13 05:33:00 -04:00
|
|
|
|
2014-11-11 17:06:47 -05:00
|
|
|
void Object::InflateMutex(void)
|
|
|
|
|
{
|
|
|
|
|
m_Mutex.Inflate();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-11 00:30:50 -04:00
|
|
|
void Object::SetField(int, const Value&)
|
2013-11-04 17:14:34 -05:00
|
|
|
{
|
2014-05-11 00:30:50 -04:00
|
|
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID."));
|
2013-11-04 17:14:34 -05:00
|
|
|
}
|
|
|
|
|
|
2014-05-11 00:30:50 -04:00
|
|
|
Value Object::GetField(int) const
|
2013-11-04 17:14:34 -05:00
|
|
|
{
|
2014-05-11 00:30:50 -04:00
|
|
|
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID."));
|
2013-11-04 17:14:34 -05:00
|
|
|
}
|
2014-05-11 00:30:50 -04:00
|
|
|
|