mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
Ref T167, allow to re-init facade
(a first approach to reconnect with DBus core) * Changes are supposed to be backward compliant. Maybe re-init fails, but there should be no regression for the 1st init * keep config as member to allow restart * disconnect from DBus before connecting (allows reconnect) * delete contexts if they are re-created * function CCoreFacade::tryToReconnectWithDBus
This commit is contained in:
committed by
Mathew Sutcliffe
parent
9748b5a442
commit
ed51d3c5dd
@@ -48,12 +48,22 @@ using namespace BlackCore::Context;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
CCoreFacade::CCoreFacade(const CCoreFacadeConfig &config, QObject *parent) : QObject(parent)
|
||||
CCoreFacade::CCoreFacade(const CCoreFacadeConfig &config, QObject *parent) :
|
||||
QObject(parent), m_config(config)
|
||||
{
|
||||
this->init(config);
|
||||
this->init();
|
||||
}
|
||||
|
||||
void CCoreFacade::init(const CCoreFacadeConfig &config)
|
||||
bool CCoreFacade::tryToReconnectWithDBus()
|
||||
{
|
||||
if (m_shuttingDown) { return false; }
|
||||
if (!m_config.requiresDBusConnection()) { return false; }
|
||||
m_initalized = false;
|
||||
this->init();
|
||||
return true;
|
||||
}
|
||||
|
||||
void CCoreFacade::init()
|
||||
{
|
||||
if (m_initalized || m_shuttingDown) { return; }
|
||||
|
||||
@@ -63,9 +73,9 @@ namespace BlackCore
|
||||
|
||||
// either use explicit setting or last value
|
||||
QString dbusAddress;
|
||||
if (config.hasDBusAddress())
|
||||
if (m_config.hasDBusAddress())
|
||||
{
|
||||
dbusAddress = config.getDBusAddress();
|
||||
dbusAddress = m_config.getDBusAddress();
|
||||
m_launcherSetup.setProperty(CLauncherSetup::IndexDBusAddress, dbusAddress);
|
||||
}
|
||||
else
|
||||
@@ -75,8 +85,8 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
// DBus
|
||||
if (config.requiresDBusSever()) { this->initDBusServer(dbusAddress); }
|
||||
if (config.requiresDBusConnection())
|
||||
if (m_config.requiresDBusSever()) { this->initDBusServer(dbusAddress); }
|
||||
if (m_config.requiresDBusConnection())
|
||||
{
|
||||
this->initDBusConnection(dbusAddress);
|
||||
if (!m_dbusConnection.isConnected())
|
||||
@@ -91,19 +101,24 @@ namespace BlackCore
|
||||
times.insert("DBus", time.restart());
|
||||
|
||||
// contexts
|
||||
m_contextApplication = IContextApplication::create(this, config.getModeApplication(), m_dbusServer, m_dbusConnection);
|
||||
if (m_contextApplication) { m_contextApplication->deleteLater(); }
|
||||
m_contextApplication = IContextApplication::create(this, m_config.getModeApplication(), m_dbusServer, m_dbusConnection);
|
||||
times.insert("Application", time.restart());
|
||||
|
||||
m_contextAudio = IContextAudio::create(this, config.getModeAudio(), m_dbusServer, m_dbusConnection);
|
||||
if (m_contextAudio) { m_contextAudio->deleteLater(); }
|
||||
m_contextAudio = IContextAudio::create(this, m_config.getModeAudio(), m_dbusServer, m_dbusConnection);
|
||||
times.insert("Audio", time.restart());
|
||||
|
||||
m_contextOwnAircraft = IContextOwnAircraft::create(this, config.getModeOwnAircraft(), m_dbusServer, m_dbusConnection);
|
||||
if (m_contextOwnAircraft) { m_contextOwnAircraft->deleteLater(); }
|
||||
m_contextOwnAircraft = IContextOwnAircraft::create(this, m_config.getModeOwnAircraft(), m_dbusServer, m_dbusConnection);
|
||||
times.insert("Own aircraft", time.restart());
|
||||
|
||||
m_contextNetwork = IContextNetwork::create(this, config.getModeNetwork(), m_dbusServer, m_dbusConnection);
|
||||
if (m_contextNetwork) { m_contextNetwork->deleteLater(); }
|
||||
m_contextNetwork = IContextNetwork::create(this, m_config.getModeNetwork(), m_dbusServer, m_dbusConnection);
|
||||
times.insert("Network", time.restart());
|
||||
|
||||
m_contextSimulator = IContextSimulator::create(this, config.getModeSimulator(), m_dbusServer, m_dbusConnection);
|
||||
if (m_contextSimulator) { m_contextSimulator->deleteLater(); }
|
||||
m_contextSimulator = IContextSimulator::create(this, m_config.getModeSimulator(), m_dbusServer, m_dbusConnection);
|
||||
times.insert("Simulator", time.restart());
|
||||
|
||||
// checks --------------
|
||||
@@ -148,8 +163,8 @@ namespace BlackCore
|
||||
|
||||
void CCoreFacade::initDBusServer(const QString &dBusAddress)
|
||||
{
|
||||
if (m_dbusServer) { return; }
|
||||
Q_ASSERT(!dBusAddress.isEmpty());
|
||||
if (m_dbusServer) { m_dbusServer->deleteLater(); } // delete if there was an existing one
|
||||
m_dbusServer = new CDBusServer(dBusAddress, this);
|
||||
CLogMessage(this).info("DBus server on address: %1") << dBusAddress;
|
||||
}
|
||||
@@ -317,15 +332,19 @@ namespace BlackCore
|
||||
if (m_initDBusConnection) { return; }
|
||||
if (address.isEmpty() || address == CDBusServer::sessionBusAddress())
|
||||
{
|
||||
QDBusConnection::disconnectFromBus(m_dbusConnection.name());
|
||||
m_dbusConnection = QDBusConnection::sessionBus();
|
||||
}
|
||||
else if (address == CDBusServer::systemBusAddress())
|
||||
{
|
||||
m_dbusConnection = QDBusConnection::sessionBus();
|
||||
QDBusConnection::disconnectFromBus(m_dbusConnection.name());
|
||||
m_dbusConnection = QDBusConnection::systemBus();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dbusConnection = QDBusConnection::connectToPeer(address, "BlackBoxRuntime");
|
||||
const QString name("BlackBoxRuntime");
|
||||
QDBusConnection::disconnectFromPeer(name);
|
||||
m_dbusConnection = QDBusConnection::connectToPeer(address, name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#ifndef BLACKCORE_COREFACADE_H
|
||||
#define BLACKCORE_COREFACADE_H
|
||||
|
||||
#include "corefacadeconfig.h"
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackcore/data/launchersetup.h"
|
||||
#include "blackcore/vatsim/vatsimsettings.h"
|
||||
@@ -24,12 +25,8 @@
|
||||
#include <QString>
|
||||
|
||||
namespace BlackMisc { class CDBusServer; }
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
// forward declaration, see review
|
||||
// https://dev.vatsim-germany.org/boards/22/topics/1350?r=1359#message-1359
|
||||
class CCoreFacadeConfig;
|
||||
namespace Context
|
||||
{
|
||||
class CContextApplication;
|
||||
@@ -66,6 +63,9 @@ namespace BlackCore
|
||||
//! DBus server (if applicable)
|
||||
const BlackMisc::CDBusServer *getDBusServer() const { return this->m_dbusServer; }
|
||||
|
||||
//! In case connection between DBus parties is lost, try to reconnect
|
||||
bool tryToReconnectWithDBus();
|
||||
|
||||
//! DBus connection (if applicable)
|
||||
const QDBusConnection &getDBusConnection() const { return this->m_dbusConnection; }
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace BlackCore
|
||||
const Context::CContextSimulator *getCContextSimulator() const;
|
||||
|
||||
//! Init
|
||||
void init(const CCoreFacadeConfig &config);
|
||||
void init();
|
||||
|
||||
//! Remote application context, indicates distributed environment
|
||||
bool hasRemoteApplicationContext() const;
|
||||
@@ -165,7 +165,8 @@ namespace BlackCore
|
||||
private:
|
||||
bool m_initalized = false; //!< flag if already initialized
|
||||
bool m_shuttingDown = false; //!< flag if shutting down
|
||||
BlackMisc::CData<Data::TLauncherSetup> m_launcherSetup { this };
|
||||
const CCoreFacadeConfig m_config; //!< used config
|
||||
BlackMisc::CData<Data::TLauncherSetup> m_launcherSetup { this }; //!< updating DBus
|
||||
|
||||
// DBus
|
||||
BlackMisc::CDBusServer *m_dbusServer = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user