Index: sources/storage/TreatmentLog.cpp =================================================================== diff -u -r1a9eb2756f33ec0387dd360e5c051ed9a04b9c1c -rf9e747f0f28df1cc6a33179f0bc78bfc03d486fc --- sources/storage/TreatmentLog.cpp (.../TreatmentLog.cpp) (revision 1a9eb2756f33ec0387dd360e5c051ed9a04b9c1c) +++ sources/storage/TreatmentLog.cpp (.../TreatmentLog.cpp) (revision f9e747f0f28df1cc6a33179f0bc78bfc03d486fc) @@ -26,9 +26,6 @@ #include "Settings.h" #include "CloudSyncController.h" -#include "GuiGlobals.h" -#include "MAlarmStatusData.h" - using namespace Storage; #define NONE "N/A" @@ -64,7 +61,7 @@ QOverload< const AdjustSerialNumberHDResponseData & >::of( &ApplicationController::didActionReceive ), [ this ] ( const AdjustSerialNumberHDResponseData &vData ) { - // The serial number is going to be recieved from HD + // The serial number is going to be received from HD // on POST or on request // and will be used for the device ID // which we designed initially to be different. @@ -343,7 +340,8 @@ QString end = "%1" ; uint index = 0 ; - // ADDTITLE("Title"); // will be added with Tx Code when gets out of pending, by receiving the Tx Code from CloudSync + ADDTITLE("Title"); + ADDALINE(QString("TxCode,%1,").arg(_gTxCode)); ADDTOLOG( ePatientID ); ADDTITLE("Treatment Parameters" ); @@ -551,54 +549,45 @@ */ void TreatmentLog::onTxCodeReceive(const QString &vTxCode) { - _txCode = vTxCode; + _rTxCode = vTxCode; // This has to be checked before the addTxCode, // because that function will change the _lastTxInfo.mFilename after it is moved from pending. - bool isLastTxInfo = ! _lastTxInfo.mFileName.isEmpty() && _pendingTx == _lastTxInfo.mFileName; + bool isLastTxInfo = ! _lastTxInfo.mFileName.isEmpty() && _pendingTxr == _lastTxInfo.mFileName; // getting the Tx out of pending and add the received Tx in the file - addTxCode(); + checkTxCode(); if ( isLastTxInfo ) { // avoid updating the screen with another pending Tx in queue - emit didTxCodeReceive(_txCode); + emit didTxCodeReceive(_rTxCode); } } /*! - * \brief TreatmentLog::addTxCode - * \details Adds the [Title] and Tx Code to the file and moves it from pending. + * \brief TreatmentLog::checkTxCode + * \details Compares the received TxCode with the generated and if matches renames Txr from pending. * \return true on success, false on any case of read, write, remove. */ -bool TreatmentLog::addTxCode() +bool TreatmentLog::checkTxCode() { bool ok = true; - QString src = _pendingTx; + QString src = _pendingTxr; QString dst = QString("%1%2.%3") .arg(_treatmentLogPath) .arg(QFileInfo(src).baseName()) .arg(_treatmentLogExtUploaded); - QString logContent; - ADDTITLE("Title"); - ADDALINE(QString("Tx Code,%1,").arg(_txCode)); - ok = FileHandler::read (src, logContent, true ); // reads the file and appends the content to logContent + ok = _gTxCode == _rTxCode; if ( ! ok ) { - LOG_DEBUG(QString("Couldn't read pending treatment log file '%1'").arg(src)); + LOG_DEBUG(QString("Generated '%1' TxCode and Received TxCode '%1' does not match").arg(_gTxCode).arg(_rTxCode)); return ok; } - ok = FileHandler::write (dst, logContent ); + ok = QFile::rename(src, dst); if ( ! ok ) { - LOG_DEBUG(QString("Couldn't settle pending treatment log file '%1'").arg(src)); + LOG_DEBUG(QString("Couldn't change the state of pending treatment log file '%1'").arg(src)); return ok; } - - QFile::remove(src); - if ( ! ok ) { - LOG_DEBUG(QString("Couldn't remove pending treatment log file '%1'").arg(src)); - return ok; - } _lastTxInfo.mFileName = dst; // Update the last Tx file to the new location [ export ] sendPending(); // start looking for the next pending, instead of waiting to timeout return ok; @@ -640,7 +629,7 @@ // the process repeats until there is no file in pending if ( pendingFiles.count() ) { // the most recent/first Tx file, to first ask for the current treatment which has just saved as pending on screen - _pendingTx = pendingFiles.first().absoluteFilePath(); - emit didTxPending( _pendingTx ); + _pendingTxr = pendingFiles.first().absoluteFilePath(); + emit didTxPending( _pendingTxr ); } }