Index: sources/cloudsync/CloudSyncController.cpp =================================================================== diff -u -rb043c5b9919a9a435e50907772ec8346823b05d6 -rfe30c662d0fdf9df32883c17772b5803b84d229e --- sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision b043c5b9919a9a435e50907772ec8346823b05d6) +++ sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision fe30c662d0fdf9df32883c17772b5803b84d229e) @@ -7,7 +7,7 @@ * * \file CloudSyncController.cpp * \author (last) Behrouz NematiPour - * \date (last) 17-Jan-2024 + * \date (last) 13-Mar-2024 * \author (original) Behrouz NematiPour * \date (original) 14-Oct-2021 * @@ -108,11 +108,15 @@ 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 &))); connect(&_DeviceController , SIGNAL(didFactoryReset (bool)), this , SLOT( onFactoryReset (bool))); + connect(&_DeviceController , SIGNAL(didDecommissioning (bool)), + this , SLOT( onDecommissioning (bool))); connect(&_TreatmentLog , SIGNAL(didPendingTxr (const QString &)), this , SLOT( onPendingTxr (const QString &))); connect(this , SIGNAL(didInitComplete ()), @@ -222,7 +226,7 @@ /*! * \brief CloudSyncController::onFactoryReset * \details this slot will be called when the DeviceController is done with the Factory Reset - * to let the UI request CS to do the Factory Reset and clean up all the Tokens. + * to let the UI request CS to do the Factory Reset and clean up all the Logs. * \param vPass - Device controller factory reset was successful. */ void CloudSyncController::onFactoryReset(bool vPass) @@ -233,6 +237,19 @@ } /*! + * \brief CloudSyncController::onDecommissioning + * \details this slot will be called when the DeviceController is done with the Decommissioning + * to let the UI request CS to do the Decommissioning and clean up all the Tokens. + * \param vPass - Device controller Decommissioning was successful. + */ +void CloudSyncController::onDecommissioning(bool vPass) +{ + if ( vPass ) { + csDecommissioning(); + } +} + +/*! * \brief CloudSyncController::onWatchFileChange * \details This slot will be called when the Device Controller identifies any changes in the watched files. * \param vFile - watched file @@ -420,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; @@ -479,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; } @@ -765,13 +784,23 @@ sendPendingTxr(vFileName); } -// ------------------------------------------------------------------------ TODO: Improve : fucntion description +/*! + * \brief CloudSyncController::onPendingLog + * \details The signal handler to call the function to send the CloudSync a message to upload the pending file. + * \param vFileName - The pending file name + * \param vChecksum - The sha256sum of the file content + */ void CloudSyncController::onPendingLog(const QString &vFileName, const QString vChecksum) { sendPendingLog(vFileName, vChecksum); } -// ------------------------------------------------------------------------ TODO: Improve : fucntion description +/*! + * \brief CloudSyncController::sendPendingLog + * \details The function to send CloudSync a message to uplaod the pending log file. + * \param vFileName - The pending file name + * \param vChecksum - The sha256sum of the file content + */ void CloudSyncController::sendPendingLog(const QString &vFileName, const QString vChecksum) { bool ok = true; Q_UNUSED(ok) @@ -801,22 +830,83 @@ if ( vMessage.params.isEmpty() ) { toLog(eError_LogNameNoParam , {}); ok = false; goto lOut; } mLogName = vMessage.params[0].trimmed(); if ( mLogName.isEmpty() ) { toLog(eError_LogNameEmpty , {}); ok = false; goto lOut; } - //DEBUG - qDebug() << " ---------- " << mLogName; + //DEBUG qDebug() << " ---------- " << mLogName; emit didLogUpload( mLogName ); lOut: 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) { @@ -829,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. @@ -864,26 +955,54 @@ /*! * \brief CloudSyncController::csFactoryReset + * \details This function is requesting CloudSync to remove all the logs + * in the logs folder (/media/sd-card/cloudsync/log/) + * during Factory Reset + * It is a request from UI to CS since UI Linux user (denali) should not have access + * to remove the CloudSync logs. + */ +bool CloudSyncController::csFactoryReset() +{ + + bool ok = true; + return ok; // NOT IMPLEMENTED + + QVariantList args ; + Errors_Enum error = eError_Unknown; + qint32 messageID = UI2CS(static_cast( eMessageID_CSFactoryReset )); + + if ( ! isRegistered() ) { error = eError_NotRegistered ; args = {}; ok = false; goto lErr; } + sendUIBuff(makeUIBuff( messageID , { } )); + + return ok; +lErr: + toLog(error, args); + return ok; +} + +/*! + * \brief CloudSyncController::Decommissioning * \details This function is requesting CloudSync to remove all the credentials and configurations * in the settings partition (/var/configurations/CloudSync) * during decommissioning * which then it means the device needs to be re-registered to able to communicate with cloud. * It is a request from UI to CS since UI Linux user (denali) should not have access * to remove the CloudSync credentials. */ -void CloudSyncController::csFactoryReset() +bool CloudSyncController::csDecommissioning() { - bool ok = true; Q_UNUSED(ok) + bool ok = true; QVariantList args ; Errors_Enum error = eError_Unknown; - qint32 messageID = UI2CS(static_cast( eMessageID_CSFactoryReset )); + qint32 messageID = UI2CS(static_cast( eMessageID_CSDecommissioning )); if ( ! isRegistered() ) { error = eError_NotRegistered ; args = {}; ok = false; goto lErr; } sendUIBuff(makeUIBuff( messageID , { } )); - return; + return ok; lErr: toLog(error, args); + return ok; } /*! @@ -1064,6 +1183,9 @@ void CloudSyncController::testReady() { bool ok = _postPass && isRegistered(); +#ifdef BUILD_FOR_DESKTOP + ok = true; +#endif emit didCloudSyncStatus( ok || gDisableCloudSyncFailStop // Development testability );