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

KIO

  • sources
  • kde-4.14
  • kdelibs
  • kio
  • kio
scheduler_p.h
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2009, 2010 Andreas Hartmetz <ahartmetz@gmail.com>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #ifndef SCHEDULER_P_H
20 #define SCHEDULER_P_H
21 #include <QSet>
22 
23 // #define SCHEDULER_DEBUG
24 
25 namespace KIO {
26 
27 class SlaveKeeper : public QObject
28 {
29  Q_OBJECT
30 public:
31  SlaveKeeper();
32  void returnSlave(KIO::Slave *slave);
33  // pick suitable slave for job and return it, return null if no slave found.
34  // the slave is removed from the keeper.
35  KIO::Slave *takeSlaveForJob(KIO::SimpleJob *job);
36  // remove slave from keeper
37  bool removeSlave(KIO::Slave *slave);
38  QList<KIO::Slave *> allSlaves() const;
39 
40 private:
41  void scheduleGrimReaper();
42 
43 private slots:
44  void grimReaper();
45 
46 private:
47  QMultiHash<QString, KIO::Slave *> m_idleSlaves;
48  QTimer m_grimTimer;
49 };
50 
51 
52 class HostQueue
53 {
54 public:
55  int lowestSerial() const;
56 
57  bool isQueueEmpty() const { return m_queuedJobs.isEmpty(); }
58  bool isEmpty() const { return m_queuedJobs.isEmpty() && m_runningJobs.isEmpty(); }
59  int runningJobsCount() const { return m_runningJobs.count(); }
60 #ifdef SCHEDULER_DEBUG
61  QList<KIO::SimpleJob *> runningJobs() const { return m_runningJobs.toList(); }
62 #endif
63  bool isJobRunning(KIO::SimpleJob *job) const { return m_runningJobs.contains(job); }
64 
65  void queueJob(KIO::SimpleJob *job);
66  KIO::SimpleJob *takeFirstInQueue();
67  bool removeJob(KIO::SimpleJob *job);
68 
69  QList<KIO::Slave *> allSlaves() const;
70 private:
71  QMap<int, KIO::SimpleJob *> m_queuedJobs;
72  QSet<KIO::SimpleJob *> m_runningJobs;
73 };
74 
75 struct PerSlaveQueue
76 {
77  PerSlaveQueue() : runningJob(0) {}
78  QList <SimpleJob *> waitingList;
79  SimpleJob *runningJob;
80 };
81 
82 class ConnectedSlaveQueue : public QObject
83 {
84  Q_OBJECT
85 public:
86  ConnectedSlaveQueue();
87 
88  bool queueJob(KIO::SimpleJob *job, KIO::Slave *slave);
89  bool removeJob(KIO::SimpleJob *job);
90 
91  void addSlave(KIO::Slave *slave);
92  bool removeSlave(KIO::Slave *slave);
93 
94  // KDE5: only one caller, for doubtful reasons. remove this if possible.
95  bool isIdle(KIO::Slave *slave);
96  bool isEmpty() const { return m_connectedSlaves.isEmpty(); }
97  QList<KIO::Slave *> allSlaves() const { return m_connectedSlaves.keys(); }
98 
99 private slots:
100  void startRunnableJobs();
101 private:
102  // note that connected slaves stay here when idle, they are not returned to SlaveKeeper
103  QHash<KIO::Slave *, PerSlaveQueue> m_connectedSlaves;
104  QSet<KIO::Slave *> m_runnableSlaves;
105  QTimer m_startJobsTimer;
106 };
107 
108 
109 class SchedulerPrivate;
110 
111 class SerialPicker
112 {
113 public:
114  // note that serial number zero is the default value from job_p.h and invalid!
115  SerialPicker()
116  : m_offset(1) {}
117 
118  int next()
119  {
120  if (m_offset >= m_jobsPerPriority) {
121  m_offset = 1;
122  }
123  return m_offset++;
124  }
125 
126  int changedPrioritySerial(int oldSerial, int newPriority) const;
127 
128 private:
129  static const uint m_jobsPerPriority = 100000000;
130  uint m_offset;
131 public:
132  static const int maxSerial = m_jobsPerPriority * 20;
133 };
134 
135 
136 class ProtoQueue : public QObject
137 {
138  Q_OBJECT
139 public:
140  ProtoQueue(KIO::SchedulerPrivate *sp, int maxSlaves, int maxSlavesPerHost);
141  ~ProtoQueue();
142 
143  void queueJob(KIO::SimpleJob *job);
144  void changeJobPriority(KIO::SimpleJob *job, int newPriority);
145  void removeJob(KIO::SimpleJob *job);
146  KIO::Slave *createSlave(const QString &protocol, KIO::SimpleJob *job, const KUrl &url);
147  bool removeSlave (KIO::Slave *slave);
148  QList<KIO::Slave *> allSlaves() const;
149  ConnectedSlaveQueue m_connectedSlaveQueue;
150 
151 private slots:
152  // start max one (non-connected) job and return
153  void startAJob();
154 
155 private:
156  SerialPicker m_serialPicker;
157  QTimer m_startJobTimer;
158  QMap<int, HostQueue *> m_queuesBySerial;
159  QHash<QString, HostQueue> m_queuesByHostname;
160  KIO::SchedulerPrivate *m_schedPrivate;
161  SlaveKeeper m_slaveKeeper;
162  int m_maxConnectionsPerHost;
163  int m_maxConnectionsTotal;
164  int m_runningJobsCount;
165 };
166 
167 } // namespace KIO
168 
169 #endif //SCHEDULER_P_H
KIO::HostQueue::isJobRunning
bool isJobRunning(KIO::SimpleJob *job) const
Definition: scheduler_p.h:63
KIO::SerialPicker::SerialPicker
SerialPicker()
Definition: scheduler_p.h:115
KIO::ProtoQueue::~ProtoQueue
~ProtoQueue()
Definition: scheduler.cpp:409
KIO::ConnectedSlaveQueue::isIdle
bool isIdle(KIO::Slave *slave)
Definition: scheduler.cpp:311
KIO::ProtoQueue::removeJob
void removeJob(KIO::SimpleJob *job)
Definition: scheduler.cpp:480
KIO::ConnectedSlaveQueue::isEmpty
bool isEmpty() const
Definition: scheduler_p.h:96
QMap
Definition: netaccess.h:36
KIO::ProtoQueue::changeJobPriority
void changeJobPriority(KIO::SimpleJob *job, int newPriority)
Definition: scheduler.cpp:457
KIO::PerSlaveQueue
Definition: scheduler_p.h:75
KIO::PerSlaveQueue::PerSlaveQueue
PerSlaveQueue()
Definition: scheduler_p.h:77
KIO::SlaveKeeper::SlaveKeeper
SlaveKeeper()
Definition: scheduler.cpp:81
KIO::ConnectedSlaveQueue::ConnectedSlaveQueue
ConnectedSlaveQueue()
Definition: scheduler.cpp:219
KIO::PerSlaveQueue::waitingList
QList< SimpleJob * > waitingList
Definition: scheduler_p.h:78
KUrl
KIO::Slave
Definition: slave.h:48
KIO::ProtoQueue::queueJob
void queueJob(KIO::SimpleJob *job)
Definition: scheduler.cpp:418
KIO::HostQueue::lowestSerial
int lowestSerial() const
Definition: scheduler.cpp:165
KIO::SlaveKeeper
Definition: scheduler_p.h:27
KIO::ConnectedSlaveQueue::addSlave
void addSlave(KIO::Slave *slave)
Definition: scheduler.cpp:281
QTimer
QHash
KIO::ProtoQueue::createSlave
KIO::Slave * createSlave(const QString &protocol, KIO::SimpleJob *job, const KUrl &url)
Definition: scheduler.cpp:533
KIO::SerialPicker::next
int next()
Definition: scheduler_p.h:118
QObject
KIO::ProtoQueue::allSlaves
QList< KIO::Slave * > allSlaves() const
Definition: scheduler.cpp:560
KIO::HostQueue::allSlaves
QList< KIO::Slave * > allSlaves() const
Definition: scheduler.cpp:206
KIO::ConnectedSlaveQueue::queueJob
bool queueJob(KIO::SimpleJob *job, KIO::Slave *slave)
Definition: scheduler.cpp:225
QSet
KIO::ConnectedSlaveQueue::removeJob
bool removeJob(KIO::SimpleJob *job)
Definition: scheduler.cpp:243
KIO::HostQueue::runningJobsCount
int runningJobsCount() const
Definition: scheduler_p.h:59
QString
QList
KIO::ConnectedSlaveQueue::allSlaves
QList< KIO::Slave * > allSlaves() const
Definition: scheduler_p.h:97
KIO::SlaveKeeper::returnSlave
void returnSlave(KIO::Slave *slave)
Definition: scheduler.cpp:87
KIO::HostQueue::removeJob
bool removeJob(KIO::SimpleJob *job)
Definition: scheduler.cpp:193
KIO::ProtoQueue::m_connectedSlaveQueue
ConnectedSlaveQueue m_connectedSlaveQueue
Definition: scheduler_p.h:149
KIO::HostQueue::isQueueEmpty
bool isQueueEmpty() const
Definition: scheduler_p.h:57
KIO::SerialPicker::changedPrioritySerial
int changedPrioritySerial(int oldSerial, int newPriority) const
Definition: scheduler.cpp:72
KIO::ConnectedSlaveQueue
Definition: scheduler_p.h:82
KIO::ProtoQueue::ProtoQueue
ProtoQueue(KIO::SchedulerPrivate *sp, int maxSlaves, int maxSlavesPerHost)
Definition: scheduler.cpp:394
KIO::SerialPicker::maxSerial
static const int maxSerial
Definition: scheduler_p.h:132
KIO::SerialPicker
Definition: scheduler_p.h:111
KIO::HostQueue
Definition: scheduler_p.h:52
KIO::HostQueue::isEmpty
bool isEmpty() const
Definition: scheduler_p.h:58
KIO::SlaveKeeper::removeSlave
bool removeSlave(KIO::Slave *slave)
Definition: scheduler.cpp:116
KIO::HostQueue::queueJob
void queueJob(KIO::SimpleJob *job)
Definition: scheduler.cpp:174
KIO::ProtoQueue::removeSlave
bool removeSlave(KIO::Slave *slave)
Definition: scheduler.cpp:552
KIO::PerSlaveQueue::runningJob
SimpleJob * runningJob
Definition: scheduler_p.h:79
KIO::HostQueue::takeFirstInQueue
KIO::SimpleJob * takeFirstInQueue()
Definition: scheduler.cpp:183
KIO::ConnectedSlaveQueue::removeSlave
bool removeSlave(KIO::Slave *slave)
Definition: scheduler.cpp:289
KIO::SlaveKeeper::allSlaves
QList< KIO::Slave * > allSlaves() const
Definition: scheduler.cpp:129
QMultiHash
KIO::ProtoQueue
Definition: scheduler_p.h:136
KIO::SlaveKeeper::takeSlaveForJob
KIO::Slave * takeSlaveForJob(KIO::SimpleJob *job)
Definition: scheduler.cpp:95
KIO::SimpleJob
A simple job (one url and one command).
Definition: jobclasses.h:322
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal