/* fifomain.c - driver for fifo. Main program allocates and frees nodes.
 */

#include "fifo.h"
#include <stdlib.h>
#include <stdio.h>

typedef struct Job{
	struct Job *next_ptr;
	int job_id;
	int file_size;
	int Event_type;
	float timeOfEvent;
	float arrivalTime;
} job;

void displayFifo(fifo_t * fifo)
{
  job * p;
  for (p = (job *)fifo->front; p; p = p->next_ptr) {
    printf("job id = %d, time of event = %f\n", p->job_id, p->timeOfEvent);
  }
}


int main(void)
{
	fifo_t jobQueue = {NULL, NULL};
	char choice[80]; 
	job *temp;

	do {
		printf("A(dd to the queue), R(emove from it), E(xit): ");
		scanf("%s", &choice);
		switch(choice[0])
		{
		case 'A':
		        temp = (job *)malloc(sizeof(job));
			if (temp == NULL) {
			  perror("Cannot allocate node ");
			  exit(1);
			}
			printf("enter job id->  ");
			scanf("%d", &(temp->job_id));
			printf("enter file size->  ");
			scanf("%d", &(temp->file_size));
			printf("enter event type->  ");
			scanf("%d", &(temp->Event_type)); 
			printf("enter arrival time -> ");
			scanf("%f", &(temp->arrivalTime));
			printf("enter time of event->  ");
			scanf("%f", &(temp->timeOfEvent));            
			put (&jobQueue, (node *)temp);
			displayFifo(&jobQueue);
			break;
		case 'R':
			if (jobQueue.front != NULL)
			{
				temp = (job *)get(&jobQueue);
				printf("item removed from queue\n");
				free(temp);
				displayFifo(&jobQueue);
			} else {
				printf("queue was empty\n");
			}
			break;	
	     case 'E':
			printf("you are quitting\n");
			displayFifo(&jobQueue);
			break;
		 default:
			printf("wrong choice try again\n");
		}
	} while(choice[0] != 'E');
	return(0);
}

