aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2020-08-17 12:08:38 +0200
committerMarvin Borner2020-08-17 12:08:38 +0200
commit0ba9ee15d0a229c619f35a5db04e45fe8861c3c9 (patch)
treeed780da6855585c42e1cfb95dfe0d527a131016b
parent4ff8a6f6d65bb7867854daada597bfe5ca47ec3f (diff)
Fixed mapping of multiple events of same type
-rw-r--r--kernel/features/event.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/kernel/features/event.c b/kernel/features/event.c
index e6639e6..320b45a 100644
--- a/kernel/features/event.c
+++ b/kernel/features/event.c
@@ -2,17 +2,20 @@
#include <assert.h>
#include <def.h>
+#include <list.h>
#include <sys.h>
-u32 (*event_table[])() = { [EVENT_KEYBOARD] = NULL, [EVENT_MOUSE] = NULL };
+struct list *event_table[] = { [EVENT_KEYBOARD] = NULL, [EVENT_MOUSE] = NULL };
-u32 event_map(enum event id, u32 (*function)())
+u32 event_map(enum event id, u32 *func)
{
- // TODO: Support multiple events of same type
+ // TODO: Check if function is already mapped
if (id >= sizeof(event_table) / sizeof(*event_table))
return -1;
- event_table[id] = function;
+ if (event_table[id] == NULL)
+ event_table[id] = (struct list *)list_new();
+ list_add((struct list *)event_table[id], (void *)func);
return 0;
}
@@ -20,13 +23,21 @@ u32 event_trigger(enum event id, u32 *data)
{
assert(id < sizeof(event_table) / sizeof(*event_table));
- u32 (*location)(u32 *) = event_table[id];
- if (!location) {
+ struct node *iterator = ((struct list *)event_table[id])->head;
+
+ if (!iterator->data) {
printf("Event %d not mapped!\n", id);
- return -1;
+ return 1;
+ }
+
+ while (1) {
+ u32 *func = iterator->data;
+ iterator = iterator->next;
+ if (iterator == NULL)
+ break;
}
// TODO: Execute event function in ring3 with process stack, ...
- location(data);
+ /* location(data); */
return 0;
}