Index: sources/device/DeviceController.h =================================================================== diff -u -r052c794d6a8db55a2fbfdad172275af073ee54c3 -r6c6f1f5d466badd9b4fd67be7c907234c342b2a2 --- sources/device/DeviceController.h (.../DeviceController.h) (revision 052c794d6a8db55a2fbfdad172275af073ee54c3) +++ sources/device/DeviceController.h (.../DeviceController.h) (revision 6c6f1f5d466badd9b4fd67be7c907234c342b2a2) @@ -1,30 +1,29 @@ /*! * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * Copyright (c) 2021-2023 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 DeviceController.h * \author (last) Behrouz NematiPour - * \date (last) 29-May-2021 + * \date (last) 19-Dec-2022 * \author (original) Behrouz NematiPour - * \date (original) 17-Jul-2020 + * \date (original) 03-Jun-2021 * */ #pragma once // Qt #include #include +#include // Project -#include "main.h" // Doxygen : don't remove -#include "Threads.h" +#include "main.h" // Doxygen : do not remove #include "DeviceGlobals.h" #include "DeviceModels.h" #include "DeviceError.h" - // Define #define _DeviceController Device::DeviceController::I() @@ -34,13 +33,53 @@ namespace Device { /*! + * \brief The TimedProcess class + * \details This is a timed process class which has a timeout + * and will kill the process if it can't be finished within the given timeout + * in milliseconds. + */ +class TimedProcess : public QObject { + Q_OBJECT + + explicit TimedProcess(QObject *parent = nullptr) : QObject(parent) { } + int _pid = 0; + int _timeout = 0; + QProcess *_process = nullptr; + QString _command = ""; + QStringList _arguments = {}; + +private slots: + void onFinish(int) { + killTimer(_pid); + _process->kill(); + _process = nullptr; + deleteLater(); + } +public: + TimedProcess(QProcess *vProcess, const QString &vCommand, int vTimeout, QStringList vArguments = {}) + : QObject(), _timeout(vTimeout), _process(vProcess), _command(vCommand), _arguments(vArguments) { + connect(_process, SIGNAL( finished(int)), + this , SLOT(onFinish (int))); + } + void start() { + _pid = startTimer(_timeout); + _process->start(_command, _arguments); + } + +protected: + void timerEvent(QTimerEvent *) { + onFinish(-1); + } +}; + +/*! * \brief The DeviceController class * \details This class is the device controller meaning all the device interactions and settings like Volume(Device), Brightness, WiFi, Date, Time, etc * has to be done through this controller and it's dedicated thread and by using the QProcess(es) which is a call to the administrative shell scripts. * It also is watching for the USB and SD-Card drives in Linux file system. * It has the interval of 1000 ms and will look if any device between /dev/sda1 to /dev/sdz1 exists then will mount it in /media/usb, * and does check if the SD-Card has been mounted under /media/sdcard, - * but for SD-Card doesn't try to mount it and it has to be mounted prior to UI Application start + * but for SD-Card does not try to mount it and it has to be mounted prior to UI Application start * and that's because from UI Application perspective it is not a removable/hot-plug device (although physically it is). * This class works in its own thread and will send notification by emitting signals about the USB device status * which are Mounted, Unmounted, Removed @@ -61,29 +100,56 @@ bool _mounted = false; bool _umounted = false; bool _removed = false; - const char *_usbDrive = ""; const int _interval = 1000; // in ms const qint8 _minRequiredAvailableSpacePercent = 10; QThread *_thread = nullptr; bool _init = false; - bool _pauseSpaceCheck = false; + QFileSystemWatcher _fileSystemWatcher; + QString _macEthernet = ""; + QString _macWireless = ""; + QString _macBluetooth = ""; + QString _netCloudSync = ""; + + bool _hasThread = false; + bool _hasSalt = false; + + //TODO: all of these should use the TimesProcess (instead of QProcess) + // to be able to kill the process automatically after the set time out. DEVICE_DEV_DEFINITION_LIST public slots: bool init(); bool init(QThread &vThread); + void quit(); void doScreenshot(const QImage &vImage, const QString &vFileName); private slots: - void quit(); - void onRemoveLogs(bool vInProgress); void onScreenshot(const QImage &vImage, const QString &vFileName); + void onUSBDriveUmount(); + void onWatchFileChanged(const QString &vFile); + + + void onEventThreadChange (); + + /*! + * \brief didPOSTData + * \details These signals will be emitted when UI is done with the POST and will let DeviceView update its property(ies). + * \param vMacEthernet - Ethernet Mac Adress + * \param vMacWireless - Wireless Mac Adress + * \param vMacBluetooth - Bluetooth Mac Adress + * \param vNetCloudSync - CloudSync IP Adress + */ + void onPOSTEthernetData (const QString &vMacAddress); + void onPOSTWirelessData (const QString &vMacAddress); + void onPOSTBluetoothData (const QString &vMacAddress); + void onPOSTCloudSyncData (const QString &vNetAddress); + protected: void timerEvent(QTimerEvent *) override; @@ -101,6 +167,10 @@ bool checkError(DeviceError::Scripts_Error_Enum vError, TModel &vModel,QString vExtraLogInfo = ""); DeviceError::Scripts_Error_Enum checkScript(QString &vScript, const QString &vShellScript); + bool addWatch(const QString &vFilePath); + + void checkConfugurationMountReady(); + signals: /*! * \brief didScreenshot @@ -128,6 +198,9 @@ */ void didUSBDriveRemove(); + void didUSBStateChange(bool vIsReady, bool vIsReadOnly); + void didUSBSpaceChange(bool vReady, qint64 vTotal, qint64 vAvailable, quint8 vPercent); + /*! * \brief didSDCardFreeSpaceChange * \param vReady - Device is mounted and ready @@ -157,20 +230,41 @@ */ void didSDCardSpaceTooLow(quint8 vAvailablePercent); - void didActionReceive( const DeviceBrightnessResponseData &vBrightness ); + void didActionReceive( const DeviceBrightnessResponseData &vBrightness ); + void didActionReceive( const DeviceRootSSHAccessResponseData &vRootSSHAccess); -private slots: - // ----- USB - void usbCheck(); + void didWatchFileChange(const QString &vFile); - bool usbMount (const QString &vDevice); - bool usbUmount(const QString &vDevice); - void usbRemove(); - void usbError (const QString &vDevice); + /*! + * \brief didEventThreadChange + * \details this signal will be emitted when the curr + */ + void didEventThreadChange (QPrivateSignal); - void onUSBDriveUmount(); + void didPOSTEthernetData (const QString &vMacAddress); + void didPOSTWirelessData (const QString &vMacAddress); + void didPOSTBluetoothData (const QString &vMacAddress); + void didPOSTCloudSyncData (const QString &vNetAddress); - // ----- SDCard + /*! + * \brief didCryptSetupMount + * \details will be emitted when decrypting the configuration partition is. + * to notify the ApplicationController to call initSettings + */ + void didCryptSetupMount ( bool vPass ); + +private: + // ----- USB + void usbCheck (); + void usbError (const QString &vDevice ); + void usbMountReq(const QString &vDevice, bool vIsMount = true ); + void usbMount (const QString &vDevice ); + void usbUmount (const QString &vDevice ); + void usbRemove (); + void sdcardSpaceCheck(); + void usbSpaceCheck(); + + SAFE_CALL_EX(doAddWatch, const QString &) }; }