// CPU.cpp     Dave Reed      1/20/05
//
// Simple CPU simulator with interrupts.  A collection of jobs/processes are read 
// in from a file, and then executed using timesharing (time slice, load delay, 
// and I/O length limits are specified by the user). 
/////////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <string>
#include "Job.h"
#include "JobStream.h"
#include "CPUScheduler.h"
using namespace std;

int main()
{
    string filename;
    cout << "Enter the job file name: ";
    cin >> filename;

    int timeSlice, loadDelay, ioMin, ioMax;
    cout << "Enter the load delay and time slice length: ";
    cin >> loadDelay >> timeSlice;
    cout << "Enter the minimum and maximum times for I/O: ";
    cin >> ioMin >> ioMax;
    cout << endl;

    JobStream arrivingJobs(filename);     
    CPUScheduler timeshare(loadDelay, timeSlice, ioMin, ioMax); 

     while (timeshare.jobsRemaining() || arrivingJobs.jobsRemaining()) {
         while (arrivingJobs.jobHasArrived(timeshare.getTime())) {    
             timeshare.addNewJob(arrivingJobs.getJob());
         }
         timeshare.execute();   
     }

  cout << "DONE PROCESSING" << endl;
  return 0;
}
