1 /* This file is part of the KDE project
3 Copyright (C) 2005 Dario Massarin <nekkar@libero.it>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; version 2
16 * @brief JobQueue class
18 * This class abstracts the concept of queue. A queue is, basically, a
19 * group of jobs that should be executed by the scheduler (if the queue
20 * is marked as active). The scheduler will execute a maximum of n jobs
21 * belonging to this queue at a time, where n can be set calling the
22 * setMaxSimultaneousJobs(int n)
27 #include "kget_export.h"
32 class KGET_EXPORT JobQueue
35 enum Status
{Running
, Stopped
};
36 typedef QList
<Job
*>::iterator iterator
;
38 JobQueue(Scheduler
* scheduler
);
42 * Sets the JobQueue status
44 * @param queueStatus the new JobQueue status
46 virtual void setStatus(Status queueStatus
);
49 * @return the jobQueue status
51 Status
status() const {return m_status
;}
54 * @return the begin of the job's list
56 iterator
begin() {return m_jobs
.begin();}
59 * @return the end of the job's list
61 iterator
end() {return m_jobs
.end();}
64 * @return the last job in the job's list
66 Job
* last() {return m_jobs
.last();}
69 * @return the number of jobs in the queue
71 int size() const {return m_jobs
.size();}
74 * @param job The job for which we want to find the index
76 * @return the job index for the given job. If the given
77 * job can't be found, it returns -1
79 int indexOf(Job
* job
) const {return m_jobs
.indexOf(job
);}
82 * @returns the Job in the queue at the given index i
84 Job
* operator[] (int i
) const;
87 * @return a list with the running Jobs
89 const QList
<Job
*> runningJobs();
92 * Sets the maximum number of jobs belonging to this queue that
93 * should executed simultaneously by the scheduler
95 * @param n The maximum number of jobs
97 void setMaxSimultaneousJobs(int n
);
100 * @return the maximum number of jobs the scheduler should ever
101 * execute simultaneously (in this queue).
103 int maxSimultaneousJobs() const;
107 * appends a job to the current queue
109 * @param job The job to append to the current queue
111 void append(Job
* job
);
114 * prepends a job to the current queue
116 * @param job The job to prepend to the current queue
118 void prepend(Job
* job
);
121 * inserts a job to the current queue after the given job
123 * @param job The job to add in the current queue
124 * @param after The job after which to add the job
126 void insert(Job
* job
, Job
* after
);
129 * removes a job from the current queue
131 * @param job The job to remove from the current queue
133 void remove(Job
* job
);
136 * Moves a job in the queue. Both the given jobs must belong to this queue
138 * @param job The job to move
139 * @param position The job after which we have to move the given job
141 void move(Job
* job
, Job
* after
);
143 Scheduler
* scheduler() {return m_scheduler
;}
148 int m_maxSimultaneousJobs
;
150 Scheduler
* m_scheduler
;