Index: sources/device/DeviceController.cpp =================================================================== diff -u -r1da89b0452b8ef9448847618e75c118f3f58bd0c -rfb43510552969e9fb3c3f10ae693ba81ea7e8d52 --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 1da89b0452b8ef9448847618e75c118f3f58bd0c) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision fb43510552969e9fb3c3f10ae693ba81ea7e8d52) @@ -565,6 +565,74 @@ } } + +///////////////////////////////////////////// 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, vData.mIsGet ? RootSSHAccess_Get : RootSSHAccess_Set), _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 + + TimedProcess *timedProcess = new TimedProcess(&_processRootSSHAccess, script, 1000, { _deviceRootSSHAccessRequest._data.mRootSSHAccess ? "YES": "no" }); + timedProcess->start(); +} + +/*! + * \brief DeviceController::onProcessRootSSHAccessFinished + * \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::onProcessRootSSHAccessExitCode(int vExitCode, QProcess::ExitStatus) +{ + if ( ! checkError(static_cast(vExitCode), _deviceRootSSHAccessResponse, _deviceRootSSHAccessResponse.toString()) ) { // has no error + if (_deviceRootSSHAccessRequest._data.mIsGet) { + bool ok = false; + bool rootSSHAccess = _processRootSSHAccess.readLine().toUInt(&ok); + if ( ok ) { + _deviceRootSSHAccessResponse._data.mMessage = _deviceRootSSHAccessResponse.toString(); + _deviceRootSSHAccessResponse._data.mRootSSHAccess = rootSSHAccess; + } + else { + checkError(DeviceError::eDevice_Scripts_Error_Incorrect_Rsp, _deviceRootSSHAccessResponse, _deviceRootSSHAccessResponse.toString()); + return; + } + } + 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 + } +} + ///////////////////////////////////////////// DeviceCryptSetup /*! * \brief DeviceController::onAttributeRequest @@ -573,7 +641,7 @@ */ void DeviceController::onAttributeRequest(const DeviceCryptSetupRequestData &vData) { - qDebug() << " ---------- " << vData.mCommand << vData.mPassword; + //DEBUG qDebug() << " ---------- " << vData.mCommand << vData.mPassword; _deviceCryptSetupRequest._data = vData; @@ -754,7 +822,7 @@ void DeviceController::onEventThreadChange() { - qDebug() << " ---------- " << __FUNCTION__ << QThread::currentThread()->objectName() << QThread::currentThread() << qApp->thread(); + //DEBUG qDebug() << " ---------- " << __FUNCTION__ << QThread::currentThread()->objectName() << QThread::currentThread() << qApp->thread(); if ( QThread::currentThread() != &Threads::_DeviceController_Thread ) { qCritical() << " ***** Device controller thread not initialized correctly ***** "; return;