Index: sources/storage/Logger.cpp =================================================================== diff -u -r3a528c6f3fce8132de2791b55d3227e715d68898 -r465a935949a85d3d1bebd11979737ff38ef96122 --- sources/storage/Logger.cpp (.../Logger.cpp) (revision 3a528c6f3fce8132de2791b55d3227e715d68898) +++ sources/storage/Logger.cpp (.../Logger.cpp) (revision 465a935949a85d3d1bebd11979737ff38ef96122) @@ -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 @@ -475,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. @@ -493,6 +597,7 @@ Q_UNUSED(vTotal ) Q_UNUSED(vAvailable ) if ( ! vReady ) return; + // DEBUG: qDebug() << vPercent << Storage::Available_Space_Percent; if ( Storage::Log_Min_Available_Total_Space_IsLow(vPercent) ) { concurrentRemoveLogs();