refs #443 Add simulator enable/disable option

* Added CPluginSelector widget
* IContextSimulator starts/stops only specified listener(s)
* No more "auto" CSimulatorPluginInfo
This commit is contained in:
Michał Garapich
2015-06-10 01:19:36 +02:00
committed by Mathew Sutcliffe
parent a4f0007414
commit 4d772050b0
14 changed files with 187 additions and 118 deletions

View File

@@ -176,7 +176,6 @@ namespace BlackCore
Q_ASSERT(c);
}
times.insert("Post setup, sim.connects", time.restart());
this->m_contextSimulator->startSimulatorPlugin(CSimulatorPluginInfo::autoPlugin());
}
// only where network and(!) own aircraft run locally

View File

@@ -99,8 +99,8 @@ namespace BlackCore
//! 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;
//! Stop listener or unload the given plugin (if currently loaded)
virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) = 0;
//! Simulator combined status
virtual int getSimulatorStatus() const = 0;

View File

@@ -50,12 +50,6 @@ namespace BlackCore
return false;
}
//! \copydoc IContextSimulator::stopSimulatorPlugin()
virtual void stopSimulatorPlugin() override
{
logEmptyContextWarning(Q_FUNC_INFO);
}
//! \copydoc IContextSimulator::getSimulatorStatus()
virtual int getSimulatorStatus() const override
{
@@ -63,6 +57,13 @@ namespace BlackCore
return 0;
}
//! \copydoc IContextSimulator::stopSimulatorPlugin()
virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override
{
Q_UNUSED(simulatorInfo);
logEmptyContextWarning(Q_FUNC_INFO);
}
//! \copydoc IContextSimulator::getAirportsInRange()
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override
{

View File

@@ -48,7 +48,7 @@ namespace BlackCore
void CContextSimulator::gracefulShutdown()
{
this->disconnect();
this->stopSimulatorPlugin();
this->unloadSimulatorPlugin();
}
CSimulatorPluginInfoList CContextSimulator::getAvailableSimulatorPlugins() const
@@ -61,9 +61,15 @@ namespace BlackCore
return this->loadSimulatorPlugin(simulatorInfo, true);
}
void CContextSimulator::stopSimulatorPlugin()
void CContextSimulator::stopSimulatorPlugin(const CSimulatorPluginInfo &simulatorInfo)
{
this->unloadSimulatorPlugin();
if (!m_simulatorPlugin.first.isUnspecified() && m_simulatorPlugin.first == simulatorInfo)
{
this->unloadSimulatorPlugin();
}
ISimulatorListener *listener = m_plugins->getListener(simulatorInfo.getIdentifier());
QMetaObject::invokeMethod(listener, "stop");
}
int CContextSimulator::getSimulatorStatus() const
@@ -281,28 +287,24 @@ namespace BlackCore
Q_ASSERT(!simulatorInfo.isUnspecified());
Q_ASSERT(CThreadUtils::isCurrentThreadApplicationThread()); // only run in main thread
if (!simulatorInfo.isValid())
{
CLogMessage(this).error("Illegal plugin");
return false;
}
// Is the plugin already loaded?
if (!m_simulatorPlugin.first.isUnspecified() &&
(m_simulatorPlugin.first == simulatorInfo || simulatorInfo.isAuto()))
if (!m_simulatorPlugin.first.isUnspecified())
{
return true;
}
stopSimulatorListeners(); // we make sure all listeners are stopped and restart those we need
unloadSimulatorPlugin(); // 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);
}
this->listenForSimulator(simulatorInfo);
return false; // not a plugin yet, just listener
}

View File

@@ -55,7 +55,7 @@ namespace BlackCore
virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
//! \copydoc IContextSimulator::stopSimulatorPlugin()
virtual void stopSimulatorPlugin() override;
virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
//! \copydoc IContextSimulator::getSimulatorStatus()
virtual int getSimulatorStatus() const override;
@@ -171,9 +171,6 @@ namespace BlackCore
//! Unload plugin, if desired restart listeners
void unloadSimulatorPlugin();
//! Load plugin from settings
bool loadSimulatorPluginFromSettings();
//! Listen for single simulator
void listenForSimulator(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo);

View File

@@ -166,9 +166,9 @@ namespace BlackCore
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("startSimulatorPlugin"), simulatorInfo);
}
void CContextSimulatorProxy::stopSimulatorPlugin()
void CContextSimulatorProxy::stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo)
{
m_dBusInterface->callDBus(QLatin1Literal("stopSimulatorPlugin"));
m_dBusInterface->callDBus(QLatin1Literal("stopSimulatorPlugin"), simulatorInfo);
}
CPixmap CContextSimulatorProxy::iconForModel(const QString &modelString) const

View File

@@ -54,7 +54,7 @@ namespace BlackCore
virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
//! \copydoc IContextSimulator::stopSimulatorPlugin()
virtual void stopSimulatorPlugin() override;
virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
//! \copydoc IContextSimulator::getSimulatorStatus()
virtual int getSimulatorStatus() const override;