-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
87 lines (69 loc) · 2.48 KB
/
Copy pathmain.cpp
File metadata and controls
87 lines (69 loc) · 2.48 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
// Copyright 2016
#include <fstream>
#include <iostream>
#include <list>
#include <thread>
#include <string>
#include "FixedPriorityScheduler.hpp"
#include "GantChartHorizontal.hpp"
#include "GanttChartWriter.hpp"
#include "Process.hpp"
#include "ProcessReader.hpp"
#include "SchedulerResult.hpp"
#include "SchedulerStep.hpp"
#include "SocketProcessSender.hpp"
#include "RoundRobinScheduler.hpp"
void fixedPriorityScheduler(std::list<Process> processes, std::string fileName,
SocketProcessSender socketSender);
void roundRobinPriorityScheduler(std::list<Process> processes, int quanta,
std::string fileName, SocketProcessSender socketSender);
void checkInput(int numberOfArguments) {
if (numberOfArguments < 3) {
std::cout << "Error de uso: especificar nombre de archivo de entrada y numero de puerto de socket" << '\n';
std::cout << "Ejemplo: " << "./main.o procesos.txt 8000" << '\n';
exit(-1);
}
}
int main(int argc, char const *argv[]) {
checkInput(argc);
ProcessReader reader(argv[1]);
auto pair = reader.read();
std::list<Process> processes = pair.second;
SocketProcessSender socketSender(atoi(argv[2]));
std::thread fixedPriorityThread(fixedPriorityScheduler, processes, argv[1],
socketSender);
std::thread roundRobinThread(roundRobinPriorityScheduler, processes,
pair.first, argv[1], socketSender);
fixedPriorityThread.join();
roundRobinThread.join();
return 0;
}
void fixedPriorityScheduler(std::list<Process> processes, std::string fileName,
SocketProcessSender socketSender) {
std::ofstream out;
out.open(fileName + "_FixedPriority");
FixedPriorityScheduler scheduler(processes);
std::cout << "Obteniendo steps" << '\n';
std::list<SchedulerStep> steps = scheduler.getSteps();
std::cout << "Listo" << '\n';
GanttChartWriter writer(steps, out);
writer.write();
out << "\n \n Gantt Chart horizontal: \n";
GanttChartHorizontal horizontal(steps, out);
horizontal.write();
out.close();
}
void roundRobinPriorityScheduler(std::list<Process> processes, int quanta,
std::string fileName, SocketProcessSender socketSender) {
std::ofstream out;
out.open(fileName + "_RoundRobin");
RoundRobinScheduler scheduler(quanta, processes);
std::list<SchedulerStep> steps = scheduler.getSteps();
GanttChartWriter writer(steps, out);
writer.write();
out << "\n \n Gantt Chart horizontal: \n";
GanttChartHorizontal horizontal(steps, out);
horizontal.write();
socketSender.send("Round robin: ", scheduler.getResult());
out.close();
}