blob: 3afc267771c2dcaeb99a2c2cc31903dd7a3da150 (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#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*> findDevices(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;
}
Device* findDevice(String _class, u32int idx) {
for (u32int i = 0; i < devices.size(); i++) {
String devclass = devices[i]->getClass();
if (devclass == _class or (devclass.size() > _class.size() and devclass.substr(0, _class.size()) == _class)) {
if (idx == 0) {
return devices[i];
} else {
idx--;
}
}
}
return NULL;
}
}
|