1/* 2 * Copyright 2011, Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef _PACKAGE__PRIVATE__JOB_QUEUE_H_ 6#define _PACKAGE__PRIVATE__JOB_QUEUE_H_ 7 8 9#include <Locker.h> 10#include <SupportDefs.h> 11 12#include <package/Job.h> 13 14 15namespace BPackageKit { 16 17namespace BPrivate { 18 19 20class JobQueue : private BJobStateListener { 21public: 22 JobQueue(); 23 virtual ~JobQueue(); 24 25 status_t InitCheck() const; 26 27 status_t AddJob(BJob* job); 28 // takes ownership 29 status_t RemoveJob(BJob* job); 30 // gives up ownership 31 32 BJob* Pop(); 33 // caller owns job 34 35 void Close(); 36 37private: 38 // BJobStateListener 39 virtual void JobSucceeded(BJob* job); 40 virtual void JobFailed(BJob* job); 41 42private: 43 struct JobPriorityLess; 44 class JobPriorityQueue; 45 46private: 47 status_t _Init(); 48 49 void _RequeueDependantJobsOf(BJob* job); 50 void _RemoveDependantJobsOf(BJob* job); 51 52 BLocker fLock; 53 uint32 fNextTicketNumber; 54 JobPriorityQueue* fQueuedJobs; 55 sem_id fHaveRunnableJobSem; 56 57 status_t fInitStatus; 58}; 59 60 61} // namespace BPrivate 62 63} // namespace BPackageKit 64 65 66#endif // _PACKAGE__PRIVATE__JOB_QUEUE_H_ 67