Index: sources/cloudsync/CloudSyncController.cpp =================================================================== diff -u -r7e503c5459ec77a2816d6c7789da9b206cedbe8a -rcd7956150072dcb5264c891ee363074623052ead --- sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision 7e503c5459ec77a2816d6c7789da9b206cedbe8a) +++ sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision cd7956150072dcb5264c891ee363074623052ead) @@ -175,6 +175,10 @@ */ void CloudSyncController::onWatchFileChange(const QString &vFile) { + // TODO: It may improve the performance of the code to make it more specific. + // Meaning, Device controller has only one file watcher and it will call all the slots of all the classes watching for a file change. + // then ignore what is not important, but it may effect, the call queue and the threading performance. + // Later investigation. if ( vFile != _date_out_File ) return; // ignore unwanted file updates. QString content; Storage::FileHandler::read(vFile, content); @@ -622,7 +626,7 @@ bool CloudSyncController::sendMessage(const Message &vMessage) { bool ok = false; - // this function is used int sendUIResponse, therefore the message IDs which are responses should be implemented here. + // this function is used in sendUIResponse, therefore the message IDs which are responses should be implemented here. switch (vMessage.id) { case eMessageID_DeviceRegister : /* No Request/Response */ break; @@ -717,12 +721,25 @@ if ( ok ) { for ( auto sourceFile : vMessage.params ) { QString fileName = QFileInfo(sourceFile).fileName(); + // NOTE: If a file with the name newName already exists, copy() returns false (i.e., QFile will not overwrite it). + // For the current scenario it is ideal, since that folder will turn RO after the successful registration and copying the files and reboot. if ( ! QFile::copy (sourceFile, destination + fileName) ) { toLog(eError_CredentialCopy , {fileName }); ok = false; goto lOut; } + else { + // TODO: Registration should be atomic so it is all or nothing. + // remove all the copied files. + // it should be all or nothing + ok = false; goto lOut; + } + } + // if all the copies are successful then remove them. + for ( auto sourceFile : vMessage.params ) { + QString fileName = QFileInfo(sourceFile).fileName(); if ( ! QFile::remove(sourceFile ) ) { toLog(eError_CredentialRemove , {fileName }); ok = false; goto lOut; } } } lOut: + if ( ok ) sendCredentialsResponse(); return ok; } @@ -747,6 +764,19 @@ } /*! + * \brief CloudSyncController::sendCredentialsResponse + * \return send the confirmation of the credential save on the device from UI to CS to let CS know when to delete them. + */ +bool CloudSyncController::sendCredentialsResponse() +{ + enum { eSucceed, eFailed }; + bool ok = false; + qint32 messageID = UI2CS(eMessageID_CredentialsSave); + ok = sendUIBuff(QString("%1,1,%2").arg( messageID ).arg( ok ? eSucceed : eFailed )); + return ok; +} + +/*! * \brief CloudSyncController::sendTxCodeDisplay * \details reads the received Tx Code from CloudSync app and notifies with a signal. * \param vMessage : message containing the Tx Code.