/*! * * Copyright (c) 2020-2022 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 ApplicationController.h * \author (last) Behrouz NematiPour * \date (last) 24-Aug-2022 * \author (original) Behrouz NematiPour * \date (original) 26-Aug-2020 * */ #pragma once // Qt #include // Project #include "main.h" // Doxygen : do not remove #include "MModel.h" #include "ApplicationPost.h" #include "GuiGlobals.h" #include "MessageGlobals.h" #include "DeviceGlobals.h" // define #define _ApplicationController ApplicationController::I() // forward declarations class tst_initializations; // namespace using namespace Gui; using namespace Can; /*! * \brief The ApplicationController class * \details Singleton class which is the main gateway of all signal/slots. * This class is the main gate keeper for decisions and will decide if a message should pass through the other observers. * Currently (08/30/2020) is a bridge and will pass all the messages. * Later with implementation/help of the main state machine will decide on the state of the device what needs to be done. * \note States are like [Idle, Run on Battery, Fault, FW connection lost] and such */ class ApplicationController : public QObject { Q_OBJECT // Singleton SINGLETON(ApplicationController) // friends friend class ::tst_initializations; QThread *_thread = nullptr; bool _init = false; QFutureWatcher _settingsWatcher; ApplicationPost _post; // I may need to be put in a concurrent. public: void initSettings(); public slots: bool init(); bool init(QThread &vThread); void quit(); private: void initConnections(); void initThread(QThread &vThread); void quitThread(); void keepAlive(); void createFakeSequencedLongMessage (QVariantList &vData, const int vFakeDataLen); void createFakeSeqAtBeginLongMessage(QVariantList &vData, const int vFakeDataLen); void settingsInit(); private slots: // Should be private for thread safety and is connected internally. void onActionReceive (GuiActionType vAction, const QVariantList &vData); // UI <= HD/DG void onActionTransmit(GuiActionType vAction, const QVariantList &vData); // UI => HD/DG void onMainTimerTimeout(); void onUSBDriveMount (); void onUSBDriveUmount(); void onUSBDriveRemove(); void onUSBSpaceChange(bool vReady, qint64 vTotal, qint64 vAvailable, quint8 vPercent); void onSDCardStateChange(bool vIsReady, bool vIsReadOnly); void onSDCardSpaceChange(bool vReady, qint64 vTotal, qint64 vAvailable, quint8 vPercent); void onSDCardSpaceTooLow(quint8 vAvailablePercent); void onExportLog (); void onExportService (); void onExportTreatment (); void onExport (); void onFailedTransmit(Sequence seq); void onSettingsInit(); void onSettingsUpdate(); void onPOSTWiFi (bool vPass); void onPOSTBluetooth (bool vPass); void onPOSTCloudSync (bool vPass); void onPOSTFail (Gui::GuiAlarmID vAlarmID); void onPOSTDone (bool vPass); signals: void didPOSTWiFi (bool vPass); void didPOSTBluetooth (bool vPass); void didPOSTCloudSync (bool vPass); signals: void didActionReceive (GuiActionType vAction, const QVariantList &vData); // UI <= HD/DG void didActionTransmit(GuiActionType vAction, const QVariantList &vData); // UI => HD/DG void didFailedTransmit(Sequence seq); void didUSBDriveMount (); void didUSBDriveUmount(); void didUSBDriveRemove(); void didUSBSpaceChange(bool vReady, qint64 vTotal, qint64 vAvailable, quint8 vPercent); void didSDCardStateChange(bool vIsReady, bool vIsReadOnly); void didSDCardSpaceChange(bool vReady, qint64 vTotal, qint64 vAvailable, quint8 vPercent); void didSDCardSpaceTooLow(quint8 vAvailablePercent); void didExport (); /*! * \brief didSettingsInit - private signal to start initializing settings * \details This signal used internally to make the read task of the settings happen in Application_Thread * It's because no thread assigned to Settings itself, since this class will be used only once * and does not need a thread by itself */ void didSettingsInit (QPrivateSignal); /*! * \brief didSettingsDone * \details This signal will be emitted when the settings are read and ready to be used. */ void didSettingsDone (); // Device Signal/Slots DEVICE_APP_BRIDGE_DEFINITION_LIST // ---- Signal/Slots ADJUST_TRANSMT_MODEL_BRIDGE_DEFINITIONS ACTION_RECEIVE_MODEL_BRIDGE_DEFINITIONS ACTION_RECEIVE_PRIVATE_SLOT_NOEMIT(UIPostFinalResultHDRequestData) { onPOSTDone(_post.isDone()); emit didActionReceive(vData); } // TODO: do the same for Settings. SAFE_CALL(startPOST) };