mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 00:25:35 +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_impl.h"
|
||||
#include "blackcore/context_application_proxy.h"
|
||||
#include "blackcore/context_application_event.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include <QCoreApplication>
|
||||
@@ -12,6 +14,21 @@ namespace BlackCore
|
||||
QList<IContextApplication *> IContextApplication::s_contexts;
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -69,6 +69,9 @@ namespace BlackCore
|
||||
//! \copydoc CContext::getPathAndContextId()
|
||||
virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); }
|
||||
|
||||
//! Factory method
|
||||
static IContextApplication *create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn);
|
||||
|
||||
//! Destructor
|
||||
virtual ~IContextApplication() {}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace BlackCore
|
||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME)
|
||||
Q_OBJECT
|
||||
friend class CRuntime;
|
||||
friend class IContextApplication;
|
||||
|
||||
public slots:
|
||||
//! \copydoc IContextApplication::ping()
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace BlackCore
|
||||
class CContextApplicationProxy : public IContextApplication
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class CRuntime;
|
||||
friend class IContextApplication;
|
||||
|
||||
public:
|
||||
//! 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()
|
||||
virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); }
|
||||
|
||||
//! Factory method
|
||||
static IContextAudio *create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn);
|
||||
|
||||
//! \brief Destructor
|
||||
virtual ~IContextAudio() {}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace BlackCore
|
||||
Q_OBJECT
|
||||
|
||||
friend class CRuntime;
|
||||
friend class IContextAudio;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace BlackCore
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME)
|
||||
friend class CRuntime;
|
||||
friend class IContextAudio;
|
||||
|
||||
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()
|
||||
virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); }
|
||||
|
||||
//! Factory method
|
||||
static IContextOwnAircraft *create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn);
|
||||
|
||||
//! Destructor
|
||||
virtual ~IContextOwnAircraft() {}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace BlackCore
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME)
|
||||
friend class CRuntime;
|
||||
friend class IContextOwnAircraft;
|
||||
|
||||
public:
|
||||
//! Destructor
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace BlackCore
|
||||
class CContextOwnAircraftProxy : public IContextOwnAircraft
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class CRuntime;
|
||||
friend class IContextOwnAircraft;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -337,75 +337,19 @@ namespace BlackCore
|
||||
times.insert("DBus", time.restart());
|
||||
|
||||
// contexts
|
||||
switch (config.getModeSettings())
|
||||
{
|
||||
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");
|
||||
}
|
||||
this->m_contextSettings = IContextSettings::create(this, config.getModeSettings(), this->m_dbusServer, this->m_dbusConnection);
|
||||
times.insert("Settings", time.restart());
|
||||
|
||||
switch (config.getModeApplication())
|
||||
{
|
||||
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");
|
||||
}
|
||||
this->m_contextApplication = IContextApplication::create(this, config.getModeApplication(), this->m_dbusServer, this->m_dbusConnection);
|
||||
times.insert("Application", time.restart());
|
||||
|
||||
switch (config.getModeOwnAircraft())
|
||||
{
|
||||
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");
|
||||
}
|
||||
this->m_contextOwnAircraft = IContextOwnAircraft::create(this, config.getModeOwnAircraft(), this->m_dbusServer, this->m_dbusConnection);
|
||||
times.insert("Own aircraft", time.restart());
|
||||
|
||||
switch (config.getModeAudio())
|
||||
{
|
||||
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
|
||||
}
|
||||
this->m_contextAudio = IContextAudio::create(this, config.getModeAudio(), this->m_dbusServer, this->m_dbusConnection);
|
||||
times.insert("Audio", time.restart());
|
||||
|
||||
switch (config.getModeSimulator())
|
||||
{
|
||||
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
|
||||
}
|
||||
this->m_contextSimulator = IContextSimulator::create(this, config.getModeSimulator(), this->m_dbusServer, this->m_dbusConnection);
|
||||
times.insert("Simulator", time.restart());
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//! Factory method
|
||||
static IContextSettings *create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn);
|
||||
|
||||
//! Destructor
|
||||
virtual ~IContextSettings() {}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace BlackCore
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSETTINGS_INTERFACENAME)
|
||||
friend class CRuntime;
|
||||
friend class IContextSettings;
|
||||
|
||||
protected:
|
||||
//! \brief Constructor
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace BlackCore
|
||||
class CContextSettingsProxy : public IContextSettings
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class CRuntime;
|
||||
friend class IContextSettings;
|
||||
|
||||
public:
|
||||
//! \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()
|
||||
virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); }
|
||||
|
||||
//! Factory method
|
||||
static IContextSimulator *create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn);
|
||||
|
||||
//! Destructor
|
||||
virtual ~IContextSimulator() {}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace BlackCore
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME)
|
||||
friend class CRuntime;
|
||||
friend class IContextSimulator;
|
||||
|
||||
public:
|
||||
//! \brief Destructor
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace BlackCore
|
||||
class CContextSimulatorProxy : public IContextSimulator
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class CRuntime;
|
||||
friend class IContextSimulator;
|
||||
|
||||
public:
|
||||
//! Destructor
|
||||
|
||||
Reference in New Issue
Block a user