* always create a job (it'll just queue itself)

* provide getters for the busy/ready states
* check the queue when we become ready

svn path=/trunk/KDE/kdelibs/; revision=1038156
This commit is contained in:
Aaron J. Seigo 2009-10-20 18:22:38 +00:00
parent 118d75bf89
commit 8df22fd9b1
2 changed files with 25 additions and 15 deletions

View File

@ -125,6 +125,16 @@ QString RemoteService::location() const
return m_location.prettyUrl(); return m_location.prettyUrl();
} }
bool RemoteService::isReady() const
{
return m_ready;
}
bool RemoteService::isBusy() const
{
return m_busy;
}
void RemoteService::callCompleted(Jolie::PendingCallWatcher *watcher) void RemoteService::callCompleted(Jolie::PendingCallWatcher *watcher)
{ {
Jolie::PendingReply reply = *watcher; Jolie::PendingReply reply = *watcher;
@ -153,6 +163,8 @@ void RemoteService::callCompleted(Jolie::PendingCallWatcher *watcher)
m_token = Message::field(Message::Field::TOKEN, response); m_token = Message::field(Message::Field::TOKEN, response);
m_ready = true; m_ready = true;
setName(m_location.prettyUrl()); setName(m_location.prettyUrl());
//if there's stuff in the queue, let it continue.
slotFinished();
} }
} else if (response.operationName() == "getEnabledOperations") { } else if (response.operationName() == "getEnabledOperations") {
//TODO: optimize. //TODO: optimize.
@ -228,27 +240,22 @@ void RemoteService::slotUpdateEnabledOperations()
ServiceJob* RemoteService::createJob(const QString& operation, ServiceJob* RemoteService::createJob(const QString& operation,
QMap<QString,QVariant>& parameters) QMap<QString,QVariant>& parameters)
{ {
if (m_ready) { if (!m_ready) {
ServiceJob *job = new RemoteServiceJob(m_location, destination(), kDebug() << "Use of this service hasn't checked for the serviceReady signal, which it should.";
operation, parameters, m_token, this);
connect(job, SIGNAL(finished(KJob *)), this, SLOT(slotFinished()));
return job;
} else {
kWarning() << "We're not yet ready, so we're starting a NullServiceJob.";
kWarning() << "This means some plasmoid doesn't check for the serviceReady signal, which it should.";
return new NullServiceJob(destination(), operation, this);
} }
ServiceJob *job = new RemoteServiceJob(m_location, destination(), operation, parameters, m_token, this);
connect(job, SIGNAL(finished(KJob *)), this, SLOT(slotFinished()));
return job;
} }
void RemoteService::slotFinished() void RemoteService::slotFinished()
{ {
if (m_queue.isEmpty()) { if (!m_queue.isEmpty()) {
return; kDebug() << "Job finished, there are still service jobs in queue, starting next in queue.";
ServiceJob *job = m_queue.dequeue();
QTimer::singleShot(0, job, SLOT(slotStart()));
} }
kDebug() << "Job finished, there are still service jobs in queue, starting next in queue.";
ServiceJob *job = m_queue.dequeue();
QTimer::singleShot(0, job, SLOT(slotStart()));
} }
Jolie::Message RemoteService::signMessage(const Jolie::Message &message) const Jolie::Message RemoteService::signMessage(const Jolie::Message &message) const

View File

@ -48,6 +48,9 @@ class RemoteService : public Plasma::Service
void setLocation(const KUrl &location); void setLocation(const KUrl &location);
QString location() const; QString location() const;
bool isReady() const;
bool isBusy() const;
protected: protected:
ServiceJob* createJob(const QString& operation, ServiceJob* createJob(const QString& operation,
QMap<QString,QVariant>& parameters); QMap<QString,QVariant>& parameters);