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; list_const_iterator iter;
VarList_t map; 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) { 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()); map.insert((*iter).first, (*iter).second.c_str());
std::cout << "done" << std::endl;
} }
return QVariant::fromValue<VarList_t>(map); return QVariant::fromValue<VarList_t>(map);
} }
@ -370,7 +366,7 @@ public:
QVariant getValue(QString name, int pos = 0); QVariant getValue(QString name, int pos = 0);
VarStorage setValue(VarStorage, QString, QVariant, int pos = 0); VarStorage setValue(VarStorage, QString, QVariant, int pos = 0);
QVariant getListOptions(QString name, 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);
int getType(QString name, QString element); int getType(QString name, QString element);
QString getName(QString name); QString getName(QString name);

View file

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

View file

@ -1,24 +1,24 @@
/* controlpanel - QtiHanClient.cpp /* controlpanel - QtiHanClient.cpp
** Copyright (c) 2010 Justin Hammond ** Copyright (c) 2010 Justin Hammond
** **
** This program is free software; you can redistribute it and/or modify ** 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 ** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or ** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version. ** (at your option) any later version.
** **
** This program is distributed in the hope that it will be useful, ** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details. ** GNU General Public License for more details.
** **
** You should have received a copy of the GNU General Public License ** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software ** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
** USA ** USA
** **
** controlpanel SVN Identification: ** controlpanel SVN Identification:
** $Rev$ ** $Rev$
*/ */
/** @file QtiHanClient.cpp /** @file QtiHanClient.cpp
* @brief * @brief
@ -62,36 +62,36 @@ QtiHanClient::QtiHanClient(QObject *parent) {
this->mt = new ModelTest(this->tdm, this); this->mt = new ModelTest(this->tdm, this);
QObject::connect(this->mh, SIGNAL(connected()), QObject::connect(this->mh, SIGNAL(connected()),
this, SLOT(HandleConnected())); this, SLOT(HandleConnected()));
QObject::connect(this->mh, SIGNAL(disconnected()), QObject::connect(this->mh, SIGNAL(disconnected()),
this, SLOT(HandleDisconnected())); this, SLOT(HandleDisconnected()));
QObject::connect(this->mh, SIGNAL(error(QString, QAbstractSocket::SocketError)), QObject::connect(this->mh, SIGNAL(error(QString, QAbstractSocket::SocketError)),
this, SLOT(HandleError(QString, QAbstractSocket::SocketError))); this, SLOT(HandleError(QString, QAbstractSocket::SocketError)));
QObject::connect(this->mh, SIGNAL(newEndPt(MessageBus)), QObject::connect(this->mh, SIGNAL(newEndPt(MessageBus)),
this, SLOT(HandleNewDevice(MessageBus))); this, SLOT(HandleNewDevice(MessageBus)));
QObject::connect(this->mh, SIGNAL(delEndPt(MessageBus)), QObject::connect(this->mh, SIGNAL(delEndPt(MessageBus)),
this, SLOT(HandleDelDevice(MessageBus))); this, SLOT(HandleDelDevice(MessageBus)));
QObject::connect(this->mh, SIGNAL(updateValues(MessageBus)), QObject::connect(this->mh, SIGNAL(updateValues(MessageBus)),
this, SLOT(HandleDeviceUpdate(MessageBus))); this, SLOT(HandleDeviceUpdate(MessageBus)));
QObject::connect(this->mh, SIGNAL(updateConfig(MessageBus)), QObject::connect(this->mh, SIGNAL(updateConfig(MessageBus)),
this, SLOT(HandleDeviceConfigUpdate(MessageBus))); this, SLOT(HandleDeviceConfigUpdate(MessageBus)));
QObject::connect(this->mh, SIGNAL(addConfig(MessageBus)), QObject::connect(this->mh, SIGNAL(addConfig(MessageBus)),
this, SLOT(HandleAddConfig(MessageBus))); this, SLOT(HandleAddConfig(MessageBus)));
QObject::connect(this->mh, SIGNAL(addVar(MessageBus)), QObject::connect(this->mh, SIGNAL(addVar(MessageBus)),
this, SLOT(HandleAddVar(MessageBus))); this, SLOT(HandleAddVar(MessageBus)));
QObject::connect(this->mh, SIGNAL(delConfig(MessageBus)), QObject::connect(this->mh, SIGNAL(delConfig(MessageBus)),
this, SLOT(HandleDelConfig(MessageBus))); this, SLOT(HandleDelConfig(MessageBus)));
QObject::connect(this->mh, SIGNAL(delVar(MessageBus)), QObject::connect(this->mh, SIGNAL(delVar(MessageBus)),
this, SLOT(HandleDelVar(MessageBus))); this, SLOT(HandleDelVar(MessageBus)));
QObject::connect(this->mh, SIGNAL(StateChange(State_e)), QObject::connect(this->mh, SIGNAL(StateChange(State_e)),
this, SLOT(HandleStateChange(State_e))); this, SLOT(HandleStateChange(State_e)));
QObject::connect(this->mh, SIGNAL(gotTermTypeMapping(MessageBus)), QObject::connect(this->mh, SIGNAL(gotTermTypeMapping(MessageBus)),
this, SLOT(HandleTermTypeMappings(MessageBus))); this, SLOT(HandleTermTypeMappings(MessageBus)));
QObject::connect(this->tdm, SIGNAL(sendMsg(MessageBus)), QObject::connect(this->tdm, SIGNAL(sendMsg(MessageBus)),
this->mh, SLOT(sendMessage(MessageBus))); this->mh, SLOT(sendMessage(MessageBus)));
QObject::connect(this->mh, SIGNAL(gotMyInfo(MessageBus)), QObject::connect(this->mh, SIGNAL(gotMyInfo(MessageBus)),
this, SLOT(HandleClientInform(MessageBus))); this, SLOT(HandleClientInform(MessageBus)));
this->type = 0; this->type = 0;
this->mh->setFlags(CLNTCAP_FLAG_VARTYPE | CLNTCAP_FLAG_TERMS); this->mh->setFlags(CLNTCAP_FLAG_VARTYPE | CLNTCAP_FLAG_TERMS);
@ -202,6 +202,8 @@ void QtiHanClient::HandleDeviceUpdate(MessageBus msg) {
std::string deviceID; std::string deviceID;
QVector<QString> updatedfields; QVector<QString> updatedfields;
VarStorage vals; VarStorage vals;
VarStorage valsdescriptor;
bool compare = true;
deviceID = msg->getSource(); deviceID = msg->getSource();
#if 0 #if 0
if (!item->getStringValue(SRVCAP_ENDPT_SERIAL, deviceID)) { 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"); qWarning("Can't get End Point Vars from GloablDevices");
return; 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; //cout << "New: " << std::endl;
//newvals->printToStream(); //newvals->printToStream();
//cout << "Old: " << std::endl; //cout << "Old: " << std::endl;
@ -234,15 +241,39 @@ void QtiHanClient::HandleDeviceUpdate(MessageBus msg) {
//qDebug() << "New Fields:"; //qDebug() << "New Fields:";
for (std::size_t i = 0; i < newfields->size(); i++) { for (std::size_t i = 0; i < newfields->size(); i++) {
//std::cout << newfields->at(i) << std::endl; //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 */ /* confirm exists in oldfields */
if (vals->getSize(newfields->at(i)) <= 0) { if (vals->getSize(newfields->at(i)) <= 0) {
qDebug() << "New Field in Update Message"; qDebug() << "New Field in Update Message";
/* do something */ compare = false;
} }
StoredType_t newtype = newvals->getType(newfields->at(i)); 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 */ /* 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)); qWarning() << "NewType: " << newtype << " Existing Type: " << vals->getType(newfields->at(i));
continue; continue;
} }
@ -255,11 +286,11 @@ void QtiHanClient::HandleDeviceUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated String Value"; qWarning() << "Couldn't get updated String Value";
continue; 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"; qWarning() << "Couldn't get Old String Value";
continue; continue;
} }
if (newval != oldval) { if ((!compare) || (newval != oldval)) {
vals->replaceStringValue(newfields->at(i), newval, j); vals->replaceStringValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str())) if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(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"; qWarning() << "Couldn't get updated Int Value";
continue; 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"; qWarning() << "Couldn't get Old Int Value";
continue; continue;
} }
if (newval != oldval) { if ((!compare) || (newval != oldval)) {
vals->replaceIntValue(newfields->at(i), newval, j); vals->replaceIntValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str())) if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(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"; qWarning() << "Couldn't get updated Long Value";
continue; 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"; qWarning() << "Couldn't get Old Long Value";
continue; continue;
} }
if (newval != oldval) { if ((!compare) || (newval != oldval)) {
vals->replaceLongValue(newfields->at(i), newval, j); vals->replaceLongValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str())) if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(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"; qWarning() << "Couldn't get updated Long Long Value";
continue; 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"; qWarning() << "Couldn't get Old Long Long Value";
continue; continue;
} }
if (newval != oldval) { if ((!compare) || (newval != oldval)) {
vals->replaceLongLongValue(newfields->at(i), newval, j); vals->replaceLongLongValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str())) if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(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"; qWarning() << "Couldn't get updated Float Value";
continue; 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"; qWarning() << "Couldn't get Old Float Value";
continue; continue;
} }
if (newval != oldval) { if ((!compare) || (newval != oldval)) {
vals->replaceFloatValue(newfields->at(i), newval, j); vals->replaceFloatValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str())) if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(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"; qWarning() << "Couldn't get updated Bool Value";
continue; 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"; qWarning() << "Couldn't get Old Bool Value";
continue; continue;
} }
if (newval != oldval) { if ((!compare) || (newval != oldval)) {
vals->replaceBoolValue(newfields->at(i), newval, j); vals->replaceBoolValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str())) if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(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"; qWarning() << "Couldn't get updated Bool Value";
continue; 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"; qWarning() << "Couldn't get Old Bool Value";
continue; continue;
} }
if (newval != oldval) { if ((!compare) || (newval != oldval)) {
vals->replaceTimeValue(newfields->at(i), newval, j); vals->replaceTimeValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str())) if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(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); vals->replaceVarStorageValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str())) if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(newfields->at(i).c_str()); updatedfields.push_back(newfields->at(i).c_str());
} }
break; break;
case ST_HASH: { 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++) { for (int i = 0; i < updatedfields.size(); i++) {
qDebug() << qPrintable(updatedfields.at(i)); qDebug() << qPrintable(updatedfields.at(i));
} }
//newvals->addStringValue(SRVCAP_ENDPT_SERIAL, deviceID);
//GlobalDevices[deviceID]->replaceVarStorageValue(SRVCAP_ENDPT_VARS, newvals);
this->tdm->updateDeviceVars(newvals); this->tdm->updateDeviceVars(newvals);
emit updateValues(deviceID.c_str(), updatedfields); emit updateValues(deviceID.c_str(), updatedfields);
} }
@ -434,6 +467,8 @@ void QtiHanClient::HandleDeviceConfigUpdate(MessageBus msg) {
std::string deviceID = msg->getSource(); std::string deviceID = msg->getSource();
QVector<QString> updatedfields; QVector<QString> updatedfields;
VarStorage vals; VarStorage vals;
VarStorage valsdescriptor;
bool compare = true;
if (!GlobalDevices.contains(deviceID)) { if (!GlobalDevices.contains(deviceID)) {
qWarning() << "Can't find Device in DeviceMap for HandleDeviceConfigUpdate"; 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"); qWarning("Can't get End Point Config from GloablDevices");
return; 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; //cout << "New: " << std::endl;
//newvals->printToStream(); //newvals->printToStream();
//cout << "Old: " << std::endl; //cout << "Old: " << std::endl;
@ -467,14 +506,41 @@ void QtiHanClient::HandleDeviceConfigUpdate(MessageBus msg) {
for (std::size_t i = 0; i < newfields->size(); i++) { for (std::size_t i = 0; i < newfields->size(); i++) {
//std::cout << newfields->at(i) << std::endl; //std::cout << newfields->at(i) << std::endl;
/* confirm exists in oldfields */ /* 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) { if (vals->getSize(newfields->at(i)) <= 0) {
qDebug() << "New Field in HandleDeviceConfigUpdate"; qDebug() << "New Field in HandleDeviceConfigUpdate";
/* do something */ /* just add it to the updates */
compare = false;
} }
StoredType_t newtype = newvals->getType(newfields->at(i)); 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 */ /* 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)); qWarning() << "NewType: " << newtype << " Existing Type: " << vals->getType(newfields->at(i));
continue; continue;
} }
@ -487,11 +553,11 @@ void QtiHanClient::HandleDeviceConfigUpdate(MessageBus msg) {
qWarning() << "Couldn't get updated String Value"; qWarning() << "Couldn't get updated String Value";
continue; 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"; qWarning() << "Couldn't get Old String Value";
continue; continue;
} }
if (newval != oldval) { if ((!compare) || (newval != oldval)) {
vals->replaceStringValue(newfields->at(i), newval, j); vals->replaceStringValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str())) if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(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"; qWarning() << "Couldn't get updated Int Value";
continue; 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"; qWarning() << "Couldn't get Old Int Value";
continue; continue;
} }
if (newval != oldval) { if ((!compare) || (newval != oldval)) {
vals->replaceIntValue(newfields->at(i), newval, j); vals->replaceIntValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str())) if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(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"; qWarning() << "Couldn't get updated Long Value";
continue; 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"; qWarning() << "Couldn't get Old Long Value";
continue; continue;
} }
if (newval != oldval) { if ((!compare) || (newval != oldval)) {
vals->replaceLongValue(newfields->at(i), newval, j); vals->replaceLongValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str())) if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(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"; qWarning() << "Couldn't get updated Long Long Value";
continue; 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"; qWarning() << "Couldn't get Old Long Long Value";
continue; continue;
} }
if (newval != oldval) { if ((!compare) || (newval != oldval)) {
vals->replaceLongLongValue(newfields->at(i), newval, j); vals->replaceLongLongValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str())) if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(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"; qWarning() << "Couldn't get updated Float Value";
continue; 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"; qWarning() << "Couldn't get Old Float Value";
continue; continue;
} }
if (newval != oldval) { if ((!compare) || (newval != oldval)) {
vals->replaceFloatValue(newfields->at(i), newval, j); vals->replaceFloatValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str())) if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(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"; qWarning() << "Couldn't get updated Bool Value";
continue; 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"; qWarning() << "Couldn't get Old Bool Value";
continue; continue;
} }
if (newval != oldval) { if ((!compare) || (newval != oldval)) {
vals->replaceBoolValue(newfields->at(i), newval, j); vals->replaceBoolValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str())) if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(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"; qWarning() << "Couldn't get updated Bool Value";
continue; 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"; qWarning() << "Couldn't get Old Bool Value";
continue; continue;
} }
if (newval != oldval) { if ((!compare) || (newval != oldval)) {
vals->replaceTimeValue(newfields->at(i), newval, j); vals->replaceTimeValue(newfields->at(i), newval, j);
if (!updatedfields.contains(newfields->at(i).c_str())) if (!updatedfields.contains(newfields->at(i).c_str()))
updatedfields.push_back(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:"; qDebug() << "Updated Config Fields:";
for (int i = 0; i < updatedfields.size(); i++) { for (int i = 0; i < updatedfields.size(); i++) {