From 9b27b93de0d982d15be7bbae833815557c9c0e51 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Sat, 14 Jun 2014 15:52:42 +0100 Subject: [PATCH] refs #246 refactored construction of all remaining contexts into factory methods --- src/blackcore/context_application.cpp | 17 ++++++ src/blackcore/context_application.h | 3 ++ src/blackcore/context_application_impl.h | 1 + src/blackcore/context_application_proxy.h | 2 +- src/blackcore/context_audio.cpp | 27 ++++++++++ src/blackcore/context_audio.h | 3 ++ src/blackcore/context_audio_impl.h | 1 + src/blackcore/context_audio_proxy.h | 2 +- src/blackcore/context_ownaircraft.cpp | 28 ++++++++++ src/blackcore/context_ownaircraft.h | 3 ++ src/blackcore/context_ownaircraft_impl.h | 1 + src/blackcore/context_ownaircraft_proxy.h | 2 +- src/blackcore/context_runtime.cpp | 66 ++--------------------- src/blackcore/context_settings.cpp | 28 ++++++++++ src/blackcore/context_settings.h | 3 ++ src/blackcore/context_settings_impl.h | 1 + src/blackcore/context_settings_proxy.h | 2 +- src/blackcore/context_simulator.cpp | 27 ++++++++++ src/blackcore/context_simulator.h | 3 ++ src/blackcore/context_simulator_impl.h | 1 + src/blackcore/context_simulator_proxy.h | 2 +- 21 files changed, 157 insertions(+), 66 deletions(-) create mode 100644 src/blackcore/context_audio.cpp create mode 100644 src/blackcore/context_ownaircraft.cpp create mode 100644 src/blackcore/context_settings.cpp create mode 100644 src/blackcore/context_simulator.cpp diff --git a/src/blackcore/context_application.cpp b/src/blackcore/context_application.cpp index 96aea8392..4a6536ea1 100644 --- a/src/blackcore/context_application.cpp +++ b/src/blackcore/context_application.cpp @@ -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 @@ -12,6 +14,21 @@ namespace BlackCore QList 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 */ diff --git a/src/blackcore/context_application.h b/src/blackcore/context_application.h index b7023cad8..dc7f1bcd3 100644 --- a/src/blackcore/context_application.h +++ b/src/blackcore/context_application.h @@ -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() {} diff --git a/src/blackcore/context_application_impl.h b/src/blackcore/context_application_impl.h index c8862af3e..deae75a03 100644 --- a/src/blackcore/context_application_impl.h +++ b/src/blackcore/context_application_impl.h @@ -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() diff --git a/src/blackcore/context_application_proxy.h b/src/blackcore/context_application_proxy.h index 3626a57fb..39ecb73c6 100644 --- a/src/blackcore/context_application_proxy.h +++ b/src/blackcore/context_application_proxy.h @@ -18,7 +18,7 @@ namespace BlackCore class CContextApplicationProxy : public IContextApplication { Q_OBJECT - friend class CRuntime; + friend class IContextApplication; public: //! Destructor diff --git a/src/blackcore/context_audio.cpp b/src/blackcore/context_audio.cpp new file mode 100644 index 000000000..2622ce645 --- /dev/null +++ b/src/blackcore/context_audio.cpp @@ -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 + } + } + +} diff --git a/src/blackcore/context_audio.h b/src/blackcore/context_audio.h index ab693ff41..d39856a32 100644 --- a/src/blackcore/context_audio.h +++ b/src/blackcore/context_audio.h @@ -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() {} diff --git a/src/blackcore/context_audio_impl.h b/src/blackcore/context_audio_impl.h index 05f517d50..fcfa35475 100644 --- a/src/blackcore/context_audio_impl.h +++ b/src/blackcore/context_audio_impl.h @@ -25,6 +25,7 @@ namespace BlackCore Q_OBJECT friend class CRuntime; + friend class IContextAudio; public: diff --git a/src/blackcore/context_audio_proxy.h b/src/blackcore/context_audio_proxy.h index cb5cb728d..c80befc1c 100644 --- a/src/blackcore/context_audio_proxy.h +++ b/src/blackcore/context_audio_proxy.h @@ -22,7 +22,7 @@ namespace BlackCore { Q_OBJECT Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME) - friend class CRuntime; + friend class IContextAudio; public: diff --git a/src/blackcore/context_ownaircraft.cpp b/src/blackcore/context_ownaircraft.cpp new file mode 100644 index 000000000..b71b35380 --- /dev/null +++ b/src/blackcore/context_ownaircraft.cpp @@ -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; + } + } + +} diff --git a/src/blackcore/context_ownaircraft.h b/src/blackcore/context_ownaircraft.h index 0b18d3242..d7f1d4132 100644 --- a/src/blackcore/context_ownaircraft.h +++ b/src/blackcore/context_ownaircraft.h @@ -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() {} diff --git a/src/blackcore/context_ownaircraft_impl.h b/src/blackcore/context_ownaircraft_impl.h index ac70868d2..a27ebd582 100644 --- a/src/blackcore/context_ownaircraft_impl.h +++ b/src/blackcore/context_ownaircraft_impl.h @@ -20,6 +20,7 @@ namespace BlackCore Q_OBJECT Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME) friend class CRuntime; + friend class IContextOwnAircraft; public: //! Destructor diff --git a/src/blackcore/context_ownaircraft_proxy.h b/src/blackcore/context_ownaircraft_proxy.h index 2e2abc792..ceedf21f0 100644 --- a/src/blackcore/context_ownaircraft_proxy.h +++ b/src/blackcore/context_ownaircraft_proxy.h @@ -17,7 +17,7 @@ namespace BlackCore class CContextOwnAircraftProxy : public IContextOwnAircraft { Q_OBJECT - friend class CRuntime; + friend class IContextOwnAircraft; public: diff --git a/src/blackcore/context_runtime.cpp b/src/blackcore/context_runtime.cpp index f432e206c..cc71e3d92 100644 --- a/src/blackcore/context_runtime.cpp +++ b/src/blackcore/context_runtime.cpp @@ -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); diff --git a/src/blackcore/context_settings.cpp b/src/blackcore/context_settings.cpp new file mode 100644 index 000000000..d468b840a --- /dev/null +++ b/src/blackcore/context_settings.cpp @@ -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; + } + } + +} diff --git a/src/blackcore/context_settings.h b/src/blackcore/context_settings.h index 3a558025e..e20fa8242 100644 --- a/src/blackcore/context_settings.h +++ b/src/blackcore/context_settings.h @@ -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() {} diff --git a/src/blackcore/context_settings_impl.h b/src/blackcore/context_settings_impl.h index a7db222ed..d5910281f 100644 --- a/src/blackcore/context_settings_impl.h +++ b/src/blackcore/context_settings_impl.h @@ -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 diff --git a/src/blackcore/context_settings_proxy.h b/src/blackcore/context_settings_proxy.h index 0133a0fb9..4380bc336 100644 --- a/src/blackcore/context_settings_proxy.h +++ b/src/blackcore/context_settings_proxy.h @@ -25,7 +25,7 @@ namespace BlackCore class CContextSettingsProxy : public IContextSettings { Q_OBJECT - friend class CRuntime; + friend class IContextSettings; public: //! \brief Destructor diff --git a/src/blackcore/context_simulator.cpp b/src/blackcore/context_simulator.cpp new file mode 100644 index 000000000..4995258fa --- /dev/null +++ b/src/blackcore/context_simulator.cpp @@ -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 + } + } + +} diff --git a/src/blackcore/context_simulator.h b/src/blackcore/context_simulator.h index 9cd398406..05abb7b3b 100644 --- a/src/blackcore/context_simulator.h +++ b/src/blackcore/context_simulator.h @@ -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() {} diff --git a/src/blackcore/context_simulator_impl.h b/src/blackcore/context_simulator_impl.h index 5bf7e5c43..f161c9cd0 100644 --- a/src/blackcore/context_simulator_impl.h +++ b/src/blackcore/context_simulator_impl.h @@ -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 diff --git a/src/blackcore/context_simulator_proxy.h b/src/blackcore/context_simulator_proxy.h index 715c79039..be632a2cc 100644 --- a/src/blackcore/context_simulator_proxy.h +++ b/src/blackcore/context_simulator_proxy.h @@ -15,7 +15,7 @@ namespace BlackCore class CContextSimulatorProxy : public IContextSimulator { Q_OBJECT - friend class CRuntime; + friend class IContextSimulator; public: //! Destructor