scheduler.h
// -*- c++ -*-
/* This file is part of the KDE libraries
Copyright (C) 2000 Stephan Kulow <coolo@kde.org>
Waldo Bastian <bastian@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _kio_scheduler_h
#define _kio_scheduler_h
#include "kio/job.h"
#include "kio/jobclasses.h"
#include <qtimer.h>
#include <qptrdict.h>
#include <qmap.h>
#include <dcopobject.h>
namespace KIO {
class Slave;
class SlaveList;
class SlaveConfig;
class SessionData;
class KIO_EXPORT Scheduler : public QObject, virtual public DCOPObject {
Q_OBJECT
public:
typedef QPtrList<SimpleJob> JobList;
// InfoDict needs Info, so we can't declare it private
class ProtocolInfo;
class JobData;
~Scheduler();
static void doJob(SimpleJob *job)
{ self()->_doJob(job); }
static void scheduleJob(SimpleJob *job)
{ self()->_scheduleJob(job); }
static void cancelJob(SimpleJob *job)
{ self()->_cancelJob(job); }
static void jobFinished(KIO::SimpleJob *job, KIO::Slave *slave)
{ self()->_jobFinished(job, slave); }
static void putSlaveOnHold(KIO::SimpleJob *job, const KURL &url)
{ self()->_putSlaveOnHold(job, url); }
static void removeSlaveOnHold()
{ self()->_removeSlaveOnHold(); }
static void publishSlaveOnHold()
{ self()->_publishSlaveOnHold(); }
static KIO::Slave *getConnectedSlave(const KURL &url, const KIO::MetaData &config = MetaData() )
{ return self()->_getConnectedSlave(url, config); }
/*
* Uses @p slave to do @p job.
* This function should be called immediately after creating a Job.
*
* @param slave The slave to use. The slave must have been obtained
* with a call to getConnectedSlave and must not
* be currently assigned to any other job.
* @param job The job to do.
*
* @return true is successful, false otherwise.
*
* @see getConnectedSlave()
* @see disconnectSlave()
* @see slaveConnected()
* @see slaveError()
*/
static bool assignJobToSlave(KIO::Slave *slave, KIO::SimpleJob *job)
{ return self()->_assignJobToSlave(slave, job); }
/*
* Disconnects @p slave.
*
* @param slave The slave to disconnect. The slave must have been
* obtained with a call to getConnectedSlave
* and must not be assigned to any job.
*
* @return true is successful, false otherwise.
*
* @see getConnectedSlave
* @see assignJobToSlave
*/
static bool disconnectSlave(KIO::Slave *slave)
{ return self()->_disconnectSlave(slave); }
static void registerWindow(QWidget *wid)
{ self()->_registerWindow(wid); }
static void unregisterWindow(QObject *wid)
{ self()->slotUnregisterWindow(wid); }
static bool connect( const char *signal, const QObject *receiver,
const char *member)
{ return QObject::connect(self(), signal, receiver, member); }
static bool connect( const QObject* sender, const char* signal,
const QObject* receiver, const char* member )
{ return QObject::connect(sender, signal, receiver, member); }
static bool disconnect( const QObject* sender, const char* signal,
const QObject* receiver, const char* member )
{ return QObject::disconnect(sender, signal, receiver, member); }
bool connect( const QObject *sender, const char *signal,
const char *member )
{ return QObject::connect(sender, signal, member); }
static void checkSlaveOnHold(bool b) { self()->_checkSlaveOnHold(b); }
void debug_info();
virtual bool process(const QCString &fun, const QByteArray &data,
QCString& replyType, QByteArray &replyData);
virtual QCStringList functions();
public slots:
void slotSlaveDied(KIO::Slave *slave);
void slotSlaveStatus(pid_t pid, const QCString &protocol,
const QString &host, bool connected);
signals:
void slaveConnected(KIO::Slave *slave);
void slaveError(KIO::Slave *slave, int error, const QString &errorMsg);
protected:
void setupSlave(KIO::Slave *slave, const KURL &url, const QString &protocol, const QString &proxy , bool newSlave, const KIO::MetaData *config=0);
bool startJobScheduled(ProtocolInfo *protInfo);
bool startJobDirect();
Scheduler();
protected slots:
void startStep();
void slotCleanIdleSlaves();
void slotSlaveConnected();
void slotSlaveError(int error, const QString &errorMsg);
void slotScheduleCoSlave();
void slotUnregisterWindow(QObject *);
private:
class ProtocolInfoDict;
class ExtraJobData;
Scheduler(const Scheduler&);
static Scheduler *self();
static Scheduler *instance;
void _doJob(SimpleJob *job);
void _scheduleJob(SimpleJob *job);
void _cancelJob(SimpleJob *job);
void _jobFinished(KIO::SimpleJob *job, KIO::Slave *slave);
void _scheduleCleanup();
void _putSlaveOnHold(KIO::SimpleJob *job, const KURL &url);
void _removeSlaveOnHold();
Slave *_getConnectedSlave(const KURL &url, const KIO::MetaData &metaData );
bool _assignJobToSlave(KIO::Slave *slave, KIO::SimpleJob *job);
bool _disconnectSlave(KIO::Slave *slave);
void _checkSlaveOnHold(bool b);
void _publishSlaveOnHold();
void _registerWindow(QWidget *wid);
Slave *findIdleSlave(ProtocolInfo *protInfo, SimpleJob *job, bool &exact);
Slave *createSlave(ProtocolInfo *protInfo, SimpleJob *job, const KURL &url);
QTimer slaveTimer;
QTimer coSlaveTimer;
QTimer cleanupTimer;
bool busy;
SlaveList *slaveList;
SlaveList *idleSlaves;
SlaveList *coIdleSlaves;
ProtocolInfoDict *protInfoDict;
Slave *slaveOnHold;
KURL urlOnHold;
JobList newJobs;
QPtrDict<JobList> coSlaves;
ExtraJobData *extraJobData;
SlaveConfig *slaveConfig;
SessionData *sessionData;
bool checkOnHold;
QMap<QObject *,WId> m_windowList;
protected:
virtual void virtual_hook( int id, void* data );
private:
class SchedulerPrivate* d;
};
}
#endif
KIO::Scheduler::registerWindow
static void registerWindow(QWidget *wid)
Send the slave that was put on hold back to KLauncher.
Definition: scheduler.h:243
KIO::Scheduler::checkSlaveOnHold
static void checkSlaveOnHold(bool b)
When true, the next job will check whether KLauncher has a slave on hold that is suitable for the job...
Definition: scheduler.h:280
KIO::Scheduler::scheduleJob
static void scheduleJob(SimpleJob *job)
Calling ths function makes that job gets scheduled for later execution, if multiple jobs are register...
Definition: scheduler.h:138
KIO::MetaData
MetaData is a simple map of key/value strings.
Definition: global.h:512
KIO::Slave
Attention developers: If you change the implementation of KIO::Slave, do not use connection() or slav...
Definition: slave.h:44
KIO::Scheduler::doJob
static void doJob(SimpleJob *job)
Register job with the scheduler.
Definition: scheduler.h:129
KIO::Scheduler::getConnectedSlave
static KIO::Slave * getConnectedSlave(const KURL &url, const KIO::MetaData &config=MetaData())
Requests a slave for use in connection-oriented mode.
Definition: scheduler.h:196
KIO::Scheduler::removeSlaveOnHold
static void removeSlaveOnHold()
Removes any slave that might have been put on hold.
Definition: scheduler.h:174
KIO::Scheduler
The KIO::Scheduler manages io-slaves for the application.
Definition: scheduler.h:111
KIO::Scheduler::cancelJob
static void cancelJob(SimpleJob *job)
Stop the execution of a job.
Definition: scheduler.h:145
KIO::SlaveConfig
SlaveConfig.
Definition: slaveconfig.h:47
KIO::Scheduler::publishSlaveOnHold
static void publishSlaveOnHold()
Send the slave that was put on hold back to KLauncher.
Definition: scheduler.h:182
KIO::Scheduler::putSlaveOnHold
static void putSlaveOnHold(KIO::SimpleJob *job, const KURL &url)
Puts a slave on notice.
Definition: scheduler.h:167
KIO::Scheduler::connect
static bool connect(const char *signal, const QObject *receiver, const char *member)
Function to connect signals emitted by the scheduler.
Definition: scheduler.h:259
KIO::Scheduler::jobFinished
static void jobFinished(KIO::SimpleJob *job, KIO::Slave *slave)
Called when a job is done.
Definition: scheduler.h:153
KIO::SimpleJob
A simple job (one url and one command).
Definition: jobclasses.h:528

KDE Home | KDE Accessibility Home | Description of Access Keys