Index: sources/storage/TreatmentLog.cpp =================================================================== diff -u -r6210028a421d6259963bf172efbe4f23abfecf2f -r5967e3c458599ea7af0f298e844eef89004acb03 --- sources/storage/TreatmentLog.cpp (.../TreatmentLog.cpp) (revision 6210028a421d6259963bf172efbe4f23abfecf2f) +++ sources/storage/TreatmentLog.cpp (.../TreatmentLog.cpp) (revision 5967e3c458599ea7af0f298e844eef89004acb03) @@ -43,6 +43,7 @@ TreatmentLog::TreatmentLog(QObject *parent) : QObject(parent) { initConnections(); logPath(Logger::eLogTrtmt, _Logger.logPath(Logger::eLogTrtmt)); + startTimer(_interval); } @@ -65,6 +66,15 @@ } /*! + * \brief TreatmentLog::timerEvent + * \details The overloaded method of the main class to capture the QObject timer. + */ +void TreatmentLog::timerEvent(QTimerEvent *) +{ + testPendingTxReports(); +} + +/*! * \brief TreatmentLog::initModel * Initializing the model for the constant values. * \param vData - the response model data. @@ -322,6 +332,9 @@ _treatmentLogAlarmData.clear(); _treatmentLogEventData.clear(); _lastTxInfo.mStatus = ok; + + sendPending(); // reset the timer to find the latest saved pending and ask for Tx Code. + return ok; } @@ -333,10 +346,6 @@ { LOG_DEBUG(QString("Save Treatment Log Ended: %1").arg(_saveWatcher.result())); isIdle(true); - if ( _lastTxInfo.mStatus ) - emit didTreatmentLogSave( _lastTxInfo.mDeviceID , - _lastTxInfo.mPatientID , - _lastTxInfo.mFileName ); } // ----- Export @@ -415,8 +424,17 @@ void TreatmentLog::onTxCodeReceive(const QString &vTxCode) { _txCode = 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; + + // getting the Tx out of pending and add the received Tx in the file addTxCode(); - emit didTxCodeReceive(_txCode); + + if ( isLastTxInfo ) { + // avoid updating the screen with another pending Tx in queue + emit didTxCodeReceive(_txCode); + } } /*! @@ -427,7 +445,7 @@ bool TreatmentLog::addTxCode() { bool ok = true; - QString src = _lastTxInfo.mFileName; + QString src = _pendingTx; QString dst = _treatmentLogPath + QFileInfo(src).fileName(); QString logContent; ADDTITLE("Title"); @@ -450,5 +468,49 @@ 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; } + +/*! + * \brief TreatmentLog::sendPending + * \details Resets the pending counter to immediately/ASAP as for the pending and won't waits for the timeout. + */ +void TreatmentLog::sendPending() +{ + _pendingCounter = 0; +} + +/*! + * \brief TreatmentLog::testPendingTxReports + * \details this function count downs for the _pendingInterval + * when the _pendingCounter reaches 0 will search for the files + * in the _TreatmentLog.logPathPending() + * and if there is any will get the recent file in the list + * and asks for the TxCode by emitting the didTxPending signal + */ +void TreatmentLog::testPendingTxReports() +{ + qDebug() << _pendingCounter; + if ( _pendingCounter ) { + _pendingCounter -- ; + return; + } + else { + _pendingCounter = _pendingInterval; // every minute + } + + QFileInfoList pendingFiles; + pendingFiles = Storage::FileHandler::find(_TreatmentLog.logPathPending(), {"*.log"}); + // look into the list. + // if there are pending files, + // send a request only for the top on the list + // * When gets the Tx Code, moves from pending then next one comes to top + // 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 ); + } +}