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
This commit is contained in:
Aleix Pol 2013-10-10 20:27:41 +02:00
parent 588a05ab7c
commit a3c7a9690f
6 changed files with 51 additions and 50 deletions

View File

@ -73,12 +73,12 @@ set(plasma_LIB_SRCS
private/componentinstaller.cpp private/componentinstaller.cpp
#runners #runners
# abstractrunner.cpp abstractrunner.cpp
# querymatch.cpp querymatch.cpp
# runnercontext.cpp runnercontext.cpp
# runnermanager.cpp runnermanager.cpp
# runnersyntax.cpp runnersyntax.cpp
# private/runnerjobs.cpp private/runnerjobs.cpp
#applets,containments,corona #applets,containments,corona
applet.cpp applet.cpp
@ -117,7 +117,7 @@ set(plasma_LIB_SRCS
#scripting #scripting
scripting/appletscript.cpp scripting/appletscript.cpp
scripting/dataenginescript.cpp scripting/dataenginescript.cpp
# scripting/runnerscript.cpp scripting/runnerscript.cpp
scripting/scriptengine.cpp scripting/scriptengine.cpp
) )
@ -181,7 +181,7 @@ set_target_properties(plasma PROPERTIES
generate_export_header(plasma) generate_export_header(plasma)
set(plasma_LIB_INCLUDES set(plasma_LIB_INCLUDES
#abstractrunner.h abstractrunner.h
applet.h applet.h
configloader.h configloader.h
containment.h containment.h
@ -196,10 +196,10 @@ set(plasma_LIB_INCLUDES
packagestructure.h packagestructure.h
plasma.h plasma.h
${CMAKE_CURRENT_BINARY_DIR}/plasma_export.h ${CMAKE_CURRENT_BINARY_DIR}/plasma_export.h
#querymatch.h querymatch.h
#runnercontext.h runnercontext.h
#runnermanager.h runnermanager.h
#runnersyntax.h runnersyntax.h
service.h service.h
servicejob.h servicejob.h
svg.h svg.h

View File

@ -47,9 +47,9 @@ DelayedRunnerPolicy& DelayedRunnerPolicy::instance()
return policy; return policy;
} }
bool DelayedRunnerPolicy::canRun(Job *job) bool DelayedRunnerPolicy::canRun(ThreadWeaver::JobPointer job)
{ {
FindMatchesJob *aJob = static_cast<FindMatchesJob*>(job); QSharedPointer<FindMatchesJob> aJob(job.dynamicCast<FindMatchesJob>());
if (QTimer *t = aJob->delayTimer()) { if (QTimer *t = aJob->delayTimer()) {
// If the timer is active, the required delay has not been reached // If the timer is active, the required delay has not been reached
//qDebug() << "delayed timer" << aJob->runner()->name() << !t->isActive(); //qDebug() << "delayed timer" << aJob->runner()->name() << !t->isActive();
@ -59,17 +59,17 @@ bool DelayedRunnerPolicy::canRun(Job *job)
return true; return true;
} }
void DelayedRunnerPolicy::free(Job *job) void DelayedRunnerPolicy::free(ThreadWeaver::JobPointer job)
{ {
Q_UNUSED(job) Q_UNUSED(job)
} }
void DelayedRunnerPolicy::release(Job *job) void DelayedRunnerPolicy::release(ThreadWeaver::JobPointer job)
{ {
free(job); free(job);
} }
void DelayedRunnerPolicy::destructed(Job *job) void DelayedRunnerPolicy::destructed(ThreadWeaver::JobInterface* job)
{ {
Q_UNUSED(job) Q_UNUSED(job)
} }
@ -88,9 +88,9 @@ DefaultRunnerPolicy& DefaultRunnerPolicy::instance()
return policy; return policy;
} }
bool DefaultRunnerPolicy::canRun(Job *job) bool DefaultRunnerPolicy::canRun(ThreadWeaver::JobPointer job)
{ {
Plasma::AbstractRunner *runner = static_cast<FindMatchesJob*>(job)->runner(); Plasma::AbstractRunner *runner = job.dynamicCast<FindMatchesJob>()->runner();
QMutexLocker l(&m_mutex); QMutexLocker l(&m_mutex);
if (m_runCounts[runner->name()] > m_cap) { 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<FindMatchesJob*>(job)->runner(); Plasma::AbstractRunner *runner = job.dynamicCast<FindMatchesJob>()->runner();
QMutexLocker l(&m_mutex); QMutexLocker l(&m_mutex);
--m_runCounts[runner->name()]; --m_runCounts[runner->name()];
} }
void DefaultRunnerPolicy::release(Job *job) void DefaultRunnerPolicy::release(ThreadWeaver::JobPointer job)
{ {
free(job); free(job);
} }
void DefaultRunnerPolicy::destructed(Job *job) void DefaultRunnerPolicy::destructed(ThreadWeaver::JobInterface* job)
{ {
Q_UNUSED(job) Q_UNUSED(job)
} }
@ -125,10 +125,11 @@ void DefaultRunnerPolicy::destructed(Job *job)
FindMatchesJob::FindMatchesJob(Plasma::AbstractRunner *runner, FindMatchesJob::FindMatchesJob(Plasma::AbstractRunner *runner,
Plasma::RunnerContext *context, QObject *parent) Plasma::RunnerContext *context, QObject *parent)
: ThreadWeaver::Job(parent), : ThreadWeaver::Job(),
m_context(*context, 0), m_context(*context, 0),
m_runner(runner), m_runner(runner),
m_timer(0) m_timer(0),
m_decorator(new ThreadWeaver::QObjectDecorator(this, true))
{ {
if (runner->speed() == Plasma::AbstractRunner::SlowSpeed) { if (runner->speed() == Plasma::AbstractRunner::SlowSpeed) {
assignQueuePolicy(&DelayedRunnerPolicy::instance()); assignQueuePolicy(&DelayedRunnerPolicy::instance());
@ -151,7 +152,7 @@ void FindMatchesJob::setDelayTimer(QTimer *timer)
m_timer = timer; m_timer = timer;
} }
void FindMatchesJob::run() void FindMatchesJob::run(ThreadWeaver::JobPointer, ThreadWeaver::Thread*)
{ {
// qDebug() << "Running match for " << m_runner->objectName() // qDebug() << "Running match for " << m_runner->objectName()
// << " in Thread " << thread()->id() << endl; // << " in Thread " << thread()->id() << endl;
@ -179,7 +180,7 @@ DelayedJobCleaner::DelayedJobCleaner(const QSet<QSharedPointer<FindMatchesJob> >
connect(m_weaver, SIGNAL(finished()), this, SLOT(checkIfFinished())); connect(m_weaver, SIGNAL(finished()), this, SLOT(checkIfFinished()));
for (auto it = m_jobs.constBegin(); it != m_jobs.constEnd(); ++it) { 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); m_jobs.remove(runJob);
runJob->deleteLater();
if (m_jobs.isEmpty()) { if (m_jobs.isEmpty()) {
deleteLater(); deleteLater();

View File

@ -27,6 +27,7 @@
#include <threadweaver/Job.h> #include <threadweaver/Job.h>
#include <threadweaver/QueuePolicy.h> #include <threadweaver/QueuePolicy.h>
#include <threadweaver/ThreadWeaver.h> #include <threadweaver/ThreadWeaver.h>
#include <QObjectDecorator.h>
#include "abstractrunner.h" #include "abstractrunner.h"
@ -46,10 +47,11 @@ public:
static DelayedRunnerPolicy &instance(); static DelayedRunnerPolicy &instance();
bool canRun(Job *job); bool canRun(ThreadWeaver::JobPointer job);
void free(Job *job); void free(ThreadWeaver::JobPointer job);
void release(Job *job); void release(ThreadWeaver::JobPointer job);
void destructed(Job *job); virtual void destructed(ThreadWeaver::JobInterface* job);
private: private:
DelayedRunnerPolicy(); DelayedRunnerPolicy();
QMutex m_mutex; QMutex m_mutex;
@ -72,10 +74,10 @@ public:
return m_cap; return m_cap;
} }
bool canRun(Job *job); bool canRun(ThreadWeaver::JobPointer job);
void free(Job *job); void free(ThreadWeaver::JobPointer job);
void release(Job *job); void release(ThreadWeaver::JobPointer job);
void destructed(Job *job); void destructed(ThreadWeaver::JobInterface* job);
private: private:
DefaultRunnerPolicy(); DefaultRunnerPolicy();
@ -92,10 +94,14 @@ private:
class DummyJob : public ThreadWeaver::Job class DummyJob : public ThreadWeaver::Job
{ {
public: public:
DummyJob(QObject *parent) : Job(parent) {} DummyJob(QObject *parent) : Job(), m_decorator(new ThreadWeaver::QObjectDecorator(this, parent)) {}
~DummyJob() {} ~DummyJob() {}
ThreadWeaver::QObjectDecorator* decorator() const { return m_decorator; }
private: private:
void run() {} virtual void run(ThreadWeaver::JobPointer, ThreadWeaver::Thread*) {}
ThreadWeaver::QObjectDecorator* m_decorator;
}; };
/* /*
@ -114,14 +120,16 @@ public:
QTimer* delayTimer() const; QTimer* delayTimer() const;
void setDelayTimer(QTimer *timer); void setDelayTimer(QTimer *timer);
ThreadWeaver::QObjectDecorator* decorator() const { return m_decorator; }
protected: protected:
void run(); virtual void run(ThreadWeaver::JobPointer self, ThreadWeaver::Thread* thread);
private: private:
Plasma::RunnerContext m_context; Plasma::RunnerContext m_context;
Plasma::AbstractRunner *m_runner; Plasma::AbstractRunner *m_runner;
QTimer *m_timer; QTimer *m_timer;
ThreadWeaver::QObjectDecorator* m_decorator;
}; };
class DelayedJobCleaner : public QObject class DelayedJobCleaner : public QObject

View File

@ -33,11 +33,10 @@
//KDE //KDE
#include <QDebug> #include <QDebug>
//Plasma //Plasma
#include "applet.h" #include "applet.h"
#include "dataengine.h" #include "dataengine.h"
//#include "abstractrunner.h" #include "abstractrunner.h"
#include "storagethread_p.h" #include "storagethread_p.h"
@ -138,13 +137,12 @@ Storage::Storage(QObject* parent)
m_clientName = engine->pluginInfo().pluginName(); m_clientName = engine->pluginInfo().pluginName();
break; break;
} }
#if 0
Plasma::AbstractRunner *runner = qobject_cast<Plasma::AbstractRunner *>(parentObject); Plasma::AbstractRunner *runner = qobject_cast<Plasma::AbstractRunner *>(parentObject);
if (runner) { if (runner) {
m_clientName = runner->id(); m_clientName = runner->id();
break; break;
} }
#endif 0
} }
m_clientName = m_clientName.replace('.', "_"); m_clientName = m_clientName.replace('.', "_");

View File

@ -236,7 +236,7 @@ public:
while (it != searchJobs.end()) { while (it != searchJobs.end()) {
auto &job = (*it); auto &job = (*it);
if (deadRunners.contains(job->runner())) { 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); it = searchJobs.erase(it);
deadJobs.insert(job); deadJobs.insert(job);
} else { } else {
@ -334,7 +334,6 @@ public:
searchJobs.remove(runJob); searchJobs.remove(runJob);
oldSearchJobs.remove(runJob); oldSearchJobs.remove(runJob);
runJob->deleteLater();
if (searchJobs.isEmpty() && context.matches().isEmpty()) { if (searchJobs.isEmpty() && context.matches().isEmpty()) {
// we finished our run, and there are no valid matches, and so no // we finished our run, and there are no valid matches, and so no
@ -394,7 +393,6 @@ public:
DummyJob *dummy = new DummyJob(q); DummyJob *dummy = new DummyJob(q);
Weaver::instance()->enqueueRaw(dummy); Weaver::instance()->enqueueRaw(dummy);
QObject::connect(dummy, SIGNAL(done(ThreadWeaver::Job*)), dummy, SLOT(deleteLater()));
} }
void runnerMatchingSuspended(bool suspended) void runnerMatchingSuspended(bool suspended)
@ -414,7 +412,7 @@ public:
{ {
if ((runner->ignoredTypes() & context.type()) == 0) { if ((runner->ignoredTypes() & context.type()) == 0) {
QSharedPointer<FindMatchesJob> job(new FindMatchesJob(runner, &context, Weaver::instance())); QSharedPointer<FindMatchesJob> 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) { if (runner->speed() == AbstractRunner::SlowSpeed) {
job->setDelayTimer(&delayTimer); job->setDelayTimer(&delayTimer);
} }

View File

@ -192,6 +192,3 @@ QString RunnerScript::mainScript() const
} }
} // Plasma namespace } // Plasma namespace
#include "moc_runnerscript.cpp"