Index: sources/device/DeviceController.cpp =================================================================== diff -u -r1bf8c894c5cc5ea6d62af0662fcf5a18e1a06459 -r59625af31d9009df82fa48310b54c0f247e829fc --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 1bf8c894c5cc5ea6d62af0662fcf5a18e1a06459) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 59625af31d9009df82fa48310b54c0f247e829fc) @@ -1181,3 +1181,55 @@ // log error and exit return; } + +///////////////////////////////////////////// DeviceStartSoftwareUpdate +void DeviceController::onAttributeRequest(const DeviceStartSoftwareUpdateRequestData &vData) +{ + _deviceStartSoftwareUpdateRequest._data = vData; + + // ----- check that script exists. + QString script = Device_StartSoftwareUpdateScriptPath; + DeviceError::Scripts_Error_Enum err = DeviceError::eDevice_OK; + QFileInfo info(script); + if ( ! info.exists () ) { err = DeviceError::eDevice_Scripts_Error_NotFound ;} + if ( ! info.isExecutable() ) { err = DeviceError::eDevice_Scripts_Error_NotExecutable ;} + + if ( checkError(err, _deviceStartSoftwareUpdateResponse, script) ) + return; + + // ----- check if the process is not running + if ( _processStartSoftwareUpdate.state() != QProcess::NotRunning ) { + checkError(DeviceError::eDevice_Scripts_Error_IsRunning, _deviceStartSoftwareUpdateResponse); + return; + } + + // ----- run the process + int timeout_ms = 10000; + TimedProcess *timedProcess = new TimedProcess(&_processStartSoftwareUpdate, script, timeout_ms, { vData.mUpdateFilePath }); + timedProcess->start(); + + MDeviceStartSoftwareUpdateResponse model; + model._data.mAccepted = false; // will indirectly set the property startSoftwareUpdateEnabled + model._data.mMessage = tr("Software Update started."); + didAttributeResponse(model.data()); +} + +/*! + * \brief DeviceController::onProcessStartSoftwareUpdateExitCode + * \param vExitCode + * \param vStatus + */ +void DeviceController::onProcessStartSoftwareUpdateExitCode(int vExitCode, QProcess::ExitStatus vStatus) +{ + // The Exit code in this script is not used. + // any other checking is done by UI Software at the moment this script is called. + // The only thing matters is the paired device info in text and it will be empty string if error happens. + MDeviceStartSoftwareUpdateResponse model; + QByteArray deviceInfo; + if ( vStatus ) vExitCode = Device::DeviceError::eDevice_Scripts_Error_Status; + else deviceInfo = _processStartSoftwareUpdate.readAll(); + model.fromByteArray( deviceInfo, &vExitCode ); + // DEBUG: qDebug() << model._data.mMessage << deviceInfo; + didAttributeResponse(model.data()); + LOG_APPED_UI(model.data().mMessage); +}