mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
refactor: Use same mode for all contexts
This commit is contained in:
@@ -86,7 +86,7 @@ namespace swift::core
|
||||
|
||||
CApplication::CApplication(const QString &applicationName, CApplicationInfo::Application application, bool init)
|
||||
: CIdentifiable(this), m_accessManager(new QNetworkAccessManager(this)), m_applicationInfo(application),
|
||||
m_applicationName(applicationName), m_coreFacadeConfig(CCoreFacadeConfig::allEmpty())
|
||||
m_applicationName(applicationName), m_coreFacadeConfig(CCoreFacadeConfig::NotUsed)
|
||||
{
|
||||
Q_ASSERT_X(!sApp, Q_FUNC_INFO, "already initialized");
|
||||
Q_ASSERT_X(QCoreApplication::instance(), Q_FUNC_INFO, "no application object");
|
||||
@@ -457,7 +457,7 @@ namespace swift::core
|
||||
m_localSettingsLoaded = true;
|
||||
|
||||
// trigger loading and saving of settings in appropriate scenarios
|
||||
if (m_coreFacadeConfig.getModeApplication() != CCoreFacadeConfig::Remote)
|
||||
if (m_coreFacadeConfig.getMode() != CCoreFacadeConfig::Remote)
|
||||
{
|
||||
// facade running here locally
|
||||
const CStatusMessage msg = CSettingsCache::instance()->loadFromStore();
|
||||
@@ -727,7 +727,7 @@ namespace swift::core
|
||||
Q_ASSERT_X(m_parsed, Q_FUNC_INFO, "Call this function after parsing");
|
||||
|
||||
m_useContexts = true; // otherwise startCoreFacade will early-return
|
||||
m_coreFacadeConfig = CCoreFacadeConfig::allEmpty();
|
||||
m_coreFacadeConfig = CCoreFacadeConfig(CCoreFacadeConfig::NotUsed);
|
||||
const CStatusMessage msg = this->initLocalSettings();
|
||||
if (msg.isFailure()) { return msg; }
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace swift::core
|
||||
|
||||
// shared state infrastructure
|
||||
m_dataLinkDBus = new shared_state::CDataLinkDBus(this);
|
||||
switch (m_config.getModeApplication())
|
||||
switch (m_config.getMode())
|
||||
{
|
||||
case CCoreFacadeConfig::NotUsed:
|
||||
case CCoreFacadeConfig::Local: m_dataLinkDBus->initializeLocal(nullptr); break;
|
||||
@@ -120,13 +120,14 @@ namespace swift::core
|
||||
// shared log history
|
||||
m_logHistorySource = new CLogHistorySource(this);
|
||||
m_logHistorySource->initialize(m_dataLinkDBus);
|
||||
if (m_config.hasLocalCore())
|
||||
if (m_config.getMode() == CCoreFacadeConfig::Local ||
|
||||
m_config.getMode() == CCoreFacadeConfig::LocalInDBusServer)
|
||||
{
|
||||
m_logHistory = new CLogHistory(this);
|
||||
m_logHistory->initialize(m_dataLinkDBus);
|
||||
}
|
||||
|
||||
if (m_config.all(CCoreFacadeConfig::NotUsed))
|
||||
if (m_config.getMode() == CCoreFacadeConfig::NotUsed)
|
||||
{
|
||||
m_initalized = true;
|
||||
return;
|
||||
@@ -134,28 +135,25 @@ namespace swift::core
|
||||
|
||||
// contexts
|
||||
if (m_contextApplication) { m_contextApplication->deleteLater(); }
|
||||
m_contextApplication =
|
||||
IContextApplication::create(this, m_config.getModeApplication(), m_dbusServer, m_dbusConnection);
|
||||
m_contextApplication = IContextApplication::create(this, m_config.getMode(), m_dbusServer, m_dbusConnection);
|
||||
times.insert("Application", time.restart());
|
||||
|
||||
if (m_contextAudio) { m_contextAudio->deleteLater(); }
|
||||
m_contextAudio = qobject_cast<CContextAudioBase *>(
|
||||
IContextAudio::create(this, m_config.getModeAudio(), m_dbusServer, m_dbusConnection));
|
||||
IContextAudio::create(this, m_config.getMode(), m_dbusServer, m_dbusConnection));
|
||||
times.insert("Audio", time.restart());
|
||||
|
||||
if (m_contextOwnAircraft) { m_contextOwnAircraft->deleteLater(); }
|
||||
m_contextOwnAircraft =
|
||||
IContextOwnAircraft::create(this, m_config.getModeOwnAircraft(), m_dbusServer, m_dbusConnection);
|
||||
m_contextOwnAircraft = IContextOwnAircraft::create(this, m_config.getMode(), m_dbusServer, m_dbusConnection);
|
||||
times.insert("Own aircraft", time.restart());
|
||||
|
||||
if (m_contextSimulator) { m_contextSimulator->deleteLater(); }
|
||||
m_contextSimulator =
|
||||
IContextSimulator::create(this, m_config.getModeSimulator(), m_dbusServer, m_dbusConnection);
|
||||
m_contextSimulator = IContextSimulator::create(this, m_config.getMode(), m_dbusServer, m_dbusConnection);
|
||||
times.insert("Simulator", time.restart());
|
||||
|
||||
// depends on own aircraft and simulator context, which is bad style
|
||||
if (m_contextNetwork) { m_contextNetwork->deleteLater(); }
|
||||
m_contextNetwork = IContextNetwork::create(this, m_config.getModeNetwork(), m_dbusServer, m_dbusConnection);
|
||||
m_contextNetwork = IContextNetwork::create(this, m_config.getMode(), m_dbusServer, m_dbusConnection);
|
||||
times.insert("Network", time.restart());
|
||||
|
||||
// checks --------------
|
||||
|
||||
@@ -5,48 +5,7 @@
|
||||
|
||||
namespace swift::core
|
||||
{
|
||||
bool CCoreFacadeConfig::requiresDBusSever() const
|
||||
{
|
||||
return (
|
||||
// those 3 should decide whether we are running the server
|
||||
m_network == LocalInDBusServer || m_ownAircraft == LocalInDBusServer || m_simulator == LocalInDBusServer ||
|
||||
bool CCoreFacadeConfig::requiresDBusSever() const { return m_contextMode == LocalInDBusServer; }
|
||||
|
||||
// added as work around
|
||||
m_audio == LocalInDBusServer);
|
||||
}
|
||||
|
||||
bool CCoreFacadeConfig::requiresDBusConnection() const { return this->any(Remote); }
|
||||
|
||||
bool CCoreFacadeConfig::any(CCoreFacadeConfig::ContextMode mode) const
|
||||
{
|
||||
return (m_application == mode || m_audio == mode || m_network == mode || m_ownAircraft == mode ||
|
||||
m_simulator == mode);
|
||||
}
|
||||
|
||||
bool CCoreFacadeConfig::all(CCoreFacadeConfig::ContextMode mode) const
|
||||
{
|
||||
return (m_application == mode && m_audio == mode && m_network == mode && m_ownAircraft == mode &&
|
||||
m_simulator == mode);
|
||||
}
|
||||
|
||||
bool CCoreFacadeConfig::anyRemote() const { return this->any(Remote); }
|
||||
|
||||
bool CCoreFacadeConfig::anyLocalInDBusServer() const { return this->any(LocalInDBusServer); }
|
||||
|
||||
CCoreFacadeConfig CCoreFacadeConfig::forCoreAllLocalInDBus(const QString &dbusBootstrapAddress)
|
||||
{
|
||||
return { LocalInDBusServer, dbusBootstrapAddress };
|
||||
}
|
||||
|
||||
CCoreFacadeConfig CCoreFacadeConfig::local(const QString &dbusBootstrapAddress)
|
||||
{
|
||||
return { Local, dbusBootstrapAddress };
|
||||
}
|
||||
|
||||
CCoreFacadeConfig CCoreFacadeConfig::remote(const QString &dbusBootstrapAddress)
|
||||
{
|
||||
return { Remote, dbusBootstrapAddress };
|
||||
}
|
||||
|
||||
CCoreFacadeConfig CCoreFacadeConfig::allEmpty() { return {}; }
|
||||
bool CCoreFacadeConfig::requiresDBusConnection() const { return m_contextMode == Remote; }
|
||||
} // namespace swift::core
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace swift::core
|
||||
{
|
||||
//! Helper to correctly run a context
|
||||
//! Configuration object for the contexts
|
||||
class SWIFT_CORE_EXPORT CCoreFacadeConfig
|
||||
{
|
||||
public:
|
||||
@@ -20,43 +20,24 @@ namespace swift::core
|
||||
enum ContextMode
|
||||
{
|
||||
NotUsed, //!< during shutdown or not used at all
|
||||
Local, //!< in same process
|
||||
LocalInDBusServer, //!< in same process, also registered in DBus, will be accessed by proxy objects too
|
||||
Remote //!< proxy object
|
||||
Local, //!< context runs in same process
|
||||
LocalInDBusServer, //!< context runs in same process. It is also registered in DBus to be accessed by proxy
|
||||
//!< objects
|
||||
Remote //!< context runs in a different process. Access will happen via proxy object
|
||||
};
|
||||
|
||||
private:
|
||||
ContextMode m_application;
|
||||
ContextMode m_audio;
|
||||
ContextMode m_network;
|
||||
ContextMode m_ownAircraft;
|
||||
ContextMode m_simulator;
|
||||
ContextMode m_contextMode; // All contexts run in the same mode
|
||||
QString m_dbusAddress; //!< for boot strapping
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CCoreFacadeConfig(ContextMode allTheSame = NotUsed, const QString &dbusBootstrapAddress = "")
|
||||
: m_application(allTheSame), m_audio(allTheSame), m_network(allTheSame), m_ownAircraft(allTheSame),
|
||||
m_simulator(allTheSame), m_dbusAddress(dbusBootstrapAddress)
|
||||
explicit CCoreFacadeConfig(ContextMode contextMode, const QString &dbusBootstrapAddress = "")
|
||||
: m_contextMode(contextMode), m_dbusAddress(dbusBootstrapAddress)
|
||||
{}
|
||||
|
||||
//! Application mode
|
||||
ContextMode getModeApplication() const { return m_application; }
|
||||
|
||||
//! Audio mode
|
||||
ContextMode getModeAudio() const { return m_audio; }
|
||||
|
||||
//! Network mode
|
||||
ContextMode getModeNetwork() const { return m_network; }
|
||||
|
||||
//! Own aircraft
|
||||
ContextMode getModeOwnAircraft() const { return m_ownAircraft; }
|
||||
|
||||
//! Simulator mode
|
||||
ContextMode getModeSimulator() const { return m_simulator; }
|
||||
|
||||
//! Local core?
|
||||
bool hasLocalCore() const { return m_application == Local || m_application == LocalInDBusServer; }
|
||||
//! Mode
|
||||
ContextMode getMode() const { return m_contextMode; }
|
||||
|
||||
//! Requires server (at least one in server)?
|
||||
bool requiresDBusSever() const;
|
||||
@@ -69,30 +50,6 @@ namespace swift::core
|
||||
|
||||
//! DBus address?
|
||||
bool hasDBusAddress() const { return !m_dbusAddress.isEmpty(); }
|
||||
|
||||
//! Any context in given mode
|
||||
bool any(ContextMode mode) const;
|
||||
|
||||
//! All contexts in given mode
|
||||
bool all(ContextMode mode) const;
|
||||
|
||||
//! Any remote context?
|
||||
bool anyRemote() const;
|
||||
|
||||
//! Any local in DBus context?
|
||||
bool anyLocalInDBusServer() const;
|
||||
|
||||
//! Predefined for Core
|
||||
static CCoreFacadeConfig forCoreAllLocalInDBus(const QString &dbusBootstrapAddress = "");
|
||||
|
||||
//! Predefined, completely local (e.g. for unit tests)
|
||||
static CCoreFacadeConfig local(const QString &dbusBootstrapAddress = "");
|
||||
|
||||
//! Predefined, completely remote
|
||||
static CCoreFacadeConfig remote(const QString &dbusBootstrapAddress = "");
|
||||
|
||||
//! Predefined, all empty configs (normally used when the real config can only be determined later)
|
||||
static CCoreFacadeConfig allEmpty();
|
||||
};
|
||||
} // namespace swift::core
|
||||
#endif // SWIFT_CORE_COREFACADECONFIG_H
|
||||
|
||||
@@ -33,7 +33,7 @@ int main(int argc, char *argv[])
|
||||
if (!a.parseCommandLineArgsAndLoadSetup()) { return EXIT_FAILURE; }
|
||||
|
||||
const QString dBusAddress(a.getCmdDBusAddressValue());
|
||||
a.initContextsAndStartCoreFacade(CCoreFacadeConfig::forCoreAllLocalInDBus(dBusAddress));
|
||||
a.initContextsAndStartCoreFacade(CCoreFacadeConfig(CCoreFacadeConfig::LocalInDBusServer, dBusAddress));
|
||||
if (!a.start())
|
||||
{
|
||||
a.gracefulShutdown();
|
||||
|
||||
@@ -62,14 +62,7 @@ CStatusMessageList CSwiftGuiStdApplication::startHookIn()
|
||||
msgs.push_back(m);
|
||||
}
|
||||
|
||||
CCoreFacadeConfig runtimeConfig;
|
||||
switch (coreMode)
|
||||
{
|
||||
case CoreModes::Distributed: runtimeConfig = CCoreFacadeConfig::remote(dBusAddress); break;
|
||||
default:
|
||||
case CoreModes::Standalone: runtimeConfig = CCoreFacadeConfig::local(dBusAddress); break;
|
||||
}
|
||||
|
||||
CCoreFacadeConfig runtimeConfig = coreModeToCoreFacadeConfig(coreMode, dBusAddress);
|
||||
const CStatusMessageList contextMsgs = this->initContextsAndStartCoreFacade(runtimeConfig);
|
||||
msgs.push_back(contextMsgs);
|
||||
return contextMsgs;
|
||||
@@ -95,3 +88,14 @@ CSwiftGuiStdApplication *CSwiftGuiStdApplication::instance()
|
||||
{
|
||||
return qobject_cast<CSwiftGuiStdApplication *>(CApplication::instance());
|
||||
}
|
||||
|
||||
CCoreFacadeConfig CSwiftGuiStdApplication::coreModeToCoreFacadeConfig(CoreModes::CoreMode coreMode,
|
||||
const QString &dBusAddress)
|
||||
{
|
||||
switch (coreMode)
|
||||
{
|
||||
case CoreModes::Distributed: return CCoreFacadeConfig(CCoreFacadeConfig::Remote, dBusAddress);
|
||||
case CoreModes::Standalone: return CCoreFacadeConfig(CCoreFacadeConfig::Local, dBusAddress); break;
|
||||
default: Q_ASSERT_X(false, Q_FUNC_INFO, "Not handled core mode");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
#include "core/coremodeenums.h"
|
||||
#include "gui/guiapplication.h"
|
||||
|
||||
/*!
|
||||
@@ -36,6 +37,9 @@ protected:
|
||||
virtual swift::misc::CStatusMessageList startHookIn() override;
|
||||
|
||||
private:
|
||||
static swift::core::CCoreFacadeConfig coreModeToCoreFacadeConfig(swift::core::CoreModes::CoreMode,
|
||||
const QString &dBusAddress);
|
||||
|
||||
QCommandLineOption m_cmdFacadeMode { { "c", "core" },
|
||||
QCoreApplication::translate("main", "Core mode: (d)istributed, (s)tandalone."),
|
||||
"coremode" }; //!< Facade startup mode
|
||||
|
||||
Reference in New Issue
Block a user