From 988a4791ab997fe5cbe1506e19a05387992b24b5 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 29 Sep 2017 03:37:10 +0200 Subject: [PATCH] Ref T167, improved tryToReconnectWithDBus * use exit to abort (close might fail) * core facade init() now private * CCoreFacade::getDBusAddress * display DBusAddress --- src/blackcore/corefacade.cpp | 49 +++++++++++++++++++--------- src/blackcore/corefacade.h | 9 +++-- src/swiftguistandard/swiftguistd.cpp | 19 +++++++---- 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/src/blackcore/corefacade.cpp b/src/blackcore/corefacade.cpp index 25bf349b5..c2bdef2ed 100644 --- a/src/blackcore/corefacade.cpp +++ b/src/blackcore/corefacade.cpp @@ -8,6 +8,7 @@ */ #include "blackcore/context/contextapplication.h" +#include "blackcore/context/contextapplicationproxy.h" #include "blackcore/context/contextapplicationimpl.h" #include "blackcore/context/contextaudio.h" #include "blackcore/context/contextaudioimpl.h" @@ -54,13 +55,25 @@ namespace BlackCore this->init(); } - bool CCoreFacade::tryToReconnectWithDBus() + CStatusMessage CCoreFacade::tryToReconnectWithDBus() { - if (m_shuttingDown) { return false; } - if (!m_config.requiresDBusConnection()) { return false; } + if (m_shuttingDown) { return CStatusMessage(this, CStatusMessage::SeverityInfo, "Shutdown"); } + if (!m_config.requiresDBusConnection()) { return CStatusMessage(this, CStatusMessage::SeverityInfo, "Not DBus based"); } + const QString dBusAddress = this->getDBusAddress(); + if (dBusAddress.isEmpty()) { return CStatusMessage(this, CStatusMessage::SeverityInfo, "Not DBus based, no address"); } + QString connectMsg; + if (!CContextApplicationProxy::isContextResponsive(dBusAddress, connectMsg)) + { + return CStatusMessage(this, CStatusMessage::SeverityError, + "Cannot connect DBus at '" + dBusAddress + "', reason: " + connectMsg); + } + + // re-init m_initalized = false; this->init(); - return true; + + // success + return CStatusMessage(this, CStatusMessage::SeverityInfo, "Re-initialized via '%1'") << dBusAddress; } void CCoreFacade::init() @@ -72,17 +85,8 @@ namespace BlackCore registerMetadata(); // either use explicit setting or last value - QString dbusAddress; - if (m_config.hasDBusAddress()) - { - dbusAddress = m_config.getDBusAddress(); - m_launcherSetup.setProperty(CLauncherSetup::IndexDBusAddress, dbusAddress); - } - else - { - CLauncherSetup setup = m_launcherSetup.get(); - dbusAddress = setup.getDBusAddress(); - } + const QString dbusAddress = this->getDBusAddress(); + m_launcherSetup.setProperty(CLauncherSetup::IndexDBusAddress, dbusAddress); // DBus if (m_config.requiresDBusSever()) { this->initDBusServer(dbusAddress); } @@ -260,6 +264,21 @@ namespace BlackCore } } + QString CCoreFacade::getDBusAddress() const + { + QString dbusAddress; + if (m_config.hasDBusAddress()) + { + dbusAddress = m_config.getDBusAddress(); + } + else + { + const CLauncherSetup setup = m_launcherSetup.get(); + dbusAddress = setup.getDBusAddress(); + } + return dbusAddress; + } + void CCoreFacade::gracefulShutdown() { if (!m_initalized) { return; } diff --git a/src/blackcore/corefacade.h b/src/blackcore/corefacade.h index b582940f2..2030e9090 100644 --- a/src/blackcore/corefacade.h +++ b/src/blackcore/corefacade.h @@ -64,7 +64,7 @@ namespace BlackCore const BlackMisc::CDBusServer *getDBusServer() const { return this->m_dbusServer; } //! In case connection between DBus parties is lost, try to reconnect - bool tryToReconnectWithDBus(); + BlackMisc::CStatusMessage tryToReconnectWithDBus(); //! DBus connection (if applicable) const QDBusConnection &getDBusConnection() const { return this->m_dbusConnection; } @@ -149,8 +149,8 @@ namespace BlackCore //! \remarks only applicable for local object const Context::CContextSimulator *getCContextSimulator() const; - //! Init - void init(); + //! DBus address if any + QString getDBusAddress() const; //! Remote application context, indicates distributed environment bool hasRemoteApplicationContext() const; @@ -182,6 +182,9 @@ namespace BlackCore Context::IContextOwnAircraft *m_contextOwnAircraft = nullptr; Context::IContextSimulator *m_contextSimulator = nullptr; + //! Init + void init(); + //! initialization of DBus connection (where applicable) void initDBusConnection(const QString &address); diff --git a/src/swiftguistandard/swiftguistd.cpp b/src/swiftguistandard/swiftguistd.cpp index 8876c6770..184f99d60 100644 --- a/src/swiftguistandard/swiftguistd.cpp +++ b/src/swiftguistandard/swiftguistd.cpp @@ -451,19 +451,26 @@ void SwiftGuiStd::displayDBusReconnectDialog() if (!sGui->getCoreFacade()) { return; } if (m_displayingDBusReconnect) { return; } m_displayingDBusReconnect = true; + const QString dBusAddress = sGui->getCoreFacade()->getDBusAddress(); + static const QString informativeText("Do you want to try to reconnect? 'Abort' will close the GUI. DBus: '%1'"); QMessageBox msgBox(this); msgBox.setIcon(QMessageBox::Critical); - msgBox.setText("swift core not reachable."); - msgBox.setInformativeText("Do you want to try to reconnect? 'Abort' will close the GUI."); + msgBox.setText("swift core not reachable!"); + msgBox.setInformativeText(informativeText.arg(dBusAddress)); msgBox.setStandardButtons(QMessageBox::Retry | QMessageBox::Abort); msgBox.setDefaultButton(QMessageBox::Retry); const int ret = msgBox.exec(); - m_displayingDBusReconnect = false; - m_coreFailures = 0; if (ret == QMessageBox::Abort) { - this->close(); + m_coreFailures = 0; + sGui->gracefulShutdown(); + CGuiApplication::exit(EXIT_FAILURE); return; } - sGui->getCoreFacade()->tryToReconnectWithDBus(); + + m_displayingDBusReconnect = false; + CStatusMessage msg = sGui->getCoreFacade()->tryToReconnectWithDBus(); + if (msg.isSuccess()) { m_coreFailures = 0; } + msg.clampSeverity(CStatusMessage::SeverityWarning); + CLogMessage::preformatted(msg); }