mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 21:56:43 +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;
|
||||
|
||||
Reference in New Issue
Block a user