* 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
This commit is contained in:
parent
8df22fd9b1
commit
979d295565
@ -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<QString, QVariant> 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;
|
||||
|
@ -53,6 +53,8 @@ class RemoteServiceJob : public Plasma::ServiceJob
|
||||
void timeout();
|
||||
|
||||
private:
|
||||
void checkValidity();
|
||||
|
||||
QByteArray m_token;
|
||||
KUrl m_location;
|
||||
RemoteService *m_service;
|
||||
|
Loading…
x
Reference in New Issue
Block a user