From deb63fa3444b51e6c204bb1199cff964168523a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 16 Nov 2015 14:06:23 +0100 Subject: [PATCH] Cancel loading in EffectsLoader on tear down When unloading all effects we should make sure that also the ones scheduled for loading are canceled. For this a new method clear() is added to the AbstractEffectLoader and all inheriting classes which clears the current load queue. For the scripted and plugin effect loader it should also cancel the future, but that's not yet implemented. --- effectloader.cpp | 24 ++++++++++++++++++++++++ effectloader.h | 18 +++++++++++++++++- effects.cpp | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/effectloader.cpp b/effectloader.cpp index f042feb1d5..ee85ac43e3 100644 --- a/effectloader.cpp +++ b/effectloader.cpp @@ -178,6 +178,11 @@ QString BuiltInEffectLoader::internalName(const QString& name) const return name.toLower(); } +void BuiltInEffectLoader::clear() +{ + m_queue->clear(); +} + static const QString s_nameProperty = QStringLiteral("X-KDE-PluginInfo-Name"); static const QString s_jsConstraint = QStringLiteral("[X-Plasma-API] == 'javascript'"); static const QString s_serviceType = QStringLiteral("KWin/Effect"); @@ -289,6 +294,12 @@ KPluginMetaData ScriptedEffectLoader::findEffect(const QString &name) const } +void ScriptedEffectLoader::clear() +{ + // TODO: cancel future + m_queue->clear(); +} + PluginEffectLoader::PluginEffectLoader(QObject *parent) : AbstractEffectLoader(parent) , m_queue(new EffectLoadQueue< PluginEffectLoader, KPluginMetaData>(this)) @@ -448,6 +459,12 @@ void PluginEffectLoader::setPluginSubDirectory(const QString &directory) m_pluginSubDirectory = directory; } +void PluginEffectLoader::clear() +{ + // TODO: cancel future + m_queue->clear(); +} + EffectLoader::EffectLoader(QObject *parent) : AbstractEffectLoader(parent) { @@ -513,4 +530,11 @@ void EffectLoader::setConfig(KSharedConfig::Ptr config) } } +void EffectLoader::clear() +{ + for (auto it = m_loaders.constBegin(); it != m_loaders.constEnd(); ++it) { + (*it)->clear(); + } +} + } // namespace KWin diff --git a/effectloader.h b/effectloader.h index 7fcb8e7643..38ca86a26a 100644 --- a/effectloader.h +++ b/effectloader.h @@ -162,6 +162,11 @@ public: */ virtual bool isEffectSupported(const QString &name) const = 0; + /** + * @brief Clears the load queue, that is all scheduled Effects are discarded from loading. + **/ + virtual void clear() = 0; + Q_SIGNALS: /** * @brief The loader emits this signal when it successfully loaded an effect. @@ -236,10 +241,17 @@ public: m_queue.enqueue(value); scheduleDequeue(); } + void clear() + { + m_queue.clear(); + m_dequeueScheduled = false; + } protected: void dequeue() override { - Q_ASSERT(!m_queue.isEmpty()); + if (m_queue.isEmpty()) { + return; + } m_dequeueScheduled = false; const auto pair = m_queue.dequeue(); m_effectLoader->loadEffect(pair.first, pair.second); @@ -274,6 +286,7 @@ public: bool isEffectSupported(const QString &name) const override; QStringList listOfKnownEffects() const override; + void clear() override; void queryAndLoadAll() override; bool loadEffect(const QString& name) override; bool loadEffect(BuiltInEffect effect, LoadEffectFlags flags); @@ -300,6 +313,7 @@ public: bool isEffectSupported(const QString &name) const override; QStringList listOfKnownEffects() const override; + void clear() override; void queryAndLoadAll() override; bool loadEffect(const QString &name) override; bool loadEffect(const KPluginMetaData &effect, LoadEffectFlags flags); @@ -322,6 +336,7 @@ public: bool isEffectSupported(const QString &name) const override; QStringList listOfKnownEffects() const override; + void clear() override; void queryAndLoadAll() override; bool loadEffect(const QString &name) override; bool loadEffect(const KPluginMetaData &info, LoadEffectFlags flags); @@ -349,6 +364,7 @@ public: bool loadEffect(const QString &name) override; void queryAndLoadAll() override; void setConfig(KSharedConfig::Ptr config) override; + void clear() override; private: QList m_loaders; diff --git a/effects.cpp b/effects.cpp index 0f0ac4e3a3..ebb7520bc5 100644 --- a/effects.cpp +++ b/effects.cpp @@ -336,6 +336,7 @@ void EffectsHandlerImpl::unloadAllEffects() delete effect; } loaded_effects.clear(); + m_effectLoader->clear(); } void EffectsHandlerImpl::setupAbstractClientConnections(AbstractClient* c)