Index: sources/cloudsync/CloudSyncController.cpp =================================================================== diff -u -re961fc7bcdeba8ffab9c96da20244b07405f8f99 -r2b671abf713c1e0cdaab0ebafdbf7087aebab176 --- sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision e961fc7bcdeba8ffab9c96da20244b07405f8f99) +++ sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision 2b671abf713c1e0cdaab0ebafdbf7087aebab176) @@ -18,13 +18,10 @@ #include // Project -#include "MainTimer.h" #include "MessageDispatcher.h" #include "ApplicationController.h" -#include "GuiController.h" #include "DeviceController.h" #include "FileHandler.h" -#include "crc.h" #include "TreatmentLog.h" SINGLETON_DISABLE(CloudSyncController) @@ -239,7 +236,7 @@ if ( vContent.isEmpty() ) { error = eError_OutFileEmpty; ok = false; goto lErr; } - lines = vContent.split('\n',QString::SkipEmptyParts); + lines = vContent.split('\n',Qt::SkipEmptyParts); buffer = lines.last(); // DEBUG: LOG_DEBUG(QString("CS [%1]").arg(buffer)); @@ -269,12 +266,10 @@ if ( eMessageID_Start > message.id || message.id > eMessageID_Count ) { error = eError_InvalidID ; ok = false; goto lErr; } // getting the parameters - for ( quint32 index = eMessage_Count; index < eMessage_Count + message.paramCount; index++ ) { - message.params.append( items[index] ); + for ( quint32 i = eMessage_Count; i < eMessage_Count + message.paramCount; i++ ) { + message.params.append( items[i] ); } - - vMessage = message; return true; @@ -333,6 +328,7 @@ 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; } return text; } @@ -374,6 +370,7 @@ 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; } @@ -553,8 +550,10 @@ QVariantList args ; Errors_Enum error = eError_Unknown; + // only sends messages if device has been registered qint32 messageID = UI2CS(static_cast(vAction)); - if ( ! _uiHistory.contains( messageID ) ) { error = eError_NoHistory; args = { messageID }; ok = false; goto lErr; } + if ( ! isRegistered() && vAction != eMessageID_DeviceRegister ) { error = eError_NotRegistered ; args = { messageID }; ok = false; goto lErr; } + if ( ! _uiHistory.contains( messageID ) ) { error = eError_NoHistory ; args = { messageID }; ok = false; goto lErr; } sendUIBuff(makeUIBuff(messageID)); @@ -821,18 +820,28 @@ */ bool CloudSyncController::testDeviceRegister() { - QString source = QString(Storage::CloudSync_Base_Path_Name) + Storage::CloudSync_Credentials_Folder_Name; - qDebug() << source; - QFileInfoList fileInfos = QDir(source).entryInfoList(QDir::NoDotAndDotDot|QDir::Files); - if( fileInfos.isEmpty() ) { - toLog(eError_CredentialEmpty,{}); // It is intentional that the vault folder path has not been sent to the log. + toLog(eError_CredentialEmpty,{}); // It is intentional that the vault folder path has not been sent to the log. + if( ! isRegistered() ) { sendDeviceRegister(); } return true; // for now always true. } /*! + * \brief CloudSyncController::isRegistered + * \details checks if the device is registered by looking for existing credentials. + * \return true if device has been registered. + */ +bool CloudSyncController::isRegistered() +{ + QString source = QString(Storage::CloudSync_Base_Path_Name) + Storage::CloudSync_Credentials_Folder_Name; + qDebug() << source; + QFileInfoList fileInfos = QDir(source).entryInfoList(QDir::NoDotAndDotDot|QDir::Files); + return !fileInfos.isEmpty(); +} + +/*! * \brief CloudSyncController::saveDeviceInfo * \details keeps the received device information and set a flag to wait for the next message. * \param vAction - the action enum which identifies information source of HD or DG.