Index: sources/device/DeviceController.cpp =================================================================== diff -u -rb7c9de054c6b7a1ca4bac9fbb0ec5d4ac06620a9 -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision b7c9de054c6b7a1ca4bac9fbb0ec5d4ac06620a9) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -430,7 +430,7 @@ QString src = (vError > DeviceError::eDevice_Scripts_Error_Start ? MAbstract::unitText(MAbstract::Unit_Enum::eUI) : MAbstract::unitText(MAbstract::Unit_Enum::eDV)) + ","; vModel._data.mAccepted = false ; vModel._data.mReason = vError ; - vModel._data.mMessage = DeviceError::deviceErrorText(vError) + QString(" [%1]").arg(vError); + vModel._data.mMessage = DeviceError::deviceErrorText(vError, vError); LOG_EVENT(src + vModel._data.mMessage + " " + vExtraLogInfo); emit didAttributeResponse(vModel._data); return true; @@ -499,6 +499,7 @@ */ void DeviceController::onProcessBrightnessExitCode(int vExitCode, QProcess::ExitStatus) { + // TODO: Move this into the model. _deviceBrightnessResponse._data.mBrightnessPercent = _deviceBrightnessRequest._data.mBrightness_old * 10; // set to old value in case of error if ( ! checkError(static_cast(vExitCode), _deviceBrightnessResponse, _deviceBrightnessResponse.toString()) ) { // has no error if (_deviceBrightnessRequest._data.mRead) { @@ -541,17 +542,49 @@ void DeviceController::onProcessBluetoothPairedResetExitCode(int vExitCode, QProcess::ExitStatus vStatus) { - DeviceBluetoothPairedResetResponseData data; - data.mAccepted = vStatus == QProcess::NormalExit; - data.mReason = vExitCode; - QString msg; - if (data.mAccepted) msg = tr("Removed previously paired devices."); - else msg = tr("Unsuccessful removal of previously paired devices."); - data.mMessage = msg; - didAttributeResponse(data); - LOG_DEBUG(msg); + // 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_EVENT_UI(model.data().mMessage); + didAttributeResponse(model.data()); } + +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 + TimedProcess *timedProcess = new TimedProcess(&_processBluetoothPairedQuery, script, 1000); + timedProcess->start(); +} + +void DeviceController::onProcessBluetoothPairedQueryExitCode(int vExitCode, QProcess::ExitStatus vStatus) +{ + // The Exit code in this script is not used and 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 ); + didAttributeResponse(model.data()); + LOG_EVENT_UI(model.data().mMessage); +} + /*! * \brief DeviceController::doScreenshot * \details emit the screenshot signal to run that in Device controller thread @@ -581,12 +614,12 @@ { if ( ! QFileInfo::exists(vFile)) { if ( ! FileHandler::write(vFile, "", false) ) { - LOG_DEBUG(DeviceError::deviceErrorText(DeviceError::eDevice_Watch_Error_NotFound)); + LOG_DEBUG(DeviceError::deviceErrorText(DeviceError::eDevice_Watch_Error_NotFound, 0)); return; } } if ( ! _fileSystemWatcher.addPath(vFile) ) { - LOG_DEBUG(DeviceError::deviceErrorText(DeviceError::eDevice_Watch_Error_NotAdded)); + LOG_DEBUG(DeviceError::deviceErrorText(DeviceError::eDevice_Watch_Error_NotAdded, 0)); } }