• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KIO

scheduler_p.h

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2009, 2010 Andreas Hartmetz <ahartmetz@gmail.com>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #ifndef SCHEDULER_P_H
00020 #define SCHEDULER_P_H
00021 #include <QSet>
00022 
00023 // #define SCHEDULER_DEBUG
00024 
00025 namespace KIO {
00026 
00027 class SlaveKeeper : public QObject
00028 {
00029     Q_OBJECT
00030 public:
00031     SlaveKeeper();
00032     void returnSlave(KIO::Slave *slave);
00033     // pick suitable slave for job and return it, return null if no slave found.
00034     // the slave is removed from the keeper.
00035     KIO::Slave *takeSlaveForJob(KIO::SimpleJob *job);
00036     // remove slave from keeper
00037     bool removeSlave(KIO::Slave *slave);
00038     QList<KIO::Slave *> allSlaves() const;
00039 
00040 private:
00041     void scheduleGrimReaper();
00042 
00043 private slots:
00044     void grimReaper();
00045 
00046 private:
00047     QMultiHash<QString, KIO::Slave *> m_idleSlaves;
00048     QTimer m_grimTimer;
00049 };
00050 
00051 
00052 class HostQueue
00053 {
00054 public:
00055     int lowestSerial() const;
00056 
00057     bool isQueueEmpty() const { return m_queuedJobs.isEmpty(); }
00058     bool isEmpty() const { return m_queuedJobs.isEmpty() && m_runningJobs.isEmpty(); }
00059     int runningJobsCount() const { return m_runningJobs.count(); }
00060 #ifdef SCHEDULER_DEBUG
00061     QList<KIO::SimpleJob *> runningJobs() const { return m_runningJobs.toList(); }
00062 #endif
00063     bool isJobRunning(KIO::SimpleJob *job) const { return m_runningJobs.contains(job); }
00064 
00065     void queueJob(KIO::SimpleJob *job);
00066     KIO::SimpleJob *nextStartingJob();
00067     bool removeJob(KIO::SimpleJob *job);
00068 
00069     QList<KIO::Slave *> allSlaves() const;
00070 private:
00071     QMap<int, KIO::SimpleJob *> m_queuedJobs;
00072     QSet<KIO::SimpleJob *> m_runningJobs;
00073 };
00074 
00075 struct PerSlaveQueue
00076 {
00077     PerSlaveQueue() : runningJob(0) {}
00078     QList <SimpleJob *> waitingList;
00079     SimpleJob *runningJob;
00080 };
00081 
00082 class ConnectedSlaveQueue : public QObject
00083 {
00084     Q_OBJECT
00085 public:
00086     ConnectedSlaveQueue();
00087 
00088     bool queueJob(KIO::SimpleJob *job, KIO::Slave *slave);
00089     bool removeJob(KIO::SimpleJob *job);
00090 
00091     void addSlave(KIO::Slave *slave);
00092     bool removeSlave(KIO::Slave *slave);
00093 
00094     // KDE5: only one caller, for doubtful reasons. remove this if possible.
00095     bool isIdle(KIO::Slave *slave);
00096     bool isEmpty() const { return m_connectedSlaves.isEmpty(); }
00097     QList<KIO::Slave *> allSlaves() const { return m_connectedSlaves.keys(); }
00098 
00099 private slots:
00100     void startRunnableJobs();
00101 private:
00102     // note that connected slaves stay here when idle, they are not returned to SlaveKeeper
00103     QHash<KIO::Slave *, PerSlaveQueue> m_connectedSlaves;
00104     QSet<KIO::Slave *> m_runnableSlaves;
00105     QTimer m_startJobsTimer;
00106 };
00107 
00108 
00109 class SchedulerPrivate;
00110 
00111 class SerialPicker
00112 {
00113 public:
00114     // note that serial number zero is the default value from job_p.h and invalid!
00115     SerialPicker()
00116      : m_offset(1) {}
00117 
00118     int next()
00119     {
00120         if (m_offset >= m_jobsPerPriority) {
00121             m_offset = 1;
00122         }
00123         return m_offset++;
00124     }
00125 
00126     int changedPrioritySerial(int oldSerial, int newPriority) const;
00127 
00128 private:
00129     static const uint m_jobsPerPriority = 100000000;
00130     uint m_offset;
00131 public:
00132     static const int maxSerial = m_jobsPerPriority * 20;
00133 };
00134 
00135 
00136 class ProtoQueue : public QObject
00137 {
00138     Q_OBJECT
00139 public:
00140     ProtoQueue(KIO::SchedulerPrivate *sp, int maxSlaves, int maxSlavesPerHost);
00141     ~ProtoQueue();
00142 
00143     void queueJob(KIO::SimpleJob *job);
00144     void changeJobPriority(KIO::SimpleJob *job, int newPriority);
00145     void removeJob(KIO::SimpleJob *job);
00146     KIO::Slave *createSlave(const QString &protocol, KIO::SimpleJob *job, const KUrl &url);
00147     bool removeSlave (KIO::Slave *slave);
00148     QList<KIO::Slave *> allSlaves() const;
00149     ConnectedSlaveQueue m_connectedSlaveQueue;
00150 
00151 private slots:
00152     // start max one (non-connected) job and return
00153     void startAJob();
00154 
00155 private:
00156     SerialPicker m_serialPicker;
00157     QTimer m_startJobTimer;
00158     QMap<int, HostQueue *> m_queuesBySerial;
00159     QHash<QString, HostQueue> m_queuesByHostname;
00160     KIO::SchedulerPrivate *m_schedPrivate;
00161     SlaveKeeper m_slaveKeeper;
00162     int m_maxConnectionsPerHost;
00163     int m_maxConnectionsTotal;
00164     int m_runningJobsCount;
00165 };
00166 
00167 } // namespace KIO
00168 
00169 #endif //SCHEDULER_P_H

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal