1 /* This file is part of the KDE project 2 3 Copyright (C) 2005 Dario Massarin <nekkar@libero.it> 4 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; either 8 version 2 of the License, or (at your option) any later version. 9 */ 10 11 12 #ifndef JOBQUEUE_H 13 #define JOBQUEUE_H 14 15 /** 16 * @brief JobQueue class 17 * 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) 23 * 24 */ 25 26 #include <QList> 27 #include <QObject> 28 #include "kget_export.h" 29 30 class Job; 31 class Scheduler; 32 33 class KGET_EXPORT JobQueue : public QObject 34 { 35 Q_OBJECT 36 public: 37 enum Status {Running, Stopped}; 38 typedef QList<Job *>::iterator iterator; 39 40 JobQueue(Scheduler * parent); 41 ~JobQueue() override; 42 43 /** 44 * Sets the JobQueue status 45 * 46 * @param queueStatus the new JobQueue status 47 */ 48 virtual void setStatus(Status queueStatus); 49 50 /** 51 * @return the jobQueue status 52 */ status()53 Status status() const {return m_status;} 54 55 /** 56 * @return the begin of the job's list 57 */ begin()58 iterator begin() {return m_jobs.begin();} 59 60 /** 61 * @return the end of the job's list 62 */ end()63 iterator end() {return m_jobs.end();} 64 65 /** 66 * @return the last job in the job's list 67 */ last()68 Job * last() {return m_jobs.last();} 69 70 /** 71 * @return the number of jobs in the queue 72 */ size()73 int size() const {return m_jobs.size();} 74 75 /** 76 * @param job The job for which we want to find the index 77 * 78 * @return the job index for the given job. If the given 79 * job can't be found, it returns -1 80 */ indexOf(Job * job)81 int indexOf(Job * job) const {return m_jobs.indexOf(job);} 82 83 /** 84 * @returns the Job in the queue at the given index i 85 */ 86 Job * operator[] (int i) const {return m_jobs[i];} 87 88 /** 89 * @return a list with the running Jobs 90 */ 91 const QList<Job *> runningJobs(); 92 93 /** 94 * FIXME not implemented 95 * Sets the maximum number of jobs belonging to this queue that 96 * should executed simultaneously by the scheduler 97 * 98 * @param n The maximum number of jobs 99 */ 100 void setMaxSimultaneousJobs(int n); 101 102 /** 103 * @return the maximum number of jobs the scheduler should ever 104 * execute simultaneously (in this queue). 105 */ 106 int maxSimultaneousJobs() const; 107 108 protected: 109 /** 110 * appends a job to the current queue 111 * 112 * @param job The job to append to the current queue 113 */ 114 void append(Job * job); 115 116 /** 117 * appends jobs to the current queue 118 * 119 * @param jobs to append to the current queue 120 */ 121 void append(const QList<Job*> &jobs); 122 123 /** 124 * prepends a job to the current queue 125 * 126 * @param job The job to prepend to the current queue 127 */ 128 void prepend(Job * job); 129 130 /** 131 * inserts a job to the current queue after the given job 132 * 133 * @param job The job to add in the current queue 134 * @param after The job after which to add the job 135 */ 136 void insert(Job * job, Job * after); 137 138 /** 139 * removes a job from the current queue 140 * 141 * @param job The job to remove from the current queue 142 */ 143 void remove(Job * job); 144 145 /** 146 * removes jobs from the current queue 147 * 148 * @param jobs The jobs to remove from the current queue 149 */ 150 void remove(const QList<Job*> jobs); 151 152 /** 153 * Moves a job in the queue. Both the given jobs must belong to this queue 154 * 155 * @param job The job to move 156 * @param after The job after which we have to move the given job 157 */ 158 void move(Job * job, Job * after); 159 scheduler()160 Scheduler * scheduler() {return m_scheduler;} 161 162 private: 163 QList<Job *> m_jobs; 164 165 int m_maxSimultaneousJobs; 166 167 Scheduler * m_scheduler; 168 Status m_status; 169 }; 170 171 #endif 172