diff --git a/src/blackcore/context_network.cpp b/src/blackcore/context_network.cpp new file mode 100644 index 000000000..d25f53772 --- /dev/null +++ b/src/blackcore/context_network.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_network.h" +#include "context_network_impl.h" +#include "context_network_proxy.h" + +namespace BlackCore +{ + + IContextNetwork *IContextNetwork::create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn) + { + switch (mode) + { + case CRuntimeConfig::Local: + case CRuntimeConfig::LocalInDbusServer: + return (new CContextNetwork(mode, parent))->registerWithDBus(server); + case CRuntimeConfig::Remote: + return new BlackCore::CContextNetworkProxy(BlackCore::CDBusServer::ServiceName, conn, mode, parent); + default: + return nullptr; // network not mandatory + } + } + +} diff --git a/src/blackcore/context_network.h b/src/blackcore/context_network.h index 7d9e1b3c5..397e39b9c 100644 --- a/src/blackcore/context_network.h +++ b/src/blackcore/context_network.h @@ -46,6 +46,9 @@ namespace BlackCore //! \copydoc CContext::getPathAndContextId() virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); } + //! Factory method + static IContextNetwork *create(CRuntime *parent, CRuntimeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &conn); + //! Destructor virtual ~IContextNetwork() {} diff --git a/src/blackcore/context_network_impl.h b/src/blackcore/context_network_impl.h index d9d8c9a09..729d9960b 100644 --- a/src/blackcore/context_network_impl.h +++ b/src/blackcore/context_network_impl.h @@ -29,6 +29,7 @@ namespace BlackCore { Q_OBJECT Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTNETWORK_INTERFACENAME) + friend class IContextNetwork; friend class CRuntime; public: diff --git a/src/blackcore/context_network_proxy.h b/src/blackcore/context_network_proxy.h index 5e60e2268..a6e3a484e 100644 --- a/src/blackcore/context_network_proxy.h +++ b/src/blackcore/context_network_proxy.h @@ -24,7 +24,7 @@ namespace BlackCore class CContextNetworkProxy : public IContextNetwork { Q_OBJECT - friend class CRuntime; + friend class IContextNetwork; public: diff --git a/src/blackcore/context_runtime.cpp b/src/blackcore/context_runtime.cpp index d7ec7929b..5ab7f73b3 100644 --- a/src/blackcore/context_runtime.cpp +++ b/src/blackcore/context_runtime.cpp @@ -394,18 +394,7 @@ namespace BlackCore } times.insert("Audio", time.restart()); - switch (config.getModeNetwork()) - { - case CRuntimeConfig::Local: - case CRuntimeConfig::LocalInDbusServer: - this->m_contextNetwork = (new CContextNetwork(config.getModeNetwork(), this))->registerWithDBus(this->m_dbusServer); - break; - case CRuntimeConfig::Remote: - this->m_contextNetwork = new BlackCore::CContextNetworkProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeNetwork(), this); - break; - default: - break; // network not mandatory - } + this->m_contextNetwork = IContextNetwork::create(this, config.getModeNetwork(), this->m_dbusServer, this->m_dbusConnection); times.insert("Network", time.restart()); switch (config.getModeSimulator())