From 979d2955653717fb6178d04e1f23c711b7dd6e24 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 20 Oct 2009 18:23:32 +0000 Subject: [PATCH] * queue the job in the service if the service isn't ready * check the validity of a job before executing; things may have changed! svn path=/trunk/KDE/kdelibs/; revision=1038158 --- private/remoteservicejob.cpp | 37 +++++++++++++++++++++++++++++++----- private/remoteservicejob_p.h | 2 ++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/private/remoteservicejob.cpp b/private/remoteservicejob.cpp index d9ef60b61..eccd0a5f1 100644 --- a/private/remoteservicejob.cpp +++ b/private/remoteservicejob.cpp @@ -54,15 +54,22 @@ void RemoteServiceJob::start() { QTimer::singleShot(30000, this, SLOT(timeout())); - Jolie::Client *client = m_service->m_client; - - if (m_service->m_busy) { + if (m_service->m_busy || !m_service->m_ready) { //enqueue and wait m_service->m_queue.enqueue(this); kDebug() << "already busy... enqueue, queue contains " << m_service->m_queue.count(); return; - } else { - m_service->m_busy = true; + } + + // the service is now busy ... with us! + m_service->m_busy = true; + + // while waiting in the queue, our validity may have changed; it's all async + // so don't assume anything + checkValidity(); + if (error()) { + emitResult(); + return; } //serialize the parameters @@ -80,12 +87,32 @@ void RemoteServiceJob::start() data.children(Message::Field::DESTINATION) << Jolie::Value(destination().toAscii()); message.setData(data); + Jolie::Client *client = m_service->m_client; Jolie::PendingCall pendingReply = client->asyncCall(m_service->signMessage(message)); Jolie::PendingCallWatcher *watcher = new Jolie::PendingCallWatcher(pendingReply, this); connect(watcher, SIGNAL(finished(Jolie::PendingCallWatcher*)), this, SLOT(callCompleted(Jolie::PendingCallWatcher*))); } +void RemoteServiceJob::checkValidity() +{ + if (!m_service->isOperationEnabled(operationName())) { + setError(-1); + setErrorText(i18n("Job no longer valid, operation is not enabled!")); + } else { + KConfigGroup description = m_service->operationDescription(operationName()); + QMapIterator param(parameters()); + while (param.hasNext()) { + param.next(); + if (!description.hasKey(param.key())) { + setError(-1); + setErrorText(i18n("Job no longer valid, invalid parameters.")); + break; + } + } + } +} + void RemoteServiceJob::callCompleted(Jolie::PendingCallWatcher *watcher) { m_service->m_busy = false; diff --git a/private/remoteservicejob_p.h b/private/remoteservicejob_p.h index e94d559f1..8535a6c5f 100644 --- a/private/remoteservicejob_p.h +++ b/private/remoteservicejob_p.h @@ -53,6 +53,8 @@ class RemoteServiceJob : public Plasma::ServiceJob void timeout(); private: + void checkValidity(); + QByteArray m_token; KUrl m_location; RemoteService *m_service;