mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
Ref T167, improved tryToReconnectWithDBus
* use exit to abort (close might fail) * core facade init() now private * CCoreFacade::getDBusAddress * display DBusAddress
This commit is contained in:
committed by
Mathew Sutcliffe
parent
0179e6e757
commit
988a4791ab
@@ -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; }
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user