Index: sources/cloudsync/CloudSyncController.cpp =================================================================== diff -u -rc36f8432854c8ab42f71b76da826b50912822cf7 -r7e4af0df6b719d54ee9ec824f17ea022faab4d2e --- sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision c36f8432854c8ab42f71b76da826b50912822cf7) +++ sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision 7e4af0df6b719d54ee9ec824f17ea022faab4d2e) @@ -108,6 +108,8 @@ this , SLOT( onCryptSetupMount(bool))); connect(&_DeviceController , SIGNAL(didPendingLog (const QString &, const QString &)), this , SLOT( onPendingLog (const QString &, const QString &))); + connect(&_Logger , SIGNAL(didRetentionLogCS (quint8)), + this , SLOT( onRetentionLog (quint8))); connect(&_DeviceController , SIGNAL(didWatchFileChange (const QString &)), this , SLOT( onWatchFileChange (const QString &))); @@ -435,6 +437,7 @@ case eError_LogNameNoParam : text = tr( "CS No Log Name provided." ) ; break; case eError_LogNameEmpty : text = tr( "CS The provided Log Name is empty." ) ; break; case eError_NotRegistered : text = tr( "CS Not Sent, Device not registered." ) ; break; + case eError_LogRetentionNoParam : text = tr( "CS No Log Retention summary provided." ) ; break; } return text; @@ -494,6 +497,7 @@ case eError_LogNameNoParam : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; case eError_LogNameEmpty : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; case eError_NotRegistered : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_LogRetentionNoParam : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; } return info; } @@ -833,14 +837,76 @@ return ok; } +/// -------------------------------------------------- Retention Log /*! + * \brief CloudSyncController::onRetentionLog + * \details The slot tha handles the received even to request for the log retention + * \param vMaxUsePercent - the maximum size of the SD-Card (log storage device) cloudsync can get for the logs + */ +void CloudSyncController::onRetentionLog(quint8 vMaxUsePercent) +{ + sendRetentionLog(vMaxUsePercent); +} + +void CloudSyncController::sendRetentionLog(quint8 vMaxUsePercent) +{ + bool ok = true; Q_UNUSED(ok) + QVariantList args ; + Errors_Enum error = eError_Unknown; + qint32 messageID = UI2CS(static_cast( eMessageID_SendLogRetention )); + // DEBUG ok = false; // using the ok bool which is true as the debug flag to bypass the registration on debug testing. + if ( ok && ! isRegistered() ) { error = eError_NotRegistered ; args = { eMessageID_SendLogRetention, vMaxUsePercent }; ok = false; goto lErr; } + sendUIBuff(makeUIBuff( messageID , { QString::number(vMaxUsePercent) } )); + + return; +lErr: + toLog(error, args); +} + +bool CloudSyncController::rcvdRetentionLog(const Message &vMessage) +{ + bool ok = true; + QString tmp; + quint16 mLogsCount; // number of deleted logs + quint32 mLogsSize ; // total current logs size + // although it has been checked in the interpreter, we won't risk the crash and check the list empty. + if ( vMessage.params.isEmpty() ) { toLog(eError_LogRetentionNoParam , {eMessageID_SendLogRetention }); ok = false; goto lOut; } + if ( vMessage.params.count () < paramCount[eMessageID_SendLogRetention]) { toLog(eError_ParamCount , {eMessageID_SendLogRetention }); ok = false; goto lOut; } + + tmp = vMessage.params[0]; + mLogsCount = tmp.toUInt(&ok); + if ( ! ok ) { toLog(eError_ParamMismatch , {eMessageID_SendLogRetention, 0}); ok = false; goto lOut; } + + tmp = vMessage.params[1]; + mLogsSize = tmp.toUInt(&ok); + if ( ! ok ) { toLog(eError_ParamMismatch , {eMessageID_SendLogRetention, 1}); ok = false; goto lOut; } + + //DEBUG qDebug() << " ---------- " << mLogsCount << mLogsSize; + emit didLogRetention( mLogsCount, mLogsSize ); + + LOG_APPED_CS(QString("Log retention deleted %1 files of total %2 MB.").arg(mLogsCount).arg(mLogsSize)); + + lOut: + return ok; +} +/// -------------------------------------------------- + +/*! * \brief CloudSyncController::sendMessage * \details Makes and Sends the appropriate message for the vAction. * Some messages are sent out upon request form the last received on the history and will not be asked from FW. * \return true if there is a history for that message and no error happened. */ bool CloudSyncController::sendMessage(const Message &vMessage) { bool ok = false; + // we are using the file system for the UI<=>CS communication, + // and the file events are multiple during the write to the file. + // if a write to the _out.buf trigeres the message to be sent more than once, + // ignore the same message, with the same sequence number. + static quint32 sequence ; + if ( sequence == vMessage.sequence ) return ok; + sequence = vMessage.sequence ; + //DEBUG qDebug() << Q_FUNC_INFO << vMessage.id; // this function is used in sendUIResponse, therefore the message IDs which are responses should be implemented here. switch (vMessage.id) { @@ -853,6 +919,7 @@ case eMessageID_TxCodeDisplay : ok = sendTxCodeDisplay ( vMessage ); break; case eMessageID_SendLogUpload : ok = rcvdPendingLog ( vMessage ); break; + case eMessageID_SendLogRetention : ok = rcvdRetentionLog ( vMessage ); 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. Index: sources/cloudsync/CloudSyncController.h =================================================================== diff -u -rc36f8432854c8ab42f71b76da826b50912822cf7 -r7e4af0df6b719d54ee9ec824f17ea022faab4d2e --- sources/cloudsync/CloudSyncController.h (.../CloudSyncController.h) (revision c36f8432854c8ab42f71b76da826b50912822cf7) +++ sources/cloudsync/CloudSyncController.h (.../CloudSyncController.h) (revision 7e4af0df6b719d54ee9ec824f17ea022faab4d2e) @@ -133,6 +133,8 @@ eError_LogNameNoParam = 973, // the received Log Name not provided eError_LogNameEmpty = 974, // the received Log Name is empty + + eError_LogRetentionNoParam = 975, // the received Log retention payload parameters not provided }; typedef QHash MessageList; @@ -181,6 +183,8 @@ eMessageID_CSDecommissioning= 9, // [ UI(1009) <-> CS(2009) ] Decommissioning Request // Log Upload eMessageID_SendLogUpload = 10, // [ UI(1010) <-> CS(2010) ] Log Upload Request/Response + // CloudSync Log Retention + eMessageID_SendLogRetention = 11, // [ UI(1011) <-> CS(2011) ] Log Retention Request/Response // Factory Reset eMessageID_CSFactoryReset = 99, // [ UI(1009) <-> CS(2009) ] Factory Reset Request // NOT IMPLEMENTED @@ -201,6 +205,7 @@ { eMessageID_TxCodeDisplay , 1 }, { eMessageID_Error , 2 }, { eMessageID_SendLogUpload , 1 }, + { eMessageID_SendLogRetention , 2 }, }; enum DeviceInfo_Enum { @@ -226,6 +231,8 @@ void onActionReceive (GuiActionType vAction, const QVariantList &vData); void onPendingTxr (const QString &vFileName ); void onPendingLog (const QString &vFileName, const QString vChecksum ); + void onRetentionLog (quint8 vMaxUsePercent); + void onInitComplete (); void onPOSTCloudSync (bool vPass ); void onCryptSetupMount (bool vPass ); @@ -236,6 +243,8 @@ void didInitComplete (); void didTxCodeReceive (const QString &vTxCode ); void didLogUpload (const QString &vFileName ); + void didLogRetention (quint16 vLogsCount, quint32 vLogsSize); + void didRegisterStart (bool vOK ); void didRegisterDone (bool vOK ); void didCloudSyncStatus (bool vReady ); @@ -321,4 +330,7 @@ void sendPendingLog (const QString &vFileName , const QString vChecksum); // eMessageID_SendLogUpload bool rcvdPendingLog (const Message &vMessage ); // eMessageID_SendLogUpload + // CloudSync log retention + void sendRetentionLog ( quint8 vMaxUsePercent ); // eMessageID_SendLogRetention + bool rcvdRetentionLog (const Message &vMessage ); // eMessageID_SendLogRetention }; Index: sources/storage/Logger.cpp =================================================================== diff -u -rc36f8432854c8ab42f71b76da826b50912822cf7 -r7e4af0df6b719d54ee9ec824f17ea022faab4d2e --- sources/storage/Logger.cpp (.../Logger.cpp) (revision c36f8432854c8ab42f71b76da826b50912822cf7) +++ sources/storage/Logger.cpp (.../Logger.cpp) (revision 7e4af0df6b719d54ee9ec824f17ea022faab4d2e) @@ -617,6 +617,11 @@ auto logFile = { vLogType }; // Is mostly used for the txr files which are in separate partition. for ( const auto &iType : ( vLogType == eLogFiles ? logFiles : logFile ) ) { + // The Application does not have access to remove the CloudSync logs, + // therefore sends CloudSync a message with expected used percent of the log files, + // to remove the logs. + if ( iType == eLogCloud ) { emit didRetentionLogCS(_logTypeMaxUsageLimit[iType]); continue; } + QString mCSource = _logPathNames [iType]; QString mCExtension = _logFileNameExt[iType]; // DEBUG: qDebug() << "@" << mCSource << mLogFileFilter << mCExtension << iType << _logTypeMaxUsageLimit[iType]; Index: sources/storage/Logger.h =================================================================== diff -u -rc36f8432854c8ab42f71b76da826b50912822cf7 -r7e4af0df6b719d54ee9ec824f17ea022faab4d2e --- sources/storage/Logger.h (.../Logger.h) (revision c36f8432854c8ab42f71b76da826b50912822cf7) +++ sources/storage/Logger.h (.../Logger.h) (revision 7e4af0df6b719d54ee9ec824f17ea022faab4d2e) @@ -39,6 +39,7 @@ #define LOG_APPED_UI(vCONTENT) emit Storage::Logger::I().didLog(" ,UI," + vCONTENT, Storage::Logger::LogType::eLogAppED, true ) #define LOG_APPED_PO(vCONTENT) emit Storage::Logger::I().didLog("POST,UI," + vCONTENT, Storage::Logger::LogType::eLogAppED, true ) #define LOG_APPED_MSG(vID, vTEXT) LOG_APPED(QString("%1,%2").arg(QString("%1").arg(vID,4,16,QLatin1Char('0')).toUpper()).arg(vTEXT)) +#define LOG_APPED_CS(vCONTENT) emit Storage::Logger::I().didLog(" ,CS," + vCONTENT, Storage::Logger::LogType::eLogAppED, true ) // forward declarations class tst_logging; @@ -230,10 +231,12 @@ void postInit(); signals: - void didLogPathSet(Logger::LogType vLogType, const QString &vLogPath); - void didLogIOFail(); - void didLogBackup ( const QString vFileName ); + void didLogPathSet ( Logger::LogType vLogType, const QString &vLogPath ); + void didLogIOFail (); + void didLogBackup ( const QString vFileName ); + void didRetentionLogCS ( quint8 vPercent ); + public slots: bool init(); bool init(QThread &vThread);