2013-07-05 09:37:04 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2016-01-12 08:29:59 +01:00
|
|
|
* Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) *
|
2013-07-05 09:37:04 +02: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 *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "db_ido/dbobject.hpp"
|
|
|
|
#include "db_ido/dbtype.hpp"
|
|
|
|
#include "db_ido/dbvalue.hpp"
|
|
|
|
#include "icinga/customvarobject.hpp"
|
|
|
|
#include "icinga/service.hpp"
|
|
|
|
#include "icinga/compatutility.hpp"
|
2016-08-15 14:39:33 +02:00
|
|
|
#include "icinga/checkcommand.hpp"
|
|
|
|
#include "icinga/eventcommand.hpp"
|
|
|
|
#include "icinga/notificationcommand.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "remote/endpoint.hpp"
|
2015-08-15 20:28:05 +02:00
|
|
|
#include "base/configobject.hpp"
|
|
|
|
#include "base/configtype.hpp"
|
2014-11-04 12:18:07 +01:00
|
|
|
#include "base/json.hpp"
|
2016-08-14 22:24:51 +02:00
|
|
|
#include "base/serializer.hpp"
|
|
|
|
#include "base/json.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/convert.hpp"
|
|
|
|
#include "base/objectlock.hpp"
|
|
|
|
#include "base/utility.hpp"
|
|
|
|
#include "base/initialize.hpp"
|
2014-10-19 14:21:12 +02:00
|
|
|
#include "base/logger.hpp"
|
2013-07-05 09:37:04 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2013-07-22 12:08:49 +02:00
|
|
|
boost::signals2::signal<void (const DbQuery&)> DbObject::OnQuery;
|
2015-12-14 11:36:03 +01:00
|
|
|
boost::signals2::signal<void (const std::vector<DbQuery>&)> DbObject::OnMultipleQueries;
|
2013-07-05 09:37:04 +02:00
|
|
|
|
2013-11-08 21:12:47 +01:00
|
|
|
INITIALIZE_ONCE(&DbObject::StaticInitialize);
|
2013-08-01 11:07:26 +02:00
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
DbObject::DbObject(const intrusive_ptr<DbType>& type, const String& name1, const String& name2)
|
2013-07-24 10:55:04 +02:00
|
|
|
: m_Name1(name1), m_Name2(name2), m_Type(type), m_LastConfigUpdate(0), m_LastStatusUpdate(0)
|
2013-07-05 09:37:04 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
void DbObject::StaticInitialize(void)
|
|
|
|
{
|
2014-03-09 18:06:24 +01:00
|
|
|
/* triggered in ProcessCheckResult(), requires UpdateNextCheck() to be called before */
|
2015-08-15 20:28:05 +02:00
|
|
|
ConfigObject::OnStateChanged.connect(boost::bind(&DbObject::StateChangedHandler, _1));
|
2014-05-12 16:45:25 +02:00
|
|
|
CustomVarObject::OnVarsChanged.connect(boost::bind(&DbObject::VarsChangedHandler, _1));
|
2015-09-15 11:59:09 +02:00
|
|
|
|
|
|
|
/* triggered on create, update and delete objects */
|
|
|
|
ConfigObject::OnVersionChanged.connect(boost::bind(&DbObject::VersionChangedHandler, _1));
|
2013-07-05 09:37:04 +02:00
|
|
|
}
|
|
|
|
|
2015-08-15 20:28:05 +02:00
|
|
|
void DbObject::SetObject(const ConfigObject::Ptr& object)
|
2013-07-05 09:37:04 +02:00
|
|
|
{
|
|
|
|
m_Object = object;
|
|
|
|
}
|
|
|
|
|
2015-08-15 20:28:05 +02:00
|
|
|
ConfigObject::Ptr DbObject::GetObject(void) const
|
2013-07-05 09:37:04 +02:00
|
|
|
{
|
|
|
|
return m_Object;
|
|
|
|
}
|
|
|
|
|
|
|
|
String DbObject::GetName1(void) const
|
|
|
|
{
|
|
|
|
return m_Name1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String DbObject::GetName2(void) const
|
|
|
|
{
|
|
|
|
return m_Name2;
|
|
|
|
}
|
|
|
|
|
2013-07-17 11:29:51 +02:00
|
|
|
DbType::Ptr DbObject::GetType(void) const
|
|
|
|
{
|
|
|
|
return m_Type;
|
|
|
|
}
|
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
String DbObject::CalculateConfigHash(const Dictionary::Ptr& configFields) const
|
|
|
|
{
|
|
|
|
Dictionary::Ptr configFieldsDup = configFields->ShallowClone();
|
|
|
|
|
|
|
|
{
|
|
|
|
ObjectLock olock(configFieldsDup);
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Dictionary::Pair& kv : configFieldsDup) {
|
2016-08-14 22:24:51 +02:00
|
|
|
if (kv.second.IsObjectType<ConfigObject>()) {
|
|
|
|
ConfigObject::Ptr obj = kv.second;
|
|
|
|
configFieldsDup->Set(kv.first, obj->GetName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Array::Ptr data = new Array();
|
|
|
|
data->Add(configFieldsDup);
|
|
|
|
|
|
|
|
CustomVarObject::Ptr custom_var_object = dynamic_pointer_cast<CustomVarObject>(GetObject());
|
|
|
|
|
|
|
|
if (custom_var_object)
|
|
|
|
data->Add(custom_var_object->GetVars());
|
|
|
|
|
|
|
|
return HashValue(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
String DbObject::HashValue(const Value& value)
|
|
|
|
{
|
|
|
|
Value temp;
|
|
|
|
|
|
|
|
Type::Ptr type = value.GetReflectionType();
|
|
|
|
|
|
|
|
if (ConfigObject::TypeInstance->IsAssignableFrom(type))
|
|
|
|
temp = Serialize(value, FAConfig);
|
|
|
|
else
|
|
|
|
temp = value;
|
|
|
|
|
|
|
|
return SHA256(JsonEncode(temp));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DbObject::SendConfigUpdateHeavy(const Dictionary::Ptr& configFields)
|
2013-07-17 11:29:51 +02:00
|
|
|
{
|
2015-03-13 13:46:00 +01:00
|
|
|
/* update custom var config and status */
|
2016-08-14 22:24:51 +02:00
|
|
|
SendVarsConfigUpdateHeavy();
|
2015-03-13 13:46:00 +01:00
|
|
|
SendVarsStatusUpdate();
|
2014-04-15 17:33:56 +02:00
|
|
|
|
2015-03-13 13:46:00 +01:00
|
|
|
/* config attributes */
|
2016-08-14 22:24:51 +02:00
|
|
|
if (!configFields)
|
2013-08-01 09:32:14 +02:00
|
|
|
return;
|
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
ASSERT(configFields->Contains("config_hash"));
|
|
|
|
|
|
|
|
ConfigObject::Ptr object = GetObject();
|
|
|
|
|
2013-08-02 08:56:36 +02:00
|
|
|
DbQuery query;
|
|
|
|
query.Table = GetType()->GetTable() + "s";
|
|
|
|
query.Type = DbQueryInsert | DbQueryUpdate;
|
2013-11-05 12:40:25 +01:00
|
|
|
query.Category = DbCatConfig;
|
2016-08-14 22:24:51 +02:00
|
|
|
query.Fields = configFields;
|
|
|
|
query.Fields->Set(GetType()->GetIDColumn(), object);
|
2013-08-02 08:56:36 +02:00
|
|
|
query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
|
|
|
query.Fields->Set("config_type", 1);
|
2014-11-08 21:17:16 +01:00
|
|
|
query.WhereCriteria = new Dictionary();
|
2016-08-14 22:24:51 +02:00
|
|
|
query.WhereCriteria->Set(GetType()->GetIDColumn(), object);
|
2014-11-08 21:17:16 +01:00
|
|
|
query.Object = this;
|
2013-08-02 15:45:50 +02:00
|
|
|
query.ConfigUpdate = true;
|
2013-08-02 08:56:36 +02:00
|
|
|
OnQuery(query);
|
2013-07-24 10:55:04 +02:00
|
|
|
|
|
|
|
m_LastConfigUpdate = Utility::GetTime();
|
2013-07-25 08:30:02 +02:00
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
OnConfigUpdateHeavy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DbObject::SendConfigUpdateLight(void)
|
|
|
|
{
|
|
|
|
OnConfigUpdateLight();
|
2013-07-22 12:08:49 +02:00
|
|
|
}
|
|
|
|
|
2014-03-20 15:41:45 +01:00
|
|
|
void DbObject::SendStatusUpdate(void)
|
2013-07-22 12:08:49 +02:00
|
|
|
{
|
2015-03-13 13:46:00 +01:00
|
|
|
/* status attributes */
|
2013-08-01 09:32:14 +02:00
|
|
|
Dictionary::Ptr fields = GetStatusFields();
|
|
|
|
|
|
|
|
if (!fields)
|
|
|
|
return;
|
|
|
|
|
2013-08-02 08:56:36 +02:00
|
|
|
DbQuery query;
|
|
|
|
query.Table = GetType()->GetTable() + "status";
|
|
|
|
query.Type = DbQueryInsert | DbQueryUpdate;
|
2013-10-29 15:54:43 +01:00
|
|
|
query.Category = DbCatState;
|
2013-08-02 08:56:36 +02:00
|
|
|
query.Fields = fields;
|
|
|
|
query.Fields->Set(GetType()->GetIDColumn(), GetObject());
|
2014-02-21 17:26:56 +01:00
|
|
|
|
2015-06-17 15:45:45 +02:00
|
|
|
/* do not override endpoint_object_id for endpoints & zones */
|
|
|
|
if (query.Table != "endpointstatus" && query.Table != "zonestatus") {
|
2014-03-20 17:40:27 +01:00
|
|
|
String node = IcingaApplication::GetInstance()->GetNodeName();
|
|
|
|
|
|
|
|
Endpoint::Ptr endpoint = Endpoint::GetByName(node);
|
|
|
|
if (endpoint)
|
|
|
|
query.Fields->Set("endpoint_object_id", endpoint);
|
|
|
|
}
|
2014-03-20 15:41:45 +01:00
|
|
|
|
2014-03-20 17:40:27 +01:00
|
|
|
query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
2014-02-21 17:26:56 +01:00
|
|
|
|
2013-08-02 08:56:36 +02:00
|
|
|
query.Fields->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime()));
|
2014-11-08 21:17:16 +01:00
|
|
|
query.WhereCriteria = new Dictionary();
|
2013-08-02 08:56:36 +02:00
|
|
|
query.WhereCriteria->Set(GetType()->GetIDColumn(), GetObject());
|
2014-11-08 21:17:16 +01:00
|
|
|
query.Object = this;
|
2013-08-02 15:45:50 +02:00
|
|
|
query.StatusUpdate = true;
|
2013-08-02 08:56:36 +02:00
|
|
|
OnQuery(query);
|
2013-07-24 10:55:04 +02:00
|
|
|
|
|
|
|
m_LastStatusUpdate = Utility::GetTime();
|
2013-07-25 08:30:02 +02:00
|
|
|
|
|
|
|
OnStatusUpdate();
|
2013-07-24 10:55:04 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
void DbObject::SendVarsConfigUpdateHeavy(void)
|
2014-04-15 17:33:56 +02:00
|
|
|
{
|
2015-08-15 20:28:05 +02:00
|
|
|
ConfigObject::Ptr obj = GetObject();
|
2014-04-15 17:33:56 +02:00
|
|
|
|
2014-05-12 16:45:25 +02:00
|
|
|
CustomVarObject::Ptr custom_var_object = dynamic_pointer_cast<CustomVarObject>(obj);
|
|
|
|
|
|
|
|
if (!custom_var_object)
|
|
|
|
return;
|
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
std::vector<DbQuery> queries;
|
|
|
|
|
|
|
|
DbQuery query1;
|
|
|
|
query1.Table = "customvariables";
|
|
|
|
query1.Type = DbQueryDelete;
|
|
|
|
query1.Category = DbCatConfig;
|
|
|
|
query1.WhereCriteria = new Dictionary();
|
|
|
|
query1.WhereCriteria->Set("object_id", obj);
|
|
|
|
|
|
|
|
queries.push_back(query1);
|
|
|
|
|
|
|
|
DbQuery query2;
|
|
|
|
query2.Table = "customvariablestatus";
|
|
|
|
query2.Type = DbQueryDelete;
|
|
|
|
query2.Category = DbCatConfig;
|
|
|
|
query2.WhereCriteria = new Dictionary();
|
|
|
|
query2.WhereCriteria->Set("object_id", obj);
|
|
|
|
|
|
|
|
queries.push_back(query2);
|
|
|
|
|
2014-05-12 16:45:25 +02:00
|
|
|
Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(custom_var_object);
|
2014-04-15 17:33:56 +02:00
|
|
|
|
|
|
|
if (vars) {
|
|
|
|
ObjectLock olock (vars);
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Dictionary::Pair& kv : vars) {
|
2014-11-02 07:22:00 +01:00
|
|
|
if (kv.first.IsEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
String value;
|
2014-11-04 12:18:07 +01:00
|
|
|
int is_json = 0;
|
2014-11-02 07:22:00 +01:00
|
|
|
|
2014-11-04 12:18:07 +01:00
|
|
|
if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>()) {
|
|
|
|
value = JsonEncode(kv.second);
|
|
|
|
is_json = 1;
|
|
|
|
} else
|
2014-11-02 07:22:00 +01:00
|
|
|
value = kv.second;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr fields = new Dictionary();
|
2014-11-02 07:22:00 +01:00
|
|
|
fields->Set("varname", kv.first);
|
|
|
|
fields->Set("varvalue", value);
|
2014-11-04 12:18:07 +01:00
|
|
|
fields->Set("is_json", is_json);
|
2014-11-02 07:22:00 +01:00
|
|
|
fields->Set("config_type", 1);
|
|
|
|
fields->Set("object_id", obj);
|
|
|
|
fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
DbQuery query3;
|
|
|
|
query3.Table = "customvariables";
|
|
|
|
query3.Type = DbQueryInsert;
|
|
|
|
query3.Category = DbCatConfig;
|
|
|
|
query3.Fields = fields;
|
2015-09-24 11:45:44 +02:00
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
queries.push_back(query3);
|
2014-04-15 17:33:56 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-14 22:24:51 +02:00
|
|
|
|
|
|
|
OnMultipleQueries(queries);
|
2014-04-15 17:33:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DbObject::SendVarsStatusUpdate(void)
|
|
|
|
{
|
2015-08-15 20:28:05 +02:00
|
|
|
ConfigObject::Ptr obj = GetObject();
|
2014-04-15 17:33:56 +02:00
|
|
|
|
2014-05-12 16:45:25 +02:00
|
|
|
CustomVarObject::Ptr custom_var_object = dynamic_pointer_cast<CustomVarObject>(obj);
|
|
|
|
|
|
|
|
if (!custom_var_object)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Dictionary::Ptr vars = CompatUtility::GetCustomAttributeConfig(custom_var_object);
|
2014-04-15 17:33:56 +02:00
|
|
|
|
|
|
|
if (vars) {
|
2016-07-12 11:44:36 +02:00
|
|
|
std::vector<DbQuery> queries;
|
2014-04-15 17:33:56 +02:00
|
|
|
ObjectLock olock (vars);
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Dictionary::Pair& kv : vars) {
|
2014-11-04 12:18:07 +01:00
|
|
|
if (kv.first.IsEmpty())
|
2014-11-02 07:22:00 +01:00
|
|
|
continue;
|
|
|
|
|
2014-11-04 12:18:07 +01:00
|
|
|
String value;
|
|
|
|
int is_json = 0;
|
|
|
|
|
|
|
|
if (kv.second.IsObjectType<Array>() || kv.second.IsObjectType<Dictionary>()) {
|
|
|
|
value = JsonEncode(kv.second);
|
|
|
|
is_json = 1;
|
|
|
|
} else
|
|
|
|
value = kv.second;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr fields = new Dictionary();
|
2014-11-04 12:18:07 +01:00
|
|
|
fields->Set("varname", kv.first);
|
|
|
|
fields->Set("varvalue", value);
|
|
|
|
fields->Set("is_json", is_json);
|
2014-11-02 07:22:00 +01:00
|
|
|
fields->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime()));
|
|
|
|
fields->Set("object_id", obj);
|
|
|
|
fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
|
|
|
|
|
|
|
DbQuery query;
|
|
|
|
query.Table = "customvariablestatus";
|
|
|
|
query.Type = DbQueryInsert | DbQueryUpdate;
|
|
|
|
query.Category = DbCatState;
|
|
|
|
query.Fields = fields;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
query.WhereCriteria = new Dictionary();
|
2014-11-02 07:22:00 +01:00
|
|
|
query.WhereCriteria->Set("object_id", obj);
|
2015-09-24 11:45:44 +02:00
|
|
|
query.WhereCriteria->Set("varname", kv.first);
|
2014-11-02 07:22:00 +01:00
|
|
|
|
2016-07-12 11:44:36 +02:00
|
|
|
queries.push_back(query);
|
2014-04-15 17:33:56 +02:00
|
|
|
}
|
2016-07-12 11:44:36 +02:00
|
|
|
|
|
|
|
OnMultipleQueries(queries);
|
2014-04-15 17:33:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-24 10:55:04 +02:00
|
|
|
double DbObject::GetLastConfigUpdate(void) const
|
|
|
|
{
|
|
|
|
return m_LastConfigUpdate;
|
|
|
|
}
|
|
|
|
|
|
|
|
double DbObject::GetLastStatusUpdate(void) const
|
|
|
|
{
|
|
|
|
return m_LastStatusUpdate;
|
|
|
|
}
|
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
void DbObject::OnConfigUpdateHeavy(void)
|
|
|
|
{
|
|
|
|
/* Default handler does nothing. */
|
|
|
|
}
|
|
|
|
|
|
|
|
void DbObject::OnConfigUpdateLight(void)
|
2013-07-25 08:30:02 +02:00
|
|
|
{
|
|
|
|
/* Default handler does nothing. */
|
|
|
|
}
|
|
|
|
|
|
|
|
void DbObject::OnStatusUpdate(void)
|
|
|
|
{
|
|
|
|
/* Default handler does nothing. */
|
|
|
|
}
|
|
|
|
|
2015-08-15 20:28:05 +02:00
|
|
|
DbObject::Ptr DbObject::GetOrCreateByObject(const ConfigObject::Ptr& object)
|
2013-07-05 09:37:04 +02:00
|
|
|
{
|
2015-03-02 16:20:22 +01:00
|
|
|
boost::mutex::scoped_lock lock(GetStaticMutex());
|
|
|
|
|
2014-11-13 11:23:57 +01:00
|
|
|
DbObject::Ptr dbobj = object->GetExtension("DbObject");
|
2013-07-05 09:37:04 +02:00
|
|
|
|
|
|
|
if (dbobj)
|
|
|
|
return dbobj;
|
|
|
|
|
2016-08-15 14:39:33 +02:00
|
|
|
DbType::Ptr dbtype = DbType::GetByName(object->GetReflectionType()->GetName());
|
2013-07-05 09:37:04 +02:00
|
|
|
|
|
|
|
if (!dbtype)
|
|
|
|
return DbObject::Ptr();
|
|
|
|
|
2013-07-17 11:29:51 +02:00
|
|
|
Service::Ptr service;
|
|
|
|
String name1, name2;
|
|
|
|
|
|
|
|
service = dynamic_pointer_cast<Service>(object);
|
|
|
|
|
|
|
|
if (service) {
|
|
|
|
Host::Ptr host = service->GetHost();
|
|
|
|
|
|
|
|
name1 = service->GetHost()->GetName();
|
|
|
|
name2 = service->GetShortName();
|
|
|
|
} else {
|
2016-08-15 14:39:33 +02:00
|
|
|
if (object->GetReflectionType() == CheckCommand::TypeInstance ||
|
|
|
|
object->GetReflectionType() == EventCommand::TypeInstance ||
|
|
|
|
object->GetReflectionType() == NotificationCommand::TypeInstance) {
|
2014-05-12 14:30:15 +02:00
|
|
|
Command::Ptr command = dynamic_pointer_cast<Command>(object);
|
|
|
|
name1 = CompatUtility::GetCommandName(command);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
name1 = object->GetName();
|
2013-07-17 11:29:51 +02:00
|
|
|
}
|
|
|
|
|
2013-07-24 10:55:04 +02:00
|
|
|
dbobj = dbtype->GetOrCreateObjectByName(name1, name2);
|
2013-07-05 09:37:04 +02:00
|
|
|
|
2015-03-02 16:20:22 +01:00
|
|
|
dbobj->SetObject(object);
|
|
|
|
object->SetExtension("DbObject", dbobj);
|
2013-07-05 09:37:04 +02:00
|
|
|
|
|
|
|
return dbobj;
|
|
|
|
}
|
|
|
|
|
2015-08-15 20:28:05 +02:00
|
|
|
void DbObject::StateChangedHandler(const ConfigObject::Ptr& object)
|
2013-07-24 10:55:04 +02:00
|
|
|
{
|
|
|
|
DbObject::Ptr dbobj = GetOrCreateByObject(object);
|
|
|
|
|
|
|
|
if (!dbobj)
|
|
|
|
return;
|
|
|
|
|
2014-03-20 15:41:45 +01:00
|
|
|
dbobj->SendStatusUpdate();
|
2013-07-24 10:55:04 +02:00
|
|
|
}
|
2014-04-15 17:33:56 +02:00
|
|
|
|
2014-05-12 16:45:25 +02:00
|
|
|
void DbObject::VarsChangedHandler(const CustomVarObject::Ptr& object)
|
2014-04-15 17:33:56 +02:00
|
|
|
{
|
|
|
|
DbObject::Ptr dbobj = GetOrCreateByObject(object);
|
|
|
|
|
|
|
|
if (!dbobj)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dbobj->SendVarsStatusUpdate();
|
|
|
|
}
|
2015-03-02 16:20:22 +01:00
|
|
|
|
2015-09-15 11:59:09 +02:00
|
|
|
void DbObject::VersionChangedHandler(const ConfigObject::Ptr& object)
|
|
|
|
{
|
|
|
|
DbObject::Ptr dbobj = DbObject::GetOrCreateByObject(object);
|
|
|
|
|
|
|
|
if (dbobj) {
|
2016-08-14 22:24:51 +02:00
|
|
|
Dictionary::Ptr configFields = dbobj->GetConfigFields();
|
|
|
|
String configHash = dbobj->CalculateConfigHash(configFields);
|
|
|
|
configFields->Set("config_hash", configHash);
|
|
|
|
|
|
|
|
dbobj->SendConfigUpdateHeavy(configFields);
|
2015-09-15 11:59:09 +02:00
|
|
|
dbobj->SendStatusUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 16:20:22 +01:00
|
|
|
boost::mutex& DbObject::GetStaticMutex(void)
|
|
|
|
{
|
|
|
|
static boost::mutex mutex;
|
|
|
|
return mutex;
|
|
|
|
}
|