-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.h
More file actions
90 lines (72 loc) · 2.48 KB
/
process.h
File metadata and controls
90 lines (72 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
88
89
90
#pragma once
#include <memory>
#include "ICommand.h"
#include <string>
#include <vector>
#include "screen-console.h"
class Process
{
public:
enum ProcessState
{
READY,
RUNNING,
WAITING,
FINISHED
};
Process(int pid, std::string name, ScreenConsole* consolePtr);
Process(int pid, std::string name, ScreenConsole* consolePtr, size_t memoryRequired, size_t frameSize);
void addCommand(ICommand::CommandType commandType);
void addCommand(ICommand::CommandType type, uint8_t ticks); //sleep
void addCommand(const std::vector<std::shared_ptr<ICommand>>& instructions, int repeats); //for
void executeCurrentCommand(int coreId) const;
void moveToNextLine();
bool isFinished() const;
int getRemainingTime() const;
int getCommandCounter () const;
int getLinesOfCode() const;
int getPID() const;
int getCPUCoreID() const;
size_t getNumPages();
ProcessState getState() const;
std::string getName() const;
void setFinishTime(const std::string& time);
std::string getFinishTime() const;
void setState(ProcessState newState);
void test_generateRandomCommands(int min, int max);
void screenProcess(int delay);
void runScreenProcess(int delay);
void generateTestCaseAlternatingCommands(int count);
void createCommandsFromInstructions(const std::string& instructions, int min, int max);
//memory
size_t getMemoryRequired() const;
void setMemoryPtr(void* ptr);
void* getMemoryPtr() const;
//symbol table management
bool declareVariable(const std::string& name, uint16_t value);
bool hasVariable(const std::string& name) const;
uint16_t getVariable(const std::string& name) const;
void setVariable(const std::string& name, uint16_t value);
void printSymbolTable() const;
const std::unordered_map<std::string, uint16_t>& getSymbolTable() const {
return symbolTable;
}
private:
int pid;
std::string name;
typedef std::vector<std::shared_ptr<ICommand>> Commands;
Commands CommandList;
ScreenConsole* consolePtr;
int commandCounter;
int cpuCoreID = -1;
std::string timeFinished;
ProcessState state;
//memory management
size_t memoryRequired;
void* memoryPtr = nullptr; // Pointer to the allocated memory
size_t pageSize;
size_t numPages;
//symbol table
static const size_t MAX_SYMBOL_TABLE_SIZE = 32;
std::unordered_map<std::string, uint16_t> symbolTable;
};