1 /******************************************************************************
3 * Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #include "base/object.hpp"
21 #include "base/value.hpp"
22 #include "base/dictionary.hpp"
23 #include "base/primitivetype.hpp"
24 #include "base/utility.hpp"
26 using namespace icinga;
28 DEFINE_TYPE_INSTANCE(Object);
31 * Default constructor for the Object class.
41 * Destructor for the Object class.
47 * Returns a string representation for the object.
49 String Object::ToString(void) const
51 return "Object of type '" + GetReflectionType()->GetName() + "'";
56 * Checks if the calling thread owns the lock on this object.
58 * @returns True if the calling thread owns the lock, false otherwise.
60 bool Object::OwnsLock(void) const
63 DWORD tid = InterlockedExchangeAdd(&m_LockOwner, 0);
65 return (tid == GetCurrentThreadId());
67 pthread_t tid = __sync_fetch_and_add(&m_LockOwner, 0);
69 return (tid == pthread_self());
74 void Object::SetField(int id, const Value&, bool, const Value&)
77 BOOST_THROW_EXCEPTION(std::runtime_error("Type field cannot be set."));
79 BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID."));
82 Value Object::GetField(int id) const
85 return GetReflectionType()->GetName();
87 BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID."));
90 void Object::Validate(int types, const ValidationUtils& utils)
92 /* Nothing to do here. */
95 void Object::ValidateField(int id, const Value& value, const ValidationUtils& utils)
97 /* Nothing to do here. */
100 void Object::NotifyField(int id, const Value& cookie)
102 BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID."));
105 Object::Ptr Object::NavigateField(int id) const
107 BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID."));
110 Object::Ptr Object::Clone(void) const
112 BOOST_THROW_EXCEPTION(std::runtime_error("Object cannot be cloned."));
115 Type::Ptr Object::GetReflectionType(void) const
117 return Object::TypeInstance;