mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 15:25:35 +08:00
refs #409 permanent plugin storage
This commit is contained in:
@@ -74,6 +74,40 @@ namespace BlackCore
|
||||
return plugin->factory;
|
||||
}
|
||||
|
||||
CVariant CContextSimulator::getPluginData(const QObject *obj, const QString& key) const
|
||||
{
|
||||
const QObject* p = obj;
|
||||
while (p && !p->inherits("BlackCore::ISimulatorFactory"))
|
||||
{
|
||||
p = p->parent();
|
||||
}
|
||||
|
||||
if (!p) return CVariant();
|
||||
auto it = std::find_if(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [p](const PluginData &plugin)
|
||||
{
|
||||
return plugin.factory == qobject_cast<ISimulatorFactory *>(p);
|
||||
});
|
||||
Q_ASSERT(it != m_simulatorPlugins.end());
|
||||
return it->m_storage.value(key);
|
||||
}
|
||||
|
||||
void CContextSimulator::setPluginData(const QObject *obj, const QString &key, const CVariant &value)
|
||||
{
|
||||
const QObject* p = obj;
|
||||
while (p && !p->inherits("BlackCore::ISimulatorFactory"))
|
||||
{
|
||||
p = p->parent();
|
||||
}
|
||||
|
||||
if (!p) { return; }
|
||||
auto it = std::find_if(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [p](const PluginData &plugin)
|
||||
{
|
||||
return plugin.factory == qobject_cast<ISimulatorFactory *>(p);
|
||||
});
|
||||
Q_ASSERT(it != m_simulatorPlugins.end());
|
||||
it->m_storage.insert(key, value);
|
||||
}
|
||||
|
||||
CSimulatorPluginInfoList CContextSimulator::getAvailableSimulatorPlugins() const
|
||||
{
|
||||
CSimulatorPluginInfoList list;
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "blackmisc/network/textmessagelist.h"
|
||||
#include "blackmisc/pixmap.h"
|
||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||
#include "blackmisc/pluginstorageprovider.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include <QTimer>
|
||||
#include <QDir>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
@@ -28,7 +30,9 @@
|
||||
namespace BlackCore
|
||||
{
|
||||
//! Network simulator concrete implementation
|
||||
class BLACKCORE_EXPORT CContextSimulator : public IContextSimulator
|
||||
class BLACKCORE_EXPORT CContextSimulator :
|
||||
public IContextSimulator,
|
||||
public BlackMisc::IPluginStorageProvider
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME)
|
||||
@@ -44,6 +48,12 @@ namespace BlackCore
|
||||
//! \todo Consider moving to private scope.
|
||||
ISimulatorFactory *getSimulatorFactory(const BlackMisc::Simulation::CSimulatorPluginInfo &simulator);
|
||||
|
||||
//! \copydoc IPluginStorageProvider::getPluginData
|
||||
virtual BlackMisc::CVariant getPluginData(const QObject *obj, const QString& key) const;
|
||||
|
||||
//! \copydoc IPluginStorageProvider::setPluginData
|
||||
virtual void setPluginData(const QObject *obj, const QString& key, const BlackMisc::CVariant &value);
|
||||
|
||||
public slots:
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorPluginList()
|
||||
@@ -199,6 +209,7 @@ namespace BlackCore
|
||||
ISimulatorListener *listener = nullptr; //!< Listener instance, nullptr by default
|
||||
ISimulator *simulator = nullptr; //!< The simulator itself (always nullptr unless it is the currently working one)
|
||||
QString fileName; //!< Plugin file name (relative to plugins/simulator)
|
||||
QHash<QString, BlackMisc::CVariant> m_storage; //!< Permanent plugin storage - data stored here will be kept even when plugin is unloaded
|
||||
};
|
||||
|
||||
//! Find and catalog all simulator plugins
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
#include "blackmisc/simulation/ownaircraftprovider.h"
|
||||
#include "blackmisc/simulation/remoteaircraftprovider.h"
|
||||
#include "blackmisc/pluginstorageprovider.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include "blackmisc/aviation/airportlist.h"
|
||||
#include "blackmisc/network/textmessage.h"
|
||||
@@ -270,18 +271,19 @@ namespace BlackCore
|
||||
//! \param info metadata about simulator
|
||||
//! \param ownAircraftProvider in memory access to own aircraft data
|
||||
//! \param renderedAircraftProvider in memory access to rendered aircraft data such as situation history and aircraft itself
|
||||
//! \param parent QObject
|
||||
//! \param pluginStorageProvider in memory access to persistent plugin data store
|
||||
//! \return driver instance
|
||||
virtual ISimulator *create(
|
||||
const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider,
|
||||
QObject *parent = nullptr) = 0;
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider) = 0;
|
||||
|
||||
//! Simulator listener instance
|
||||
virtual ISimulatorListener *createListener(QObject *parent = nullptr) = 0;
|
||||
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_INTERFACE(BlackCore::ISimulatorFactory, "org.swift-project.blackcore.simulatorinterface")
|
||||
|
||||
@@ -25,10 +25,11 @@ namespace BlackCore
|
||||
CSimulatorCommon::CSimulatorCommon(const CSimulatorPluginInfo &info,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
QObject *parent)
|
||||
IPluginStorageProvider *pluginStorageProvider, QObject *parent)
|
||||
: ISimulator(parent),
|
||||
COwnAircraftAware(ownAircraftProvider),
|
||||
CRemoteAircraftAware(remoteAircraftProvider),
|
||||
CPluginStorageAware(pluginStorageProvider),
|
||||
m_simulatorPluginInfo(info)
|
||||
{
|
||||
this->setObjectName(info.getIdentifier());
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
#include "blackmisc/simulation/ownaircraftprovider.h"
|
||||
#include "blackmisc/simulation/remoteaircraftprovider.h"
|
||||
#include "blackmisc/pluginstorageprovider.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include "blackmisc/aviation/airportlist.h"
|
||||
#include "blackmisc/network/textmessage.h"
|
||||
@@ -34,8 +35,9 @@ namespace BlackCore
|
||||
//! Common base class with providers, interface and some base functionality
|
||||
class BLACKCORE_EXPORT CSimulatorCommon :
|
||||
public BlackCore::ISimulator,
|
||||
public BlackMisc::Simulation::COwnAircraftAware, // gain access to in memor own aircraft data
|
||||
public BlackMisc::Simulation::CRemoteAircraftAware // gain access to in memory remote aircraft data
|
||||
public BlackMisc::Simulation::COwnAircraftAware, // gain access to in memory own aircraft data
|
||||
public BlackMisc::Simulation::CRemoteAircraftAware, // gain access to in memory remote aircraft data
|
||||
public BlackMisc::CPluginStorageAware // gain access to in memory plugin storage
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
@@ -116,7 +118,8 @@ namespace BlackCore
|
||||
CSimulatorCommon(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
QObject *parent = nullptr);
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider,
|
||||
QObject *parent);
|
||||
|
||||
//! \copydoc IContextSimulator::logicallyAddRemoteAircraft
|
||||
virtual bool logicallyAddRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft) override;
|
||||
|
||||
69
src/blackmisc/pluginstorageprovider.h
Normal file
69
src/blackmisc/pluginstorageprovider.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_PLUGINSTORAGEPROVIDER_H
|
||||
#define BLACKMISC_PLUGINSTORAGEPROVIDER_H
|
||||
|
||||
#include "blackmisc/variant.h"
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
//! Interface for a plugin storage provider.
|
||||
//! It allows plugins to store any arbitrary data which can be packed into a \sa CVariant
|
||||
//! Every plugin shall have its own data area. This means mulitple plugins can store
|
||||
//! data under the same key without overwriting each other.
|
||||
class IPluginStorageProvider
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//! Destructor
|
||||
virtual ~IPluginStorageProvider() {}
|
||||
|
||||
//! Get plugin data stored for object and identified by key
|
||||
virtual CVariant getPluginData(const QObject *obj, const QString& key) const = 0;
|
||||
|
||||
//! Store plugin data for object, identified by key and packed into value
|
||||
virtual void setPluginData(const QObject *obj, const QString& key, const CVariant &value) = 0;
|
||||
};
|
||||
|
||||
//! Delegating class which can be directly used to access an \sa IPluginStorageProvider instance
|
||||
class CPluginStorageAware
|
||||
{
|
||||
public:
|
||||
//! \copydoc IPluginStorageProvider::getPluginData
|
||||
virtual CVariant getPluginData(const QObject *obj, const QString& key) const
|
||||
{
|
||||
return m_pluginStorageProvider->getPluginData(obj, key);
|
||||
}
|
||||
|
||||
//! \copydoc IOwnAircraftProvider::ownAircraft
|
||||
virtual void setPluginData(const QObject *obj, const QString& key, const CVariant &value)
|
||||
{
|
||||
m_pluginStorageProvider->setPluginData(obj, key, value);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
CPluginStorageAware(IPluginStorageProvider *pluginStorageProvider) :
|
||||
m_pluginStorageProvider(pluginStorageProvider)
|
||||
{
|
||||
Q_ASSERT(pluginStorageProvider);
|
||||
}
|
||||
IPluginStorageProvider *m_pluginStorageProvider = nullptr; //!< access to object
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
||||
@@ -50,8 +50,9 @@ namespace BlackSimPlugin
|
||||
const CSimulatorPluginInfo &info,
|
||||
IOwnAircraftProvider *ownAircraftProvider,
|
||||
IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
IPluginStorageProvider *pluginStorageProvider,
|
||||
QObject *parent) :
|
||||
CSimulatorFsCommon(info, ownAircraftProvider, remoteAircraftProvider, parent)
|
||||
CSimulatorFsCommon(info, ownAircraftProvider, remoteAircraftProvider, pluginStorageProvider, parent)
|
||||
{
|
||||
connect(lobbyClient.data(), &CLobbyClient::disconnected, this, std::bind(&CSimulatorFs9::simulatorStatusChanged, this, 0));
|
||||
this->m_interpolator = new BlackCore::CInterpolatorLinear(remoteAircraftProvider, this);
|
||||
@@ -369,9 +370,9 @@ namespace BlackSimPlugin
|
||||
const CSimulatorPluginInfo &info,
|
||||
IOwnAircraftProvider *ownAircraftProvider,
|
||||
IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
QObject *parent)
|
||||
IPluginStorageProvider *pluginStorageProvider)
|
||||
{
|
||||
return new CSimulatorFs9(info, ownAircraftProvider, remoteAircraftProvider, parent);
|
||||
return new CSimulatorFs9(info, ownAircraftProvider, remoteAircraftProvider, pluginStorageProvider, this);
|
||||
}
|
||||
|
||||
BlackCore::ISimulatorListener *CSimulatorFs9Factory::createListener(QObject *parent)
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace BlackSimPlugin
|
||||
const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
@@ -159,7 +160,7 @@ namespace BlackSimPlugin
|
||||
const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
QObject *parent) override;
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider) override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulatorFactory::createListener
|
||||
virtual BlackCore::ISimulatorListener *createListener(QObject *parent = nullptr) override;
|
||||
|
||||
@@ -29,8 +29,9 @@ namespace BlackSimPlugin
|
||||
const CSimulatorPluginInfo &info,
|
||||
IOwnAircraftProvider *ownAircraftProvider,
|
||||
IRemoteAircraftProvider *renderedAircraftProvider,
|
||||
IPluginStorageProvider *pluginStorageProvider,
|
||||
QObject *parent) :
|
||||
CSimulatorCommon(info, ownAircraftProvider, renderedAircraftProvider, parent),
|
||||
CSimulatorCommon(info, ownAircraftProvider, renderedAircraftProvider, pluginStorageProvider, parent),
|
||||
m_fsuipc(new CFsuipc())
|
||||
{
|
||||
// hack to init mapper
|
||||
|
||||
@@ -83,6 +83,7 @@ namespace BlackSimPlugin
|
||||
CSimulatorFsCommon(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider,
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
QString simulatorDetails; //!< describes version etc.
|
||||
|
||||
@@ -38,12 +38,12 @@ namespace BlackSimPlugin
|
||||
{
|
||||
namespace Fsx
|
||||
{
|
||||
CSimulatorFsx::CSimulatorFsx(
|
||||
const CSimulatorPluginInfo &info,
|
||||
CSimulatorFsx::CSimulatorFsx(const CSimulatorPluginInfo &info,
|
||||
IOwnAircraftProvider *ownAircraftProvider,
|
||||
IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
IPluginStorageProvider *pluginStorageProvider,
|
||||
QObject *parent) :
|
||||
CSimulatorFsCommon(info, ownAircraftProvider, remoteAircraftProvider, parent)
|
||||
CSimulatorFsCommon(info, ownAircraftProvider, remoteAircraftProvider, pluginStorageProvider, parent)
|
||||
{
|
||||
Q_ASSERT(ownAircraftProvider);
|
||||
Q_ASSERT(remoteAircraftProvider);
|
||||
|
||||
@@ -78,6 +78,7 @@ namespace BlackSimPlugin
|
||||
const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
|
||||
@@ -18,10 +18,13 @@ namespace BlackSimPlugin
|
||||
{
|
||||
namespace Fsx
|
||||
{
|
||||
BlackCore::ISimulator *CSimulatorFsxFactory::create(const BlackMisc::Simulation::CSimulatorPluginInfo &info, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider, QObject *parent)
|
||||
BlackCore::ISimulator *CSimulatorFsxFactory::create(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider,
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider)
|
||||
{
|
||||
Q_ASSERT(ownAircraftProvider);
|
||||
return new CSimulatorFsx(info, ownAircraftProvider, renderedAircraftProvider, parent);
|
||||
return new CSimulatorFsx(info, ownAircraftProvider, renderedAircraftProvider, pluginStorageProvider, this);
|
||||
}
|
||||
|
||||
BlackCore::ISimulatorListener *CSimulatorFsxFactory::createListener(QObject *parent)
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace BlackSimPlugin
|
||||
virtual BlackCore::ISimulator *create(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider,
|
||||
QObject *parent) override;
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider) override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulatorFactory::getListener
|
||||
virtual BlackCore::ISimulatorListener *createListener(QObject *parent = nullptr) override;
|
||||
|
||||
@@ -37,12 +37,12 @@ namespace BlackSimPlugin
|
||||
namespace XPlane
|
||||
{
|
||||
|
||||
CSimulatorXPlane::CSimulatorXPlane(
|
||||
const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
CSimulatorXPlane::CSimulatorXPlane(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
IOwnAircraftProvider *ownAircraftProvider,
|
||||
IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
IPluginStorageProvider *pluginStorageProvider,
|
||||
QObject *parent) :
|
||||
CSimulatorCommon(info, ownAircraftProvider, remoteAircraftProvider, parent)
|
||||
CSimulatorCommon(info, ownAircraftProvider, remoteAircraftProvider, pluginStorageProvider, parent)
|
||||
{
|
||||
m_watcher = new QDBusServiceWatcher(this);
|
||||
m_watcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
|
||||
@@ -434,13 +434,12 @@ namespace BlackSimPlugin
|
||||
return true;
|
||||
}
|
||||
|
||||
BlackCore::ISimulator *CSimulatorXPlaneFactory::create(
|
||||
const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
BlackCore::ISimulator *CSimulatorXPlaneFactory::create(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
IOwnAircraftProvider *ownAircraftProvider,
|
||||
IRemoteAircraftProvider *renderedAircraftProvider,
|
||||
QObject *parent)
|
||||
IPluginStorageProvider *pluginStorageProvider)
|
||||
{
|
||||
return new CSimulatorXPlane(info, ownAircraftProvider, renderedAircraftProvider, parent);
|
||||
return new CSimulatorXPlane(info, ownAircraftProvider, renderedAircraftProvider, pluginStorageProvider, this);
|
||||
}
|
||||
|
||||
CSimulatorXPlaneListener::CSimulatorXPlaneListener(QObject *parent): ISimulatorListener(parent)
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace BlackSimPlugin
|
||||
CSimulatorXPlane(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
//! \copydoc ISimulator::isTimeSynchronized
|
||||
@@ -218,7 +219,7 @@ namespace BlackSimPlugin
|
||||
virtual BlackCore::ISimulator *create(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
|
||||
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
|
||||
BlackMisc::Simulation::IRemoteAircraftProvider *renderedAircraftProvider,
|
||||
QObject *parent) override;
|
||||
BlackMisc::IPluginStorageProvider *pluginStorageProvider) override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulatorFactory::createListener
|
||||
virtual BlackCore::ISimulatorListener *createListener(QObject *parent = nullptr) override { return new CSimulatorXPlaneListener(parent); }
|
||||
|
||||
Reference in New Issue
Block a user