krazy and doc fixes
[kdenetwork.git] / kget / core / job.h
blob3d1596fba920cfb02aaac4494c57002caf84f293
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
8 of the License.
9 */
11 #ifndef JOB_H
12 #define JOB_H
14 /**
15 * @brief Job class
17 * We want to abstract this common interface in order to simplify the
18 * Scheduler code. A Job can be either a Transfer or a search through the net.
19 * It is basically something you execute in background and that the scheduler
20 * can decide to start, stop or cancel. In this way we don't expose the complex
21 * API of a Transfer (or a Search), to the scheduler.
22 * By definition a job must always belong to a JobQueue (see jobqueue.h).
23 **/
25 #include "kget_export.h"
27 class QDomNode;
29 class Scheduler;
30 class JobQueue;
32 class KGET_EXPORT Job
34 public:
35 /**
36 * The status property describes the current job status
38 enum Status {
39 Running, ///< The job is being executed
40 Delayed, ///< The job is delayed. This means that the scheduler should
41 /// not start it until it exits from the delayed state
42 Stopped, ///< The job is stopped
43 Aborted, ///< The job is stopped, but this also indicates that it
44 /// stopped because an error occurred
45 Finished ///< The job exited from its Running state successfully
48 /**
49 * The policy property describes how the scheduler should manage this job.
51 enum Policy {Start, ///< The scheduler should start this job even if its queue
52 /// isn't in a Running status
53 Stop, ///< The scheduler shouldn't never start this job, even if
54 /// if its queue is in a Running status
55 None ///< The scheduler should start this job depending on its
56 /// queue status
59 Job(JobQueue * parent, Scheduler * scheduler);
60 virtual ~Job();
62 //Job commands
63 virtual void start()=0;
64 virtual void stop()=0;
66 virtual void setDelay(int seconds)=0;
67 virtual void delayTimerEvent()=0;
69 JobQueue * jobQueue() {return m_jobQueue;}
71 //Job properties
72 void setStatus(Status jobStatus);
73 void setPolicy(Policy jobPolicy);
75 Status status() const {return m_status;}
76 Policy policy() const {return m_policy;}
78 virtual int elapsedTime() const =0;
79 virtual int remainingTime() const =0;
81 //Job capabilities
82 virtual bool isResumable() const =0;
84 protected:
85 Scheduler * scheduler() const {return m_scheduler;}
87 void read(QDomNode * n);
88 void write(QDomNode * n);
90 /**
91 * This one posts a job event to the scheduler
93 void postJobEvent(Status); //do we need a JobEvent instead of JobStatus?
95 JobQueue * m_jobQueue;
96 Scheduler * m_scheduler;
98 private:
99 Status m_status;
100 Policy m_policy;
103 #endif