A program that mimics an OS

So I have to write a program that mimics the operating system, such as having PCBs, ReadyQueues and DeviceQueues. Devices and DeviceQueues is where I'm having trouble understanding. So from what I know, DeviceQueues has PCBs that wait for the device, and then those PCBs goes into the ReadyQueue afterwards. I was wondering if my approach is correct. I created a DeviceQueue class that has the functions to add into the queue, pop from the queue, prints the queue and returns the front of the queue. Then in my Device class I set the name of the device and the device ID, and I also have a deviceQueue object inside my class, which would mean that my device has a queue of PCBs that can be then pushed into the ReadyQueue. My concern right now is creating a device object and placing those items into that queue. I have this function :
1
2
3
4
void setQueueForDevice(DeviceQueue theDQ){

		d.setDeviceQueue(theDQ);
	}
in another class and I don't know if that's enough to set a DeviceQueue as the Device's queue, and then when I create a new Device, I'll add the PCBs into the device.

DeviceQueue.h
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
#ifndef DEVICE_QUEUE_H
#define DEVICE_QUEUE_H
#include <list>
#include <memory>
#include "PCB.h"

class DeviceQueue{

public:

	DeviceQueue(){}

	~DeviceQueue(){}

	void pushIntoQueue(std::shared_ptr<PCB> aPCB){

		dQueue.push_back(aPCB);
	}

	// Gets whatever is at the front of the queue
	std::shared_ptr<PCB> getFront(){

		return dQueue.front();
	}

	// Removes the first element in the queue
	void deviceQueueDequeue(){

		dQueue.pop_front();
	}

	// Prints the numbers of the PCBs
	void printDQ(){

		for(std::list< std::shared_ptr<PCB> >::iterator it = dQueue.begin(); it != dQueue.end(); it++ ){

			std::cout << (*it)->getPID() << " ";
		}
		std::cout << '\n';
	}


private:
	std::list< std::shared_ptr<PCB> > dQueue;
};

#endif 


Device.h
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
#ifndef DEVICE_H
#define DEVICE_H
#include "DeviceQueue.h"

static int printerNumber = 0;
static int cdNumber = 0;
static int diskNumber = 0;
class Device{

public:

	Device() : deviceID(0), deviceName("") {}

	int getNumber(){

		return deviceID;
	}

	std::string getName(){

		return deviceName;
	}

	void setPrinter(){
		
		deviceName = "Printer";	
		printerNumber++;	
		deviceID = printerNumber;
	}

	void setCD(){

		deviceName = "CD/RW";
		cdNumber++;
		deviceID = cdNumber;
	}

	void setDisk(){

		deviceName = "Disk";
		diskNumber++;
		deviceID = diskNumber;
	}

	void print(){

		std::cout << deviceName << " " << deviceID << '\n';
	}

	void dequeue(){

		aDeviceQueue.deviceQueueDequeue();
	}

	void printDQ(){

		aDeviceQueue.printDQ();
	}

	void setDeviceQueue(DeviceQueue aQueue){

		aDeviceQueue = aQueue;
	}

	std::shared_ptr<PCB> getFront(){

		return aDeviceQueue.getFront();
	}

	
private:

	int deviceID;
	std::string deviceName;
	DeviceQueue aDeviceQueue;
};

#endif 
Topic archived. No new replies allowed.