// JobQueue.h Dave Reed 9/3/02 // // JobQueue class /////////////////////////////////////////////////////////////////////////////// #ifndef _JOBQUEUE_ #define _JOBQUEUE_ #include #include #include "Queue.h" using namespace std; enum JobStatus {OK, DONE}; class JobQueue { public: JobQueue(string filename); // constructor bool JobsRemaining(); // determines if any jobs in queue int GetCurrentID(); // gets ID of current job void InterruptCurrentJob(); // interrupts current job, to end of queue void RemoveCurrentJob(); // removes current job from queue JobStatus ExecuteCurrentJob(); // executes current job for one cycle private: class Job { public: int ID; int length; }; Queue jobQueue; }; JobQueue::JobQueue(string filename) // Assumes: filename is the name of the job data file // Results: constructs a queue of jobs from file { ifstream infile(filename.c_str()); int id, len; while (infile >> id >> len) { Job j; j.ID = id; j.length = len; jobQueue.Enter(j); } } bool JobQueue::JobsRemaining() // Returns: true if job queue contains a job, false if empty { return !jobQueue.IsEmpty(); } int JobQueue::GetCurrentID() // Returns: ID of current job (front of queue) { return jobQueue.Front().ID; } void JobQueue::RemoveCurrentJob() // Results: removes current job (at front of queue) { jobQueue.Remove(); } void JobQueue::InterruptCurrentJob() // Results: interrupts current job, moves to end of queue { jobQueue.Enter(jobQueue.Front()); jobQueue.Remove(); } JobStatus JobQueue::ExecuteCurrentJob() // Returns: status after executing current job for a cycle { jobQueue.Front().length--; if (jobQueue.Front().length == 0) { return DONE; } else { return OK; } } #endif