From 211a7dcc5beaad2f574206261c33b09c01b82527 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sun, 28 Feb 2016 12:37:38 +0100 Subject: [PATCH] CPluginManagerSimulator::getListener should not create listeners Up to now, CPluginManagerSimulator::getListener was allocating a listener automatically in the background which was not always the desired behaviour. For example in case simulators are stopped, it is unnecessary to allocate all listeners and call stop on them. It is enough to stop the existing ones. In order to achieve the correct behaviour the creation part is moved to CPluginManagerSimulator::createListener. refs #606 --- src/blackcore/contextsimulatorimpl.cpp | 5 +++-- src/blackcore/pluginmanagersimulator.cpp | 13 ++++++++++++- src/blackcore/pluginmanagersimulator.h | 7 ++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/blackcore/contextsimulatorimpl.cpp b/src/blackcore/contextsimulatorimpl.cpp index 8d84512d3..b40fe6081 100644 --- a/src/blackcore/contextsimulatorimpl.cpp +++ b/src/blackcore/contextsimulatorimpl.cpp @@ -69,6 +69,7 @@ namespace BlackCore } ISimulatorListener *listener = m_plugins->getListener(simulatorInfo.getIdentifier()); + Q_ASSERT(listener); QMetaObject::invokeMethod(listener, "stop"); } @@ -396,7 +397,7 @@ namespace BlackCore m_listenersThread.start(QThread::LowPriority); } - ISimulatorListener *listener = m_plugins->getListener(simulatorInfo.getIdentifier()); + ISimulatorListener *listener = m_plugins->createListener(simulatorInfo.getIdentifier()); Q_ASSERT_X(listener, Q_FUNC_INFO, "No listener"); if (listener->thread() != &m_listenersThread) @@ -584,7 +585,7 @@ namespace BlackCore for (const auto &info : getAvailableSimulatorPlugins()) { ISimulatorListener *listener = m_plugins->getListener(info.getIdentifier()); - QMetaObject::invokeMethod(listener, "stop"); + if(listener) { QMetaObject::invokeMethod(listener, "stop"); } } } diff --git a/src/blackcore/pluginmanagersimulator.cpp b/src/blackcore/pluginmanagersimulator.cpp index 43d2df3ec..d948a67a2 100644 --- a/src/blackcore/pluginmanagersimulator.cpp +++ b/src/blackcore/pluginmanagersimulator.cpp @@ -58,7 +58,7 @@ namespace BlackCore return getPluginById(pluginId); } - ISimulatorListener *CPluginManagerSimulator::getListener(const QString &pluginId) + ISimulatorListener *CPluginManagerSimulator::createListener(const QString &pluginId) { if (!m_plugins.contains(pluginId)) { @@ -83,6 +83,17 @@ namespace BlackCore return plugin.listener; } + ISimulatorListener *CPluginManagerSimulator::getListener(const QString &pluginId) + { + if (!m_plugins.contains(pluginId)) + { + return nullptr; + } + + PluginExtended &plugin = m_plugins[pluginId]; + return plugin.listener; + } + CSimulatorPluginInfoList CPluginManagerSimulator::getAvailableSimulatorPlugins() const { CSimulatorPluginInfoList list; diff --git a/src/blackcore/pluginmanagersimulator.h b/src/blackcore/pluginmanagersimulator.h index 17aa9a7a8..c26edd7a6 100644 --- a/src/blackcore/pluginmanagersimulator.h +++ b/src/blackcore/pluginmanagersimulator.h @@ -47,7 +47,12 @@ namespace BlackCore //! Get simulator factory from the plugin ISimulatorFactory *getFactory(const QString &pluginId); - //! Get simulator listener from the plugin + //! Create simulator listener from the plugin + //! In case one is existing already, it is returned instead. + ISimulatorListener *createListener(const QString &pluginId); + + //! Get previously created simulator listener from the plugin + //! Returns nullptr if listener is not yet created ISimulatorListener *getListener(const QString &pluginId); //! Get all simulator driver plugins