/* Defines the interface and data structures for a generic scheduling
 * algorithm.  The scheduler_simulation can thus be linked with any
 * object file that implements these methods.
 * 
 * Created by Henry Walker, 27 September 2004
 * Revised by
 *   Jerod Weinman, 27 May 2008
 */
#ifndef __SCHEDULER_H__
#define __SCHEDULER_H__

/* Event structure models job details in the system */
struct Event {
  double arrivalTime; /* time when Event entered system */
  double cpuTime;     /* overall CPU time required for the event */
  int priority;       /* priority value if priority scheduling used */
  double cpuTimeLeft; /* CPU time remaining for processing the event */
  int hasStarted;     /* Initially false; set to true when the process 
                       * has been scheduled for the first time. */
};

/* List data structures for the job list of a scheduler */
struct jobQueueNode {
  struct Event * job;
  struct jobQueueNode * next;
};

struct jobQueue {
  struct jobQueueNode * first;
  struct jobQueueNode * last;
};

/* Shorthand for a event handler function pointer */
typedef void EventHandlerFunc (struct Event *);

/* List structure for events in the simulation queue */
struct eventListStruct {
  double arrivalTime;
  struct Event * job;
  EventHandlerFunc * eventHandler;  /* called fire in Nutt */
  struct eventListStruct * next;
};

/* returns true (1) if queue is empty and false (0) otherwise */
int jobQueueIsEmpty (void);

/* initialize jobQueue to a null queue */
void initializeJobQueue (void);

/* insert job into job queue */
void insertJob (struct Event * job);

/* return the next job to be run */
struct Event * selectJob (void);

#endif
