From a3c7a9690f4321700154d2dcf0974de0dd8a7818 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 10 Oct 2013 20:27:41 +0200 Subject: [PATCH] Make the runners API compile again Recently there's been some big changes in the ThreadWeaver API. So big that they break the source compatibility we were supposed to maintain, big time. This patch tries to port plasma-framework to that new API. REVIEW: 113179 --- src/plasma/CMakeLists.txt | 24 ++++++++++---------- src/plasma/private/runnerjobs.cpp | 32 +++++++++++++-------------- src/plasma/private/runnerjobs_p.h | 30 ++++++++++++++++--------- src/plasma/private/storage.cpp | 6 ++--- src/plasma/runnermanager.cpp | 6 ++--- src/plasma/scripting/runnerscript.cpp | 3 --- 6 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src/plasma/CMakeLists.txt b/src/plasma/CMakeLists.txt index 33f23febf..7aecb56bd 100644 --- a/src/plasma/CMakeLists.txt +++ b/src/plasma/CMakeLists.txt @@ -73,12 +73,12 @@ set(plasma_LIB_SRCS private/componentinstaller.cpp #runners -# abstractrunner.cpp -# querymatch.cpp -# runnercontext.cpp -# runnermanager.cpp -# runnersyntax.cpp -# private/runnerjobs.cpp + abstractrunner.cpp + querymatch.cpp + runnercontext.cpp + runnermanager.cpp + runnersyntax.cpp + private/runnerjobs.cpp #applets,containments,corona applet.cpp @@ -117,7 +117,7 @@ set(plasma_LIB_SRCS #scripting scripting/appletscript.cpp scripting/dataenginescript.cpp - # scripting/runnerscript.cpp + scripting/runnerscript.cpp scripting/scriptengine.cpp ) @@ -181,7 +181,7 @@ set_target_properties(plasma PROPERTIES generate_export_header(plasma) set(plasma_LIB_INCLUDES - #abstractrunner.h + abstractrunner.h applet.h configloader.h containment.h @@ -196,10 +196,10 @@ set(plasma_LIB_INCLUDES packagestructure.h plasma.h ${CMAKE_CURRENT_BINARY_DIR}/plasma_export.h - #querymatch.h - #runnercontext.h - #runnermanager.h - #runnersyntax.h + querymatch.h + runnercontext.h + runnermanager.h + runnersyntax.h service.h servicejob.h svg.h diff --git a/src/plasma/private/runnerjobs.cpp b/src/plasma/private/runnerjobs.cpp index d11f7e93c..3c24c698b 100644 --- a/src/plasma/private/runnerjobs.cpp +++ b/src/plasma/private/runnerjobs.cpp @@ -47,9 +47,9 @@ DelayedRunnerPolicy& DelayedRunnerPolicy::instance() return policy; } -bool DelayedRunnerPolicy::canRun(Job *job) +bool DelayedRunnerPolicy::canRun(ThreadWeaver::JobPointer job) { - FindMatchesJob *aJob = static_cast(job); + QSharedPointer aJob(job.dynamicCast()); if (QTimer *t = aJob->delayTimer()) { // If the timer is active, the required delay has not been reached //qDebug() << "delayed timer" << aJob->runner()->name() << !t->isActive(); @@ -59,17 +59,17 @@ bool DelayedRunnerPolicy::canRun(Job *job) return true; } -void DelayedRunnerPolicy::free(Job *job) +void DelayedRunnerPolicy::free(ThreadWeaver::JobPointer job) { Q_UNUSED(job) } -void DelayedRunnerPolicy::release(Job *job) +void DelayedRunnerPolicy::release(ThreadWeaver::JobPointer job) { free(job); } -void DelayedRunnerPolicy::destructed(Job *job) +void DelayedRunnerPolicy::destructed(ThreadWeaver::JobInterface* job) { Q_UNUSED(job) } @@ -88,9 +88,9 @@ DefaultRunnerPolicy& DefaultRunnerPolicy::instance() return policy; } -bool DefaultRunnerPolicy::canRun(Job *job) +bool DefaultRunnerPolicy::canRun(ThreadWeaver::JobPointer job) { - Plasma::AbstractRunner *runner = static_cast(job)->runner(); + Plasma::AbstractRunner *runner = job.dynamicCast()->runner(); QMutexLocker l(&m_mutex); if (m_runCounts[runner->name()] > m_cap) { @@ -101,20 +101,20 @@ bool DefaultRunnerPolicy::canRun(Job *job) } } -void DefaultRunnerPolicy::free(Job *job) +void DefaultRunnerPolicy::free(ThreadWeaver::JobPointer job) { - Plasma::AbstractRunner *runner = static_cast(job)->runner(); + Plasma::AbstractRunner *runner = job.dynamicCast()->runner(); QMutexLocker l(&m_mutex); --m_runCounts[runner->name()]; } -void DefaultRunnerPolicy::release(Job *job) +void DefaultRunnerPolicy::release(ThreadWeaver::JobPointer job) { free(job); } -void DefaultRunnerPolicy::destructed(Job *job) +void DefaultRunnerPolicy::destructed(ThreadWeaver::JobInterface* job) { Q_UNUSED(job) } @@ -125,10 +125,11 @@ void DefaultRunnerPolicy::destructed(Job *job) FindMatchesJob::FindMatchesJob(Plasma::AbstractRunner *runner, Plasma::RunnerContext *context, QObject *parent) - : ThreadWeaver::Job(parent), + : ThreadWeaver::Job(), m_context(*context, 0), m_runner(runner), - m_timer(0) + m_timer(0), + m_decorator(new ThreadWeaver::QObjectDecorator(this, true)) { if (runner->speed() == Plasma::AbstractRunner::SlowSpeed) { assignQueuePolicy(&DelayedRunnerPolicy::instance()); @@ -151,7 +152,7 @@ void FindMatchesJob::setDelayTimer(QTimer *timer) m_timer = timer; } -void FindMatchesJob::run() +void FindMatchesJob::run(ThreadWeaver::JobPointer, ThreadWeaver::Thread*) { // qDebug() << "Running match for " << m_runner->objectName() // << " in Thread " << thread()->id() << endl; @@ -179,7 +180,7 @@ DelayedJobCleaner::DelayedJobCleaner(const QSet > connect(m_weaver, SIGNAL(finished()), this, SLOT(checkIfFinished())); for (auto it = m_jobs.constBegin(); it != m_jobs.constEnd(); ++it) { - connect((*it).data(), &Job::done, this, &DelayedJobCleaner::jobDone); + connect((*it)->decorator(), &ThreadWeaver::QObjectDecorator::done, this, &DelayedJobCleaner::jobDone); } } @@ -197,7 +198,6 @@ void DelayedJobCleaner::jobDone(ThreadWeaver::JobPointer job) } m_jobs.remove(runJob); - runJob->deleteLater(); if (m_jobs.isEmpty()) { deleteLater(); diff --git a/src/plasma/private/runnerjobs_p.h b/src/plasma/private/runnerjobs_p.h index 7fd707698..dfc2acaac 100644 --- a/src/plasma/private/runnerjobs_p.h +++ b/src/plasma/private/runnerjobs_p.h @@ -27,6 +27,7 @@ #include #include #include +#include #include "abstractrunner.h" @@ -46,10 +47,11 @@ public: static DelayedRunnerPolicy &instance(); - bool canRun(Job *job); - void free(Job *job); - void release(Job *job); - void destructed(Job *job); + bool canRun(ThreadWeaver::JobPointer job); + void free(ThreadWeaver::JobPointer job); + void release(ThreadWeaver::JobPointer job); + virtual void destructed(ThreadWeaver::JobInterface* job); + private: DelayedRunnerPolicy(); QMutex m_mutex; @@ -72,10 +74,10 @@ public: return m_cap; } - bool canRun(Job *job); - void free(Job *job); - void release(Job *job); - void destructed(Job *job); + bool canRun(ThreadWeaver::JobPointer job); + void free(ThreadWeaver::JobPointer job); + void release(ThreadWeaver::JobPointer job); + void destructed(ThreadWeaver::JobInterface* job); private: DefaultRunnerPolicy(); @@ -92,10 +94,14 @@ private: class DummyJob : public ThreadWeaver::Job { public: - DummyJob(QObject *parent) : Job(parent) {} + DummyJob(QObject *parent) : Job(), m_decorator(new ThreadWeaver::QObjectDecorator(this, parent)) {} ~DummyJob() {} + + ThreadWeaver::QObjectDecorator* decorator() const { return m_decorator; } + private: - void run() {} + virtual void run(ThreadWeaver::JobPointer, ThreadWeaver::Thread*) {} + ThreadWeaver::QObjectDecorator* m_decorator; }; /* @@ -114,14 +120,16 @@ public: QTimer* delayTimer() const; void setDelayTimer(QTimer *timer); + ThreadWeaver::QObjectDecorator* decorator() const { return m_decorator; } protected: - void run(); + virtual void run(ThreadWeaver::JobPointer self, ThreadWeaver::Thread* thread); private: Plasma::RunnerContext m_context; Plasma::AbstractRunner *m_runner; QTimer *m_timer; + ThreadWeaver::QObjectDecorator* m_decorator; }; class DelayedJobCleaner : public QObject diff --git a/src/plasma/private/storage.cpp b/src/plasma/private/storage.cpp index 35b222e8b..c9d71004d 100644 --- a/src/plasma/private/storage.cpp +++ b/src/plasma/private/storage.cpp @@ -33,11 +33,10 @@ //KDE #include - //Plasma #include "applet.h" #include "dataengine.h" -//#include "abstractrunner.h" +#include "abstractrunner.h" #include "storagethread_p.h" @@ -138,13 +137,12 @@ Storage::Storage(QObject* parent) m_clientName = engine->pluginInfo().pluginName(); break; } -#if 0 + Plasma::AbstractRunner *runner = qobject_cast(parentObject); if (runner) { m_clientName = runner->id(); break; } -#endif 0 } m_clientName = m_clientName.replace('.', "_"); diff --git a/src/plasma/runnermanager.cpp b/src/plasma/runnermanager.cpp index 135279e73..ee4851f29 100644 --- a/src/plasma/runnermanager.cpp +++ b/src/plasma/runnermanager.cpp @@ -236,7 +236,7 @@ public: while (it != searchJobs.end()) { auto &job = (*it); if (deadRunners.contains(job->runner())) { - QObject::disconnect(job.data(), SIGNAL(done(ThreadWeaver::JobPointer)), q, SLOT(jobDone(ThreadWeaver::JobPointer))); + QObject::disconnect(job->decorator(), SIGNAL(done(ThreadWeaver::JobPointer)), q, SLOT(jobDone(ThreadWeaver::JobPointer))); it = searchJobs.erase(it); deadJobs.insert(job); } else { @@ -334,7 +334,6 @@ public: searchJobs.remove(runJob); oldSearchJobs.remove(runJob); - runJob->deleteLater(); if (searchJobs.isEmpty() && context.matches().isEmpty()) { // we finished our run, and there are no valid matches, and so no @@ -394,7 +393,6 @@ public: DummyJob *dummy = new DummyJob(q); Weaver::instance()->enqueueRaw(dummy); - QObject::connect(dummy, SIGNAL(done(ThreadWeaver::Job*)), dummy, SLOT(deleteLater())); } void runnerMatchingSuspended(bool suspended) @@ -414,7 +412,7 @@ public: { if ((runner->ignoredTypes() & context.type()) == 0) { QSharedPointer job(new FindMatchesJob(runner, &context, Weaver::instance())); - QObject::connect(job.data(), SIGNAL(done(ThreadWeaver::JobPointer)), q, SLOT(jobDone(ThreadWeaver::JobPointer))); + QObject::connect(job->decorator(), SIGNAL(done(ThreadWeaver::JobPointer)), q, SLOT(jobDone(ThreadWeaver::JobPointer))); if (runner->speed() == AbstractRunner::SlowSpeed) { job->setDelayTimer(&delayTimer); } diff --git a/src/plasma/scripting/runnerscript.cpp b/src/plasma/scripting/runnerscript.cpp index d5142a27a..366d3efbd 100644 --- a/src/plasma/scripting/runnerscript.cpp +++ b/src/plasma/scripting/runnerscript.cpp @@ -192,6 +192,3 @@ QString RunnerScript::mainScript() const } } // Plasma namespace - - -#include "moc_runnerscript.cpp"