refs #246 refactored construction of all remaining contexts into factory methods

This commit is contained in:
Mathew Sutcliffe
2014-06-14 15:52:42 +01:00
parent 9e0909666e
commit 9b27b93de0
21 changed files with 157 additions and 66 deletions

View File

@@ -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
*/

View File

@@ -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() {}

View File

@@ -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()

View File

@@ -18,7 +18,7 @@ namespace BlackCore
class CContextApplicationProxy : public IContextApplication
{
Q_OBJECT
friend class CRuntime;
friend class IContextApplication;
public:
//! Destructor

View 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
}
}
}

View File

@@ -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() {}

View File

@@ -25,6 +25,7 @@ namespace BlackCore
Q_OBJECT
friend class CRuntime;
friend class IContextAudio;
public:

View File

@@ -22,7 +22,7 @@ namespace BlackCore
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME)
friend class CRuntime;
friend class IContextAudio;
public:

View 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;
}
}
}

View File

@@ -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() {}

View File

@@ -20,6 +20,7 @@ namespace BlackCore
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTOWNAIRCRAFT_INTERFACENAME)
friend class CRuntime;
friend class IContextOwnAircraft;
public:
//! Destructor

View File

@@ -17,7 +17,7 @@ namespace BlackCore
class CContextOwnAircraftProxy : public IContextOwnAircraft
{
Q_OBJECT
friend class CRuntime;
friend class IContextOwnAircraft;
public:

View File

@@ -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);

View 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;
}
}
}

View File

@@ -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() {}

View File

@@ -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

View File

@@ -25,7 +25,7 @@ namespace BlackCore
class CContextSettingsProxy : public IContextSettings
{
Q_OBJECT
friend class CRuntime;
friend class IContextSettings;
public:
//! \brief Destructor

View 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
}
}
}

View File

@@ -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() {}

View File

@@ -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

View File

@@ -15,7 +15,7 @@ namespace BlackCore
class CContextSimulatorProxy : public IContextSimulator
{
Q_OBJECT
friend class CRuntime;
friend class IContextSimulator;
public:
//! Destructor