mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-15 09:15:34 +08:00
Add methods to load and unload specific simulator plugins
refs #215 fixes #208
This commit is contained in:
@@ -66,6 +66,12 @@ namespace BlackCore
|
||||
//! Simulator info
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const = 0;
|
||||
|
||||
//! Load specific simulator plugin
|
||||
virtual bool loadSimulatorPlugin (const BlackSim::CSimulatorInfo &simulatorInfo) = 0;
|
||||
|
||||
//! Unload simulator plugin
|
||||
virtual void unloadSimulatorPlugin () = 0;
|
||||
|
||||
//! Simulator avialable?
|
||||
bool isSimulatorAvailable() const { return !getSimulatorInfo().isUnspecified(); }
|
||||
|
||||
|
||||
@@ -5,16 +5,14 @@
|
||||
|
||||
#include "context_simulator_impl.h"
|
||||
#include <QPluginLoader>
|
||||
#include <QLibrary>
|
||||
#include "context_runtime.h"
|
||||
|
||||
#ifdef BLACK_WITH_FSX
|
||||
#include "fsx/simulator_fsx.h"
|
||||
#endif
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackSim;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
@@ -23,6 +21,8 @@ namespace BlackCore
|
||||
{
|
||||
m_updateTimer = new QTimer(this);
|
||||
findSimulatorPlugins();
|
||||
loadSimulatorPlugin(CSimulatorInfo::FSX());
|
||||
|
||||
connect(m_updateTimer, &QTimer::timeout, this, &CContextSimulator::updateOwnAircraft);
|
||||
connectTo();
|
||||
}
|
||||
@@ -30,6 +30,7 @@ namespace BlackCore
|
||||
CContextSimulator::~CContextSimulator()
|
||||
{
|
||||
disconnectFrom();
|
||||
unloadSimulatorPlugin();
|
||||
}
|
||||
|
||||
bool CContextSimulator::isConnected() const
|
||||
@@ -73,6 +74,35 @@ namespace BlackCore
|
||||
return m_simulator->getSimulatorInfo();
|
||||
}
|
||||
|
||||
bool CContextSimulator::loadSimulatorPlugin(const CSimulatorInfo &simulatorInfo)
|
||||
{
|
||||
ISimulatorFactory *factory = nullptr;
|
||||
QSet<ISimulatorFactory*>::iterator iterator = std::find_if(m_simulatorFactories.begin(), m_simulatorFactories.end(), [ = ](const ISimulatorFactory *factory)
|
||||
{
|
||||
return factory->getSimulatorInfo() == simulatorInfo;
|
||||
});
|
||||
|
||||
if(iterator == m_simulatorFactories.end())
|
||||
return false;
|
||||
|
||||
factory = *iterator;
|
||||
Q_ASSERT(factory);
|
||||
|
||||
m_simulator = factory->create(this);
|
||||
Q_ASSERT(m_simulator);
|
||||
|
||||
connect(m_simulator, SIGNAL(connectionChanged(bool)), this, SLOT(setConnectionStatus(bool)));
|
||||
return true;
|
||||
}
|
||||
|
||||
void CContextSimulator::unloadSimulatorPlugin()
|
||||
{
|
||||
if(m_simulator)
|
||||
m_simulator->deleteLater();
|
||||
|
||||
m_simulator = nullptr;
|
||||
}
|
||||
|
||||
void CContextSimulator::updateOwnAircraft()
|
||||
{
|
||||
m_ownAircraft = m_simulator->getOwnAircraft();
|
||||
@@ -100,6 +130,9 @@ namespace BlackCore
|
||||
|
||||
foreach(QString fileName, m_pluginsDir.entryList(QDir::Files))
|
||||
{
|
||||
if (!QLibrary::isLibrary(fileName))
|
||||
continue;
|
||||
|
||||
QPluginLoader loader(m_pluginsDir.absoluteFilePath(fileName));
|
||||
QObject *plugin = loader.instance();
|
||||
if (plugin)
|
||||
|
||||
@@ -48,6 +48,12 @@ namespace BlackCore
|
||||
//! \copydoc IContextSimulator::getSimulatorInfo()
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::loadSimulatorPlugin()
|
||||
virtual bool loadSimulatorPlugin (const BlackSim::CSimulatorInfo &simulatorInfo) override;
|
||||
|
||||
//! \copydoc IContextSimulator::unloadSimulatorPlugin()
|
||||
virtual void unloadSimulatorPlugin () override;
|
||||
|
||||
protected:
|
||||
//! \brief Constructor
|
||||
CContextSimulator(CRuntimeConfig::ContextMode, CRuntime *runtime);
|
||||
|
||||
@@ -57,4 +57,14 @@ namespace BlackCore
|
||||
return m_dBusInterface->callDBusRet<BlackSim::CSimulatorInfo>(QLatin1Literal("getSimulatorInfo"));
|
||||
}
|
||||
|
||||
bool CContextSimulatorProxy::loadSimulatorPlugin(const BlackSim::CSimulatorInfo &simulatorInfo)
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("loadSimulatorPlugin"), simulatorInfo);
|
||||
}
|
||||
|
||||
void CContextSimulatorProxy::unloadSimulatorPlugin()
|
||||
{
|
||||
m_dBusInterface->callDBus(QLatin1Literal("unloadSimulatorPlugin"));
|
||||
}
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
@@ -53,6 +53,12 @@ namespace BlackCore
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorInfo
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::loadSimulatorPlugin
|
||||
virtual bool loadSimulatorPlugin (const BlackSim::CSimulatorInfo &simulatorInfo) override;
|
||||
|
||||
//! \copydoc IContextSimulator::unloadSimulatorPlugin()
|
||||
virtual void unloadSimulatorPlugin () override;
|
||||
};
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
@@ -89,6 +89,9 @@ namespace BlackCore
|
||||
* \return
|
||||
*/
|
||||
virtual ISimulator *create(QObject *parent = nullptr) = 0;
|
||||
|
||||
//! Simulator info
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const = 0;
|
||||
};
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
Reference in New Issue
Block a user