Index: sources/cloudsync/CloudSyncController.cpp =================================================================== diff -u -r656094cd72dfcb6cec410b8e36570abf5c9d6975 -r1bf8c894c5cc5ea6d62af0662fcf5a18e1a06459 --- sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision 656094cd72dfcb6cec410b8e36570abf5c9d6975) +++ sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision 1bf8c894c5cc5ea6d62af0662fcf5a18e1a06459) @@ -25,7 +25,8 @@ #include "TreatmentLog.h" #include "crc.h" -SINGLETON_DISABLE(CloudSyncController) +//TODO testing the CloudSync and Application execution order +// SINGLETON_DISABLE(CloudSyncController) /*! * \brief CloudSyncController::CloudSyncController @@ -96,9 +97,10 @@ */ void CloudSyncController::initConnections() { - if ( ! gDisableCloudSyncFailStop ) { - SINGLETON_DISABLE_CONNECT(didPOSTCloudSync) - } + //TODO testing the CloudSync and Application execution order + // if ( ! gDisableCloudSyncFailStop ) { + // SINGLETON_DISABLE_CONNECT(didPOSTCloudSync) + // } connect(&_ApplicationController , SIGNAL(didPOSTCloudSync(bool)), this , SLOT( onPOSTCloudSync(bool))); @@ -161,8 +163,8 @@ */ void CloudSyncController::timerEvent(QTimerEvent *) { - // TODO: touch the inp file to as a check-in for CloudSync to know we are up - // a simple touch or a check-in message? + TIME_CALL(sendCheckIn(), _checkinIntervalSend); // call every x times/second - will be called on first call. + TIME_CALL(testCheckIn(), _checkinIntervalTest); // call every x times/second - will be called on first call. testWatchBuffDate(); testDeviceInfoWait(); } @@ -195,9 +197,9 @@ * \details This the handler for the ApplicationController::didPOSTCloudSync(bool) * \param vPass - will be true if the POST test of CloudSync passed and it is running. */ -void CloudSyncController::onPOSTCloudSync(bool vPass) +void CloudSyncController::onPOSTCloudSync(bool) { - _postPass = vPass; + //TOD _postPass = vPass; } /*! @@ -249,15 +251,33 @@ */ bool CloudSyncController::addCSBuffWatch() { + // this makeFolder function call investigated for permissions + // during setup the folder if does not exists will be created (root) + // the lockdown.sh script will set the permissions for it. + // on power cycle to normal operation the folder with the correct exists. + // *** NOTE: the makeFolder returns true if the folder already exists. *** bool ok = Storage::FileHandler::makeFolder(_location); QVariantList args {}; Errors_Enum error = eError_Unknown; - if ( ! ok ) { error = eError_LogFolder; args = {{ _location }}; ok = false; goto lErr; } - _date_out_File = _location + // The location - _dateFormatted + _dateSeparator + _out_File; // The file name - // watching for the cloud sync output file buffer. - _DeviceController.doAddWatch(_date_out_File); + _date_out_File = _location + // The location + _dateFormatted + _dateSeparator + _out_File; // The file name + // watching for the cloud sync output file buffer. + if ( ! QFileInfo(_date_out_File).exists() ) { + // if the file does not exists, send a check-in to the CS and wait for the response. + // by CS sending the response it will create the out file and next time this function with start watching the file. + // since this class has a one second timer set, next call is next second + // TODO: during this less that 1s UI will not see messages from CS, since the file was not there to watch. + sendCheckIn(); + // send device state to make the CloudSync send back a message to create the out buff with its user to own the file + return ok; + } + _DeviceController.doAddWatch(_date_out_File, false); + // since the buff files will be deleted on each power cycle, when the out buf is created it means the CloudSync is running. + // we emit the ApplicationController to check the post.log for the CloudSync status check. + _postPass = true; + testReady(); + return ok; lErr: @@ -603,7 +623,6 @@ { bool ok = true; QString inpBuff = "%1,%2,%3,%4"; - inpBuff = inpBuff .arg( _secSinceEpoch ) .arg( Types::safeIncrement(_seq)) @@ -748,7 +767,7 @@ // 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; - + case eMessageID_CheckIn : ok = takeCheckIn ( ); break; case eMessageID_DeviceInfo : ok = sendDeviceInfo ( ); break; case eMessageID_CredentialsSave : ok = sendCredentialsSave( vMessage ); break; case eMessageID_UIFactoryReset : ok = sendFactoryReset ( ); break; @@ -884,6 +903,42 @@ } /*! + * \brief CloudSyncController::sendCheckIn + * \details Send a check-in message and expects the same check-in message from CS + * \return + */ +bool CloudSyncController::sendCheckIn() +{ + _checkinRcvd = false; + qint32 messageID = UI2CS(eMessageID_CheckIn); + return sendUIBuff( { QString("%1").arg( messageID ) ,"0" } ); +} + +/*! + * \brief CloudSyncController::testCheckIn + * \details + * \return + */ +void CloudSyncController::testCheckIn() +{ + if ( ! _checkinRcvd ) { + LOG_APPED_UI(QString("CloudSync check-in failed")); + } +} + +/*! + * \brief CloudSyncController::takeCheckIn + * \details if the check-in received this method will be called + * \return true - + */ +bool CloudSyncController::takeCheckIn() +{ + _checkinRcvd = true; + emit didCheckInReceive(); + return true; +} + +/*! * \brief CloudSyncController::sendTxCodeDisplay * \details reads the received Tx Code from CloudSync app and notifies with a signal. * \param vMessage : message containing the Tx Code.