blob: 9556c6c7cf5f7630a0a0ddb829b23b8e0e164f3f (
plain) (
blame)
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
|
#include "Dev.ns.h"
namespace Dev {
Vector<Device*> devices;
Device* irqHandler[16] = { NULL };
void handleIRQ(registers_t regs, int irq) {
if (irqHandler[irq] != NULL)
irqHandler[irq]->handleIRQ(regs, irq);
}
void registerDevice(Device* dev) {
unregisterDevice(dev); //Bad things could have happened
devices.push(dev);
}
void unregisterDevice(Device* dev) {
for (u32int i = 0; i < devices.size(); i++) {
if (devices[i] == dev) {
devices[i] = devices.back();
devices.pop();
return;
}
}
}
bool requestIRQ(Device* dev, int irq) {
if (irqHandler[irq] == NULL) {
irqHandler[irq] = dev;
return true;
} else {
return false;
}
}
Vector<Device*> findDevice(String _class) {
if (_class.empty()) return devices;
Vector<Device*> ret;
for (u32int i = 0; i < devices.size(); i++) {
String devclass = devices[i]->getClass();
if (devclass == _class) {
ret.push(devices[i]);
} else if (devclass.size() > _class.size()) {
if (devclass.substr(0, _class.size()) == _class) ret.push(devices[i]);
}
}
return ret;
}
}
|