Index: sources/cloudsync/CloudSyncController.cpp =================================================================== diff -u -r301c0a2101eb9374145ae274c8d91460fc9a6a62 -r4a67c01045f365be38f1a12a8572c0070d343e1e --- sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision 301c0a2101eb9374145ae274c8d91460fc9a6a62) +++ sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision 4a67c01045f365be38f1a12a8572c0070d343e1e) @@ -73,11 +73,11 @@ */ void CloudSyncController::quit() { - // coco begin validated: CloudSync termination is not correctly done in coco!!! + // disabled coco begin validated: CloudSync termination is not correctly done in coco!!! // it has been tested and works perfectly fine in normal run. quitThread(); // validated } -// coco end +// disabled coco end /*! * \brief CloudSyncController::initConnections @@ -121,15 +121,15 @@ */ void CloudSyncController::quitThread() { - // coco begin validated: CloudSync termination is not correctly done in coco!!! + // disabled coco begin validated: CloudSync termination is not correctly done in coco!!! // it has been tested and works perfectly fine in normal run. if ( ! _thread ) return; // runs in thread moveToThread(qApp->thread()); // validated } -// coco end +// disabled coco end /*! * \brief CloudSyncController::timerEvent @@ -312,6 +312,7 @@ case eError_ParamMismatch : text = tr( "CS Mismatch parameter count" ) ; break; case eError_ParamMissing : text = tr( "CS Missing parameter" ) ; break; case eError_NoHistory : text = tr( "CS No history available" ) ; break; + case eError_Duplicate : text = tr( "CS Duplicate data" ) ; break; case eError_LogFolder : text = tr( "CS The log folder cannot be created." ) ; break; case eError_LogFileInp : text = tr( "CS Error writing to the input file." ) ; break; case eError_CredentialFile : text = tr( "CS The credentials file does not exist." ) ; break; @@ -350,6 +351,7 @@ case eError_ParamMismatch : info = QString( "[%1:%2/%3]" ).arg( vErrorID ).arg( item(0) ).arg( item(1) ) ; break; case eError_ParamMissing : info = QString( "[%1:%2/%3]" ).arg( vErrorID ).arg( item(0) ).arg( item(1) ) ; break; case eError_NoHistory : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_Duplicate : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; case eError_LogFolder : ; break; case eError_LogFileInp : ; break; case eError_CredentialFile : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; @@ -389,7 +391,7 @@ // TODO: messages have to have a sequence. // if the seq is duplicate it will be ignored. // seq, id, payload - // qDebug() << vContent; + // DEBUG: qDebug() << vContent; bool ok = true; Message message; @@ -431,10 +433,21 @@ .arg( msg ) .arg( len ) .arg( prm ) - ; + ; } /*! + * \brief CloudSyncController::isDuplicate + * \param vMessage - current action/messageID received. + * \param vData - current data to compare with the history + * \return true if duplicate + */ +bool CloudSyncController::isDuplicate(const qint32 vMessageID, const QStringList &vData) +{ + return _uiHistory.contains(vMessageID) && _uiHistory[vMessageID] == vData; +} + +/*! * \brief CloudSyncController::writeInpFile * \details Writes to the CS Input buffer * \param vBuffer - the string out buffer. @@ -473,7 +486,7 @@ QString inpBuff = "%1,%2,%3,%4"; inpBuff = inpBuff .arg( _secSinceEpoch ) - .arg( _seq++ ) + .arg( Types::safeIncrement(_seq)) .arg( generateCRC() ) .arg( vData ); @@ -497,12 +510,12 @@ qint32 messageID = UI2CS(static_cast(vAction)); QStringList data; - if ( vData.isEmpty() ) { error = eError_NoHistory; args = { messageID }; ok = false; goto lErr; } + if ( vData.isEmpty() ) { error = eError_NoHistory; args = { messageID }; ok = false; goto lErr; } - // convert the data to string list - for (auto datum : vData) { - data += datum.toString(); - } + data = Format::fromVariantList(vData); + + if ( isDuplicate(messageID, data) ) { error = eError_Duplicate; args = { messageID }; ok = false; return ok; } // goto lErr; } don't log it just ignore and return false. + // store the last message data _uiHistory[messageID] = data; @@ -556,8 +569,8 @@ // case GuiActionType::ID_PostTreatmentStates : // has not been discussed how to be sent out. // case GuiActionType::ID_DisinfectStates : // has not been discussed how to be sent out. case GuiActionType::ID_HDOperationModeData : - saveUIHistory(eMessageID_DeviceState , vData ); - sendUIHistory(eMessageID_DeviceState ); // can be removed if CS doesn't need it. + if (saveUIHistory(eMessageID_DeviceState , vData )) // if not empty, nor duplicate, and saved + sendUIHistory(eMessageID_DeviceState ); break; case GuiActionType::ID_AdjustSerialHDRsp : @@ -574,15 +587,15 @@ /*! * \brief CloudSyncController::onTreatmentLogSave * \details The slot being called when the TreatmentLogController notifies the CloudSyncController, about the treatment log being successfully saved. - * \param vPatientID - Patient ID * \param vDeviceID - Device ID + * \param vPatientID - Patient ID * \param vFileName - The complete Treatment log path and file name. */ -void CloudSyncController::onTreatmentLogSave(const QString &vPatientID, const QString &vDeviceID, const QString &vFileName) +void CloudSyncController::onTreatmentLogSave(const QString &/*vDeviceID*/, const QString &/*vPatientID*/, const QString &vFileName) { - QStringList data { vPatientID, vDeviceID, vFileName }; - _uiHistory [eMessageID_TxReport] = data; - sendUIHistory (eMessageID_TxReport); + QVariantList data { /*vDeviceID, vPatientID,*/ vFileName }; + saveUIHistory(eMessageID_TxReport, data ); + sendUIHistory(eMessageID_TxReport ); } /*! @@ -604,7 +617,7 @@ case eMessageID_ResetFactory : ok = sendResetFactory ( ); break; case eMessageID_DeviceState : ok = sendDeviceState ( ); break; - case eMessageID_TxReport : break; + case eMessageID_TxReport : /* No Req/Rsp, it is event based */ break; // This message doesn't have the response since there is no request. UI will send when the data ready by HD. } return ok; @@ -722,11 +735,11 @@ bool CloudSyncController::testDeviceRegister() { QString source = QString(Storage::CloudSync_Base_Path_Name) + Storage::CloudSync_Credentials_Folder_Name; + qDebug() << source; QFileInfoList fileInfos = QDir(source).entryInfoList(QDir::NoDotAndDotDot|QDir::Files); - if( ! fileInfos.isEmpty() ) { - sendDeviceRegister(); - } else { + if( fileInfos.isEmpty() ) { toLog(eError_CredentialEmpty,{}); // It is intentional that the vault folder path has not been sent to the log. + sendDeviceRegister(); } return true; // for now always true. @@ -780,14 +793,14 @@ { bool ok = false; if ( _deviceInfoUI.isEmpty() ) { _deviceInfoUI = qApp->applicationVersion(); } - ok = saveUIHistory(eMessageID_DeviceInfo , { _deviceInfoHD, _deviceInfoDG, _deviceInfoUI } ) && - saveUIHistory(eMessageID_DeviceRegister , { _deviceInfoHD, _deviceInfoDG, _deviceInfoUI } ) && // the device registration request format is the same as Device info with different message id. - sendDeviceInfo(); + saveUIHistory(eMessageID_DeviceInfo , { _deviceInfoHD, _deviceInfoDG, _deviceInfoUI } ); + saveUIHistory(eMessageID_DeviceRegister , { _deviceInfoHD, _deviceInfoDG, _deviceInfoUI } ); // the device registration request format is the same as Device info with different message id. - if ( testDeviceRegister() ) - sendDeviceRegister(); + testDeviceRegister (); // it is expected on the CloudSync App to get the + sendDeviceInfo (); // this one may need to be removed and only will be sent on the request - if ( ok ) stopDeviceInfoWait(); + stopDeviceInfoWait(); + return ok; } @@ -809,7 +822,8 @@ */ void CloudSyncController::testDeviceInfoWait() { - if (_deviceInfoWait == _deviceInfoStop ) return; + if (_deviceInfoStop ) return; + // DEBUG: qDebug() << _deviceInfoWait; if (_deviceInfoWait ){ _deviceInfoWait -- ; } @@ -823,7 +837,7 @@ * \details stops waiting for the device info. */ void CloudSyncController::stopDeviceInfoWait() { - _deviceInfoWait = _deviceInfoStop; + _deviceInfoStop = true; // NOTE: if it is accepted to use the last received info just comment these 3 cleanup lines. // so the last message will update the history only and it will be sent out. _deviceInfoHD = ""; @@ -836,7 +850,8 @@ * \details if currently not not in wait, then set the wait to the secs of wait. */ void CloudSyncController::initDeviceInfoWait() { - if ( _deviceInfoWait == _deviceInfoStop ) { // if timer is stopped - _deviceInfoWait = _deviceInfoSecs; // enable the timer. + if ( _deviceInfoStop ) { // if timer is stopped + _deviceInfoWait = _deviceInfoSecs; // enable the timer. + _deviceInfoStop = false; } }