00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _kio_scheduler_h
00023 #define _kio_scheduler_h
00024
00025 #include "kio/job.h"
00026 #include "kio/jobclasses.h"
00027 #include <qtimer.h>
00028 #include <qptrdict.h>
00029 #include <qmap.h>
00030
00031 #include <dcopobject.h>
00032
00033 namespace KIO {
00034
00035 class Slave;
00036 class SlaveList;
00037 class SlaveConfig;
00038 class SessionData;
00039
00111 class KIO_EXPORT Scheduler : public QObject, virtual public DCOPObject {
00112 Q_OBJECT
00113
00114 public:
00115 typedef QPtrList<SimpleJob> JobList;
00116
00117
00118 class ProtocolInfo;
00119 class JobData;
00120
00121 ~Scheduler();
00122
00129 static void doJob(SimpleJob *job)
00130 { self()->_doJob(job); }
00131
00138 static void scheduleJob(SimpleJob *job)
00139 { self()->_scheduleJob(job); }
00140
00145 static void cancelJob(SimpleJob *job)
00146 { self()->_cancelJob(job); }
00147
00153 static void jobFinished(KIO::SimpleJob *job, KIO::Slave *slave)
00154 { self()->_jobFinished(job, slave); }
00155
00167 static void putSlaveOnHold(KIO::SimpleJob *job, const KURL &url)
00168 { self()->_putSlaveOnHold(job, url); }
00169
00174 static void removeSlaveOnHold()
00175 { self()->_removeSlaveOnHold(); }
00176
00182 static void publishSlaveOnHold()
00183 { self()->_publishSlaveOnHold(); }
00184
00196 static KIO::Slave *getConnectedSlave(const KURL &url, const KIO::MetaData &config = MetaData() )
00197 { return self()->_getConnectedSlave(url, config); }
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 static bool assignJobToSlave(KIO::Slave *slave, KIO::SimpleJob *job)
00216 { return self()->_assignJobToSlave(slave, job); }
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 static bool disconnectSlave(KIO::Slave *slave)
00231 { return self()->_disconnectSlave(slave); }
00232
00243 static void registerWindow(QWidget *wid)
00244 { self()->_registerWindow(wid); }
00245
00250 static void unregisterWindow(QObject *wid)
00251 { self()->slotUnregisterWindow(wid); }
00252
00259 static bool connect( const char *signal, const QObject *receiver,
00260 const char *member)
00261 { return QObject::connect(self(), signal, receiver, member); }
00262
00263 static bool connect( const QObject* sender, const char* signal,
00264 const QObject* receiver, const char* member )
00265 { return QObject::connect(sender, signal, receiver, member); }
00266
00267 static bool disconnect( const QObject* sender, const char* signal,
00268 const QObject* receiver, const char* member )
00269 { return QObject::disconnect(sender, signal, receiver, member); }
00270
00271 bool connect( const QObject *sender, const char *signal,
00272 const char *member )
00273 { return QObject::connect(sender, signal, member); }
00274
00280 static void checkSlaveOnHold(bool b) { self()->_checkSlaveOnHold(b); }
00281
00282 void debug_info();
00283
00284 virtual bool process(const QCString &fun, const QByteArray &data,
00285 QCString& replyType, QByteArray &replyData);
00286
00287 virtual QCStringList functions();
00288
00289 public slots:
00290 void slotSlaveDied(KIO::Slave *slave);
00291 void slotSlaveStatus(pid_t pid, const QCString &protocol,
00292 const QString &host, bool connected);
00293 signals:
00294 void slaveConnected(KIO::Slave *slave);
00295 void slaveError(KIO::Slave *slave, int error, const QString &errorMsg);
00296
00297 protected:
00298 void setupSlave(KIO::Slave *slave, const KURL &url, const QString &protocol, const QString &proxy , bool newSlave, const KIO::MetaData *config=0);
00299 bool startJobScheduled(ProtocolInfo *protInfo);
00300 bool startJobDirect();
00301 Scheduler();
00302
00303 protected slots:
00304 void startStep();
00305 void slotCleanIdleSlaves();
00306 void slotSlaveConnected();
00307 void slotSlaveError(int error, const QString &errorMsg);
00308 void slotScheduleCoSlave();
00310 void slotUnregisterWindow(QObject *);
00311
00312 private:
00313 class ProtocolInfoDict;
00314 class ExtraJobData;
00315
00316 Scheduler(const Scheduler&);
00317 static Scheduler *self();
00318 static Scheduler *instance;
00319 void _doJob(SimpleJob *job);
00320 void _scheduleJob(SimpleJob *job);
00321 void _cancelJob(SimpleJob *job);
00322 void _jobFinished(KIO::SimpleJob *job, KIO::Slave *slave);
00323 void _scheduleCleanup();
00324 void _putSlaveOnHold(KIO::SimpleJob *job, const KURL &url);
00325 void _removeSlaveOnHold();
00326 Slave *_getConnectedSlave(const KURL &url, const KIO::MetaData &metaData );
00327 bool _assignJobToSlave(KIO::Slave *slave, KIO::SimpleJob *job);
00328 bool _disconnectSlave(KIO::Slave *slave);
00329 void _checkSlaveOnHold(bool b);
00330 void _publishSlaveOnHold();
00331 void _registerWindow(QWidget *wid);
00332
00333 Slave *findIdleSlave(ProtocolInfo *protInfo, SimpleJob *job, bool &exact);
00334 Slave *createSlave(ProtocolInfo *protInfo, SimpleJob *job, const KURL &url);
00335
00336
00337 QTimer slaveTimer;
00338 QTimer coSlaveTimer;
00339 QTimer cleanupTimer;
00340 bool busy;
00341
00342 SlaveList *slaveList;
00343 SlaveList *idleSlaves;
00344 SlaveList *coIdleSlaves;
00345
00346 ProtocolInfoDict *protInfoDict;
00347 Slave *slaveOnHold;
00348 KURL urlOnHold;
00349 JobList newJobs;
00350
00351 QPtrDict<JobList> coSlaves;
00352 ExtraJobData *extraJobData;
00353 SlaveConfig *slaveConfig;
00354 SessionData *sessionData;
00355 bool checkOnHold;
00356 QMap<QObject *,WId> m_windowList;
00357 protected:
00358 virtual void virtual_hook( int id, void* data );
00359 private:
00360 class SchedulerPrivate* d;
00361 };
00362
00363 }
00364 #endif