Index: sources/ApplicationController.cpp =================================================================== diff -u -r20b370a54d2737831b307a0de82aec9e06e2b772 -r99cf0dc3002c0395f0d10d1d4fb34e2052449fd6 --- sources/ApplicationController.cpp (.../ApplicationController.cpp) (revision 20b370a54d2737831b307a0de82aec9e06e2b772) +++ sources/ApplicationController.cpp (.../ApplicationController.cpp) (revision 99cf0dc3002c0395f0d10d1d4fb34e2052449fd6) @@ -1,13 +1,13 @@ /*! * - * Copyright (c) 2020-2023 Diality Inc. - All Rights Reserved. + * 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.cpp - * \author (last) Behrouz NematiPour - * \date (last) 19-Dec-2022 + * \author (last) Dara Navaei + * \date (last) 26-Mar-2024 * \author (original) Behrouz NematiPour * \date (original) 26-Aug-2020 * @@ -89,7 +89,10 @@ */ void ApplicationController::initConnections() { - + connect(&_post , SIGNAL(didOSVersion (bool)), + this , SLOT( onOSVersion (bool))); + connect(&_post , SIGNAL( didEthernet (bool)), + this , SLOT(onPOSTEthernet (bool))); connect(&_post , SIGNAL( didWiFi (bool)), this , SLOT(onPOSTWiFi (bool))); connect(&_post , SIGNAL( didBluetooth(bool)), @@ -108,6 +111,10 @@ // From GUI connect(&_GuiController , SIGNAL(didActionTransmit(GuiActionType, const QVariantList &)), this , SLOT( onActionTransmit(GuiActionType, const QVariantList &))); + connect(&_GuiController , SIGNAL(didQuitApplication()), + this , SLOT( onQuitApplication())); + connect(&_GuiController , SIGNAL(didTreatmentRangesDone(bool)), + this , SLOT( onTreatmentRangesDone(bool))); // From HD/DG connect(&_MessageDispatcher, SIGNAL(didActionReceive(GuiActionType, const QVariantList &)), @@ -134,6 +141,10 @@ connect(&_DeviceController , SIGNAL(didSDCardSpaceTooLow(quint8)), this , SLOT( onSDCardSpaceTooLow(quint8))); + // Configuration Partition + connect(&_DeviceController , SIGNAL(didCryptSetupMount(bool)), + this , SLOT( onCryptSetupMount(bool))); + connect(&_GuiController , SIGNAL(didExportLog (const GuiStringIndexMap &)), this , SLOT( onExportLog (const GuiStringIndexMap &))); connect(&_GuiController , SIGNAL(didExportService (const GuiStringIndexMap &)), @@ -145,14 +156,12 @@ this , SLOT( onExport ())); connect(&_Logger , SIGNAL(didExportStat (quint32, const QString &, quint8)), this , SLOT( onExportStat (quint32, const QString &, quint8))); + connect(&_Logger , SIGNAL(didLogIOFail ()), + this , SLOT( onLogIOFail ())); - // Settings - move to application thread - connect(this, SIGNAL(didSettingsInit()), - this, SLOT( onSettingsInit())); connect(&_settingsWatcher, SIGNAL(finished ()), this , SLOT(onSettingsUpdate())); - // Device Signal/Slots DEVICE_APP_INIT_CONNECTIONS_LIST @@ -506,6 +515,14 @@ } // disabled coco end + +void ApplicationController::postDoneRequest() +{ + AdjustUIPostFinalResultRequestData data; + data.mResult = _post.isDone(); + emit didAdjustment(data); +} + /*! * \brief ApplicationController::initSettings * \details The external method available to request for initializing the settings @@ -529,16 +546,20 @@ * This method also initializes the Settings model singleton object to let it live in the Application thread. * To start the setting initialization QConcurrent is used with QFuture to signal the Application when it's done. */ -void ApplicationController::onSettingsInit() +/*void ApplicationController::onSettingsInit() { // That is enough to call to the I function here to create the object in the thread that Settings is leaving in, // which currently is Application_Thread, since the Settings is created in that thread. _Settings; - QFuture mFuture = QtConcurrent::run(this, &ApplicationController::settingsInit); + QFuture mFuture = QtConcurrent::run( [=]() -> int { // made the call a lambda to make sure there is no function to accidentally being called, out of thread [developer safety]. + //TODO The Settings shall be the Singleton SettingsController and modify the MSettings like the others. + Storage::Settings settings; + return settings.read(); + }); _settingsWatcher.setFuture(mFuture); } - +*/ /*! * \brief onSettingsUpdate * \details when the Settings reads the .conf files and fills the MSettings emits this finished signal @@ -548,21 +569,57 @@ { onActionReceive(SettingsData()); - // call initialization functions when setting's ready. - _Settings.datetimeFormat(); + /// POST /// + //call initialization functions when setting's ready. + //TODO move the initSettig in the Application POST since it is part of the post. + _settingsError = _settingsWatcher.result(); + //DEBUG qDebug() << " ***** " << sender() << _settingsError; + _post.isDone( ! _settingsError ); + if ( _settingsError ) { + LOG_APPED_PO(QString("Settings read failed")); + alarmTrigger(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_SETTINGS_BAD); + } else { + _Settings.datetimeFormat(); + } - emit didSettingsDone(); + // this singal can be emmited here [ others are postponed to the onTreatmentRangesDone ] + // here we know the CRC was fine with not empty configuration and all files can be read. + emit didSettingsDone( ); // MessageDispatcher -> MessageInterpreter : updateUnhandledMessages } /*! + * \brief ApplicationController::onOSVersion + * \details Notifies the OS Version POST status + */ +void ApplicationController::onOSVersion(bool vPass) { + // sending the data first, therefore in the slot for the didPOST we have the vPass and the Data to decide to use the data or not. + emit didPOSTOSVersionData (_post.osVersion()); + emit didPOSTOSVersion (vPass); +} + +/*! + * \brief ApplicationController::onPOSTEthernet + * \details sends the Ethernet mac to device controller + */ +void ApplicationController::onPOSTEthernet(bool vPass) { + // sending the data first, therefore in the slot for the didPOST we have the vPass and the Data to decide to use the data or not. + emit didPOSTEthernetData(_post.macEthernet()); + emit didPOSTEthernet (vPass); +} + +/*! * \brief ApplicationController::onPOSTWiFi * \details Starts the WiFi Interface */ void ApplicationController::onPOSTWiFi(bool vPass) { if (vPass) { _WifiInterface.doStart(); } - emit didPOSTWiFi(vPass); + // sending the data first, therefore in the slot for the didPOST we have the vPass and the Data to decide to use the data or not. + emit didPOSTWirelessData(_post.macWireless()); + emit didPOSTWireless (vPass); + + //DEBUG qDebug() << " ---------- " << _post.macWireless(); } /*! @@ -576,64 +633,119 @@ } else { _BluetoothInterface.doNotifyStatePOSTError(); - emit didPOSTBluetooth(vPass); } + // sending the data first, therefore in the slot for the didPOST we have the vPass and the Data to decide to use the data or not. + emit didPOSTBluetoothData (_post.macBluetooth()); + emit didPOSTBluetooth (vPass); } /*! * \brief ApplicationController::onPOSTCloudSync * \details Notifies the CloudSync POST status */ -void ApplicationController::onPOSTCloudSync(bool vPass) +void ApplicationController::onPOSTCloudSync(bool vPass) { + // sending the data first, therefore in the slot for the didPOST we have the vPass and the Data to decide to use the data or not. + emit didPOSTCloudSyncData("" /*_post.netCloudSync*/); // not needed and POST is not getting it yet. [ApplicationController => DeviceController] + emit didPOSTCloudSync (vPass); +} + +/*! + * \brief ApplicationController::alarmTrigger + * \details Queues the alarms, or send the list, or send one alarm + * \param vAlarmID - The alarm ID to be triggered or queued. + * \param vSend - if true the list of queued alarms will be send + * \param vSingle - if true and vSend is true only the alarm vAlarmID will be triggered. + */ +void ApplicationController::alarmTrigger(GuiAlarmID vAlarmID, bool vSend, bool vSingle) { - emit didPOSTCloudSync(vPass); + static QVector failList; + if ( vSend ) { + if ( vSingle ) { + emit didActionTransmit(Gui::GuiActionType::ID_AlarmTriggered, {vAlarmID ,0,0,0,0,0,0,0}); + } + else { + for ( auto alarmID : failList ) { + //DEBUG qDebug()<< "sending POST fail alarm# "<< alarmID; + emit didActionTransmit(Gui::GuiActionType::ID_AlarmTriggered, {alarmID ,0,0,0,0,0,0,0}); + } + } + } + else { + failList.append(vAlarmID); + } } /*! * \brief ApplicationController::onPOSTFail - * \details sends the Alarm Trigger message, used when the POST Failed. - * \param vAlarmID + * \details Sends the Alarm Trigger message, if the vSend is true, + * or + * Queues the alarms if vSend is false. + * \param vAlarmID - The alarm ID + * \param vSend - False to queue the vAlarmID alarm ID, or True to send the list of the queued alarms. */ void ApplicationController::onPOSTFail(GuiAlarmID vAlarmID) { - emit didActionTransmit(GuiActionType::ID_AlarmTriggered, {vAlarmID ,0,0,0,0,0,0,0}); + alarmTrigger(vAlarmID, false, false); } /*! * \brief ApplicationController::onPOSTDone * \details Sends the POST Final message */ +//<<<<<<< HEAD +//void ApplicationController::onPOSTDone(bool /*vPass*/) { +// LOG_DEBUG("ApplicationPOST Done"); + + /// in manufacturing or update mode the configurations must reside in /root/home + /// therefore the settings can be initialized after POST. +//#ifdef BUILD_FOR_DESKTOP +// initSettings(); +//#else +// if ( gEnableManufacturing || gEnableUpdating ) initSettings(); +//#endif +//} +//======= void ApplicationController::onPOSTDone(bool vPass) { emit didPOSTDone(vPass); // Used by Update SW. AdjustUIPostFinalResultRequestData data; data.mResult = vPass; emit didAdjustment(data); LOG_DEBUG("ApplicationPost Done"); - versionsRequest(vPass); + /// in manufacturing or update mode the configurations must reside in /root/home + /// therefore the settings can be initialized after POST. +#ifdef BUILD_FOR_DESKTOP + initSettings(); +#else + if ( gEnableManufacturing || gEnableUpdating ) initSettings(); +#endif } +//>>>>>>> DEN-sunrise-prb +void ApplicationController::onQuitApplication() +{ + //DEBUG qDebug() << metaObject()->className() << __FUNCTION__ << QThread::currentThread(); + emit didQuitApplication(); + qApp->quit(); +} + /*! * \brief ApplicationController::versionsRequest * \details Sends a version request - * \param vPass - condition to request for version if POST is done */ -void ApplicationController::versionsRequest(bool vPass) { - if (vPass) { - AdjustVersionsRequestData adjustVersionsRequestData; - emit didAdjustment(adjustVersionsRequestData); - LOG_DEBUG("POSTInfReq Sent"); - } +void ApplicationController::versionsRequest() { + AdjustVersionsRequestData adjustVersionsRequestData; + emit didAdjustment(adjustVersionsRequestData); + LOG_DEBUG("POSTVersionReq Sent"); } /*! - * \brief ApplicationController::settingsInit - * \details The Settings read function is called in this method. - * This callback function for the QCuncurrnent run. + * \brief ApplicationController::institutionalRequest + * \details Sends an institutional record request */ -void ApplicationController::settingsInit() -{ - Storage::Settings settings; - settings.read(); +void ApplicationController::institutionalRequest() { + AdjustInstitutionalRequestData adjustInstitutionalRequestData; + emit didAdjustment(adjustInstitutionalRequestData); + LOG_DEBUG("POSTInstitutionalRecordReq Sent"); } /*! @@ -647,6 +759,57 @@ */ void ApplicationController::onstartPOST() { LOG_DEBUG("ApplicationPost Start"); - emit didActionTransmit(GuiActionType::ID_KeepAlive, {}); _post.start(); } + +/*! + * \brief ApplicationController::onCryptSetupMount + * \details It is the slot to handle _DeviceController::didCryptSetupMount signal. + * Tells the settings start initiate. + */ +void ApplicationController::onCryptSetupMount(bool vPass) +{ + //DEBUG qDebug() << " ***** " << Q_FUNC_INFO << vPass; + if ( ! vPass ) { + _post.isDone(vPass); + LOG_APPED_PO(QString("Configuration partition encryption failed.")); + alarmTrigger(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_SETTINGS_BAD); + } + // if ( vPass ) // it needs more investigation + initSettings(); +} + +/*! + * \brief ApplicationController::onLogIOFail + * \details This slot is when an SD I/O failure is indicated + */ +void ApplicationController::onLogIOFail() +{ + //DEBUG qDebug()<<"SENDING " << Gui::GuiAlarmID::ALARM_ID_HD_UI_SDCARD_FAILURE; + alarmTrigger(Gui::GuiAlarmID::ALARM_ID_HD_UI_SDCARD_FAILURE, true, true); // send, single, this happens after POST. +} + +/*! + * \brief ApplicationController::onTreatmentRangesDone + * \details This slot is when the treatment ranges during initial post process is done + */ +void ApplicationController::onTreatmentRangesDone(bool vPass) +{ + //DEBUG qDebug() << " ***** " << Q_FUNC_INFO; + if ( ! vPass ) { + _post.isDone(vPass); + LOG_APPED_PO(QString("Configuration treatment ranges failed.")); + alarmTrigger(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_SETTINGS_BAD); + } + + // HD POST + // UI is done, let HD start the communication [ UI Check-in is the HD commjunication listener starter ] + keepAlive(); + emit didKeepAliveBegin (); + alarmTrigger (Gui::GuiAlarmID::ALARM_ID_NO_ALARM, true); // send queued fails + postDoneRequest (); // send HD the POST result + versionsRequest (); // send HD the version request + institutionalRequest (); // send HD the institutional record request + emit didPOSTPass (_post.isDone( )); // GuiController -> GuiView : didPOSTPass(bool) +} +