-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIO.cpp
More file actions
97 lines (79 loc) · 2.44 KB
/
IO.cpp
File metadata and controls
97 lines (79 loc) · 2.44 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// IO.cpp
//
#include <iostream>
#include <string>
#include <sstream>
#include <stddef.h>
#include <list>
#include <vector>
#include <algorithm>
#include <fstream>
#include <math.h>
#include "CPU.h"
#include "IO.h"
using namespace std;
//command - d #
void IO::commandRequestHardDisk(int num){
if(current_process_in_CPU_pid != -1){
//push the process that was in CPU into the hard disk #
hardDisks[num-1].push_back(current_process_in_CPU_pid);
//remove from CPU
removeProcessfromCPU();
}
else{ //when there is no process in cpu
cout << "*Error; There is no process in CPU." << endl;
return;
}
}
//command - p #
void IO::commandRequestPrinter(int num){
if(current_process_in_CPU_pid != -1){
//push the process that was in CPU into the printer #
printers[num-1].push_back(current_process_in_CPU_pid);
//remove from CPU
removeProcessfromCPU();
}
else{
cout << "*Error; There is no process in CPU." << endl;
return;
}
}
//command - S i
void IO::commandShowIO(){
//print out hard disks are currently used and in ready queue
for(int i = 0; i < num_of_hard_disks; i++){
if(!hardDisks[i].empty()){
checkIODevices = true;
cout << "Hard Disk " << i+1 << ": P" << hardDisks[i].front();
if(hardDisks[i].size() > 1){
cout << " ( ";
for(list<int>::iterator it= next(hardDisks[i].begin(), 1); it !=hardDisks[i].end(); ++it){
cout << "P" << *it << " ";
}
cout << ")";
}
cout << endl;
}
}
//print out printers are currently used and in ready queue
for(int j = 0; j < num_of_printers; j++){
if(!printers[j].empty()){
checkIODevices = true;
cout << "Printer " << j+1 << ": P" << printers[j].front();
if(printers[j].size() > 1){
cout << " ( ";
for(list<int>::iterator it= next(printers[j].begin(), 1); it !=printers[j].end(); ++it){
cout << "P" << *it << " ";
}
cout << ")";
}
cout << endl;
}
}
if(!checkIODevices){
cout << "There is no process in I/O devices." << endl;
}
else
cout << "*The processes in ( ) are in its Ready Queue." << endl;
}