bin/pc: Mark non-returning function as void
[haiku.git] / headers / os / support / Job.h
blob84d4a9efe20036bf038f53ab3c1497f7ac98b223
1 /*
2 * Copyright 2011-2015, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _SUPPORT_JOB_H_
6 #define _SUPPORT_JOB_H_
9 #include <ObjectList.h>
10 #include <String.h>
13 namespace BSupportKit {
16 class BJob;
19 struct BJobStateListener {
20 virtual ~BJobStateListener();
22 // these default implementations do nothing
23 virtual void JobStarted(BJob* job);
24 virtual void JobProgress(BJob* job);
25 virtual void JobSucceeded(BJob* job);
26 virtual void JobFailed(BJob* job);
27 virtual void JobAborted(BJob* job);
31 enum BJobState {
32 B_JOB_STATE_WAITING_TO_RUN,
33 B_JOB_STATE_STARTED,
34 B_JOB_STATE_IN_PROGRESS,
35 B_JOB_STATE_SUCCEEDED,
36 B_JOB_STATE_FAILED,
37 B_JOB_STATE_ABORTED,
41 class BJob {
42 public:
43 BJob(const BString& title);
44 virtual ~BJob();
46 status_t InitCheck() const;
48 virtual status_t Run();
50 const BString& Title() const;
51 BJobState State() const;
52 status_t Result() const;
53 const BString& ErrorString() const;
55 uint32 TicketNumber() const;
57 status_t AddStateListener(BJobStateListener* listener);
58 status_t RemoveStateListener(
59 BJobStateListener* listener);
61 bool IsRunnable() const;
62 status_t AddDependency(BJob* job);
63 status_t RemoveDependency(BJob* job);
64 int32 CountDependencies() const;
66 BJob* DependantJobAt(int32 index) const;
68 class Private;
70 protected:
71 virtual status_t Execute() = 0;
72 virtual void Cleanup(status_t jobResult);
74 void SetState(BJobState state);
75 void SetErrorString(const BString&);
77 void NotifyStateListeners();
79 private:
80 friend class Private;
82 void _SetTicketNumber(uint32 ticketNumber);
83 void _ClearTicketNumber();
85 private:
86 status_t fInitStatus;
87 BString fTitle;
89 BJobState fState;
90 status_t fResult;
91 BString fErrorString;
93 uint32 fTicketNumber;
95 typedef BObjectList<BJob> JobList;
96 JobList fDependencies;
97 JobList fDependantJobs;
99 typedef BObjectList<BJobStateListener> StateListenerList;
100 StateListenerList fStateListeners;
104 } // namespace BSupportKit
107 #endif // _SUPPORT_JOB_H_