Index: sources/device/DeviceController.cpp =================================================================== diff -u -r5a4a26f106ba03759e3a89b19690fa678f8a3aca -r3b402a2cfb9e673bf0bac3fcc8eeee75a0adc475 --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 5a4a26f106ba03759e3a89b19690fa678f8a3aca) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 3b402a2cfb9e673bf0bac3fcc8eeee75a0adc475) @@ -410,27 +410,12 @@ * \param vDevice - USB device to be mounted (e.g. /dev/sda1) * \return true on successful mount */ -bool DeviceController::usbMount(const QString &vDevice) +void DeviceController::usbMount(const QString &vDevice) { // disabled coco begin validated: This needs user interaction to plug-in the USB device // has been tested manually - bool ok; _usbDrive = vDevice.toLatin1().constData(); - ok = ::mount(_usbDrive, USB_Mount_Point, USB_File_System, - MS_SYNCHRONOUS | - MS_NOEXEC | // Disallow program execution - MS_NODEV | - MS_NOSUID , // Setting this option on a file system prevents users from introducing privileged programs onto the system and allowing non-root users to execute them. - "") == 0; - if (ok) { - _mounted = true; - _removed = false; - LOG_DEBUG(QString("USB flash drive %1 has been mounted on %2").arg(vDevice).arg(USB_Mount_Point)); - emit didUSBDriveMount(); - } else { - usbError(vDevice); - } - return ok; + requestUSBMount(false, _usbDrive); } // disabled coco end @@ -441,21 +426,11 @@ * \param vDevice - USB device to be unmounted (e.g. /dev/sda1) * \return true on successful unmount */ -bool DeviceController::usbUmount(const QString &vDevice) +void DeviceController::usbUmount(const QString &vDevice) { // disabled coco begin validated: This needs user interaction to plug-out the USB device // has been tested manually - bool ok; - ok = ::umount(vDevice.toLatin1().constData()) == 0; - if (ok) { - _mounted = false; - LOG_DEBUG(QString("USB drive %2 unmounted").arg(vDevice)); - emit didUSBDriveUmount(); - } else { - // the error is irrelevant, commented out for now - //usbError(vDevice); - } - return ok; + requestUSBMount(true, vDevice.toLatin1().constData()); } // disabled coco end @@ -993,3 +968,71 @@ didAttributeResponse(model.data()); LOG_APPED_UI(model.data().mMessage); } + +///////////////////////////////////////////// DeviceUSBMounting +/*! + * \brief DeviceController::onAttributeRequest + * \details Calls the Usb unmount/mount script with the model data DeviceUSBRequestData + * \param vData - the model data + */ +void DeviceController::onAttributeRequest(const DeviceUSBMountRequestData &vData) +{ + Q_UNUSED(vData) + // TODO - VY ideally we don't have this function, but macros used needs it declared +} +void DeviceController::requestUSBMount(bool vIsUnmount, const QString vUSBDrive) +{ + _deviceUSBMountRequest._data.isUnmountRequest = vIsUnmount; + + // ----- check that script exists. + QString script; + if ( checkError( DeviceError::checkScript(script, (vIsUnmount ? UnmountUSB : MountUSB)), _deviceUSBMountResponse, script) ) + return; + + // ----- check if the process is not running + if ( _processUSBMount.state() != QProcess::NotRunning ) { + checkError(DeviceError::eDevice_Scripts_Error_IsRunning, _deviceUSBMountResponse); + return; + } + + // ----- run the process + int timeout_ms = 10000; + TimedProcess *timedProcess = new TimedProcess(&_processUSBMount, script, timeout_ms, {vUSBDrive, USB_Mount_Point, USB_File_System}); + timedProcess->start(); + + MDeviceUSBMountResponse model; + model._data.mAccepted = false; + model._data.mMessage = vIsUnmount ? tr("USB unmount started.") : tr("USB mount started"); + didAttributeResponse(model.data()); +} + +/*! + * \brief DeviceController::onProcessFactoryResetExitCode + * \param vExitCode + * \param vStatus + */ +void DeviceController::onProcessUSBMountExitCode(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. + MDeviceUSBMountResponse model; + QByteArray deviceInfo = _processUSBMount.readAll(); + if ( vStatus ) vExitCode = Device::DeviceError::eDevice_Scripts_Error_Status; + else deviceInfo = _processUSBMount.readAll(); + model.fromByteArray( deviceInfo, &vExitCode ); + // DEBUG: qDebug() << model._data.mMessage << deviceInfo; + didAttributeResponse(model.data()); + LOG_APPED_UI(model.data().mMessage); + + if(_deviceUSBMountRequest._data.isUnmountRequest) { + _mounted = false; +// LOG_DEBUG(QString("USB drive %2 unmounted").arg(_deviceUSBMountRequest._data.usbDrive)); + emit didUSBDriveUmount(); + } else { + _mounted = true; + _removed = false; +// LOG_DEBUG(QString("USB flash drive %1 has been mounted on %2").arg(_deviceUSBMountRequest._data.usbDrive).arg(_deviceUSBMountRequest._data.usbMountPoint)); + emit didUSBDriveMount(); + } +}