Index: sources/storage/Logger.cpp =================================================================== diff -u -r54c4136d95375116e6daf23b7d4179159cf13d0c -rfec49d1a8016d25cedff4cf2fefb4c4cd1c7c259 --- sources/storage/Logger.cpp (.../Logger.cpp) (revision 54c4136d95375116e6daf23b7d4179159cf13d0c) +++ sources/storage/Logger.cpp (.../Logger.cpp) (revision fec49d1a8016d25cedff4cf2fefb4c4cd1c7c259) @@ -141,6 +141,8 @@ connect(&_removeLogsWatcher, SIGNAL(finished ()), this , SLOT(onRemoveLogs())); + connect(&_DeviceController, SIGNAL( didSDCardStateChange(bool, bool)), + this , SLOT( onSDCardStateChange(bool, bool))); connect(&_DeviceController, SIGNAL( didSDCardSpaceChange(bool, qint64, qint64, quint8)), this , SLOT( onSDCardSpaceChange(bool, qint64, qint64, quint8))); } @@ -183,6 +185,15 @@ void Logger::onLog(const QString &vContent, LogType vLogType, bool vTimestamp) { + static bool notified = false; + if ( ! _logStorageReady && ! gDisableSDCFailLogStop ) { + if ( ! notified ) { + notified = true; + qDebug() << "Log storage not ready, logging rejected"; + } + return; + } + log(vContent, vLogType, vTimestamp); } @@ -335,7 +346,7 @@ int result = 0; static QString mOSource; QString mDestination = USB_Mount_Point; - for ( const auto &iType : { eLogEvent, eLogDatum /*, eLogDebug*/ } ) { + for ( const auto &iType : { eLogEvent, eLogDatum } ) { QString mCSource = _logPathNames[iType]; // if the event and datum are mixed (mOSource == mCSource) in one file then no need to go over the same files in same folder and do it again. if (mOSource != mCSource) { @@ -349,31 +360,113 @@ } /*! + * \brief Logger::exportService + * \details Exports the service files from service folder (Storage::Log_Base_Path_Name_Location) + * into USB drive folder (Storage::USB_Mount_Point) + * \return true if at least one file has been exported + */ +bool Logger::exportErrs() +{ + // qDebug() << " ~~~~~~~~~~ " << QThread::currentThread()->objectName(); + int result = 0; + QString mDestination = USB_Mount_Point; + QString mSource = _logPathNames[eLogDebug]; + // Copy Folder + result = FileHandler::copyFolder( mSource, mDestination); + return result >= 0; // refer to QProcess::execute(hit F1 on execute) doc. +} + +/*! + * \brief Logger::exportTreatment + * \details Exports the treatment files from treatment folder (Storage::Log_Base_Path_Name_Location) + * into USB drive folder (Storage::USB_Mount_Point) + * \return true if at least one file has been exported + */ +bool Logger::exportTrts() +{ + // qDebug() << " ~~~~~~~~~~ " << QThread::currentThread()->objectName(); + int result = 0; + QString mDestination = USB_Mount_Point; + QString mSource = _logPathNames[eLogTrtmt]; + // Copy Folder + result = FileHandler::copyFolder( mSource, mDestination); + return result >= 0; // refer to QProcess::execute(hit F1 on execute) doc. +} + +/*! + * \brief Logger::concurrentExportTest + * \details Tests if a log is running + * \return if running return false + */ +bool Logger::concurrentExportIsOk() +{ + if ( _exportLogsWatcher.isRunning() ) { + LOG_DEBUG(QString("Export type of %1 is running").arg(_logNames[_exportLogsType])); + return false; + } + return true; +} + +/*! * \brief Logger::concurrentExportLogs * \details Export logs scheduler. * \return always returns true for now. * \note This method uses QtConcurrent run to execute the FileHandler copyFolder method. */ bool Logger::concurrentExportLogs() { - // disabled coco begin validated: This needs user interaction to export to USB device - // has been tested manually - LOG_DEBUG("Export Logs Start"); - QFuture future = QtConcurrent::run(this, &Logger::exportLogs); + if ( ! concurrentExportIsOk() ) return false; + + _exportLogsType = eLogEvent; + LOG_DEBUG(QString("Export %1 start").arg(_logNames[_exportLogsType])); + QFuture future = QtConcurrent::run(this, &Logger::exportLogs); _exportLogsWatcher.setFuture(future); return true; } -// disabled coco end /*! + * \brief Logger::concurrentExportLogs + * \details Export logs scheduler. + * \return always returns true for now. + * \note This method uses QtConcurrent run to execute the FileHandler copyFolder method. + */ +bool Logger::concurrentExportErrs() +{ + if ( ! concurrentExportIsOk() ) return false; + + _exportLogsType = eLogDebug; + LOG_DEBUG(QString("Export %1 start").arg(_logNames[_exportLogsType])); + QFuture future = QtConcurrent::run(this, &Logger::exportErrs); + _exportLogsWatcher.setFuture(future); + return true; +} + +/*! + * \brief Logger::concurrentExportLogs + * \details Export logs scheduler. + * \return always returns true for now. + * \note This method uses QtConcurrent run to execute the FileHandler copyFolder method. + */ +bool Logger::concurrentExportTrts() +{ + if ( ! concurrentExportIsOk() ) return false; + + _exportLogsType = eLogTrtmt; + LOG_DEBUG(QString("Export %1 start").arg(_logNames[_exportLogsType])); + QFuture future = QtConcurrent::run(this, &Logger::exportTrts); + _exportLogsWatcher.setFuture(future); + return true; +} + +/*! * \brief Logger::onExportLogs * \details Export log notification slot which logs result of export. */ void Logger::onExportLogs() { // disabled coco begin validated: This needs user interaction to export to USB device // has been tested manually - LOG_DEBUG(QString("Export Logs Ended: %1").arg(_exportLogsWatcher.result())); + LOG_DEBUG(QString("Export %1 ended: %2").arg(_logNames[_exportLogsType]).arg(_exportLogsWatcher.result())); emit didExportLogs(); } // disabled coco end @@ -401,9 +494,14 @@ mOSource = mCSource; mOExtension = mCExtension; // Remove Logs + // TODO: It appeared to me that the filter on extension may not be necessary, since the folder of each type is different. + // NOTE: The filter on the extension comes from the idea that in the same folder(log) we may want to separate the event(log) from datum(dat) with different usage percentage. +#ifdef MIXED_EVENT_DATUM + mLogFileFilter = QString("*%1").arg(".*"); +#else mLogFileFilter = QString("*%1").arg(mCExtension); - // DEBUG: since it has been manually tested this will help next time for test. - // qDebug() << "@" << mCSource << mLogFileFilter << mCExtension << iType << _logTypeMaxUsageLimit[iType]; +#endif + // DEBUG: qDebug() << "@" << mCSource << mLogFileFilter << mCExtension << iType << _logTypeMaxUsageLimit[iType]; QFileInfoList fileInfoList = FileHandler::find(mCSource, {mLogFileFilter}, _logTypeMaxUsageLimit[iType]); removeCount = fileInfoList.count(); // qDebug() << "@" << removeCount << fileInfoList; @@ -419,8 +517,7 @@ } else { QString mFileName = mCSource + info.fileName(); - // DEBUG: since it has been manually tested this will help next time for test. - // qDebug() << "#" << mFileName; + // DEBUG: qDebug() << "#" << mFileName; bool ok = QFile::remove(mFileName); if (ok) { LOG_DEBUG(QString("Removing %1 succeeded").arg(mFileName)); @@ -471,6 +568,17 @@ } // disabled coco end +void Logger::onSDCardStateChange(bool vReady, bool vReadonly) +{ +#if BUILD_FOR_DESKTOP + Q_UNUSED(vReady ) + Q_UNUSED(vReadonly ) + _logStorageReady = true; +#else + _logStorageReady = vReady && !vReadonly; +#endif +} + /*! * \brief Logger::onSDCardSpaceChange * \details SD Card storage space parameter change slot. @@ -489,8 +597,9 @@ Q_UNUSED(vTotal ) Q_UNUSED(vAvailable ) if ( ! vReady ) return; - /// DEBUG: qDebug() << vPercent << Storage::Available_Space_Percent; - if ( vPercent < Storage::Available_Space_Percent ) { + + // DEBUG: qDebug() << vPercent << Storage::Available_Space_Percent; + if ( Storage::Log_Min_Available_Total_Space_IsLow(vPercent) ) { concurrentRemoveLogs(); } }