-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrival.cpp
More file actions
44 lines (41 loc) · 1.47 KB
/
Copy pathArrival.cpp
File metadata and controls
44 lines (41 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
*Name: Kabir Bhakta Student Number: 7900098
*Purpose: Arrvial Event implementation. When a process arrives in system.
*/
#include "Arrival.h"
#include "Simulation.h"
#include "StartCpu.h"
#include "Process.h"
#include "TimeOut.h"
#include <iostream>
using namespace std;
//constructor
Arrival::Arrival(int arriveT, Process *currProcess, Simulation *sim) : Event(arriveT, currProcess, sim) {}
//Handle event will do the main processing and create another event accordingly
void Arrival::handleEvent()
{
Simulation *sim = this->getSim();
Process *process = this->getProcess();
if (sim->isCpuBusy()) //check if cpu is currently proccessing anything or not
{
sim->addtoCpu(process); //if it is proccessing then add to end of the queue
}
else
{
sim->addtoCpu(process); //if cpu is free then add to queue and start cpu event should be added to the event list
StartCpu *newEvent = new StartCpu(this->getTime(), process, sim);
sim->addEvent(newEvent);
}
sim->getNextProcess(); //read new arriavl from the file
}
void Arrival::print()
{
if (!getSim()->isCpuBusy())
{
cout << "Time\t" << this->getTime() << ":\tProcess\t" << this->getProcess()->getId() << " arrives in system: CPU is free(Process begins execution)." << endl;
}
else
{
cout << "Time\t" << this->getTime() << ":\tProcess\t" << this->getProcess()->getId() << " arrives in system: CPU is busy(Process will be queued)." << endl;
}
}