mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
refs #438, revised context plugin handling
* only 2 public interface functions start/stopSimulatorPlugin * internal functions like starting the listeners private * removed loading from settings, it does not make any sense as auto will find the running sim * only 2 central functions in impl: un/loadSimulatorPlugin - rest is handled automatically from there * graceful shutdown when runtime goes down * utility function getSimulatorStatusEnum()
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Simulation;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
@@ -198,9 +199,9 @@ namespace BlackCore
|
||||
if (this->m_contextSettings)
|
||||
{
|
||||
connect(this->m_contextSettings, &IContextSettings::changedSettings, this->m_contextSimulator, &IContextSimulator::settingsChanged);
|
||||
this->m_contextSimulator->listenForSimulatorFromSettings();
|
||||
times.insert("Post setup, load sim. listener(s)", time.restart());
|
||||
}
|
||||
this->m_contextSimulator->startSimulatorPlugin(CSimulatorPluginInfo::autoPlugin());
|
||||
}
|
||||
|
||||
// only where network and(!) own aircraft run locally
|
||||
@@ -236,13 +237,17 @@ namespace BlackCore
|
||||
disconnect(this);
|
||||
|
||||
// unregister all from DBus
|
||||
if (this->m_dbusServer) this->m_dbusServer->unregisterAllObjects();
|
||||
if (this->m_dbusServer) { this->m_dbusServer->unregisterAllObjects(); }
|
||||
|
||||
// handle contexts
|
||||
if (this->getIContextSimulator())
|
||||
{
|
||||
disconnect(this->getIContextSimulator());
|
||||
this->getIContextSimulator()->disconnectFromSimulator();
|
||||
if (this->getIContextSimulator()->isUsingImplementingObject())
|
||||
{
|
||||
// shutdown the plugins
|
||||
this->getCContextSimulator()->gracefulShutdown();
|
||||
}
|
||||
this->getIContextSimulator()->deleteLater();
|
||||
this->m_contextSimulator = nullptr;
|
||||
}
|
||||
|
||||
@@ -48,4 +48,9 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
ISimulator::SimulatorStatus IContextSimulator::getSimulatorStatusEnum() const
|
||||
{
|
||||
return static_cast<ISimulator::SimulatorStatus>(this->getSimulatorStatus());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "blackcoreexport.h"
|
||||
#include "context.h"
|
||||
#include "blackcore/simulator.h"
|
||||
#include "blackcore/dbus_server.h"
|
||||
#include "blackcore/context_runtime.h"
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
@@ -90,17 +91,24 @@ namespace BlackCore
|
||||
void airspaceSnapshotHandled();
|
||||
|
||||
public slots:
|
||||
//! Simulator info, currently loaded plugin
|
||||
virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const = 0;
|
||||
|
||||
//! Return list of available simulator plugins
|
||||
virtual BlackMisc::Simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const = 0;
|
||||
|
||||
//! Disconnect from simulator
|
||||
virtual bool disconnectFromSimulator() = 0;
|
||||
//! Load and start specific simulator plugin
|
||||
virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) = 0;
|
||||
|
||||
//! Stop and unload simulator plugin and listeners
|
||||
virtual void stopSimulatorPlugin() = 0;
|
||||
|
||||
//! Simulator combined status
|
||||
virtual int getSimulatorStatus() const = 0;
|
||||
|
||||
//! Simulator info
|
||||
virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const = 0;
|
||||
//! Get simulator status as enum
|
||||
//! \todo To be removed with Qt 5.5 when getSimualtorStatus directly provides the enum
|
||||
ISimulator::SimulatorStatus getSimulatorStatusEnum() const;
|
||||
|
||||
//! Simulator setup
|
||||
virtual BlackMisc::Simulation::CSimulatorSetup getSimulatorSetup() const = 0;
|
||||
@@ -160,24 +168,6 @@ namespace BlackCore
|
||||
//! Time synchronization offset
|
||||
virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const = 0;
|
||||
|
||||
//! Load specific simulator plugin
|
||||
virtual bool loadSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) = 0;
|
||||
|
||||
//! Load specific simulator plugin as set in settings
|
||||
virtual bool loadSimulatorPluginFromSettings() = 0;
|
||||
|
||||
//! Listen for the specific simulator to start, load plugin automatically
|
||||
virtual void listenForSimulator(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) = 0;
|
||||
|
||||
//! Listen for all available simulators
|
||||
virtual void listenForAllSimulators() = 0;
|
||||
|
||||
//! Listen for simulator as set in settings
|
||||
virtual void listenForSimulatorFromSettings() = 0;
|
||||
|
||||
//! Unload simulator plugin
|
||||
virtual void unloadSimulatorPlugin() = 0;
|
||||
|
||||
//! Simulator avialable (driver available)?
|
||||
bool isSimulatorAvailable() const { return BlackMisc::CProject::isCompiledWithFlightSimulatorSupport() && !getSimulatorPluginInfo().isUnspecified(); }
|
||||
|
||||
|
||||
@@ -17,10 +17,12 @@
|
||||
#include "blackmisc/propertyindexvariantmap.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/loghandler.h"
|
||||
#include "blackmisc/settingutilities.h"
|
||||
#include <QPluginLoader>
|
||||
#include <QLibrary>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Settings;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Network;
|
||||
@@ -43,8 +45,7 @@ namespace BlackCore
|
||||
|
||||
CContextSimulator::~CContextSimulator()
|
||||
{
|
||||
disconnectFromSimulator();
|
||||
unloadSimulatorPlugin();
|
||||
this->gracefulShutdown();
|
||||
}
|
||||
|
||||
ISimulatorFactory *CContextSimulator::getSimulatorFactory(const CSimulatorPluginInfo &simulator)
|
||||
@@ -109,21 +110,34 @@ namespace BlackCore
|
||||
it->m_storage.insert(key, value);
|
||||
}
|
||||
|
||||
void CContextSimulator::gracefulShutdown()
|
||||
{
|
||||
this->disconnect();
|
||||
this->stopSimulatorPlugin();
|
||||
}
|
||||
|
||||
CSimulatorPluginInfoList CContextSimulator::getAvailableSimulatorPlugins() const
|
||||
{
|
||||
CSimulatorPluginInfoList list;
|
||||
|
||||
std::for_each(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [&list](const PluginData & driver)
|
||||
{
|
||||
list.push_back(driver.info);
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
bool CContextSimulator::startSimulatorPlugin(const CSimulatorPluginInfo &simulatorInfo)
|
||||
{
|
||||
return this->loadSimulatorPlugin(simulatorInfo, true);
|
||||
}
|
||||
|
||||
void CContextSimulator::stopSimulatorPlugin()
|
||||
{
|
||||
this->unloadSimulatorPlugin(false);
|
||||
}
|
||||
|
||||
int CContextSimulator::getSimulatorStatus() const
|
||||
{
|
||||
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulatorPlugin) { return 0; }
|
||||
|
||||
@@ -131,18 +145,6 @@ namespace BlackCore
|
||||
return m_simulatorPlugin->simulator->getSimulatorStatus();
|
||||
}
|
||||
|
||||
bool CContextSimulator::disconnectFromSimulator()
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
if (!m_simulatorPlugin)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Q_ASSERT(m_simulatorPlugin->simulator);
|
||||
return m_simulatorPlugin->simulator->disconnectFrom();
|
||||
}
|
||||
|
||||
BlackMisc::Simulation::CSimulatorPluginInfo CContextSimulator::getSimulatorPluginInfo() const
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
|
||||
@@ -351,14 +353,14 @@ namespace BlackCore
|
||||
return this->m_simulatorPlugin->simulator->getTimeSynchronizationOffset();
|
||||
}
|
||||
|
||||
bool CContextSimulator::loadSimulatorPlugin(const CSimulatorPluginInfo &simulatorInfo)
|
||||
bool CContextSimulator::loadSimulatorPlugin(const CSimulatorPluginInfo &simulatorInfo, bool withListener)
|
||||
{
|
||||
Q_ASSERT(getIContextApplication());
|
||||
Q_ASSERT(getIContextApplication()->isUsingImplementingObject());
|
||||
Q_ASSERT(!simulatorInfo.isUnspecified());
|
||||
|
||||
// warning if we do not have any plugins
|
||||
if (m_simulatorPlugins.isEmpty() || simulatorInfo.isUnspecified())
|
||||
// error if we do not have any plugins
|
||||
if (m_simulatorPlugins.isEmpty())
|
||||
{
|
||||
CLogMessage(this).error("No simulator plugins");
|
||||
return false;
|
||||
@@ -370,6 +372,29 @@ namespace BlackCore
|
||||
return true;
|
||||
}
|
||||
|
||||
unloadSimulatorPlugin(false); // old plugin unloaded
|
||||
|
||||
// now we have a state where no driver is loaded
|
||||
if (withListener)
|
||||
{
|
||||
// hand over to listeners, when listener is done, it will call this function again
|
||||
if (simulatorInfo.isAuto())
|
||||
{
|
||||
this->listenForAllSimulators();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->listenForSimulator(simulatorInfo);
|
||||
}
|
||||
return false; // not a plugin yet, just listener
|
||||
}
|
||||
|
||||
if (!simulatorInfo.isValid() || simulatorInfo.isUnspecified())
|
||||
{
|
||||
CLogMessage(this).error("Illegal plugin");
|
||||
return false;
|
||||
}
|
||||
|
||||
ISimulatorFactory *factory = getSimulatorFactory(simulatorInfo);
|
||||
Q_ASSERT(factory);
|
||||
|
||||
@@ -380,9 +405,7 @@ namespace BlackCore
|
||||
IOwnAircraftProvider *ownAircraftProvider = this->getRuntime()->getCContextOwnAircraft();
|
||||
IRemoteAircraftProvider *renderedAircraftProvider = this->getRuntime()->getCContextNetwork();
|
||||
ISimulator *newSimulator = factory->create(simulatorInfo, ownAircraftProvider, renderedAircraftProvider, this);
|
||||
Q_ASSERT(newSimulator);
|
||||
|
||||
unloadSimulatorPlugin(); // old plugin unloaded
|
||||
Q_ASSERT_X(newSimulator, Q_FUNC_INFO, "no simulator driver can be created");
|
||||
|
||||
PluginData *plugin = findPlugin(simulatorInfo);
|
||||
plugin->simulator = newSimulator;
|
||||
@@ -413,57 +436,19 @@ namespace BlackCore
|
||||
Q_ASSERT(networkContext);
|
||||
Q_ASSERT(networkContext->isLocalObject());
|
||||
|
||||
// initially add aircraft
|
||||
for (const CSimulatedAircraft &simulatedAircraft : networkContext->getAircraftInRange())
|
||||
{
|
||||
Q_ASSERT(!simulatedAircraft.getCallsign().isEmpty());
|
||||
m_simulatorPlugin->simulator->logicallyAddRemoteAircraft(simulatedAircraft);
|
||||
}
|
||||
|
||||
// apply latest settings
|
||||
settingsChanged(static_cast<uint>(IContextSettings::SettingsSimulator));
|
||||
|
||||
// try to connect
|
||||
m_simulatorPlugin->simulator->connectTo();
|
||||
emit simulatorPluginChanged(this->m_simulatorPlugin->info);
|
||||
CLogMessage(this).info("Simulator plugin loaded: %1") << this->m_simulatorPlugin->info.toQString(true);
|
||||
|
||||
if (m_simulatorPlugin) // can be already nullptr if connectTo() is synchronous and fails
|
||||
{
|
||||
emit simulatorPluginChanged(this->m_simulatorPlugin->info);
|
||||
CLogMessage(this).info("Simulator plugin loaded: %1") << this->m_simulatorPlugin->info.toQString(true);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CContextSimulator::loadSimulatorPluginFromSettings()
|
||||
{
|
||||
Q_ASSERT(this->getIContextSettings());
|
||||
if (!this->getIContextSettings()) return false; // TODO assert or if?
|
||||
|
||||
// TODO warnings if we didn't load the plugin which the settings asked for
|
||||
|
||||
CSimulatorPluginInfoList plugins = this->getAvailableSimulatorPlugins();
|
||||
if (plugins.size() == 1)
|
||||
{
|
||||
// load, independent from settings, we have only driver
|
||||
return this->loadSimulatorPlugin(plugins.front());
|
||||
}
|
||||
else if (plugins.size() > 1)
|
||||
{
|
||||
if (this->loadSimulatorPlugin(
|
||||
this->getIContextSettings()->getSimulatorSettings().getSelectedPlugin()
|
||||
)) return true;
|
||||
|
||||
// we have plugins, but none got loaded
|
||||
// just load first one
|
||||
return this->loadSimulatorPlugin(plugins.front());
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CContextSimulator::listenForSimulator(const CSimulatorPluginInfo &simulatorInfo)
|
||||
@@ -472,13 +457,6 @@ namespace BlackCore
|
||||
Q_ASSERT(this->getIContextApplication()->isUsingImplementingObject());
|
||||
Q_ASSERT(!simulatorInfo.isUnspecified());
|
||||
|
||||
if (this->m_simulatorPlugin)
|
||||
{
|
||||
// already loaded
|
||||
CLogMessage(this).warning("Cannot listen for simulator while the driver %1 is still loaded") << m_simulatorPlugin->info.toQString();
|
||||
return;
|
||||
}
|
||||
|
||||
// warning if we do not have any plugins
|
||||
if (m_simulatorPlugins.isEmpty())
|
||||
{
|
||||
@@ -486,6 +464,19 @@ namespace BlackCore
|
||||
return;
|
||||
}
|
||||
|
||||
ISimulator::SimulatorStatus simStatus = getSimulatorStatusEnum();
|
||||
if (this->m_simulatorPlugin && this->m_simulatorPlugin->info == simulatorInfo && simStatus.testFlag(ISimulator::Connected))
|
||||
{
|
||||
// the simulator is already connected and running
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->m_simulatorPlugin)
|
||||
{
|
||||
// wrong or disconnected plugin, we start from the scratch
|
||||
this->unloadSimulatorPlugin(false);
|
||||
}
|
||||
|
||||
PluginData *plugin = findPlugin(simulatorInfo);
|
||||
if (!plugin)
|
||||
{
|
||||
@@ -511,7 +502,7 @@ namespace BlackCore
|
||||
}
|
||||
|
||||
ISimulatorListener *listener = plugin->listener;
|
||||
Q_ASSERT(listener);
|
||||
Q_ASSERT_X(listener, Q_FUNC_INFO, "No listener");
|
||||
|
||||
if (!m_listenersThread.isRunning())
|
||||
{
|
||||
@@ -525,49 +516,43 @@ namespace BlackCore
|
||||
void CContextSimulator::listenForAllSimulators()
|
||||
{
|
||||
auto plugins = getAvailableSimulatorPlugins();
|
||||
for (const auto &p : plugins)
|
||||
for (const CSimulatorPluginInfo &p : plugins)
|
||||
{
|
||||
listenForSimulator(p);
|
||||
if (p.isUnspecified()) { continue; }
|
||||
if (p.isValid())
|
||||
{
|
||||
listenForSimulator(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CContextSimulator::listenForSimulatorFromSettings()
|
||||
void CContextSimulator::unloadSimulatorPlugin(bool startListeners)
|
||||
{
|
||||
Q_ASSERT(this->getIContextSettings());
|
||||
|
||||
auto plugin = getIContextSettings()->getSimulatorSettings().getSelectedPlugin();
|
||||
if (plugin.isUnspecified())
|
||||
if (m_simulatorPlugin)
|
||||
{
|
||||
listenForAllSimulators();
|
||||
ISimulator *sim = this->m_simulatorPlugin->simulator;
|
||||
m_simulatorPlugin = nullptr;
|
||||
|
||||
Q_ASSERT(this->getIContextNetwork());
|
||||
Q_ASSERT(this->getIContextNetwork()->isLocalObject());
|
||||
|
||||
// unload and disconnect
|
||||
if (sim)
|
||||
{
|
||||
// disconnect signals and delete
|
||||
sim->unload();
|
||||
this->disconnect(sim);
|
||||
sim->deleteLater();
|
||||
emit simulatorPluginChanged(CSimulatorPluginInfo());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (startListeners)
|
||||
{
|
||||
listenForSimulator(plugin);
|
||||
this->listenForAllSimulators();
|
||||
}
|
||||
}
|
||||
|
||||
void CContextSimulator::unloadSimulatorPlugin()
|
||||
{
|
||||
if (!m_simulatorPlugin) { return; }
|
||||
|
||||
// depending on shutdown order, network might already have been deleted
|
||||
emit simulatorPluginChanged(CSimulatorPluginInfo());
|
||||
|
||||
Q_ASSERT(this->getIContextNetwork());
|
||||
Q_ASSERT(this->getIContextNetwork()->isLocalObject());
|
||||
Q_ASSERT(m_simulatorPlugin->simulator);
|
||||
|
||||
// unload and disconnect
|
||||
m_simulatorPlugin->simulator->unload();
|
||||
|
||||
// disconnect signals
|
||||
this->disconnect(m_simulatorPlugin->simulator);
|
||||
|
||||
m_simulatorPlugin->simulator->deleteLater();
|
||||
m_simulatorPlugin->simulator = nullptr;
|
||||
m_simulatorPlugin = nullptr;
|
||||
}
|
||||
|
||||
void CContextSimulator::ps_addRemoteAircraft(const CSimulatedAircraft &remoteAircraft)
|
||||
{
|
||||
// todo:
|
||||
@@ -602,19 +587,17 @@ namespace BlackCore
|
||||
|
||||
void CContextSimulator::ps_onSimulatorStatusChanged(int status)
|
||||
{
|
||||
Q_ASSERT(m_simulatorPlugin);
|
||||
Q_ASSERT(m_simulatorPlugin->simulator);
|
||||
|
||||
if (!(status & ISimulator::Connected))
|
||||
ISimulator::SimulatorStatus statusEnum = ISimulator::statusToEnum(status);
|
||||
if (!statusEnum.testFlag(ISimulator::Connected))
|
||||
{
|
||||
// we got disconnected
|
||||
unloadSimulatorPlugin();
|
||||
// we got disconnected, plugin no longer needed
|
||||
unloadSimulatorPlugin(false);
|
||||
|
||||
// do not immediately listen again, but allow some time for the simulator to shutdown
|
||||
// otherwise we risk reconnecting to a closing simulator
|
||||
BlackMisc::singleShot(1000, QThread::currentThread(), [ = ]()
|
||||
{
|
||||
listenForSimulatorFromSettings();
|
||||
listenForAllSimulators();
|
||||
});
|
||||
}
|
||||
emit simulatorStatusChanged(status);
|
||||
@@ -679,33 +662,9 @@ namespace BlackCore
|
||||
void CContextSimulator::settingsChanged(uint type)
|
||||
{
|
||||
auto settingsType = static_cast<IContextSettings::SettingsType>(type);
|
||||
if (settingsType != IContextSettings::SettingsSimulator)
|
||||
return;
|
||||
if (settingsType != IContextSettings::SettingsSimulator) { return; }
|
||||
|
||||
// plugin
|
||||
CSettingsSimulator settingsSim = this->getIContextSettings()->getSimulatorSettings();
|
||||
CSimulatorPluginInfo plugin = getIContextSettings()->getSimulatorSettings().getSelectedPlugin();
|
||||
|
||||
// no simulator loaded yet, listen
|
||||
if (!m_simulatorPlugin)
|
||||
{
|
||||
stopSimulatorListeners();
|
||||
if (plugin.isUnspecified())
|
||||
{
|
||||
listenForAllSimulators();
|
||||
}
|
||||
else
|
||||
{
|
||||
listenForSimulator(plugin);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// time sync
|
||||
bool timeSync = settingsSim.isTimeSyncEnabled();
|
||||
CTime syncOffset = settingsSim.getSyncTimeOffset();
|
||||
m_simulatorPlugin->simulator->setTimeSynchronization(timeSync, syncOffset);
|
||||
}
|
||||
// simulator code would go here
|
||||
}
|
||||
|
||||
CPixmap CContextSimulator::iconForModel(const QString &modelString) const
|
||||
@@ -754,7 +713,7 @@ namespace BlackCore
|
||||
|
||||
CLogMessage(this).debug() << plugin->info.toQString() << "started";
|
||||
stopSimulatorListeners();
|
||||
loadSimulatorPlugin(plugin->info);
|
||||
loadSimulatorPlugin(plugin->info, false);
|
||||
}
|
||||
|
||||
void CContextSimulator::findSimulatorPlugins()
|
||||
@@ -799,7 +758,9 @@ namespace BlackCore
|
||||
std::for_each(m_simulatorPlugins.begin(), m_simulatorPlugins.end(), [](PluginData & plugin)
|
||||
{
|
||||
if (plugin.listener)
|
||||
{
|
||||
QMetaObject::invokeMethod(plugin.listener, "stop");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include "blackcore/context_simulator.h"
|
||||
#include "blackcore/simulator.h"
|
||||
#include "blackmisc/worker.h"
|
||||
#include "blackmisc/simulation/simulatorplugininfo.h"
|
||||
#include "blackmisc/simulation/simulatorplugininfolist.h"
|
||||
#include "blackmisc/network/textmessagelist.h"
|
||||
#include "blackmisc/pixmap.h"
|
||||
@@ -31,8 +30,8 @@ namespace BlackCore
|
||||
{
|
||||
//! Network simulator concrete implementation
|
||||
class BLACKCORE_EXPORT CContextSimulator :
|
||||
public IContextSimulator,
|
||||
public BlackMisc::IPluginStorageProvider
|
||||
public IContextSimulator,
|
||||
public BlackMisc::IPluginStorageProvider
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME)
|
||||
@@ -43,31 +42,31 @@ namespace BlackCore
|
||||
//! Destructor
|
||||
virtual ~CContextSimulator();
|
||||
|
||||
//! Lazy-loads the driver, instantiates the factory and returns it.
|
||||
//! \return nullptr if no corresponding driver was found or an error occured during loading it.
|
||||
//! \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;
|
||||
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);
|
||||
virtual void setPluginData(const QObject *obj, const QString &key, const BlackMisc::CVariant &value);
|
||||
|
||||
//! Gracefully shut down, e.g. for plugin unloading
|
||||
void gracefulShutdown();
|
||||
|
||||
public slots:
|
||||
//! \copydoc IContextSimulator::getSimulatorPluginInfo()
|
||||
virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorPluginList()
|
||||
//! \copydoc IContextSimulator::getAvailableSimulatorPlugins()
|
||||
virtual BlackMisc::Simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::startSimulatorPlugin()
|
||||
virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
|
||||
|
||||
//! \copydoc IContextSimulator::stopSimulatorPlugin()
|
||||
virtual void stopSimulatorPlugin() override;
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorStatus()
|
||||
virtual int getSimulatorStatus() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::disconnectFrom
|
||||
virtual bool disconnectFromSimulator() override;
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorPluginInfo()
|
||||
virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorSetup()
|
||||
virtual BlackMisc::Simulation::CSimulatorSetup getSimulatorSetup() const override;
|
||||
|
||||
@@ -125,24 +124,6 @@ namespace BlackCore
|
||||
//! \copydoc IContextSimulator::getTimeSynchronizationOffset
|
||||
virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::loadSimulatorPlugin()
|
||||
virtual bool loadSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
|
||||
|
||||
//! \copydoc IContextSimulator::loadSimulatorPluginFromSettings()
|
||||
virtual bool loadSimulatorPluginFromSettings() override;
|
||||
|
||||
//! \copydoc IContextSimulator::listenForSimulator()
|
||||
virtual void listenForSimulator(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
|
||||
|
||||
//! \copydoc IContextSimulator::listenForAllSimulators()
|
||||
virtual void listenForAllSimulators() override;
|
||||
|
||||
//! \copydoc IContextSimulator::listenForSimulatorFromSettings()
|
||||
virtual void listenForSimulatorFromSettings() override;
|
||||
|
||||
//! \copydoc IContextSimulator::unloadSimulatorPlugin()
|
||||
virtual void unloadSimulatorPlugin() override;
|
||||
|
||||
//! \copydoc IContextSimulator::settingsChanged
|
||||
virtual void settingsChanged(uint type) override;
|
||||
|
||||
@@ -209,12 +190,31 @@ 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
|
||||
QHash<QString, BlackMisc::CVariant> m_storage; //!< Permanent plugin storage - data stored here will be kept even when plugin is unloaded
|
||||
};
|
||||
|
||||
//! Lazy-loads the driver, instantiates the factory and returns it.
|
||||
//! \return nullptr if no corresponding driver was found or an error occured during loading it.
|
||||
ISimulatorFactory *getSimulatorFactory(const BlackMisc::Simulation::CSimulatorPluginInfo &simulator);
|
||||
|
||||
//! Load plugin, if required start listeners before
|
||||
bool loadSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo, bool withListeners);
|
||||
|
||||
//! Unload plugin, if desired restart listeners
|
||||
void unloadSimulatorPlugin(bool startListeners);
|
||||
|
||||
//! Find and catalog all simulator plugins
|
||||
void findSimulatorPlugins();
|
||||
|
||||
//! Load plugin from settings
|
||||
bool loadSimulatorPluginFromSettings();
|
||||
|
||||
//! Listen for single simulator
|
||||
void listenForSimulator(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo);
|
||||
|
||||
//! Listen for all simulators
|
||||
void listenForAllSimulators();
|
||||
|
||||
//! Call stop() on all loaded listeners
|
||||
void stopSimulatorListeners();
|
||||
|
||||
|
||||
@@ -66,11 +66,6 @@ namespace BlackCore
|
||||
return m_dBusInterface->callDBusRet<int>(QLatin1Literal("getSimulatorStatus"));
|
||||
}
|
||||
|
||||
bool CContextSimulatorProxy::disconnectFromSimulator()
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("disconnectFromSimulator"));
|
||||
}
|
||||
|
||||
CAirportList CContextSimulatorProxy::getAirportsInRange() const
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<BlackMisc::Aviation::CAirportList>(QLatin1Literal("getAirportsInRange"));
|
||||
@@ -171,34 +166,14 @@ namespace BlackCore
|
||||
return m_dBusInterface->callDBusRet<BlackMisc::PhysicalQuantities::CTime>(QLatin1Literal("getTimeSynchronizationOffset"));
|
||||
}
|
||||
|
||||
bool CContextSimulatorProxy::loadSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo)
|
||||
bool CContextSimulatorProxy::startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo)
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("loadSimulatorPlugin"), simulatorInfo);
|
||||
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("startSimulatorPlugin"), simulatorInfo);
|
||||
}
|
||||
|
||||
bool CContextSimulatorProxy::loadSimulatorPluginFromSettings()
|
||||
void CContextSimulatorProxy::stopSimulatorPlugin()
|
||||
{
|
||||
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("loadSimulatorPluginFromSettings"));
|
||||
}
|
||||
|
||||
void CContextSimulatorProxy::listenForSimulator(const CSimulatorPluginInfo &simulatorInfo)
|
||||
{
|
||||
m_dBusInterface->callDBus(QLatin1Literal("listenForSimulator"), simulatorInfo);
|
||||
}
|
||||
|
||||
void CContextSimulatorProxy::listenForAllSimulators()
|
||||
{
|
||||
m_dBusInterface->callDBus(QLatin1Literal("listenForAllSimulators"));
|
||||
}
|
||||
|
||||
void CContextSimulatorProxy::listenForSimulatorFromSettings()
|
||||
{
|
||||
m_dBusInterface->callDBus(QLatin1Literal("listenForSimulatorFromSettings"));
|
||||
}
|
||||
|
||||
void CContextSimulatorProxy::unloadSimulatorPlugin()
|
||||
{
|
||||
m_dBusInterface->callDBus(QLatin1Literal("unloadSimulatorPlugin"));
|
||||
m_dBusInterface->callDBus(QLatin1Literal("stopSimulatorPlugin"));
|
||||
}
|
||||
|
||||
void CContextSimulatorProxy::settingsChanged(uint type)
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
//! \brief DBus proxy for Simulator Context
|
||||
//! DBus proxy for Simulator Context
|
||||
//! \ingroup dbus
|
||||
class BLACKCORE_EXPORT CContextSimulatorProxy : public IContextSimulator
|
||||
{
|
||||
@@ -44,13 +44,21 @@ namespace BlackCore
|
||||
CContextSimulatorProxy(const QString &serviceName, QDBusConnection &connection, CRuntimeConfig::ContextMode mode, CRuntime *runtime);
|
||||
|
||||
public slots:
|
||||
//! \copydoc IContextSimulator::getSimulatorPluginInfo()
|
||||
virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getSimualtorStatus()
|
||||
//! \copydoc IContextSimulator::getAvailableSimulatorPlugins()
|
||||
virtual BlackMisc::Simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::startSimulatorPlugin()
|
||||
virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
|
||||
|
||||
//! \copydoc IContextSimulator::stopSimulatorPlugin()
|
||||
virtual void stopSimulatorPlugin() override;
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorStatus()
|
||||
virtual int getSimulatorStatus() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::disconnectFrom
|
||||
virtual bool disconnectFromSimulator() override;
|
||||
|
||||
//! \copydoc IContextSimulator::getAirportsInRange()
|
||||
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override;
|
||||
|
||||
@@ -69,15 +77,9 @@ namespace BlackCore
|
||||
//! \copydoc IContextSimulator::getIcaoForModelString
|
||||
virtual BlackMisc::Aviation::CAircraftIcaoData getIcaoForModelString(const QString &modelString) const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorPluginInfo
|
||||
virtual BlackMisc::Simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorSetup
|
||||
virtual BlackMisc::Simulation::CSimulatorSetup getSimulatorSetup() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::getSimulatorPluginList()
|
||||
virtual BlackMisc::Simulation::CSimulatorPluginInfoList getAvailableSimulatorPlugins() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::setTimeSynchronization
|
||||
virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) override;
|
||||
|
||||
@@ -114,24 +116,6 @@ namespace BlackCore
|
||||
//! \copydoc IContextSimulator::getTimeSynchronizationOffset
|
||||
virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override;
|
||||
|
||||
//! \copydoc IContextSimulator::loadSimulatorPlugin
|
||||
virtual bool loadSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
|
||||
|
||||
//! \copydoc IContextSimulator::loadSimulatorPluginFromSettings()
|
||||
virtual bool loadSimulatorPluginFromSettings();
|
||||
|
||||
//! \copydoc IContextSimulator::listenForSimulator()
|
||||
virtual void listenForSimulator(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
|
||||
|
||||
//! \copydoc IContextSimulator::listenForAllSimulators()
|
||||
virtual void listenForAllSimulators() override;
|
||||
|
||||
//! \copydoc IContextSimulator::listenForSimulatorFromSettings()
|
||||
virtual void listenForSimulatorFromSettings() override;
|
||||
|
||||
//! \copydoc IContextSimulator::unloadSimulatorPlugin()
|
||||
virtual void unloadSimulatorPlugin() override;
|
||||
|
||||
//! \copydoc IContextSimulator::settingsChanged
|
||||
virtual void settingsChanged(uint type) override;
|
||||
|
||||
@@ -143,9 +127,7 @@ namespace BlackCore
|
||||
|
||||
//! \copydoc ISimulator::enableDebuggingMessages
|
||||
virtual void enableDebugMessages(bool driver, bool interpolator) override;
|
||||
|
||||
};
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user