1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
6 #include "db_ido/i2-db_ido.hpp"
7 #include "db_ido/dbreference.hpp"
8 #include "db_ido/dbquery.hpp"
9 #include "db_ido/dbtype.hpp"
10 #include "icinga/customvarobject.hpp"
11 #include "base/configobject.hpp"
16 enum DbObjectUpdateType
25 DbObjectTypeService = 2,
26 DbObjectTypeHostGroup = 3,
27 DbObjectTypeServiceGroup = 4,
28 DbObjectTypeHostEscalation = 5,
29 DbObjectTypeServiceEscalation = 6,
30 DbObjectTypeHostDependency = 7,
31 DbObjectTypeServiceDependency = 8,
32 DbObjectTypeTimePeriod = 9,
33 DbObjectTypeContact = 10,
34 DbObjectTypeContactGroup = 11,
35 DbObjectTypeCommand = 12,
36 DbObjectTypeEndpoint = 13,
37 DbObjectTypeZone = 14,
45 class DbObject : public Object
48 DECLARE_PTR_TYPEDEFS(DbObject);
50 static void StaticInitialize();
52 void SetObject(const ConfigObject::Ptr& object);
53 ConfigObject::Ptr GetObject() const;
55 String GetName1() const;
56 String GetName2() const;
57 intrusive_ptr<DbType> GetType() const;
59 virtual Dictionary::Ptr GetConfigFields() const = 0;
60 virtual Dictionary::Ptr GetStatusFields() const = 0;
62 static DbObject::Ptr GetOrCreateByObject(const ConfigObject::Ptr& object);
64 static boost::signals2::signal<void (const DbQuery&)> OnQuery;
65 static boost::signals2::signal<void (const std::vector<DbQuery>&)> OnMultipleQueries;
67 void SendConfigUpdateHeavy(const Dictionary::Ptr& configFields);
68 void SendConfigUpdateLight();
69 void SendStatusUpdate();
70 void SendVarsConfigUpdateHeavy();
71 void SendVarsStatusUpdate();
73 double GetLastConfigUpdate() const;
74 double GetLastStatusUpdate() const;
76 virtual String CalculateConfigHash(const Dictionary::Ptr& configFields) const;
79 DbObject(intrusive_ptr<DbType> type, String name1, String name2);
81 virtual void OnConfigUpdateHeavy();
82 virtual void OnConfigUpdateLight();
83 virtual void OnStatusUpdate();
85 static String HashValue(const Value& value);
90 intrusive_ptr<DbType> m_Type;
91 ConfigObject::Ptr m_Object;
92 double m_LastConfigUpdate;
93 double m_LastStatusUpdate;
95 static void StateChangedHandler(const ConfigObject::Ptr& object);
96 static void VarsChangedHandler(const CustomVarObject::Ptr& object);
97 static void VersionChangedHandler(const ConfigObject::Ptr& object);
99 static boost::mutex& GetStaticMutex();
106 #endif /* DBOBJECT_H */