mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-04 17:30:12 +08:00
refs #246 refactored construction of all remaining contexts into factory methods
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
#include "blackcore/context_application.h"
|
#include "blackcore/context_application.h"
|
||||||
|
#include "blackcore/context_application_impl.h"
|
||||||
|
#include "blackcore/context_application_proxy.h"
|
||||||
#include "blackcore/context_application_event.h"
|
#include "blackcore/context_application_event.h"
|
||||||
#include "blackmisc/statusmessage.h"
|
#include "blackmisc/statusmessage.h"
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
@@ -12,6 +14,21 @@ namespace BlackCore
|
|||||||
QList<IContextApplication *> IContextApplication::s_contexts;
|
QList<IContextApplication *> IContextApplication::s_contexts;
|
||||||
QtMessageHandler IContextApplication::s_oldHandler = nullptr;
|
QtMessageHandler IContextApplication::s_oldHandler = nullptr;
|
||||||
|
|
||||||
|
IContextApplication *IContextApplication::create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn)
|
||||||
|
{
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case CRuntimeConfig::Local:
|
||||||
|
case CRuntimeConfig::LocalInDbusServer:
|
||||||
|
return (new CContextApplication(mode, parent))->registerWithDBus(server);
|
||||||
|
case CRuntimeConfig::Remote:
|
||||||
|
return new BlackCore::CContextApplicationProxy(BlackCore::CDBusServer::ServiceName, conn, mode, parent);
|
||||||
|
default:
|
||||||
|
qFatal("Always initialize an application context");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -69,6 +69,9 @@ namespace BlackCore
|
|||||||
//! \copydoc CContext::getPathAndContextId()
|
//! \copydoc CContext::getPathAndContextId()
|
||||||
virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); }
|
virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); }
|
||||||
|
|
||||||
|
//! Factory method
|
||||||
|
static IContextApplication *create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~IContextApplication() {}
|
virtual ~IContextApplication() {}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ namespace BlackCore
|
|||||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME)
|
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME)
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
friend class CRuntime;
|
friend class CRuntime;
|
||||||
|
friend class IContextApplication;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//! \copydoc IContextApplication::ping()
|
//! \copydoc IContextApplication::ping()
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace BlackCore
|
|||||||
class CContextApplicationProxy : public IContextApplication
|
class CContextApplicationProxy : public IContextApplication
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
friend class CRuntime;
|
friend class IContextApplication;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Destructor
|
//! Destructor
|
||||||
|
|||||||
27
src/blackcore/context_audio.cpp
Normal file
27
src/blackcore/context_audio.cpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "context_audio.h"
|
||||||
|
#include "context_audio_impl.h"
|
||||||
|
#include "context_audio_proxy.h"
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
|
||||||
|
IContextAudio *IContextAudio::create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn)
|
||||||
|
{
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case CRuntimeConfig::Local:
|
||||||
|
case CRuntimeConfig::LocalInDbusServer:
|
||||||
|
return (new CContextAudio(mode, parent))->registerWithDBus(server);
|
||||||
|
case CRuntimeConfig::Remote:
|
||||||
|
return new BlackCore::CContextAudioProxy(BlackCore::CDBusServer::ServiceName, conn, mode, parent);
|
||||||
|
default:
|
||||||
|
return nullptr; // audio not mandatory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -50,6 +50,9 @@ namespace BlackCore
|
|||||||
//! \copydoc CContext::getPathAndContextId()
|
//! \copydoc CContext::getPathAndContextId()
|
||||||
virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); }
|
virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); }
|
||||||
|
|
||||||
|
//! Factory method
|
||||||
|
static IContextAudio *create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn);
|
||||||
|
|
||||||
//! \brief Destructor
|
//! \brief Destructor
|
||||||
virtual ~IContextAudio() {}
|
virtual ~IContextAudio() {}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace BlackCore
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
friend class CRuntime;
|
friend class CRuntime;
|
||||||
|
friend class IContextAudio;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME)
|
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME)
|
||||||
friend class CRuntime;
|
friend class IContextAudio;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
28
src/blackcore/context_ownaircraft.cpp
Normal file
28
src/blackcore/context_ownaircraft.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "context_ownaircraft.h"
|
||||||
|
#include "context_ownaircraft_impl.h"
|
||||||
|
#include "context_ownaircraft_proxy.h"
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
|
||||||
|
IContextOwnAircraft *IContextOwnAircraft::create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn)
|
||||||
|
{
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case CRuntimeConfig::Local:
|
||||||
|
case CRuntimeConfig::LocalInDbusServer:
|
||||||
|
return (new CContextOwnAircraft(mode, parent))->registerWithDBus(server);
|
||||||
|
case CRuntimeConfig::Remote:
|
||||||
|
return new BlackCore::CContextOwnAircraftProxy(BlackCore::CDBusServer::ServiceName, conn, mode, parent);
|
||||||
|
default:
|
||||||
|
qFatal("Always initialize an ownaircraft context");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -40,6 +40,9 @@ namespace BlackCore
|
|||||||
//! \copydoc CContext::getPathAndContextId()
|
//! \copydoc CContext::getPathAndContextId()
|
||||||
virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); }
|
virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); }
|
||||||
|
|
||||||
|
//! Factory method
|
||||||
|
static IContextOwnAircraft *create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~IContextOwnAircraft() {}
|
virtual ~IContextOwnAircraft() {}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace BlackCore
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME)
|
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME)
|
||||||
friend class CRuntime;
|
friend class CRuntime;
|
||||||
|
friend class IContextOwnAircraft;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Destructor
|
//! Destructor
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace BlackCore
|
|||||||
class CContextOwnAircraftProxy : public IContextOwnAircraft
|
class CContextOwnAircraftProxy : public IContextOwnAircraft
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
friend class CRuntime;
|
friend class IContextOwnAircraft;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|||||||
@@ -337,75 +337,19 @@ namespace BlackCore
|
|||||||
times.insert("DBus", time.restart());
|
times.insert("DBus", time.restart());
|
||||||
|
|
||||||
// contexts
|
// contexts
|
||||||
switch (config.getModeSettings())
|
this->m_contextSettings = IContextSettings::create(this, config.getModeSettings(), this->m_dbusServer, this->m_dbusConnection);
|
||||||
{
|
|
||||||
case CRuntimeConfig::Local:
|
|
||||||
case CRuntimeConfig::LocalInDbusServer:
|
|
||||||
Q_ASSERT(settings);
|
|
||||||
this->m_contextSettings = settings->registerWithDBus(this->m_dbusServer);
|
|
||||||
break;
|
|
||||||
case CRuntimeConfig::Remote:
|
|
||||||
this->m_contextSettings = new BlackCore::CContextSettingsProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeSettings(), this);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
qFatal("Always initialize a settings context");
|
|
||||||
}
|
|
||||||
times.insert("Settings", time.restart());
|
times.insert("Settings", time.restart());
|
||||||
|
|
||||||
switch (config.getModeApplication())
|
this->m_contextApplication = IContextApplication::create(this, config.getModeApplication(), this->m_dbusServer, this->m_dbusConnection);
|
||||||
{
|
|
||||||
case CRuntimeConfig::Local:
|
|
||||||
case CRuntimeConfig::LocalInDbusServer:
|
|
||||||
this->m_contextApplication = (new CContextApplication(config.getModeApplication(), this))->registerWithDBus(this->m_dbusServer);
|
|
||||||
break;
|
|
||||||
case CRuntimeConfig::Remote:
|
|
||||||
this->m_contextApplication = new BlackCore::CContextApplicationProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeApplication(), this);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
qFatal("Always initialize an application context");
|
|
||||||
}
|
|
||||||
times.insert("Application", time.restart());
|
times.insert("Application", time.restart());
|
||||||
|
|
||||||
switch (config.getModeOwnAircraft())
|
this->m_contextOwnAircraft = IContextOwnAircraft::create(this, config.getModeOwnAircraft(), this->m_dbusServer, this->m_dbusConnection);
|
||||||
{
|
|
||||||
case CRuntimeConfig::Local:
|
|
||||||
case CRuntimeConfig::LocalInDbusServer:
|
|
||||||
this->m_contextOwnAircraft = (new CContextOwnAircraft(config.getModeApplication(), this))->registerWithDBus(this->m_dbusServer);
|
|
||||||
break;
|
|
||||||
case CRuntimeConfig::Remote:
|
|
||||||
this->m_contextOwnAircraft = new BlackCore::CContextOwnAircraftProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeOwnAircraft(), this);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
qFatal("Always initialize own aircraft context");
|
|
||||||
}
|
|
||||||
times.insert("Own aircraft", time.restart());
|
times.insert("Own aircraft", time.restart());
|
||||||
|
|
||||||
switch (config.getModeAudio())
|
this->m_contextAudio = IContextAudio::create(this, config.getModeAudio(), this->m_dbusServer, this->m_dbusConnection);
|
||||||
{
|
|
||||||
case CRuntimeConfig::Local:
|
|
||||||
case CRuntimeConfig::LocalInDbusServer:
|
|
||||||
this->m_contextAudio = (new CContextAudio(config.getModeAudio(), this))->registerWithDBus(this->m_dbusServer);
|
|
||||||
break;
|
|
||||||
case CRuntimeConfig::Remote:
|
|
||||||
this->m_contextAudio = new BlackCore::CContextAudioProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeAudio(), this);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break; // audio not mandatory
|
|
||||||
}
|
|
||||||
times.insert("Audio", time.restart());
|
times.insert("Audio", time.restart());
|
||||||
|
|
||||||
switch (config.getModeSimulator())
|
this->m_contextSimulator = IContextSimulator::create(this, config.getModeSimulator(), this->m_dbusServer, this->m_dbusConnection);
|
||||||
{
|
|
||||||
case CRuntimeConfig::Local:
|
|
||||||
case CRuntimeConfig::LocalInDbusServer:
|
|
||||||
this->m_contextSimulator = (new CContextSimulator(config.getModeSimulator(), this))->registerWithDBus(this->m_dbusServer);
|
|
||||||
break;
|
|
||||||
case CRuntimeConfig::Remote:
|
|
||||||
this->m_contextSimulator = new BlackCore::CContextSimulatorProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeSimulator(), this);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break; // network not mandatory
|
|
||||||
}
|
|
||||||
times.insert("Simulator", time.restart());
|
times.insert("Simulator", time.restart());
|
||||||
|
|
||||||
this->m_contextNetwork = IContextNetwork::create(this, config.getModeNetwork(), this->m_dbusServer, this->m_dbusConnection);
|
this->m_contextNetwork = IContextNetwork::create(this, config.getModeNetwork(), this->m_dbusServer, this->m_dbusConnection);
|
||||||
|
|||||||
28
src/blackcore/context_settings.cpp
Normal file
28
src/blackcore/context_settings.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "context_settings.h"
|
||||||
|
#include "context_settings_impl.h"
|
||||||
|
#include "context_settings_proxy.h"
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
|
||||||
|
IContextSettings *IContextSettings::create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn)
|
||||||
|
{
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case CRuntimeConfig::Local:
|
||||||
|
case CRuntimeConfig::LocalInDbusServer:
|
||||||
|
return (new CContextSettings(mode, parent))->registerWithDBus(server);
|
||||||
|
case CRuntimeConfig::Remote:
|
||||||
|
return new BlackCore::CContextSettingsProxy(BlackCore::CDBusServer::ServiceName, conn, mode, parent);
|
||||||
|
default:
|
||||||
|
qFatal("Always initialize a settings context");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -96,6 +96,9 @@ namespace BlackCore
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Factory method
|
||||||
|
static IContextSettings *create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~IContextSettings() {}
|
virtual ~IContextSettings() {}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ namespace BlackCore
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSETTINGS_INTERFACENAME)
|
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSETTINGS_INTERFACENAME)
|
||||||
friend class CRuntime;
|
friend class CRuntime;
|
||||||
|
friend class IContextSettings;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! \brief Constructor
|
//! \brief Constructor
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace BlackCore
|
|||||||
class CContextSettingsProxy : public IContextSettings
|
class CContextSettingsProxy : public IContextSettings
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
friend class CRuntime;
|
friend class IContextSettings;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! \brief Destructor
|
//! \brief Destructor
|
||||||
|
|||||||
27
src/blackcore/context_simulator.cpp
Normal file
27
src/blackcore/context_simulator.cpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "context_simulator.h"
|
||||||
|
#include "context_simulator_impl.h"
|
||||||
|
#include "context_simulator_proxy.h"
|
||||||
|
|
||||||
|
namespace BlackCore
|
||||||
|
{
|
||||||
|
|
||||||
|
IContextSimulator *IContextSimulator::create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn)
|
||||||
|
{
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case CRuntimeConfig::Local:
|
||||||
|
case CRuntimeConfig::LocalInDbusServer:
|
||||||
|
return (new CContextSimulator(mode, parent))->registerWithDBus(server);
|
||||||
|
case CRuntimeConfig::Remote:
|
||||||
|
return new BlackCore::CContextSimulatorProxy(BlackCore::CDBusServer::ServiceName, conn, mode, parent);
|
||||||
|
default:
|
||||||
|
return nullptr; // simulator not mandatory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -45,6 +45,9 @@ namespace BlackCore
|
|||||||
//! \copydoc CContext::getPathAndContextId()
|
//! \copydoc CContext::getPathAndContextId()
|
||||||
virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); }
|
virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); }
|
||||||
|
|
||||||
|
//! Factory method
|
||||||
|
static IContextSimulator *create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~IContextSimulator() {}
|
virtual ~IContextSimulator() {}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ namespace BlackCore
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME)
|
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME)
|
||||||
friend class CRuntime;
|
friend class CRuntime;
|
||||||
|
friend class IContextSimulator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! \brief Destructor
|
//! \brief Destructor
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace BlackCore
|
|||||||
class CContextSimulatorProxy : public IContextSimulator
|
class CContextSimulatorProxy : public IContextSimulator
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
friend class CRuntime;
|
friend class IContextSimulator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Destructor
|
//! Destructor
|
||||||
|
|||||||
Reference in New Issue
Block a user