36 lines
873 B
C
36 lines
873 B
C
#include <hook.h>
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
tc_hooklist_s tc_new_hooklist(u32_t capacity)
|
|
{
|
|
tc_hooklist_s hooklist;
|
|
hooklist.capacity = capacity;
|
|
hooklist.num_hooks = 0;
|
|
hooklist.hooks = malloc(sizeof(tc_hook_s));
|
|
|
|
return hooklist;
|
|
}
|
|
|
|
void tc_add_to_hooklist(tc_hooklist_s *list, tc_fn_hook function, void *userdata)
|
|
{
|
|
if(list->num_hooks >= list->capacity)
|
|
{
|
|
puts("hook.c: Hook-Capacity exceeded!\n");
|
|
return;
|
|
}
|
|
list->hooks[list->num_hooks].function = function;
|
|
list->hooks[list->num_hooks].userdata = userdata;
|
|
++list->num_hooks;
|
|
}
|
|
|
|
void tc_run_hooklist(tc_hooklist_s *list, void *subject)
|
|
{
|
|
for(u32_t index = 0; index < list->num_hooks; ++index)
|
|
{
|
|
list->hooks[index].function(subject, list->hooks[index].userdata);
|
|
}
|
|
}
|
|
|