Index: sources/cloudsync/CloudSyncController.cpp =================================================================== diff -u -r80b5e8f1ebb90c03c37d90d90cd2da3bd95d6803 -rdff4ac319c6619a1ccb894c7d6079e8e4a46b776 --- sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision 80b5e8f1ebb90c03c37d90d90cd2da3bd95d6803) +++ sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision dff4ac319c6619a1ccb894c7d6079e8e4a46b776) @@ -108,6 +108,8 @@ connect(&_DeviceController , SIGNAL(didWatchFileChange (const QString &)), this , SLOT( onWatchFileChange (const QString &))); + connect(&_DeviceController , SIGNAL(didFactoryReset (bool)), + this , SLOT( onFactoryReset (bool))); connect(&_MessageDispatcher , SIGNAL(didActionReceive (GuiActionType , const QVariantList &)), this , SLOT( onActionReceive (GuiActionType , const QVariantList &))); connect(&_TreatmentLog , SIGNAL(didTxPending (const QString &)), @@ -210,6 +212,19 @@ } /*! + * \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. + * \param vPass - Device controller factory reset was successful. + */ +void CloudSyncController::onFactoryReset(bool vPass) +{ + if ( vPass ) { + csFactoryReset(); + } +} + +/*! * \brief CloudSyncController::onWatchFileChange * \details This slot will be called when the Device Controller identifies any changes in the watched files. * \param vFile - watched file @@ -278,15 +293,14 @@ buffer = lines.last(); // DEBUG: LOG_DEBUG(QString("CS [%1]").arg(buffer)); - items = buffer.split(_separator); count = items.count(); // check the required message length if ( count < eMessage_Count ) { error = eError_HeaderCount ; ok = false; goto lErr; } index = eMessage_Timestamp ; message.timestamp = items[index].toUInt(&ok); if (!ok) { error = eError_Timestamp ; ok = false; goto lErr; } index = eMessage_Sequence ; message.sequence = items[index].toUInt(&ok); if (!ok) { error = eError_Sequence ; ok = false; goto lErr; } - index = eMessage_CRC ; message.crc = items[index].toUInt(&ok); if (!ok) { error = eError_CRC ; ok = false; goto lErr; } + index = eMessage_CRC ; message.crc = items[index].toUInt(&ok); if (!ok) { error = eError_CSCRC ; ok = false; goto lErr; } index = eMessage_MessageID ; message.id = items[index].toInt (&ok); if (!ok) { error = eError_MessageID ; ok = false; goto lErr; } index = eMessage_ParamCount; message.paramCount = items[index].toUInt(&ok); if (!ok) { error = eError_ParamCount ; ok = false; goto lErr; } @@ -296,9 +310,8 @@ // check missing parameters id = CS2UI(message.id); if ( ! paramCount.contains(id)) paramCount[id] = 0; - if ( paramCount[id] != message.paramCount ) { error = eError_ParamMissing ; ok = false; goto lErr; } + if ( message.paramCount < paramCount[id] ) { error = eError_ParamMissing ; ok = false; goto lErr; } - // convert the message id and check its validity message.id = CS2UI(static_cast(message.id)); if ( eMessageID_Start > message.id || message.id > eMessageID_Count ) { error = eError_InvalidID ; ok = false; goto lErr; } @@ -319,7 +332,7 @@ case eError_HeaderCount : args = { count , eMessage_Count }; break; case eError_Timestamp : args = { items[index].trimmed() }; break; case eError_Sequence : args = { items[index].trimmed() }; break; - case eError_CRC : args = { items[index].trimmed() }; break; + case eError_CSCRC : args = { items[index].trimmed() }; break; case eError_MessageID : args = { items[index].trimmed() }; break; case eError_InvalidID : args = { items[index].trimmed() }; break; case eError_ParamCount : args = { items[index].trimmed() }; break; @@ -344,31 +357,44 @@ QString text = tr( "CS Unknown Error" ) ; if ( vErrorID == 0 ) return text; switch (vErrorID) { - case eError_Unknown : /* "CS Unknown Error" */ ; break; - case eError_OutFileEmpty : text = tr( "CS Out buffer empty" ) ; break; - case eError_HeaderCount : text = tr( "CS Incorrect header" ) ; break; - case eError_Timestamp : text = tr( "CS Incorrect timestamp" ) ; break; - case eError_Sequence : text = tr( "CS Incorrect sequence" ) ; break; - case eError_CRC : text = tr( "CS Incorrect CRC" ) ; break; - case eError_MessageID : text = tr( "CS Incorrect ID" ) ; break; - case eError_ParamCount : text = tr( "CS Incorrect parameter count" ) ; break; - case eError_InvalidID : text = tr( "CS Invalid ID" ) ; break; - case eError_ParamMismatch : text = tr( "CS Mismatch parameter count" ) ; break; - case eError_ParamMissing : text = tr( "CS Missing parameter" ) ; break; - case eError_NoHistory : text = tr( "CS No history available" ) ; break; - case eError_Duplicate : text = tr( "CS Duplicate data" ) ; break; - case eError_LogFolder : text = tr( "CS The log folder cannot be created." ) ; break; - case eError_LogFileInp : text = tr( "CS Error writing to the input file." ) ; break; - case eError_CredentialFile : text = tr( "CS The credentials file does not exist." ) ; break; - case eError_CredentialPath : text = tr( "CS The credentials folder is incorrect." ) ; break; - case eError_CredentialCount : text = tr( "CS No credential file name provided." ) ; break; - case eError_CredentialEmpty : text = tr( "CS The credentials folder is empty." ) ; break; - case eError_TxCodeNoParam : text = tr( "CS No Treatment Code provided." ) ; break; - case eError_TxCodeEmpty : text = tr( "CS The provided Treatment Code is empty." ) ; break; - case eError_NotRegistered : text = tr( "CS Not Sent, Device not registered." ) ; break; + case eError_Unknown : /* "CS Unknown Error" */ ; break; + // CS Errors + case eError_Registration : text = tr( "CS The device registration failed" ) ; break; + case eError_DeviceState : text = tr( "CS Invalid Device State" ) ; break; + case eError_TxReport : text = tr( "CS The treatment report delivery failed" ) ; break; + case eError_UICRC : text = tr( "CS Invalid UI Message CRC" ) ; break; + case eError_DeviceValidation : text = tr( "CS DRT device registration failed" ) ; break; + case eError_PatientAssociation : text = tr( "CS Patient association failed" ) ; break; + case eError_GetNewTokenCert : text = tr( "CS New token certification failed" ) ; break; + case eError_VerifyToken : text = tr( "CS Token verification failed" ) ; break; + case eError_ValidateDevice : text = tr( "CS Cloud device validation failed" ) ; break; + case eError_PatientIdExists : text = tr( "CS Patient ID does not exists" ) ; break; + case eError_TemporaryPatient : text = tr( "CS Temporary patient ID creation failed" ) ; break; + case eError_SaveCredentials : text = tr( "CS Save credentials failed" ) ; break; + case eError_UnknownDeviceState : text = tr( "CS Unknown device state" ) ; break; + // UI Errors + case eError_OutFileEmpty : text = tr( "CS Out buffer empty" ) ; break; + case eError_HeaderCount : text = tr( "CS Incorrect header" ) ; break; + case eError_Timestamp : text = tr( "CS Incorrect timestamp" ) ; break; + case eError_Sequence : text = tr( "CS Incorrect sequence" ) ; break; + case eError_CSCRC : text = tr( "CS Incorrect CRC" ) ; break; + case eError_MessageID : text = tr( "CS Incorrect ID" ) ; break; + case eError_ParamCount : text = tr( "CS Incorrect parameter count" ) ; break; + case eError_InvalidID : text = tr( "CS Invalid ID" ) ; break; + case eError_ParamMismatch : text = tr( "CS Mismatch parameter count" ) ; break; + case eError_ParamMissing : text = tr( "CS Missing parameter" ) ; break; + case eError_NoHistory : text = tr( "CS No history available" ) ; break; + case eError_Duplicate : text = tr( "CS Duplicate data" ) ; break; + case eError_LogFolder : text = tr( "CS The log folder cannot be created." ) ; break; + case eError_LogFileInp : text = tr( "CS Error writing to the input file." ) ; break; + case eError_CredentialFile : text = tr( "CS The credentials file does not exist." ) ; break; + case eError_CredentialPath : text = tr( "CS The credentials folder is incorrect." ) ; break; + case eError_CredentialCount : text = tr( "CS No credential file name provided." ) ; break; + case eError_CredentialEmpty : text = tr( "CS The credentials folder is empty." ) ; break; + case eError_TxCodeNoParam : text = tr( "CS No Treatment Code provided." ) ; break; + case eError_TxCodeEmpty : text = tr( "CS The provided Treatment Code is empty." ) ; break; + case eError_NotRegistered : text = tr( "CS Not Sent, Device not registered." ) ; break; - case eError_Registration : text = tr( "CS The device registration failed." ) ; break; - case eError_TxReport : text = tr( "CS The treatment report delivery failed." ) ; break; } return text; } @@ -386,32 +412,45 @@ // It means it is designed to not throw out of bound error and just use "~" as a missing info argument. auto item = [=](uint i) { return vInfoItems.value(i,"~").toString(); }; - QString info = QString( "[%1]" ).arg( vErrorID ) ; + QString info = QString( "[%1]" ).arg( vErrorID ) ; switch (vErrorID) { - case eError_Unknown : ; break; - case eError_OutFileEmpty : ; break; - case eError_HeaderCount : info = QString( "[%1:%2/%3]" ).arg( vErrorID ).arg( item(0) ).arg( item(1) ) ; break; - case eError_Timestamp : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_Sequence : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_CRC : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_MessageID : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_InvalidID : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_ParamCount : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_ParamMismatch : info = QString( "[%1:%2/%3]" ).arg( vErrorID ).arg( item(0) ).arg( item(1) ) ; break; - case eError_ParamMissing : info = QString( "[%1:%2/%3]" ).arg( vErrorID ).arg( item(0) ).arg( item(1) ) ; break; - case eError_NoHistory : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_Duplicate : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_LogFolder : ; break; - case eError_LogFileInp : ; break; - case eError_CredentialFile : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_CredentialPath : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_CredentialCount : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_CredentialEmpty : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_TxCodeNoParam : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_TxCodeEmpty : 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_Registration : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; - case eError_TxReport : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_Unknown : ; break; + // CS Errors + case eError_Registration : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_DeviceState : ; break; + case eError_TxReport : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_UICRC : /* info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) */ ; break; + case eError_DeviceValidation : ; break; + case eError_PatientAssociation : ; break; + case eError_GetNewTokenCert : ; break; + case eError_VerifyToken : ; break; + case eError_ValidateDevice : ; break; + case eError_PatientIdExists : ; break; + case eError_TemporaryPatient : ; break; + case eError_SaveCredentials : ; break; + case eError_UnknownDeviceState : ; break; + // UI Errors + case eError_OutFileEmpty : ; break; + case eError_HeaderCount : info = QString( "[%1:%2/%3]" ).arg( vErrorID ).arg( item(0) ).arg( item(1) ) ; break; + case eError_Timestamp : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_Sequence : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_CSCRC : /* info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) */ ; break; + case eError_MessageID : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_InvalidID : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_ParamCount : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_ParamMismatch : info = QString( "[%1:%2/%3]" ).arg( vErrorID ).arg( item(0) ).arg( item(1) ) ; break; + case eError_ParamMissing : info = QString( "[%1:%2/%3]" ).arg( vErrorID ).arg( item(0) ).arg( item(1) ) ; break; + case eError_NoHistory : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_Duplicate : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_LogFolder : ; break; + case eError_LogFileInp : ; break; + case eError_CredentialFile : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_CredentialPath : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_CredentialCount : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_CredentialEmpty : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_TxCodeNoParam : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_TxCodeEmpty : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; + case eError_NotRegistered : info = QString( "[%1:%2]" ).arg( vErrorID ).arg( item(0) ) ; break; } return info; } @@ -677,9 +716,9 @@ } } -void CloudSyncController::onTxPending(const QString &vFileName) +void CloudSyncController::sendPendingLog(const QString &vFileName) { - bool ok = true; Q_UNUSED(ok); + bool ok = true; Q_UNUSED(ok) QVariantList args ; Errors_Enum error = eError_Unknown; qint32 messageID = UI2CS(static_cast( eMessageID_TxReport )); @@ -692,6 +731,11 @@ toLog(error, args); } +void CloudSyncController::onTxPending(const QString &vFileName) +{ + sendPendingLog(vFileName); +} + /*! * \brief CloudSyncController::sendMessage * \details Makes and Sends the appropriate message for the vAction. @@ -707,7 +751,7 @@ case eMessageID_DeviceInfo : ok = sendDeviceInfo ( ); break; case eMessageID_CredentialsSave : ok = sendCredentialsSave( vMessage ); break; - case eMessageID_ResetFactory : ok = sendResetFactory ( ); break; + case eMessageID_UIFactoryReset : ok = sendFactoryReset ( ); break; case eMessageID_DeviceState : ok = sendDeviceState ( ); break; case eMessageID_TxCodeDisplay : ok = sendTxCodeDisplay ( vMessage ); break; @@ -744,12 +788,31 @@ return ok; } +void CloudSyncController::csFactoryReset() +{ + bool ok = true; Q_UNUSED(ok) + QVariantList args ; + Errors_Enum error = eError_Unknown; + qint32 messageID = UI2CS(static_cast( eMessageID_CSFactoryReset )); + + if ( ! isRegistered() ) { error = eError_NotRegistered ; args = { vFileName }; ok = false; goto lErr; } + sendUIBuff(makeUIBuff( messageID , { } )); + + return; +lErr: + toLog(error, args); +} + +void CloudSyncController::onFactoryReset() { + csFactoryReset(); +} + /*! - * \brief CloudSyncController::doResetFactory + * \brief CloudSyncController::factoryReset * \details does the reset factory * \return true on successful reset */ -bool CloudSyncController::doResetFactory() +bool CloudSyncController::uiFactoryReset() { // reset factory has not been implemented yet. bool ok = true; @@ -759,17 +822,17 @@ } /*! - * \brief CloudSyncController::sendResetFactory + * \brief CloudSyncController::sendFactoryReset * \details sends the factory reset response to CloudSync * \return true on successful send. */ -bool CloudSyncController::sendResetFactory() +bool CloudSyncController::sendFactoryReset() { enum { eSucceed, eFailed }; bool ok = false; - ok = doResetFactory(); + ok = uiFactoryReset(); // if ( ! ok ) { } /* Not defined */ - qint32 messageID = UI2CS(eMessageID_ResetFactory); + qint32 messageID = UI2CS(eMessageID_UIFactoryReset); // TODO : Store registration success in here ok = sendUIBuff({ QString("%1").arg( messageID ) ,"1", QString("%1").arg( ok ? eSucceed : eFailed ) }); return ok;