Index: sources/storage/usbwatcher.cpp =================================================================== diff -u -r862dc0590b73c618fac73dce2c976e3526e0404a -r44a85c96ab55e424866ec4cca0270aa218355f82 --- sources/storage/usbwatcher.cpp (.../usbwatcher.cpp) (revision 862dc0590b73c618fac73dce2c976e3526e0404a) +++ sources/storage/usbwatcher.cpp (.../usbwatcher.cpp) (revision 44a85c96ab55e424866ec4cca0270aa218355f82) @@ -1,15 +1,16 @@ /*! - * + * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. - * copyright - * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, - * IN PART OR IN WHOLE, - * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. - * - * file usbwatcher.cpp - * date 12/31/2019 - * author Behrouz NematiPour - * + * \copyright + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN + * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * \file usbwatcher.cpp + * \author (last) Behrouz NematiPour + * \date (last) 07-May-2020 + * \author (original) Behrouz NematiPour + * \date (original) 02-Jan-2020 + * */ #include "usbwatcher.h" @@ -29,6 +30,12 @@ // namespace using namespace Storage; +/*! + * \brief USBWatcher::USBWatcher + * \details Constructor + * \param parent - QObject parent owner object. + * Qt handles the children destruction by their parent objects life-cycle. + */ USBWatcher::USBWatcher(QObject *parent) : QObject(parent) { } /*! @@ -43,7 +50,7 @@ // runs in USBWatcher thread initConnections(); - startTimer(_checkInterval); + startTimer(_interval); return true; } @@ -70,8 +77,11 @@ */ void USBWatcher::quit() { - quitThread(); + // coco begin validated: Application termination is not correctly done in coco!!! + // it has been tested and works perfectly fine in normal run. + quitThread(); // validated } +// coco end /*! * \brief USBWatcher::initConnections @@ -109,11 +119,15 @@ */ void USBWatcher::quitThread() { + // coco begin validated: Application termination is not correctly done in coco!!! + // it has been tested and works perfectly fine in normal run. + if ( ! _thread ) return; // runs in thread - moveToThread(qApp->thread()); + moveToThread(qApp->thread()); // validated } +// coco end /*! * \brief USBWatcher::usbSeek @@ -125,6 +139,7 @@ */ bool USBWatcher::usbSeek(QString &vDevice) { + // coco begin validated: Needed User Interaction so tested manually QString device = ""; for (char a = 'a'; a <= 'z'; a++) { device = QString("/dev/sd%1%2").arg(a).arg('1'); @@ -135,6 +150,7 @@ } vDevice = device; return false; + // coco end } /*! @@ -156,6 +172,7 @@ */ void USBWatcher::usbcheck() { + // coco begin validated: Needed User Interaction so tested manually QString device = ""; if (usbSeek(device)) { if (! _umounted ) { @@ -168,6 +185,7 @@ usbRemove(); } } + // coco end } /*! @@ -180,22 +198,27 @@ */ void USBWatcher::usbError(const QString &vDevice) { + // coco begin validated: This needs user interaction to plug-in/out the USB device + // has been tested manually QString error; static QString lastError; switch (errno) { case EBUSY: error = tr("%1 - Device or resource busy (%2)").arg(errno).arg(vDevice); _mounted = true; break; + default: error = tr("%1 - %2 (%3 , %4)").arg(errno).arg(strerror(errno)).arg(vDevice).arg(USB_Mount_Point); break; + } if (error != lastError) { LOG_ERROR(error); lastError = error; } } +// coco end /*! * \brief USBWatcher::onUSBDriveUmount @@ -204,8 +227,11 @@ */ void USBWatcher::onUSBDriveUmount() { + // coco begin validated: This needs user interaction to plug-in/out the USB device + // has been tested manually _umounted = true; } +// coco end /*! * \brief USBWatcher::usbMount @@ -216,6 +242,8 @@ */ bool USBWatcher::usbMount(const QString &vDevice) { + // 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, 0, "") == 0; @@ -229,6 +257,7 @@ } return ok; } +// coco end /*! * \brief USBWatcher::usbUmount @@ -239,8 +268,10 @@ */ bool USBWatcher::usbUmount(const QString &vDevice) { + // 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; + ok = ::umount(vDevice.toLatin1().constData()) == 0; if (ok) { _mounted = false; LOG_EVENT(tr("USB drive unmounted")); @@ -251,6 +282,7 @@ } return ok; } +// coco end /*! * \brief USBWatcher::usbRemove @@ -260,9 +292,12 @@ */ void USBWatcher::usbRemove() { + // coco begin validated: This needs user interaction to plug-out the USB device + // has been tested manually usbUmount(USB_Mount_Point); _umounted = false; _removed = true; LOG_EVENT(tr("USB drive removed")); emit didUSBDriveRemove(); } +// coco end