From 0eaab1753da615818b0873f82bc0df10d4a75a53 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sat, 25 Mar 2017 18:52:42 +0100 Subject: [PATCH] Unload simulator driver when unchecked in settings refs #909 --- src/blackcore/context/contextsimulatorimpl.cpp | 14 ++++++++++++++ src/blackcore/context/contextsimulatorimpl.h | 5 ++++- .../components/settingssimulatorcomponent.h | 1 - 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index 88b73bc6c..b11c7fbe8 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -555,6 +555,20 @@ namespace BlackCore } } + void CContextSimulator::changeEnabledSimulators() + { + CSimulatorPluginInfo currentPluginInfo = m_simulatorPlugin.first; + const QStringList enabledSimulators = m_enabledSimulators.getThreadLocal(); + + // Unload the current plugin, if it is no longer enabled + if (!currentPluginInfo.isUnspecified() && !enabledSimulators.contains(currentPluginInfo.getIdentifier())) + { + unloadSimulatorPlugin(); + emit simulatorStatusChanged(ISimulator::Disconnected); + } + restoreSimulatorPlugins(); + } + void CContextSimulator::restoreSimulatorPlugins() { stopSimulatorListeners(); diff --git a/src/blackcore/context/contextsimulatorimpl.h b/src/blackcore/context/contextsimulatorimpl.h index 83e98a4df..81276eb35 100644 --- a/src/blackcore/context/contextsimulatorimpl.h +++ b/src/blackcore/context/contextsimulatorimpl.h @@ -172,6 +172,9 @@ namespace BlackCore void ps_relayStatusMessageToSimulator(const BlackMisc::CStatusMessage &message); private: + //! Handle a change in enabled simulators + void changeEnabledSimulators(); + //! Reads list of enabled simulators, starts listeners void restoreSimulatorPlugins(); @@ -204,7 +207,7 @@ namespace BlackCore BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { this }; //!< load model set from caches QMap m_matchingMessages; BlackMisc::CSettingReadOnly m_messageSettings { this }; //!< settings for messages - BlackMisc::CSettingReadOnly m_enabledSimulators { this, &CContextSimulator::restoreSimulatorPlugins }; + BlackMisc::CSettingReadOnly m_enabledSimulators { this, &CContextSimulator::changeEnabledSimulators }; QString m_networkSessionId; //! Network session, if not connected empty bool m_initallyAddAircrafts = false; bool m_enableMatchingMessages = true; diff --git a/src/blackgui/components/settingssimulatorcomponent.h b/src/blackgui/components/settingssimulatorcomponent.h index f58fe113f..cc30cdd8e 100644 --- a/src/blackgui/components/settingssimulatorcomponent.h +++ b/src/blackgui/components/settingssimulatorcomponent.h @@ -46,7 +46,6 @@ namespace BlackGui private slots: //! Driver plugin enabled/disabled - //! \todo Unload plugin if user disables it while running void ps_pluginStateChanged(const QString &identifier, bool enabled); //! Apply max.aircraft