From 000d79016bb565fbf1cd8a71410981f8a50416a4 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 28 Jul 2009 03:36:06 +0000 Subject: [PATCH] new setup/teardown api for runners so we don't hang onto tons of data and live connections when not matching svn path=/trunk/KDE/kdelibs/; revision=1003355 --- abstractrunner.h | 20 ++++++++++++++++++++ runnermanager.cpp | 32 ++++++++++++++++++++++++++++++-- runnermanager.h | 17 +++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/abstractrunner.h b/abstractrunner.h index a898c5e77..1da66242e 100644 --- a/abstractrunner.h +++ b/abstractrunner.h @@ -244,6 +244,26 @@ class PLASMA_EXPORT AbstractRunner : public QObject */ static QMutex *bigLock(); + Q_SIGNALS: + /** + * This signal is emitted when matching is about to commence, giving runners + * an opportunity to prepare themselves, e.g. loading data sets or preparing + * IPC or network connections. This method should be fast so as not to cause + * slow downs. Things that take longer or which should be loaded once and + * remain extant for the lifespan of the AbstractRunner should be done in init(). + * @see init() + * @since 4.4 + */ + void prepare(); + + /** + * This signal is emitted when a session of matches is complete, giving runners + * the opportunity to tear down anything set up as a result of the prepare() + * method. + * @since 4.4 + */ + void teardown(); + protected: friend class RunnerManager; friend class RunnerManagerPrivate; diff --git a/runnermanager.cpp b/runnermanager.cpp index d19714f48..9ad67fdf6 100644 --- a/runnermanager.cpp +++ b/runnermanager.cpp @@ -56,7 +56,8 @@ public: RunnerManagerPrivate(RunnerManager *parent) : q(parent), - deferredRun(0) + deferredRun(0), + prepped(false) { matchChangeTimer.setSingleShot(true); delayTimer.setSingleShot(true); @@ -218,8 +219,9 @@ public: QHash runners; QSet searchJobs; QSet oldSearchJobs; - bool loadAll; KConfigGroup config; + bool loadAll : 1; + bool prepped : 1; }; /***************************************************** @@ -325,13 +327,39 @@ QList RunnerManager::actionsForMatch(const QueryMatch &match) return QList(); } +void RunnerManager::setupMatchSession() +{ + if (d->prepped) { + return; + } + + foreach (AbstractRunner *runner, d->runners) { + emit runner->prepare(); + } +} + +void RunnerManager::matchSessionComplete() +{ + if (!d->prepped) { + return; + } + + foreach (AbstractRunner *runner, d->runners) { + emit runner->teardown(); + } + + d->prepped = false; +} + void RunnerManager::launchQuery(const QString &term) { + setupMatchSession(); launchQuery(term, QString()); } void RunnerManager::launchQuery(const QString &untrimmedTerm, const QString &runnerName) { + setupMatchSession(); QString term = untrimmedTerm.trimmed(); if (d->runners.isEmpty()) { diff --git a/runnermanager.h b/runnermanager.h index 04f9179de..f9fbdd050 100644 --- a/runnermanager.h +++ b/runnermanager.h @@ -105,6 +105,23 @@ class PLASMA_EXPORT RunnerManager : public QObject void reloadConfiguration(); public Q_SLOTS: + /** + * Call this method when the runners should be prepared for a query session. + * Call matchSessionComplete when the query session is finished for the time + * being. + * @since 4.4 + * @see matchSessionComplete + */ + void setupMatchSession(); + + /** + * Call this method when the query session is finished for the time + * being. + * @since 4.4 + * @see prepareForMatchSession + */ + void matchSessionComplete(); + /** * Launch a query, this will create threads and return inmediately. * When the information will be available can be known using the