Index: sources/device/DeviceController.cpp =================================================================== diff -u -rc73feffa73c7fe073a7a7581144f5806dfc91beb -rf0ffeb8c9ec7a838f039b904ce253b001561b5db --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision c73feffa73c7fe073a7a7581144f5806dfc91beb) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision f0ffeb8c9ec7a838f039b904ce253b001561b5db) @@ -724,3 +724,56 @@ _macWireless = vMacWireless .trimmed(); _macBluetooth = vMacBluetooth .trimmed(); } + +///////////////////////////////////////////// DeviceFactoryReset +/*! + * \brief DeviceController::onAttributeRequest + * \details Calls the FactoryReset script with the model data DeviceFactoryResetRequestData + * \param vData - the model data + */ +void DeviceController::onAttributeRequest(const DeviceFactoryResetRequestData &vData) +{ + _deviceFactoryResetRequest._data = vData; + + // ----- check that script exists. + QString script; + if ( checkError( DeviceError::checkScript(script, Factory_Reset), _deviceFactoryResetResponse, script) ) + return; + + // ----- check if the process is not running + if ( _processFactoryReset.state() != QProcess::NotRunning ) { + checkError(DeviceError::eDevice_Scripts_Error_IsRunning, _deviceFactoryResetResponse); + return; + } + + + // ----- run the process + int timeout = 10000; + TimedProcess *timedProcess = new TimedProcess(&_processFactoryReset, script, timeout); + timedProcess->start(); + + MDeviceFactoryResetResponse model; + model._data.mAccepted = false; // will indirectly set the property factoryResetEnabled + model._data.mMessage = tr("Factory Reset started."); + didAttributeResponse(model.data()); +} + +/*! + * \brief DeviceController::onProcessFactoryResetExitCode + * \param vExitCode + * \param vStatus + */ +void DeviceController::onProcessFactoryResetExitCode(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. + MDeviceFactoryResetResponse model; + QByteArray deviceInfo = _processFactoryReset.readAll(); + if ( vStatus ) vExitCode = Device::DeviceError::eDevice_Scripts_Error_Status; + else deviceInfo = _processFactoryReset.readAll(); + model.fromByteArray( deviceInfo, &vExitCode ); + // DEBUG: qDebug() << model._data.mEchoInfo; + didAttributeResponse(model.data()); + LOG_APPED_UI(model.data().mMessage); +}