/*! * * 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 "ApplicationPost.h" #include "MessageGlobals.h" #include "MessageInterpreter.h" // define #define _ApplicationController ApplicationController::I() // forward declarations class tst_initializations; // namespace 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(); void doUnhandledMsgAppController(const QVariantList &msg); private: void initConnections(); void initThread(QThread &vThread); void quitThread(); void initSetttings(); void keepAlive(); void createFakeSequencedLongMessage (QVariantList &vData, const int vFakeDataLen); void createFakeSeqAtBeginLongMessage(QVariantList &vData, const int vFakeDataLen); private slots: // Should be private for thread safety and is connected internally. void onMainTimerTimeout(); void onActionReceive (const QVariantList &vData); // UI <= HD/DG void onActionTransmit(const QVariantList &vData); void onExport (); void onExportStat (quint32 vIndex, const QString &vFileName, quint8 vPercent); void onFailedTransmit(Sequence seq); void onSettingsUpdate(); void onPOSTDone (bool vPass); void onQuitApplication (); void onLogIOFail(); signals: signals: void didActionReceive (const QVariantList &vData); // UI <= HD/DG void didActionTransmit(const QVariantList &vData); // UI => HD/DG void didFailedTransmit(Sequence seq); 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 didKeepAliveBegin * \details this signal will be emitted by ApplicationController * when it is done with all the messaging and has nothing to say * just to keep the conversation alive and let HD know UI is alive. */ void didKeepAliveBegin (); /*! * \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 (); void didUnhandledMsgAppController(const QVariantList &msg); SAFE_CALL(startPOST) };