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

KIO

  • 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
25namespace KIO {
26
27class SlaveKeeper : public QObject
28{
29 Q_OBJECT
30public:
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
40private:
41 void scheduleGrimReaper();
42
43private slots:
44 void grimReaper();
45
46private:
47 QMultiHash<QString, KIO::Slave *> m_idleSlaves;
48 QTimer m_grimTimer;
49};
50
51
52class HostQueue
53{
54public:
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;
70private:
71 QMap<int, KIO::SimpleJob *> m_queuedJobs;
72 QSet<KIO::SimpleJob *> m_runningJobs;
73};
74
75struct PerSlaveQueue
76{
77 PerSlaveQueue() : runningJob(0) {}
78 QList <SimpleJob *> waitingList;
79 SimpleJob *runningJob;
80};
81
82class ConnectedSlaveQueue : public QObject
83{
84 Q_OBJECT
85public:
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
99private slots:
100 void startRunnableJobs();
101private:
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
109class SchedulerPrivate;
110
111class SerialPicker
112{
113public:
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
128private:
129 static const uint m_jobsPerPriority = 100000000;
130 uint m_offset;
131public:
132 static const int maxSerial = m_jobsPerPriority * 20;
133};
134
135
136class ProtoQueue : public QObject
137{
138 Q_OBJECT
139public:
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
151private slots:
152 // start max one (non-connected) job and return
153 void startAJob();
154
155private:
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::ConnectedSlaveQueue
Definition: scheduler_p.h:83
KIO::ConnectedSlaveQueue::removeSlave
bool removeSlave(KIO::Slave *slave)
Definition: scheduler.cpp:289
KIO::ConnectedSlaveQueue::addSlave
void addSlave(KIO::Slave *slave)
Definition: scheduler.cpp:281
KIO::ConnectedSlaveQueue::ConnectedSlaveQueue
ConnectedSlaveQueue()
Definition: scheduler.cpp:219
KIO::ConnectedSlaveQueue::allSlaves
QList< KIO::Slave * > allSlaves() const
Definition: scheduler_p.h:97
KIO::ConnectedSlaveQueue::queueJob
bool queueJob(KIO::SimpleJob *job, KIO::Slave *slave)
Definition: scheduler.cpp:225
KIO::ConnectedSlaveQueue::removeJob
bool removeJob(KIO::SimpleJob *job)
Definition: scheduler.cpp:243
KIO::ConnectedSlaveQueue::isIdle
bool isIdle(KIO::Slave *slave)
Definition: scheduler.cpp:311
KIO::ConnectedSlaveQueue::isEmpty
bool isEmpty() const
Definition: scheduler_p.h:96
KIO::HostQueue
Definition: scheduler_p.h:53
KIO::HostQueue::lowestSerial
int lowestSerial() const
Definition: scheduler.cpp:165
KIO::HostQueue::runningJobsCount
int runningJobsCount() const
Definition: scheduler_p.h:59
KIO::HostQueue::removeJob
bool removeJob(KIO::SimpleJob *job)
Definition: scheduler.cpp:193
KIO::HostQueue::isJobRunning
bool isJobRunning(KIO::SimpleJob *job) const
Definition: scheduler_p.h:63
KIO::HostQueue::isEmpty
bool isEmpty() const
Definition: scheduler_p.h:58
KIO::HostQueue::isQueueEmpty
bool isQueueEmpty() const
Definition: scheduler_p.h:57
KIO::HostQueue::queueJob
void queueJob(KIO::SimpleJob *job)
Definition: scheduler.cpp:174
KIO::HostQueue::takeFirstInQueue
KIO::SimpleJob * takeFirstInQueue()
Definition: scheduler.cpp:183
KIO::HostQueue::allSlaves
QList< KIO::Slave * > allSlaves() const
Definition: scheduler.cpp:206
KIO::ProtoQueue
Definition: scheduler_p.h:137
KIO::ProtoQueue::changeJobPriority
void changeJobPriority(KIO::SimpleJob *job, int newPriority)
Definition: scheduler.cpp:457
KIO::ProtoQueue::removeSlave
bool removeSlave(KIO::Slave *slave)
Definition: scheduler.cpp:552
KIO::ProtoQueue::~ProtoQueue
~ProtoQueue()
Definition: scheduler.cpp:409
KIO::ProtoQueue::allSlaves
QList< KIO::Slave * > allSlaves() const
Definition: scheduler.cpp:560
KIO::ProtoQueue::queueJob
void queueJob(KIO::SimpleJob *job)
Definition: scheduler.cpp:418
KIO::ProtoQueue::m_connectedSlaveQueue
ConnectedSlaveQueue m_connectedSlaveQueue
Definition: scheduler_p.h:149
KIO::ProtoQueue::removeJob
void removeJob(KIO::SimpleJob *job)
Definition: scheduler.cpp:480
KIO::ProtoQueue::createSlave
KIO::Slave * createSlave(const QString &protocol, KIO::SimpleJob *job, const KUrl &url)
Definition: scheduler.cpp:533
KIO::SerialPicker
Definition: scheduler_p.h:112
KIO::SerialPicker::SerialPicker
SerialPicker()
Definition: scheduler_p.h:115
KIO::SerialPicker::changedPrioritySerial
int changedPrioritySerial(int oldSerial, int newPriority) const
Definition: scheduler.cpp:72
KIO::SerialPicker::maxSerial
static const int maxSerial
Definition: scheduler_p.h:132
KIO::SerialPicker::next
int next()
Definition: scheduler_p.h:118
KIO::SimpleJob
A simple job (one url and one command).
Definition: jobclasses.h:322
KIO::SlaveKeeper
Definition: scheduler_p.h:28
KIO::SlaveKeeper::returnSlave
void returnSlave(KIO::Slave *slave)
Definition: scheduler.cpp:87
KIO::SlaveKeeper::takeSlaveForJob
KIO::Slave * takeSlaveForJob(KIO::SimpleJob *job)
Definition: scheduler.cpp:95
KIO::SlaveKeeper::SlaveKeeper
SlaveKeeper()
Definition: scheduler.cpp:81
KIO::SlaveKeeper::removeSlave
bool removeSlave(KIO::Slave *slave)
Definition: scheduler.cpp:116
KIO::SlaveKeeper::allSlaves
QList< KIO::Slave * > allSlaves() const
Definition: scheduler.cpp:129
KIO::Slave
Definition: slave.h:49
KUrl
QHash
QList
QMap
QObject
QSet
KIO
A namespace for KIO globals.
Definition: kbookmarkmenu.h:55
KIO::PerSlaveQueue
Definition: scheduler_p.h:76
KIO::PerSlaveQueue::PerSlaveQueue
PerSlaveQueue()
Definition: scheduler_p.h:77
KIO::PerSlaveQueue::waitingList
QList< SimpleJob * > waitingList
Definition: scheduler_p.h:78
KIO::PerSlaveQueue::runningJob
SimpleJob * runningJob
Definition: scheduler_p.h:79
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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