2 * Copyright 2011-2015, Haiku, Inc.
3 * Distributed under the terms of the MIT License.
5 #ifndef _SUPPORT_JOB_H_
6 #define _SUPPORT_JOB_H_
9 #include <ObjectList.h>
13 namespace BSupportKit
{
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
);
32 B_JOB_STATE_WAITING_TO_RUN
,
34 B_JOB_STATE_IN_PROGRESS
,
35 B_JOB_STATE_SUCCEEDED
,
43 BJob(const BString
& title
);
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;
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();
82 void _SetTicketNumber(uint32 ticketNumber
);
83 void _ClearTicketNumber();
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_