Changeset View
Changeset View
Standalone View
Standalone View
src/runnerjobs.cpp
Show All 15 Lines | |||||
16 | * Free Software Foundation, Inc., | 16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "runnerjobs_p.h" | 20 | #include "runnerjobs_p.h" | ||
21 | 21 | | |||
22 | #include <QTimer> | 22 | #include <QTimer> | ||
23 | #include <QMutexLocker> | 23 | #include <QMutexLocker> | ||
24 | #include <ThreadWeaver/Lambda> | ||||
24 | #include "krunner_debug.h" | 25 | #include "krunner_debug.h" | ||
25 | 26 | | |||
26 | #include "runnermanager.h" | 27 | #include "runnermanager.h" | ||
27 | #include "querymatch.h" | 28 | #include "querymatch.h" | ||
28 | 29 | | |||
29 | using ThreadWeaver::Job; | 30 | using ThreadWeaver::Job; | ||
30 | using ThreadWeaver::Queue; | 31 | using ThreadWeaver::Queue; | ||
31 | 32 | | |||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | |||||
117 | } | 118 | } | ||
118 | 119 | | |||
119 | //////////////////// | 120 | //////////////////// | ||
120 | // Jobs | 121 | // Jobs | ||
121 | //////////////////// | 122 | //////////////////// | ||
122 | 123 | | |||
123 | FindMatchesJob::FindMatchesJob(Plasma::AbstractRunner *runner, | 124 | FindMatchesJob::FindMatchesJob(Plasma::AbstractRunner *runner, | ||
124 | Plasma::RunnerContext *context, QObject *) | 125 | Plasma::RunnerContext *context, QObject *) | ||
125 | : ThreadWeaver::Job(), | 126 | : ThreadWeaver::QObjectDecorator(new ThreadWeaver::Lambda<std::function<void()>>([this] { | ||
127 | if (m_context.isValid()) { | ||||
128 | m_runner->performMatch(m_context); | ||||
129 | } | ||||
130 | })), | ||||
126 | m_context(*context, nullptr), | 131 | m_context(*context, nullptr), | ||
127 | m_runner(runner), | 132 | m_runner(runner), | ||
128 | m_timer(nullptr), | 133 | m_timer(nullptr) | ||
129 | m_decorator(new ThreadWeaver::QObjectDecorator(this, true)) | | |||
130 | { | 134 | { | ||
131 | QMutexLocker l(mutex()); Q_UNUSED(l); | 135 | QMutexLocker l(mutex()); Q_UNUSED(l); | ||
132 | if (runner->speed() == Plasma::AbstractRunner::SlowSpeed) { | 136 | if (runner->speed() == Plasma::AbstractRunner::SlowSpeed) { | ||
133 | assignQueuePolicy(&DelayedRunnerPolicy::instance()); | 137 | assignQueuePolicy(&DelayedRunnerPolicy::instance()); | ||
134 | } else { | 138 | } else { | ||
135 | assignQueuePolicy(&DefaultRunnerPolicy::instance()); | 139 | assignQueuePolicy(&DefaultRunnerPolicy::instance()); | ||
136 | } | 140 | } | ||
137 | } | 141 | } | ||
138 | 142 | | |||
139 | FindMatchesJob::~FindMatchesJob() | 143 | FindMatchesJob::~FindMatchesJob() | ||
140 | { | 144 | { | ||
141 | } | 145 | } | ||
142 | 146 | | |||
143 | QTimer* FindMatchesJob::delayTimer() const | 147 | QTimer* FindMatchesJob::delayTimer() const | ||
144 | { | 148 | { | ||
145 | return m_timer; | 149 | return m_timer; | ||
146 | } | 150 | } | ||
147 | 151 | | |||
148 | void FindMatchesJob::setDelayTimer(QTimer *timer) | 152 | void FindMatchesJob::setDelayTimer(QTimer *timer) | ||
149 | { | 153 | { | ||
150 | m_timer = timer; | 154 | m_timer = timer; | ||
151 | } | 155 | } | ||
152 | 156 | | |||
153 | void FindMatchesJob::run(ThreadWeaver::JobPointer, ThreadWeaver::Thread*) | | |||
154 | { | | |||
155 | // qCDebug(KRUNNER) << "Running match for " << m_runner->objectName() | | |||
156 | // << " in Thread " << thread()->id() << endl; | | |||
157 | if (m_context.isValid()) { | | |||
158 | m_runner->performMatch(m_context); | | |||
159 | } | | |||
160 | } | | |||
161 | | ||||
162 | int FindMatchesJob::priority() const | 157 | int FindMatchesJob::priority() const | ||
163 | { | 158 | { | ||
164 | return m_runner->priority(); | 159 | return m_runner->priority(); | ||
165 | } | 160 | } | ||
166 | 161 | | |||
167 | Plasma::AbstractRunner* FindMatchesJob::runner() const | 162 | Plasma::AbstractRunner* FindMatchesJob::runner() const | ||
168 | { | 163 | { | ||
169 | return m_runner; | 164 | return m_runner; | ||
170 | } | 165 | } | ||
171 | 166 | | |||
172 | DelayedJobCleaner::DelayedJobCleaner(const QSet<QSharedPointer<FindMatchesJob> > &jobs, const QSet<AbstractRunner *> &runners) | 167 | DelayedJobCleaner::DelayedJobCleaner(const QSet<QSharedPointer<FindMatchesJob> > &jobs, const QSet<AbstractRunner *> &runners) | ||
173 | : QObject(Queue::instance()), | 168 | : QObject(Queue::instance()), | ||
174 | m_weaver(Queue::instance()), | 169 | m_weaver(Queue::instance()), | ||
175 | m_jobs(jobs), | 170 | m_jobs(jobs), | ||
176 | m_runners(runners) | 171 | m_runners(runners) | ||
177 | { | 172 | { | ||
178 | connect(m_weaver, SIGNAL(finished()), this, SLOT(checkIfFinished())); | 173 | connect(m_weaver, SIGNAL(finished()), this, SLOT(checkIfFinished())); | ||
179 | 174 | | |||
180 | for (auto it = m_jobs.constBegin(); it != m_jobs.constEnd(); ++it) { | 175 | for (auto it = m_jobs.constBegin(); it != m_jobs.constEnd(); ++it) { | ||
181 | connect((*it)->decorator(), &ThreadWeaver::QObjectDecorator::done, this, &DelayedJobCleaner::jobDone); | 176 | connect(it->data(), &ThreadWeaver::QObjectDecorator::done, this, &DelayedJobCleaner::jobDone); | ||
182 | } | 177 | } | ||
183 | } | 178 | } | ||
184 | 179 | | |||
185 | DelayedJobCleaner::~DelayedJobCleaner() | 180 | DelayedJobCleaner::~DelayedJobCleaner() | ||
186 | { | 181 | { | ||
187 | qDeleteAll(m_runners); | 182 | qDeleteAll(m_runners); | ||
188 | } | 183 | } | ||
189 | 184 | | |||
Show All 26 Lines |