/*! * * Copyright (c) 2020-2024 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) Dara Navaei * \date (last) 26-Mar-2024 * \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; int _settingsError = 0; 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 initSetttings(); void checkIn(); void createFakeSequencedLongMessage (QVariantList &vData, const int vFakeDataLen); void createFakeSeqAtBeginLongMessage(QVariantList &vData, const int vFakeDataLen); void postDoneRequest(); void versionsRequest(); void institutionalRequest(); void advancedInstitutionalRequest(); void alarmTrigger (Gui::GuiAlarmID vAlarmID, bool vSend = false, bool vSingle = false); private slots: // Should be private for thread safety and is connected internally. void onActionReceive (GuiActionType vAction, const QVariantList &vData); // UI <= TD/DD void onActionTransmit(GuiActionType vAction, const QVariantList &vData); // UI => TD/DD 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 onCryptSetupMount (bool vPass); void onExportLog (const GuiStringIndexMap &vExportList); void onExportService (const GuiStringIndexMap &vExportList); void onExportTreatment (const GuiStringIndexMap &vExportList); void onExport (); void onExportStat (quint32 vIndex, const QString &vFileName, quint8 vPercent); void onFailedTransmit(Sequence seq); void onSettingsUpdate(); void onOSVersion (bool vPass); void onPOSTEthernet (bool vPass); void onPOSTWiFi (bool vPass); void onPOSTBluetooth (bool vPass); void onPOSTCloudSync (bool vPass); void onPOSTFail (Gui::GuiAlarmID vAlarmID); void onPOSTDone (bool vPass); void onQuitApplication (); void onLogIOFail(); void onTreatmentRangesDone(bool vPass); signals: void didPOSTOSVersion (bool vPass); void didPOSTEthernet (bool vPass); void didPOSTWireless (bool vPass); void didPOSTBluetooth (bool vPass); void didPOSTCloudSync (bool vPass); void didPOSTOSVersionData (const QString &vOSVersion ); void didPOSTEthernetData (const QString &vMacAddress); void didPOSTWirelessData (const QString &vMacAddress); void didPOSTBluetoothData (const QString &vMacAddress); void didPOSTCloudSyncData (const QString &vNetAddress); signals: void didActionReceive (GuiActionType vAction, const QVariantList &vData); // UI <= TD/DD void didActionTransmit(GuiActionType vAction, const QVariantList &vData); // UI => TD/DD 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 (); void didExportStat (quint32 vIndex, const QString &vFileName, quint8 vPercent); /*! * \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 (); /*! * \brief didPOSTPass * \details This signal will be emitted when UI is done with the POST and will let other layers to know the result. * As an example the Manufacturing or update will not start if the POST failed since it needs POST info for the Encrypted partition. * \param vPass - true if passed. */ void didPOSTPass (bool vPass); /*! * \brief didCheckInBegin * \details this signal will be emitted by ApplicationController * when it is done with all the POST to nitify the TD device to start the conversation. */ void didCheckInBegin (); /*! * \brief didQuitApplication * \details this signal is a placeholder for any farther notification to any class which needs to close itself. * it will be used to let the other classes to stop and move to main thread. */ void didQuitApplication (); // 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) { postDoneRequest(); emit didActionReceive(vData); } // TODO: do the same for Settings. SAFE_CALL(startPOST) };