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
#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

View File

@ -47,9 +47,9 @@ DelayedRunnerPolicy& DelayedRunnerPolicy::instance()
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 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<FindMatchesJob*>(job)->runner();
Plasma::AbstractRunner *runner = job.dynamicCast<FindMatchesJob>()->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<FindMatchesJob*>(job)->runner();
Plasma::AbstractRunner *runner = job.dynamicCast<FindMatchesJob>()->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<QSharedPointer<FindMatchesJob> >
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();

View File

@ -27,6 +27,7 @@
#include <threadweaver/Job.h>
#include <threadweaver/QueuePolicy.h>
#include <threadweaver/ThreadWeaver.h>
#include <QObjectDecorator.h>
#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

View File

@ -33,11 +33,10 @@
//KDE
#include <QDebug>
//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<Plasma::AbstractRunner *>(parentObject);
if (runner) {
m_clientName = runner->id();
break;
}
#endif 0
}
m_clientName = m_clientName.replace('.', "_");

View File

@ -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<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) {
job->setDelayTimer(&delayTimer);
}

View File

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