2013-07-05 09:37:04 +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 *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef DBOBJECT_H
|
|
|
|
#define DBOBJECT_H
|
|
|
|
|
2013-07-22 12:08:49 +02:00
|
|
|
#include "ido/dbreference.h"
|
|
|
|
#include "ido/dbquery.h"
|
2013-08-01 13:20:30 +02:00
|
|
|
#include "ido/dbtype.h"
|
2013-07-05 09:37:04 +02:00
|
|
|
#include "base/dynamicobject.h"
|
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2013-07-22 12:08:49 +02:00
|
|
|
enum DbObjectUpdateType
|
2013-07-05 09:37:04 +02:00
|
|
|
{
|
|
|
|
DbObjectCreated,
|
|
|
|
DbObjectRemoved
|
|
|
|
};
|
|
|
|
|
2013-08-02 17:12:07 +02:00
|
|
|
enum DbObjectType
|
|
|
|
{
|
|
|
|
DbObjectTypeHost = 1,
|
|
|
|
DbObjectTypeService = 2,
|
|
|
|
DbObjectTypeHostGroup = 3,
|
|
|
|
DbObjectTypeServiceGroup = 4,
|
|
|
|
DbObjectTypeHostEscalation = 5,
|
|
|
|
DbObjectTypeServiceEscalation = 6,
|
|
|
|
DbObjectTypeHostDependency = 7,
|
|
|
|
DbObjectTypeServiceDependency = 8,
|
|
|
|
DbObjectTypeTimePeriod = 9,
|
|
|
|
DbObjectTypeContact = 10,
|
|
|
|
DbObjectTypeContactGroup = 11,
|
|
|
|
DbObjectTypeCommand = 12,
|
|
|
|
};
|
|
|
|
|
2013-07-05 09:37:04 +02:00
|
|
|
/**
|
|
|
|
* A database object.
|
|
|
|
*
|
|
|
|
* @ingroup ido
|
|
|
|
*/
|
|
|
|
class DbObject : public Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DECLARE_PTR_TYPEDEFS(DbObject);
|
|
|
|
|
2013-08-01 11:14:33 +02:00
|
|
|
static void StaticInitialize(void);
|
|
|
|
|
2013-07-05 09:37:04 +02:00
|
|
|
void SetObject(const DynamicObject::Ptr& object);
|
|
|
|
DynamicObject::Ptr GetObject(void) const;
|
|
|
|
|
|
|
|
String GetName1(void) const;
|
|
|
|
String GetName2(void) const;
|
2013-07-17 11:29:51 +02:00
|
|
|
boost::shared_ptr<DbType> GetType(void) const;
|
2013-07-05 09:37:04 +02:00
|
|
|
|
2013-07-22 12:08:49 +02:00
|
|
|
virtual Dictionary::Ptr GetConfigFields(void) const = 0;
|
|
|
|
virtual Dictionary::Ptr GetStatusFields(void) const = 0;
|
2013-07-05 09:37:04 +02:00
|
|
|
|
|
|
|
static DbObject::Ptr GetOrCreateByObject(const DynamicObject::Ptr& object);
|
|
|
|
|
2013-07-22 12:08:49 +02:00
|
|
|
static boost::signals2::signal<void (const DbObject::Ptr&)> OnRegistered;
|
|
|
|
static boost::signals2::signal<void (const DbObject::Ptr&)> OnUnregistered;
|
|
|
|
static boost::signals2::signal<void (const DbQuery&)> OnQuery;
|
2013-07-05 09:37:04 +02:00
|
|
|
|
2013-07-22 12:08:49 +02:00
|
|
|
void SendConfigUpdate(void);
|
|
|
|
void SendStatusUpdate(void);
|
2013-07-17 11:29:51 +02:00
|
|
|
|
2013-07-24 10:55:04 +02:00
|
|
|
double GetLastConfigUpdate(void) const;
|
|
|
|
double GetLastStatusUpdate(void) const;
|
|
|
|
|
2013-07-05 09:37:04 +02:00
|
|
|
protected:
|
2013-07-17 11:29:51 +02:00
|
|
|
DbObject(const boost::shared_ptr<DbType>& type, const String& name1, const String& name2);
|
2013-07-05 09:37:04 +02:00
|
|
|
|
2013-07-24 10:55:04 +02:00
|
|
|
virtual bool IsConfigAttribute(const String& attribute) const;
|
|
|
|
virtual bool IsStatusAttribute(const String& attribute) const;
|
|
|
|
|
2013-07-25 08:30:02 +02:00
|
|
|
virtual void OnConfigUpdate(void);
|
|
|
|
virtual void OnStatusUpdate(void);
|
|
|
|
|
2013-07-05 09:37:04 +02:00
|
|
|
private:
|
|
|
|
String m_Name1;
|
|
|
|
String m_Name2;
|
2013-07-17 11:29:51 +02:00
|
|
|
boost::shared_ptr<DbType> m_Type;
|
2013-07-05 09:37:04 +02:00
|
|
|
DynamicObject::Ptr m_Object;
|
2013-07-24 10:55:04 +02:00
|
|
|
double m_LastConfigUpdate;
|
|
|
|
double m_LastStatusUpdate;
|
2013-07-05 09:37:04 +02:00
|
|
|
|
|
|
|
friend boost::shared_ptr<DbObject> boost::make_shared<>(const icinga::String&, const icinga::String&);
|
|
|
|
|
|
|
|
static void ObjectRegisteredHandler(const DynamicObject::Ptr& object);
|
|
|
|
static void ObjectUnregisteredHandler(const DynamicObject::Ptr& object);
|
2013-07-24 10:55:04 +02:00
|
|
|
static void AttributesChangedHandler(const DynamicObject::Ptr& object, const std::set<String, string_iless>& attributes);
|
2013-07-22 12:08:49 +02:00
|
|
|
//static void TransactionClosingHandler(double tx, const std::set<DynamicObject::WeakPtr>& modifiedObjects);
|
|
|
|
//static void FlushObjectHandler(double tx, const DynamicObject::Ptr& object);
|
2013-07-05 09:37:04 +02:00
|
|
|
|
|
|
|
friend class DbType;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DBOBJECT_H */
|