aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/events/event.c
blob: d479ab73918270b1756650af157d230f6918f91f (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
#include <common.h>
#include <stddef.h>
#include <stdint.h>
#include <system.h>

typedef u32 (*event_func)(u8 *);

u32 (*event_table[])() = { [MAP_KEYBOARD] = NULL, [MAP_MOUSE] = NULL };

u32 event_map(u32 id, u8 *function)
{
	if (id >= sizeof(event_map) / sizeof(*event_map))
		return -1;

	event_table[id] = (u32)function;
	return 0;
}

u32 event_trigger(u32 id, u8 *data)
{
	if (id >= sizeof(event_map) / sizeof(*event_map)) {
		panic("Unknown event id!");
		return -1;
	}

	event_func location = (event_func)event_table[id];
	if (!location) {
		warn("Event %d not mapped!", id);
		return -1;
	}

	location(data);
	return 0;
}