Function Callback with a Simple Button Example - XBH-66

This commit is contained in:
Justin Hammond 2015-02-02 22:44:54 +08:00
parent c3913961c9
commit cfcb72f730
4 changed files with 219 additions and 138 deletions

View file

@ -297,12 +297,8 @@ public:
list_const_iterator iter;
VarList_t map;
std::cout << Var << std::endl;
std::cout << name.toStdString() << std::endl;
for (iter = Var->getListIterBegin(name.toStdString(), pos); iter != Var->getListIterEnd(name.toStdString(), pos); ++iter) {
std::cout << (*iter).first << " " << (*iter).second.c_str() << std::endl;
map.insert((*iter).first, (*iter).second.c_str());
std::cout << "done" << std::endl;
}
return QVariant::fromValue<VarList_t>(map);
}
@ -370,7 +366,7 @@ public:
QVariant getValue(QString name, int pos = 0);
VarStorage setValue(VarStorage, QString, QVariant, int pos = 0);
QVariant getListOptions(QString name, int pos = 0);
int getRealType(QString name);
t_ConfigType getRealType(QString name);
int getType(QString name);
int getType(QString name, QString element);
QString getName(QString name);

View file

@ -91,6 +91,8 @@ Q_SIGNALS:
void delDeviceConfig(QString , QString );
void delDeviceVar(QString , QString );
void StateChange(State_e);
void configCallback(QString, QString, VarStorage);
void valCallback(QString, QString, VarStorage);
public Q_SLOTS:
void sendMessage(MessageBus);
private Q_SLOTS:

View file

