Index: sources/device/DeviceController.cpp =================================================================== diff -u -r3c547f89553d3aabe59423b82ecb7f8c28f9d32a -r472c10e72a8d278f13d2343f9c81c1def14490ff --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 3c547f89553d3aabe59423b82ecb7f8c28f9d32a) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 472c10e72a8d278f13d2343f9c81c1def14490ff) @@ -103,11 +103,11 @@ connect(&_ApplicationController , SIGNAL(didUSBDriveUmount()), this , SLOT( onUSBDriveUmount())); - connect(this , SIGNAL(didScreenshot(const QImage &, const QString &)), - this , SLOT( onScreenshot(const QImage &, const QString &))); + connect(this , SIGNAL(didScreenshot (const QImage &, const QString &)), + this , SLOT( onScreenshot (const QImage &, const QString &))); - connect(&_fileSystemWatcher , SIGNAL( fileChanged(const QString &)), - this , SLOT( onWatchFileChanged(const QString &))); + connect(&_fileSystemWatcher , SIGNAL( fileChanged (const QString &)), + this , SLOT( onWatchFileChanged (const QString &))); connect(&_ApplicationController , SIGNAL(didPOSTOSVersionData (const QString &)), this , SLOT( onPOSTOSVersionData (const QString &))); @@ -538,319 +538,7 @@ return false; } -///////////////////////////////////////////// DeviceBrightness /*! - * \brief DeviceController::onAttributeRequest - * \details Sets the brightness level - * \param vBrightness - */ -void DeviceController::onAttributeRequest(const DeviceBrightnessRequestData &vData) -{ - // ----- initializing the member variable models - _deviceBrightnessRequest ._data = vData; - - - // ----- extract the required data - _deviceBrightnessRequest.setBrightnessSysVal(); - LOG_APPED( _deviceBrightnessRequest.toString()); - - // ----- check that script exists. - QString script; - if ( checkError( DeviceError::checkScript(script, vData.mRead ? Brightness_Get : Brightness_Set), _deviceBrightnessResponse, script) ) - return; - - // ----- check if the process is not running - if ( _processBrightness.state() != QProcess::NotRunning ) { - checkError(DeviceError::eDevice_Scripts_Error_IsRunning, _deviceBrightnessResponse); - return; - } - - // ----- run the process - int timeout_ms = 10000; - QStringList params; - params << QString::number(_deviceBrightnessRequest._data.mBrightness_val); - TimedProcess *timedProcess = new TimedProcess(&_processBrightness, script, timeout_ms, params); - timedProcess->start(); - -} - -/*! - * \brief DeviceController::processBrightnessResponse - * \details Called when the process to set the brightness has finished - * \param vExitCode (int) the exit code - * \note exit code -> 0 : set Accept [MBase] -> Log -> emit - * !0 : set Attrib [MBrgh] -> Log -> emit - * 1 - get an error when in onAttributeRequest : scriptErrorText([Gui Enum ]) - * 2 - get an error when in onProcessBrightnessExitCode : scriptErrorText([vExitCode]) - * 3 - get no error when in onProcessBrightnessExitCode : MDeviceResponse.toString() - * - in case 3 the specific model _data has to be filled prior to the toString to have it in the log. - */ -void DeviceController::processBrightnessResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel /*vChannel*/) -{ - //DEBUG - qDebug() << __FUNCTION__ << vExitCode << vStatus; - - if ( ! checkError(static_cast(vExitCode), _deviceBrightnessResponse, _deviceBrightnessResponse.toString()) ) { // has no error - if (_deviceBrightnessRequest._data.mRead) { - bool ok = false; - int brightness = _processBrightness.readLine().toInt(&ok); - if (ok) { - _deviceBrightnessResponse.setBrightnessPercent(brightness); - } - else { - checkError(DeviceError::eDevice_Scripts_Error_Incorrect_Rsp,_deviceBrightnessResponse, _deviceBrightnessResponse.toString()); - return; - } - } - else { - _deviceBrightnessResponse.setBrightnessPercent(_deviceBrightnessRequest._data.mBrightness_val); - _deviceBrightnessResponse._data.mMessage = _deviceBrightnessResponse.toString(); - } - LOG_APPED(_deviceBrightnessResponse._data.mMessage); - emit didAttributeResponse(_deviceBrightnessResponse._data); - } -} - - -///////////////////////////////////////////// DeviceRootSSHAccess -/*! - * \brief DeviceController::onAttributeRequest - * \details Sets the RootSSHAccess - * \param vRootSSHAccess - */ -void DeviceController::onAttributeRequest(const DeviceRootSSHAccessRequestData &vData) -{ - // ----- initializing the member variable models - _deviceRootSSHAccessRequest._data = vData; - LOG_APPED( _deviceRootSSHAccessRequest.toString()); - - // ----- check that script exists. - QString script; - if ( checkError( DeviceError::checkScript(script, RootSSHAccess), _deviceRootSSHAccessResponse, script) ) - return; - - // ----- check if the process is not running - if ( _processRootSSHAccess.state() != QProcess::NotRunning ) { - checkError(DeviceError::eDevice_Scripts_Error_IsRunning, _deviceRootSSHAccessResponse); - return; - } - - // ----- run the process - int timeout_ms = 10000; - QStringList params; - if ( ! _deviceRootSSHAccessRequest._data.mIsGet ) params << FSN(_deviceRootSSHAccessRequest._data.mRootSSHAccess); - TimedProcess *timedProcess = new TimedProcess(&_processRootSSHAccess, script, timeout_ms, params); - timedProcess->start(); -} - -/*! - * \brief DeviceController::processRootSSHAccessResponse - * \details Called when the process to set the RootSSHAccess has finished - * \param vExitCode (int) the exit code - * \note exit code -> 0 : set Accept [MBase] -> Log -> emit - * !0 : set Attrib [MBrgh] -> Log -> emit - * 1 - get an error when in onAttributeRequest : scriptErrorText([Gui Enum ]) - * 2 - get an error when in onProcessRootSSHAccessExitCode : scriptErrorText([vExitCode]) - * 3 - get no error when in onProcessRootSSHAccessExitCode : MDeviceResponse.toString() - * - in case 3 the specific model _data has to be filled prior to the toString to have it in the log. - */ -void DeviceController::processRootSSHAccessResponse(int vExitCode, QProcess::ExitStatus, QProcess::ProcessChannel /*vChannel*/) -{ - if ( ! checkError(static_cast(vExitCode), _deviceRootSSHAccessResponse, _deviceRootSSHAccessResponse.toString()) ) { // has no error - if (_deviceRootSSHAccessRequest._data.mIsGet) { - bool ok = true; - Qt::CheckState rootSSHAccess = Qt:: Unchecked; - uint value = _processRootSSHAccess.readLine().toUInt(&ok); - if ( ! ok ) goto lError; - - switch (value) { - case 0 : rootSSHAccess = Qt:: Unchecked; break; - case 1 : rootSSHAccess = Qt::PartiallyChecked; break; - case 2 : rootSSHAccess = Qt:: Checked; break; - default : ok = false; - } - - if ( ! ok ) goto lError; - - _deviceRootSSHAccessResponse._data.mMessage = _deviceRootSSHAccessResponse.toString(); - _deviceRootSSHAccessResponse._data.mRootSSHAccess = rootSSHAccess; - } - else { - _deviceRootSSHAccessResponse._data.mMessage = _deviceRootSSHAccessResponse.toString(); - _deviceRootSSHAccessResponse._data.mRootSSHAccess = _deviceRootSSHAccessRequest._data.mRootSSHAccess; - } - - LOG_APPED(_deviceRootSSHAccessResponse._data.mMessage); - emit didAttributeResponse(_deviceRootSSHAccessResponse._data); - } - else { - // the error in this case is handled in the checkError - } - return; - -lError: - checkError(DeviceError::eDevice_Scripts_Error_Incorrect_Rsp, _deviceRootSSHAccessResponse, _deviceRootSSHAccessResponse.toString()); -} - -///////////////////////////////////////////// DeviceCryptSetup -/*! - * \brief DeviceController::onAttributeRequest - * \details Calls the CryptSetup script with the model data DeviceCryptSetupRequestData - * \param vData - the model data - */ -void DeviceController::onAttributeRequest(const DeviceCryptSetupRequestData &vData) -{ - //DEBUG qDebug() << " ---------- " << vData.mCommand << vData.mPassword; - - _deviceCryptSetupRequest._data = vData; - - // ----- check that script exists. - QString script; - if ( checkError( DeviceError::checkScript(script, Crypt_Setup), _deviceCryptSetupResponse, script) ) - return; - - // ----- check if the process is not running - if ( _processCryptSetup.state() != QProcess::NotRunning ) { - checkError(DeviceError::eDevice_Scripts_Error_IsRunning, _deviceCryptSetupResponse); - return; - } - - - // ----- run the process - int timeout = 10000; - TimedProcess *timedProcess = new TimedProcess(&_processCryptSetup, script, timeout, { _deviceCryptSetupRequest._data.mCommand }); - _processCryptSetup.setEnvironment(QProcess::systemEnvironment() << QString("PASSWORD=%1").arg(_deviceCryptSetupRequest._data.mPassword)); - timedProcess->start(); - - // Update UI with a response - MDeviceCryptSetupResponse model; - model._data.mAccepted = false; - model._data.mMessage = tr("Encrypted Partition %1 started.").arg(_deviceCryptSetupRequest._data.mCommand); - emit didAttributeResponse(model.data()); -} - -/*! - * \brief DeviceController::processCryptSetupResponse - * \param vExitCode - * \param vStatus - */ -void DeviceController::processCryptSetupResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel /*vChannel*/) -{ - const int ERR_CRYPTSETUP_MOUNT_ISMOUNT=134; // is used in crypt_setup.sh do not modify - - // 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 pared device info in text and it will be empty string if error happens. - MDeviceCryptSetupResponse model; - QByteArray deviceInfo; - if ( vStatus ) vExitCode = Device::DeviceError::eDevice_Scripts_Error_Status; - else deviceInfo = _processCryptSetup.readAll(); - model.fromByteArray( deviceInfo, &vExitCode ); - // DEBUG: qDebug() << model._data.mEchoInfo; - emit didAttributeResponse(model.data()); - LOG_APPED_UI(model.data().mMessage); - - bool isSetup = _deviceCryptSetupRequest._data.mCommand == "setup"; - bool isMount = _deviceCryptSetupRequest._data.mCommand == "mount"; - bool isMounted = isMount && ( - vExitCode == ERR_CRYPTSETUP_MOUNT_ISMOUNT || // is already mounted - vExitCode == 0 // successful mount - ); - bool isUpdate = gEnableUpdating && isMounted; - - if ( isMount ) emit didCryptSetupMount(model._data.mAccepted); - - QString msg = ""; - int err = 0 ; - // moving the configuration files if the encrypted partition creation was successful. - if ( isUpdate ) goto lMove; // if it is gEnableUpdating, bypass the mAccepted for already mounted. - if ( ! model._data.mAccepted ) goto lErr ; // any other case goto error - if ( ! isSetup ) goto lOut ; // if not setup do NOT continue to move configurations - -lMove: - err = Storage::Settings::configurationsMove(&msg, isUpdate); - if ( err ) { - model._data.mAccepted = false ; - model._data.mReason = err ; - model._data.mMessage = msg ; - emit didAttributeResponse(model.data()); - LOG_APPED_UI(model.data().mMessage); - } - -lOut: - return; - -lErr: - LOG_DEBUG(QString("Encrypted Partition %1 failed").arg(_deviceCryptSetupRequest._data.mCommand)); -} - -///////////////////////////////////////////// DeviceBluetoothPaired -void DeviceController::onAttributeRequest(const DeviceBluetoothPairedResetRequestData &) -{ - // ----- check that script exists. - QString script; - if ( checkError( DeviceError::checkScript(script, Bluetooth_Paired_Reset), _deviceBluetoothPairedResetResponse, script) ) - return; - - // ----- check if the process is not running - if ( _processBluetoothPairedReset.state() != QProcess::NotRunning ) { - checkError(DeviceError::eDevice_Scripts_Error_IsRunning, _deviceBluetoothPairedResetResponse); - return; - } - - // ----- run the process - int timeout_ms = 10000; - TimedProcess *timedProcess = new TimedProcess(&_processBluetoothPairedReset, script, timeout_ms); - timedProcess->start(); -} - -void DeviceController::processBluetoothPairedResetResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel /*vChannel*/) -{ - // TODO: review the usage and definition of this object _deviceBluetoothPairedResetResponse. do we need it any more? - MDeviceBluetoothPairedResetResponse model; - QByteArray deviceInfo; - if ( vStatus ) vExitCode = Device::DeviceError::eDevice_Scripts_Error_Status; - else deviceInfo = _processBluetoothPairedReset.readAll(); - model.fromByteArray( deviceInfo, &vExitCode ); - LOG_APPED_UI(model.data().mMessage); - emit didAttributeResponse(model.data()); -} - -///////////////////////////////////////////// DeviceBluetoothPairedQuery -void DeviceController::onAttributeRequest(const DeviceBluetoothPairedQueryRequestData &) -{ - // ----- check that script exists. - QString script; - if ( checkError( DeviceError::checkScript(script, Bluetooth_Paired_Query), _deviceBluetoothPairedQueryResponse, script) ) - return; - - // ----- check if the process is not running - if ( _processBluetoothPairedQuery.state() != QProcess::NotRunning ) { - checkError(DeviceError::eDevice_Scripts_Error_IsRunning, _deviceBluetoothPairedQueryResponse); - return; - } - - // ----- run the process - int timeout_ms = 10000; - TimedProcess *timedProcess = new TimedProcess(&_processBluetoothPairedQuery, script, timeout_ms); - timedProcess->start(); -} - -void DeviceController::processBluetoothPairedQueryResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel /*vChannel*/) -{ - // 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 pared device info in text and it will be empty string if error happens. - MDeviceBluetoothPairedQueryResponse model; - QByteArray deviceInfo; - if ( vStatus ) vExitCode = Device::DeviceError::eDevice_Scripts_Error_Status; - else deviceInfo = _processBluetoothPairedQuery.readAll(); - model.fromByteArray( deviceInfo, &vExitCode ); - emit didAttributeResponse(model.data()); - LOG_APPED_UI(model.data().mMessage); -} - -/*! * \brief DeviceController::doScreenshot * \details emit the screenshot signal to run that in Device controller thread * \param vCurrentDateTime @@ -1061,7 +749,7 @@ // status(tr("Not enough secure information provided")); } else { - onAttributeRequest(data); + // onAttributeRequest(data); // ==================================================== FIX ME } // I_AM_HERE @@ -1128,108 +816,8 @@ return; } -///////////////////////////////////////////// DeviceFactoryReset -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_ms = 10000; - TimedProcess *timedProcess = new TimedProcess(&_processFactoryReset, script, timeout_ms); - timedProcess->start(); - - MDeviceFactoryResetResponse model; - model._data.mAccepted = false; // will indirectly set the property factoryResetEnabled - model._data.mMessage = tr("Factory Reset started."); - emit didAttributeResponse(model.data()); -} - -/*! - * \brief DeviceController::processFactoryResetResponse - * \param vExitCode - the script exit code. - * \param vStatus - the script echoed message. - */ -void DeviceController::processFactoryResetResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel /*vChannel*/) -{ - // 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; - if ( vStatus ) vExitCode = Device::DeviceError::eDevice_Scripts_Error_Status; - else deviceInfo = _processFactoryReset.readAll(); - model.fromByteArray( deviceInfo, &vExitCode ); - // DEBUG: qDebug() << model._data.mMessage << deviceInfo; - emit didAttributeResponse (model.data()); - emit didFactoryReset (model._data.mAccepted); - - LOG_APPED_UI(model.data().mMessage); -} - -///////////////////////////////////////////// DeviceDecommission -void DeviceController::onAttributeRequest(const DeviceDecommissionRequestData &vData) -{ - _deviceDecommissionRequest._data = vData; - - // ----- check that script exists. - QString script; - if ( checkError( DeviceError::checkScript(script, Device_Decommission), _deviceDecommissionResponse, script) ) - return; - - // ----- check if the process is not running - if ( _processDecommission.state() != QProcess::NotRunning ) { - checkError(DeviceError::eDevice_Scripts_Error_IsRunning, _deviceDecommissionResponse); - return; - } - - - // ----- run the process - int timeout_ms = 10000; - TimedProcess *timedProcess = new TimedProcess(&_processDecommission, script, timeout_ms, { CloudSyncPath }); - _processDecommission.setEnvironment(QProcess::systemEnvironment() << QString("PASSWORD=%1").arg(_deviceDecommissionRequest._data.mPassword)); - timedProcess->start(); - - MDeviceDecommissionResponse model; - model._data.mAccepted = false; // will indirectly set the property decommissionEnabled - model._data.mMessage = tr("Decommissioning started."); - emit didAttributeResponse(model.data()); -} - -/*! - * \brief DeviceController::processDecommissionResponse - * \param vExitCode - * \param vStatus - */ -void DeviceController::processDecommissionResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel /*vChannel*/) -{ - // 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. - MDeviceDecommissionResponse model; - QByteArray deviceInfo; - if ( vStatus ) vExitCode = Device::DeviceError::eDevice_Scripts_Error_Status; - else deviceInfo = _processDecommission.readAll(); - model.fromByteArray( deviceInfo, &vExitCode ); - // DEBUG: qDebug() << model._data.mMessage << deviceInfo; - emit didAttributeResponse (model.data()); - emit didDecommissioning (model._data.mAccepted); - - LOG_APPED_UI(model.data().mMessage); -} - -///////////////////////////////////////////// DeviceUSBMounting +////////////////////////////////////////////////////////////////////////////////////////////////// DeviceUSBMounting void DeviceController::onAttributeRequest(const DeviceUSBMountRequestData &vData) { usbMountReq(vData.usbDevice, vData.isMountRequest); @@ -1243,13 +831,13 @@ */ void DeviceController::usbMountReq(const QString &vDevice, bool vIsMount) { - qDebug() << __FUNCTION__ << vDevice << vIsMount; + // DEBUG qDebug() << __FUNCTION__ << vDevice << vIsMount; _deviceUSBMountRequest._data.isMountRequest = vIsMount ; _deviceUSBMountRequest._data.usbDevice = vDevice ; // not necessary, but to be consistent // ----- check that script exists. QString script; - if ( checkError( DeviceError::checkScript(script, (vIsMount ? USB_Mount : USB_Unmount )), _deviceUSBMountResponse, script) ) + if ( checkError( DeviceError::checkScript(script, (vIsMount ? Scripts_USB_Mount : Scripts_USB_Unmount )), _deviceUSBMountResponse, script) ) return; // ----- check if the process is not running @@ -1314,7 +902,79 @@ return; } -///////////////////////////////////////////// DeviceWifiList +////////////////////////////////////////////////////////////////////////////////////////////////// DeviceBrightness +/*! + * \brief DeviceController::onAttributeRequest + * \details Sets the brightness level + * \param vBrightness + */ +void DeviceController::onAttributeRequest(const DeviceBrightnessRequestData &vData) +{ + DeviceError::Scripts_Error_Enum error = DeviceError::eDevice_OK; + + // ----- initializing the member variable models + _deviceBrightnessRequest._data = vData; + + // ----- extract the required data + LOG_APPED( _deviceBrightnessRequest.toString() ); + + // ----- check that script exists. + QString script; + if ( checkError( DeviceError::checkScript(script, Scripts_Brightness), _deviceBrightnessResponse, script) ) + return; + + // ----- check if the process is not running + if ( _processBrightness.state() != QProcess::NotRunning ) { + checkError(DeviceError::eDevice_Scripts_Error_IsRunning, _deviceBrightnessResponse); + return; + } + + QStringList params; + params << _deviceBrightnessRequest.toByteArray(&error); + if ( error ) { + checkError(error, _deviceBrightnessResponse); + return; + } + + // ----- run the process + int timeout_ms = 10000; + TimedProcess *timedProcess = new TimedProcess(&_processBrightness, script, timeout_ms, params); + timedProcess->start(); +} + +/*! + * \brief DeviceController::processBrightnessResponse + * \details Called when the process to set the brightness has finished + * \param vExitCode (int) the exit code + * \note exit code -> 0 : set Accept [MBase] -> Log -> emit + * !0 : set Attrib [MBrgh] -> Log -> emit + * 1 - get an error when in onAttributeRequest : scriptErrorText([Gui Enum ]) + * 2 - get an error when in onProcessBrightnessExitCode : scriptErrorText([vExitCode]) + * 3 - get no error when in onProcessBrightnessExitCode : MDeviceResponse.toString() + * - in case 3 the specific model _data has to be filled prior to the toString to have it in the log. + */ +void DeviceController::processBrightnessResponse(int vExitCode, QProcess::ExitStatus vStatus, QProcess::ProcessChannel vChannel) +{ + Q_UNUSED(vStatus ) + Q_UNUSED(vChannel ) + //DEBUG qDebug() << " 1 ---------- " << __FUNCTION__ << vExitCode << vStatus << vChannel; + static MDeviceBrightnessResponse model; + + if ( vExitCode < 0 ) { + emit didAttributeResponse(model.data()); + switch (vChannel) { + case QProcess::StandardOutput : processBrightnessReadyOut(model); break; + case QProcess::StandardError : processBrightnessReadyErr(model); break; + } + } + else { + processBrightnessComplete(model, vExitCode, vStatus); + emit didAttributeResponse(model.data()); + model._data.clear(); + } +} + +////////////////////////////////////////////////////////////////////////////////////////////////// DeviceWifiList void DeviceController::onAttributeRequest(const DeviceWifiListRequestData &) { wifiListRequest(); @@ -1329,7 +989,7 @@ { // ----- check that script exists. QString script; - if ( checkError( DeviceError::checkScript(script, Wifi_Scan_For_Networks), _deviceWifiListResponse, script) ) + if ( checkError( DeviceError::checkScript(script, Scripts_Wifi_Scan), _deviceWifiListResponse, script) ) return; // ----- check if the process is not running