1 /***************************************************************************
2 * Copyright (C) 2009-2010 by Stefan Fuhrmann *
3 * stefanfuhrmann@alice-dsl.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
26 // forward declaration
31 * Common interface to all job objects that can be handled by
32 * \ref CJobScheduler instances.
34 * Jobs will be executed only once making the \ref done state
35 * the final state of the internal state machine.
43 * Possible values returned by \ref GetStatus().
44 * The state machine linearly follows the value order.
57 virtual ~IJob(void) {}
59 /// call this to put the job into the scheduler.
60 /// If \ref transferOwnership is set, the scheduler must
61 /// delete this instance after exection.
63 virtual void Schedule ( bool transferOwnership
64 , CJobScheduler
* scheduler
) = 0;
66 /// will be called by job execution thread.
68 virtual void Execute() = 0;
70 /// may be called by other (observing) threads.
71 /// Please note that the information returned may already
72 /// be outdated as soon as the function returns.
74 virtual Status
GetStatus() const = 0;
76 /// Efficiently wait for instance to reach the
77 /// \ref done \ref Status.
78 /// If \ref inlineExecution is set, the job will be
79 /// executed in the current thread if it is still waiting.
81 virtual void WaitUntilDone (bool inlineExecution
= false) = 0;
85 /// Called by the \ref CJobScheduler instance before
86 /// it actually add this job to its execution list.
88 virtual void OnSchedule (CJobScheduler
* scheduler
) = 0;
90 /// Called by the \ref CJobScheduler instance after
91 /// it removed this job from its execution list.
92 /// The job must not be deleted before this function
95 virtual void OnUnSchedule (CJobScheduler
* scheduler
) = 0;
97 // callbacks are ment to be used by \ref CJobScheduler only
99 friend class CJobScheduler
;