2011-01-22 01:18:58 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2011, Haiku, Inc.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2011-01-25 20:07:27 +03:00
|
|
|
#ifndef _PACKAGE__JOB_H_
|
|
|
|
#define _PACKAGE__JOB_H_
|
2011-01-22 01:18:58 +03:00
|
|
|
|
|
|
|
|
|
|
|
#include <ObjectList.h>
|
|
|
|
#include <String.h>
|
|
|
|
|
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
namespace BPackageKit {
|
2011-01-22 01:18:58 +03:00
|
|
|
|
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
class BContext;
|
|
|
|
class BJob;
|
2011-01-22 01:18:58 +03:00
|
|
|
|
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
struct BJobStateListener {
|
|
|
|
virtual ~BJobStateListener();
|
2011-01-22 01:18:58 +03:00
|
|
|
|
|
|
|
// these default implementations do nothing
|
2011-01-25 20:07:27 +03:00
|
|
|
virtual void JobStarted(BJob* job);
|
|
|
|
virtual void JobSucceeded(BJob* job);
|
|
|
|
virtual void JobFailed(BJob* job);
|
|
|
|
virtual void JobAborted(BJob* job);
|
2011-01-22 01:18:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
enum BJobState {
|
2011-01-22 01:18:58 +03:00
|
|
|
JOB_STATE_WAITING_TO_RUN,
|
|
|
|
JOB_STATE_RUNNING,
|
|
|
|
JOB_STATE_SUCCEEDED,
|
|
|
|
JOB_STATE_FAILED,
|
|
|
|
JOB_STATE_ABORTED,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
namespace BPrivate {
|
|
|
|
class JobQueue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class BJob {
|
2011-01-22 01:18:58 +03:00
|
|
|
public:
|
2011-01-25 20:07:27 +03:00
|
|
|
BJob(const BContext& context,
|
2011-01-22 22:30:21 +03:00
|
|
|
const BString& title);
|
2011-01-25 20:07:27 +03:00
|
|
|
virtual ~BJob();
|
2011-01-22 01:18:58 +03:00
|
|
|
|
|
|
|
status_t InitCheck() const;
|
|
|
|
|
|
|
|
virtual status_t Run();
|
|
|
|
|
|
|
|
const BString& Title() const;
|
2011-01-25 20:07:27 +03:00
|
|
|
BJobState State() const;
|
2011-01-22 01:18:58 +03:00
|
|
|
status_t Result() const;
|
2011-01-24 23:48:03 +03:00
|
|
|
const BString& ErrorString() const;
|
2011-01-22 01:18:58 +03:00
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
uint32 TicketNumber() const;
|
|
|
|
|
|
|
|
status_t AddStateListener(BJobStateListener* listener);
|
2011-01-22 01:18:58 +03:00
|
|
|
status_t RemoveStateListener(
|
2011-01-25 20:07:27 +03:00
|
|
|
BJobStateListener* listener);
|
2011-01-22 01:18:58 +03:00
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
bool IsRunnable() const;
|
|
|
|
status_t AddDependency(BJob* job);
|
|
|
|
status_t RemoveDependency(BJob* job);
|
2011-01-22 01:18:58 +03:00
|
|
|
int32 CountDependencies() const;
|
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
BJob* DependantJobAt(int32 index) const;
|
2011-01-22 01:18:58 +03:00
|
|
|
protected:
|
|
|
|
virtual status_t Execute() = 0;
|
|
|
|
virtual void Cleanup(status_t jobResult);
|
|
|
|
|
2011-01-24 23:48:03 +03:00
|
|
|
void SetErrorString(const BString&);
|
|
|
|
|
2011-01-22 01:18:58 +03:00
|
|
|
void NotifyStateListeners();
|
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
const BContext& fContext;
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class BPrivate::JobQueue;
|
|
|
|
void _SetTicketNumber(uint32 ticketNumber);
|
|
|
|
void _ClearTicketNumber();
|
|
|
|
|
2011-01-22 01:18:58 +03:00
|
|
|
private:
|
|
|
|
status_t fInitStatus;
|
|
|
|
BString fTitle;
|
2011-01-22 22:30:21 +03:00
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
BJobState fState;
|
2011-01-22 01:18:58 +03:00
|
|
|
status_t fResult;
|
2011-01-24 23:48:03 +03:00
|
|
|
BString fErrorString;
|
2011-01-22 01:18:58 +03:00
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
uint32 fTicketNumber;
|
|
|
|
|
|
|
|
typedef BObjectList<BJob> JobList;
|
2011-01-22 01:18:58 +03:00
|
|
|
JobList fDependencies;
|
|
|
|
JobList fDependantJobs;
|
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
typedef BObjectList<BJobStateListener> StateListenerList;
|
2011-01-22 01:18:58 +03:00
|
|
|
StateListenerList fStateListeners;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
} // namespace BPackageKit
|
2011-01-22 01:18:58 +03:00
|
|
|
|
|
|
|
|
2011-01-25 20:07:27 +03:00
|
|
|
#endif // _PACKAGE__JOB_H_
|