@ -264,6 +264,7 @@ void DeviceModel_t::updateDeviceConfig(const VarStorage &device) {
}
void DeviceModel_t::addDeviceVarDescriptors(const std::string &device, const VarStorage &cd) {
Q_UNUSED(cd);
QModelIndexList Items = this->match(this->index(0, 0, QModelIndex()), (int) SerialRole, QString::fromStdString(device), 2, Qt::MatchRecursive);
if (Items.count() <= 0) {
qWarning() << "Can't find Device in match list for Model";
@ -276,6 +277,7 @@ void DeviceModel_t::addDeviceVarDescriptors(const std::string &device, const Var
}
}
void DeviceModel_t::addDeviceConfigDescriptors(const std::string &device, const VarStorage &cd) {
Q_UNUSED(cd);
QModelIndexList Items = this->match(this->index(0, 0, QModelIndex()), (int) SerialRole, QString::fromStdString(device), 2, Qt::MatchRecursive);
if (Items.count() <= 0) {
qWarning() << "Can't find Device in match list for Model";
@ -288,6 +290,7 @@ void DeviceModel_t::addDeviceConfigDescriptors(const std::string &device, const
}
}
void DeviceModel_t::delDeviceVarDescriptors(const std::string &device, const std::string &field) {
Q_UNUSED(field);
QModelIndexList Items = this->match(this->index(0, 0, QModelIndex()), (int) SerialRole, QString::fromStdString(device), 2, Qt::MatchRecursive);
if (Items.count() <= 0) {
qWarning() << "Can't find Device in match list for Model";
@ -301,6 +304,7 @@ void DeviceModel_t::delDeviceVarDescriptors(const std::string &device, const std
}
void DeviceModel_t::delDeviceConfigDescriptors(const std::string &device, const std::string &field) {
Q_UNUSED(field);
QModelIndexList Items = this->match(this->index(0, 0, QModelIndex()), (int) SerialRole, QString::fromStdString(device), 2, Qt::MatchRecursive);
if (Items.count() <= 0) {
qWarning() << "Can't find Device in match list for Model";
@ -660,50 +664,48 @@ VarStorageHelper_t::~VarStorageHelper_t() {
QString VarStorageHelper_t::getSerial() {
return this->Serial;
}
int VarStorageHelper_t::getRealType(QString name) {
t_ConfigType VarStorageHelper_t::getRealType(QString name) {
HashVals hv;
//std::cout << "GetType" << this->descriptor << std::endl;
if (!this->descriptor->getHashValue(name.toStdString(), hv)) {
qWarning() << "Couldn't get ConfigDescriptor for getType:" << name;
return ST_INVALID;
return TC_NULL;
}
return boost::get<int>(hv["Type"]);
return (t_ConfigType)boost::get<int>(hv["Type"]);
}
int VarStorageHelper_t::getType(QString name) {
HashVals hv;
//std::cout << "GetType" << this->descriptor << std::endl;
if (!this->descriptor->getHashValue(name.toStdString(), hv)) {
qWarning() << "Couldn't get ConfigDescriptor for getType:" << name;
return QVariant::Invalid;
}
//std::cout << "GetType: " << hv << std::endl;
switch (boost::get<int>(hv["Type"])) {
case ST_STRING:
switch (this->getRealType(name)) {
case TC_STRING:
return QVariant::String;
case ST_INT:
case TC_INT:
return QVariant::Int;
case ST_LONG:
case TC_LONG:
return QVariant::LongLong;
case ST_LONGLONG:
case TC_LONGLONG:
return QVariant::LongLong;
case ST_FLOAT:
case TC_FLOAT:
return QVariant::Double;
case ST_HASH:
case TC_HASH:
return qMetaTypeId<HashVals>();
case ST_BOOL:
case TC_BOOL:
return QVariant::Bool;
case ST_DATETIME:
case TC_DATETIME:
return QVariant::DateTime;
case ST_VARSTORAGE:
case TC_VARSTORAGE:
return QMetaType::type("VarStorage");
case ST_LIST:
case TC_LIST:
return QMetaType::type("VarList_t");
case TC_CALLBACK:
return QMetaType::type("VarStorage");
case ST_INVALID:
case TC_IPADDR:
return QVariant::Invalid;
}
qWarning() << "Unhandled type in getType: " << boost::get<int>(hv["Type"]);
qWarning() << "Unhandled type in getType: " << this->getRealType(name);
return QVariant::Invalid;
}
@ -833,17 +835,17 @@ QVariant VarStorageHelper_t::getValue(QString name, int pos) {
switch (this->getRealType(fieldName)) {
case ST_STRING:
case TC_STRING:
return QVariant(VSE.getString(val, fieldName, pos));
case ST_INT:
case TC_INT:
return QVariant(VSE.getInt(val, fieldName, pos));
case ST_LONG:
case TC_LONG:
return QVariant(VSE.getLong(val, fieldName, pos));
case ST_LONGLONG:
case TC_LONGLONG:
return QVariant(VSE.getLongLong(val, fieldName, pos));
case ST_FLOAT:
case TC_FLOAT:
return QVariant(VSE.getFloat(val, fieldName, pos));
case ST_HASH:
case TC_HASH:
/* HASH's have to have : as a field Seperator
*/
if (name.contains(':')) {
@ -852,15 +854,18 @@ QVariant VarStorageHelper_t::getValue(QString name, int pos) {
//qWarning() << "Invalid fieldName for Hash Container: " << name;
return QVariant(VSE.getHash(val, fieldName, pos));
}
case ST_BOOL:
case TC_BOOL:
return QVariant(VSE.getBool(val, fieldName, pos));
case ST_DATETIME:
case TC_DATETIME:
return QVariant(QDateTime::fromString(VSE.getTime(val, fieldName, pos), Qt::ISODate));
case ST_VARSTORAGE:
case TC_VARSTORAGE:
return QVariant(VSE.getVarStorage(val, fieldName, pos));
case ST_LIST:
case TC_LIST:
return QVariant(VSE.getListSelection(val, fieldName, pos));
case ST_INVALID:
case TC_CALLBACK:
return QVariant(VSE.getVarStorage(val, fieldName, pos));
case TC_IPADDR:
case TC_NULL:
qWarning() << "Unknown Type Requested from getValue(name): " << name << " Type: " << val->getType(fieldName.toStdString());
qWarning() << "fieldName: " << fieldName << ", Container: " << containerName << ", VarStorage: ";
val->printToStream();
@ -914,26 +919,30 @@ qlonglong VarStorageHelper_t::getMax(QString name) {
QVariant VarStorageHelper_t::getDefault(QString name) {
HashVals vals;
try {
if (this->descriptor->getHashValue(name.toStdString(), vals)) {
switch (boost::get<int>(vals["Type"])) {
case ST_STRING:
case ST_DATETIME:
switch (this->getRealType(name)) {
case TC_STRING:
case TC_DATETIME:
return QVariant((char *) boost::get<std::string>(vals["defaultstr"]).c_str());
case ST_INT:
case ST_LONG:
case ST_LONGLONG:
case ST_FLOAT:
case ST_BOOL:
case ST_LIST:
case TC_INT:
case TC_LONG:
case TC_LONGLONG:
case TC_FLOAT:
case TC_BOOL:
case TC_LIST:
return QVariant((long long) boost::get<long long>(vals["defaultnum"]));
case ST_HASH:
case ST_VARSTORAGE:
case ST_INVALID:
qWarning() << "Unsupported Type Requested from getDefault(name): " << name;
return QVariant();
/* for Hash, VarStorage and Callback Types, return empty values */
case TC_HASH: {
HashVals vals;
return QVariant::fromValue<HashVals>(vals);
}
} else {
qWarning() << name << " does not exist in Descriptors (getDescription())";
case TC_VARSTORAGE:
case TC_CALLBACK: {
VarContainerFactory(vals1);
return QVariant::fromValue<VarStorage>(vals1);
}
case TC_IPADDR:
case TC_NULL:
qWarning() << "Unsupported Type Requested from getDefault(name): " << name;
return QVariant();
}
} catch (std::exception &e) {
@ -991,39 +1000,39 @@ VarStorage VarStorageHelper_t::setValue(VarStorage updateVals, QString field, QV
}
switch (this->getRealType(field)) {
case ST_STRING:
case TC_STRING:
updateVals->replaceStringValue(field.toStdString(), data.toString().toStdString(), pos);
break;
case ST_INT:
case TC_INT:
updateVals->replaceIntValue(field.toStdString(), data.toInt(), pos);
break;
case ST_LONG:
case TC_LONG:
updateVals->replaceLongValue(field.toStdString(), data.toLongLong(), pos);
break;
case ST_LONGLONG:
case TC_LONGLONG:
updateVals->replaceLongValue(field.toStdString(), data.toLongLong(), pos);
break;
case ST_FLOAT:
case TC_FLOAT:
updateVals->replaceFloatValue(field.toStdString(), data.toFloat(), pos);
break;
case ST_HASH:
case TC_HASH:
updateVals->replaceHashValue(field.toStdString(), data.value<HashVals>(), pos);
break;
case ST_BOOL:
case TC_BOOL:
updateVals->replaceBoolValue(field.toStdString(), data.toBool(), pos);
break;
case ST_DATETIME: {
case TC_DATETIME: {
boost::posix_time::ptime dt;
dt = boost::posix_time::from_iso_string(data.toDateTime().toString(Qt::ISODate).toStdString());
updateVals->replaceTimeValue(field.toStdString(), dt, pos);
break;
}
case ST_VARSTORAGE: {
case TC_VARSTORAGE: {
VarStorage vars = data.value<VarStorage>();
updateVals->replaceVarStorageValue(field.toStdString(), vars, pos);
break;
}
case ST_LIST: {
case TC_LIST: {
if (data.type() == QVariant::Int) {
updateVals->setListSelectedValue(field.toStdString(), data.toUInt(), pos);
} else if (data.userType() == QMetaType::type("VarList_t")) {
@ -1031,7 +1040,13 @@ VarStorage VarStorageHelper_t::setValue(VarStorage updateVals, QString field, QV
}
break;
}
case ST_INVALID:
case TC_CALLBACK: {
VarStorage vars = data.value<VarStorage>();
updateVals->replaceVarStorageValue(field.toStdString(), vars, pos);
break;
}
case TC_NULL:
case TC_IPADDR:
qDebug() << " SetValue Called on a ST_INVALID Field";
break;
}

View file

@ -1,24 +1,24 @@
/* controlpanel - QtiHanClient.cpp
** Copyright (c) 2010 Justin Hammond
**
** 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
** USA
**
** controlpanel SVN Identification:
** $Rev$
*/
** Copyright (c) 2010 Justin Hammond
**
** 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
** USA
**
** controlpanel SVN Identification:
** $Rev$
*/
/** @file QtiHanClient.cpp
* @brief
@ -202,6 +202,8 @@ void QtiHanClient::HandleDeviceUpdate(MessageBus msg) {
std::string deviceID;
QVector<QString> updatedfields;
VarStorage vals;
VarStorage valsdescriptor;
bool compare = true;
deviceID = msg->getSource();
#if 0
if (!item->getStringValue(SRVCAP_ENDPT_SERIAL, deviceID)) {
@ -225,6 +227,11 @@ void QtiHanClient::HandleDeviceUpdate(MessageBus msg) {
qWarning("Can't get End Point Vars from GloablDevices");
return;
}
if (GlobalDevices[deviceID]->getVarStorageValue(SRVCAP_ENDPT_VARS_DESC, valsdescriptor) == false) {
qWarning("Can't get End Point Var Descriptors from GloablDevices");
return;
}
//cout << "New: " << std::endl;
//newvals->printToStream();
//cout << "Old: " << std::endl;
@ -234,15 +241,39 @@ void QtiHanClient::HandleDeviceUpdate(MessageBus msg) {
//qDebug() << "New Fields:";
for (std::size_t i = 0; i < newfields->size(); i++) {
//std::cout << newfields->at(i) << std::endl;
/* check if the NewField is a Callback */
HashVals desc;
if (valsdescriptor->getHashValue(newfields->at(i), desc)) {
try {
if ((t_ConfigType)boost::get<int>(desc["Type"]) == TC_CALLBACK) {
VarStorage cb;
if (newvals->getVarStorageValue(newfields->at(i), cb)) {
qDebug() << "Got Config Callback for Device " << deviceID.c_str() << " on Field " << QString::fromStdString(newfields->at(i));
emit configCallback(deviceID.c_str(), QString::fromStdString(newfields->at(i)), cb);
} else {
qWarning() << "Couldn't retrieve Callback Value from Update Message";
}
continue;
}
} catch (std::exception &e) {
qWarning() << "Exception in HandleDeviceUpdate: " << e.what();
continue;
}
} else {
qWarning() << "Couldn't Retrieve VarValDescriptor for Field " << QString::fromStdString(newfields->at(i));
continue;
}
/* confirm exists in oldfields */
if (vals->getSize(newfields->at(i)) <= 0) {
qDebug() << "New Field in Update Message";
/* do something */
compare = false;
}
StoredType_t newtype = newvals->getType(newfields->at(i));
if (newtype != vals->getType(newfields->at(i))) {
if ((compare) && (newtype != vals->getType(newfields->at(i)))) {
/* values do not match type */
qWarning() << "Updated Field is not the same type as existing field";
qWarning() << "Updated Field " << QString::fromStdString(newfields->at(i)) << " is not the same type as existing field";
qWarning() << "NewType: " << newtype << " Existing Type: " << vals->getType(newfields->at(i));
continue;
}
@ -255,11 +286,11 @@ void QtiHanClient::HandleDeviceUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated String Value";
continue;
}
if (!vals->getStringValue(newfields->at(i), oldval, j)) {
if ((compare) && (!vals->getStringValue(newfields->at(i), oldval, j))) {
qWarning() << "Couldn't get Old String Value";
continue;
}
if (newval != oldval) {
if ((!compare) || (newval != oldval)) {
vals->replaceStringValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str());
@ -273,11 +304,11 @@ void QtiHanClient::HandleDeviceUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated Int Value";
continue;
}
if (!vals->getIntValue(newfields->at(i), oldval, j)) {
if ((compare) && (!vals->getIntValue(newfields->at(i), oldval, j))) {
qWarning() << "Couldn't get Old Int Value";
continue;
}
if (newval != oldval) {
if ((!compare) || (newval != oldval)) {
vals->replaceIntValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str());
@ -291,11 +322,11 @@ void QtiHanClient::HandleDeviceUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated Long Value";
continue;
}
if (!vals->getLongValue(newfields->at(i), oldval, j)) {
if ((compare) && (!vals->getLongValue(newfields->at(i), oldval, j))) {
qWarning() << "Couldn't get Old Long Value";
continue;
}
if (newval != oldval) {
if ((!compare) || (newval != oldval)) {
vals->replaceLongValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str());
@ -309,11 +340,11 @@ void QtiHanClient::HandleDeviceUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated Long Long Value";
continue;
}
if (!vals->getLongLongValue(newfields->at(i), oldval, j)) {
if ((compare) && (!vals->getLongLongValue(newfields->at(i), oldval, j))) {
qWarning() << "Couldn't get Old Long Long Value";
continue;
}
if (newval != oldval) {
if ((!compare) || (newval != oldval)) {
vals->replaceLongLongValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str());
@ -327,11 +358,11 @@ void QtiHanClient::HandleDeviceUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated Float Value";
continue;
}
if (!vals->getFloatValue(newfields->at(i), oldval, j)) {
if ((compare) && (!vals->getFloatValue(newfields->at(i), oldval, j))) {
qWarning() << "Couldn't get Old Float Value";
continue;
}
if (newval != oldval) {
if ((!compare) || (newval != oldval)) {
vals->replaceFloatValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str());
@ -345,11 +376,11 @@ void QtiHanClient::HandleDeviceUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated Bool Value";
continue;
}
if (!vals->getBoolValue(newfields->at(i), oldval, j)) {
if ((compare) && (!vals->getBoolValue(newfields->at(i), oldval, j))) {
qWarning() << "Couldn't get Old Bool Value";
continue;
}
if (newval != oldval) {
if ((!compare) || (newval != oldval)) {
vals->replaceBoolValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str());
@ -363,11 +394,11 @@ void QtiHanClient::HandleDeviceUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated Bool Value";
continue;
}
if (!vals->getTimeValue(newfields->at(i), oldval, j)) {
if ((compare) && (!vals->getTimeValue(newfields->at(i), oldval, j))) {
qWarning() << "Couldn't get Old Bool Value";
continue;
}
if (newval != oldval) {
if ((!compare) || (newval != oldval)) {
vals->replaceTimeValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str());
@ -384,6 +415,7 @@ void QtiHanClient::HandleDeviceUpdate(MessageBus msg) {
vals->replaceVarStorageValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str());
}
break;
case ST_HASH: {
@ -418,13 +450,14 @@ void QtiHanClient::HandleDeviceUpdate(MessageBus msg) {
}
}
qDebug() << "Updated Fields:";
if (updatedfields.size() == 0)
return;
qDebug() << "Updated Var Fields:";
for (int i = 0; i < updatedfields.size(); i++) {
qDebug() << qPrintable(updatedfields.at(i));
}
//newvals->addStringValue(SRVCAP_ENDPT_SERIAL, deviceID);
//GlobalDevices[deviceID]->replaceVarStorageValue(SRVCAP_ENDPT_VARS, newvals);
this->tdm->updateDeviceVars(newvals);
emit updateValues(deviceID.c_str(), updatedfields);
}
@ -434,6 +467,8 @@ void QtiHanClient::HandleDeviceConfigUpdate(MessageBus msg) {
std::string deviceID = msg->getSource();
QVector<QString> updatedfields;
VarStorage vals;
VarStorage valsdescriptor;
bool compare = true;
if (!GlobalDevices.contains(deviceID)) {
qWarning() << "Can't find Device in DeviceMap for HandleDeviceConfigUpdate";
@ -457,6 +492,10 @@ void QtiHanClient::HandleDeviceConfigUpdate(MessageBus msg) {
qWarning("Can't get End Point Config from GloablDevices");
return;
}
if (GlobalDevices[deviceID]->getVarStorageValue(SRVCAP_ENDPT_CONFIG_DESC, valsdescriptor) == false) {
qWarning("Can't get End Point Var Descriptors from GloablDevices");
return;
}
//cout << "New: " << std::endl;
//newvals->printToStream();
//cout << "Old: " << std::endl;
@ -467,14 +506,41 @@ void QtiHanClient::HandleDeviceConfigUpdate(MessageBus msg) {
for (std::size_t i = 0; i < newfields->size(); i++) {
//std::cout << newfields->at(i) << std::endl;
/* confirm exists in oldfields */
/* check if the NewField is a Callback */
HashVals desc;
if (valsdescriptor->getHashValue(newfields->at(i), desc)) {
try {
if ((t_ConfigType)boost::get<int>(desc["Type"]) == TC_CALLBACK) {
VarStorage cb;
if (newvals->getVarStorageValue(newfields->at(i), cb)) {
qDebug() << "Got Config Callback for Device " << deviceID.c_str() << " on Field " << QString::fromStdString(newfields->at(i));
emit configCallback(deviceID.c_str(), QString::fromStdString(newfields->at(i)), cb);
} else {
qWarning() << "Couldn't retrieve Callback Value from Update Message";
}
continue;
}
} catch (std::exception &e) {
qWarning() << "Exception in HandleDeviceUpdate: " << e.what();
continue;
}
} else {
qWarning() << "Couldn't Retrieve ConfigVarDescriptor for Field " << QString::fromStdString(newfields->at(i));
continue;
}
if (vals->getSize(newfields->at(i)) <= 0) {
qDebug() << "New Field in HandleDeviceConfigUpdate";
/* do something */
/* just add it to the updates */
compare = false;
}
StoredType_t newtype = newvals->getType(newfields->at(i));
if (newtype != vals->getType(newfields->at(i))) {
if ((compare) && (newtype != vals->getType(newfields->at(i)))) {
/* values do not match type */
qWarning() << "Updated Field is not the same type as existing field";
qWarning() << "Updated Field " << QString::fromStdString(newfields->at(i)) << " is not the same type as existing field";
qWarning() << "NewType: " << newtype << " Existing Type: " << vals->getType(newfields->at(i));
continue;
}
@ -487,11 +553,11 @@ void QtiHanClient::HandleDeviceConfigUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated String Value";
continue;
}
if (!vals->getStringValue(newfields->at(i), oldval, j)) {
if ((compare) && (!vals->getStringValue(newfields->at(i), oldval, j))) {
qWarning() << "Couldn't get Old String Value";
continue;
}
if (newval != oldval) {
if ((!compare) || (newval != oldval)) {
vals->replaceStringValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str());
@ -505,11 +571,11 @@ void QtiHanClient::HandleDeviceConfigUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated Int Value";
continue;
}
if (!vals->getIntValue(newfields->at(i), oldval, j)) {
if ((compare) && (!vals->getIntValue(newfields->at(i), oldval, j))) {
qWarning() << "Couldn't get Old Int Value";
continue;
}
if (newval != oldval) {
if ((!compare) || (newval != oldval)) {
vals->replaceIntValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str());
@ -523,11 +589,11 @@ void QtiHanClient::HandleDeviceConfigUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated Long Value";
continue;
}
if (!vals->getLongValue(newfields->at(i), oldval, j)) {
if ((compare) && (!vals->getLongValue(newfields->at(i), oldval, j))) {
qWarning() << "Couldn't get Old Long Value";
continue;
}
if (newval != oldval) {
if ((!compare) || (newval != oldval)) {
vals->replaceLongValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str());
@ -541,11 +607,11 @@ void QtiHanClient::HandleDeviceConfigUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated Long Long Value";
continue;
}
if (!vals->getLongLongValue(newfields->at(i), oldval, j)) {
if ((compare) && (!vals->getLongLongValue(newfields->at(i), oldval, j))) {
qWarning() << "Couldn't get Old Long Long Value";
continue;
}
if (newval != oldval) {
if ((!compare) || (newval != oldval)) {
vals->replaceLongLongValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str());
@ -559,11 +625,11 @@ void QtiHanClient::HandleDeviceConfigUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated Float Value";
continue;
}
if (!vals->getFloatValue(newfields->at(i), oldval, j)) {
if ((compare) && (!vals->getFloatValue(newfields->at(i), oldval, j))) {
qWarning() << "Couldn't get Old Float Value";
continue;
}
if (newval != oldval) {
if ((!compare) || (newval != oldval)) {
vals->replaceFloatValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str());
@ -577,11 +643,11 @@ void QtiHanClient::HandleDeviceConfigUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated Bool Value";
continue;
}
if (!vals->getBoolValue(newfields->at(i), oldval, j)) {
if ((compare) && (!vals->getBoolValue(newfields->at(i), oldval, j))) {
qWarning() << "Couldn't get Old Bool Value";
continue;
}
if (newval != oldval) {
if ((!compare) || (newval != oldval)) {
vals->replaceBoolValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str());
@ -595,11 +661,11 @@ void QtiHanClient::HandleDeviceConfigUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated Bool Value";
continue;
}
if (!vals->getTimeValue(newfields->at(i), oldval, j)) {
if ((compare) && (!vals->getTimeValue(newfields->at(i), oldval, j))) {
qWarning() << "Couldn't get Old Bool Value";
continue;
}
if (newval != oldval) {
if ((!compare) || (newval != oldval)) {
vals->replaceTimeValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str());
@ -649,6 +715,8 @@ void QtiHanClient::HandleDeviceConfigUpdate(MessageBus msg) {
};
}
}
if (updatedfields.size() == 0)
return;
qDebug() << "Updated Config Fields:";
for (int i = 0; i < updatedfields.size(); i++) {