Provide (experimental) clang-format file
[TortoiseGit.git] / src / AsyncFramework / IJob.h
blob0623e6c5b2432450c19c32c2eb0a234a036c5971
1 /***************************************************************************
2 * Copyright (C) 2009-2010 by Stefan Fuhrmann *
3 * stefanfuhrmann@alice-dsl.de *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
21 #pragma once
23 namespace async
26 // forward declaration
28 class CJobScheduler;
30 /**
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.
38 class IJob
40 public:
42 /**
43 * Possible values returned by \ref GetStatus().
44 * The state machine linearly follows the value order.
47 enum Status
49 waiting = 0,
50 running = 1,
51 suspended = 2,
52 done = 3
55 /// destruction
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 execution.
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;
83 private:
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
93 /// has been called.
95 virtual void OnUnSchedule (CJobScheduler* scheduler) = 0;
97 // callbacks are ment to be used by \ref CJobScheduler only
99 friend class CJobScheduler;