Index: sources/device/DeviceController.cpp =================================================================== diff -u -rdeaef8b5bdfe9be7293e63fb6ac256a9ce3cd3f4 -re7adb742d7dd362b2deb795259694b223eea3bc0 --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision deaef8b5bdfe9be7293e63fb6ac256a9ce3cd3f4) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision e7adb742d7dd362b2deb795259694b223eea3bc0) @@ -1179,10 +1179,7 @@ */ void DeviceController::processWifiConnectResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel vChannel) { - Q_UNUSED(vStatus ) - Q_UNUSED(vChannel ) static MDeviceWifiConnectResponse model; - if ( vExitCode < 0 ) { emit didAttributeResponse(model.data()); switch (vChannel) { @@ -1196,3 +1193,61 @@ model._data.clear(); } } + +////////////////////////////////////////////////////////////////////////////////////////////////// DeviceFactoryReset +void DeviceController::onAttributeRequest(const DeviceFactoryResetRequestData &) +{ + factoryResetRequest(); +} + +/*! + * \brief DeviceController::factoryResetRequest + * \details Calls the factoryReset script + * \note This function is created to be able to call independently if needed in this class. + */ +void DeviceController::factoryResetRequest() +{ + // ----- check that script exists. + QString script; + if ( checkError( DeviceError::checkScript(script, Scripts_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_ms = 10000; + TimedProcess *timedProcess = new TimedProcess(&_processFactoryReset, script, timeout_ms, {}); + timedProcess->start(); + + MDeviceFactoryResetResponse model; + model._data.mCompleted = false; + model._data.mAccepted = false; + model._data.mMessage = tr("Factory Reset started."); + emit didAttributeResponse(model.data()); +} + +/*! + * \brief DeviceController::processFactoryResetResponse + * \param vExitCode + * \param vStatus + */ +void DeviceController::processFactoryResetResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel vChannel) +{ + static MDeviceFactoryResetResponse model; + if ( vExitCode < 0 ) { + emit didAttributeResponse(model.data()); + switch (vChannel) { + case QProcess::StandardOutput : processFactoryResetReadyOut(model); break; + case QProcess::StandardError : processFactoryResetReadyErr(model); break; + } + } + else { + processFactoryResetComplete(model, vExitCode, vStatus); + emit didAttributeResponse(model.data()); + model._data.clear(); + } +}