c5d77517 |
1 | #ifndef HOOK_H |
2 | #define HOOK_H |
3 | |
858bd80a |
4 | #include <glib.h> |
c5d77517 |
5 | |
6 | /* A hook is a function to call with the supplied hook data, and with |
7 | call site specific data (e.g., hooks for events are called with a |
8 | pointer to the current event). */ |
dc877563 |
9 | |
10 | typedef gboolean (*LttvHook)(void *hook_data, void *call_data); |
c5d77517 |
11 | |
12 | |
13 | /* A list of hooks allows registering hooks to be called later. */ |
14 | |
996acd92 |
15 | typedef GArray LttvHooks; |
dc877563 |
16 | |
17 | |
18 | /* Create and destroy a list of hooks */ |
19 | |
20 | LttvHooks *lttv_hooks_new(); |
21 | |
22 | void lttv_hooks_destroy(LttvHooks *h); |
23 | |
24 | |
25 | /* Add a hook and its hook data to the list */ |
26 | |
27 | void lttv_hooks_add(LttvHooks *h, LttvHook f, void *hook_data); |
28 | |
29 | |
30 | /* Add a list of hooks to the list h */ |
31 | |
ffd54a90 |
32 | void lttv_hooks_add_list(LttvHooks *h, LttvHooks *list); |
dc877563 |
33 | |
34 | |
35 | /* Remove a hook from the list. Return the hook data. */ |
36 | |
37 | void *lttv_hooks_remove(LttvHooks *h, LttvHook f); |
38 | |
39 | |
40 | /* Remove a hook from the list checking that the hook data match. */ |
41 | |
42 | void lttv_hooks_remove_data(LttvHooks *h, LttvHook f, void *hook_data); |
43 | |
44 | |
45 | /* Remove a list of hooks from the hooks list in h. */ |
c5d77517 |
46 | |
ffd54a90 |
47 | void lttv_hooks_remove_data_list(LttvHooks *h, LttvHook *list); |
c5d77517 |
48 | |
c5d77517 |
49 | |
dc877563 |
50 | /* Return the number of hooks in the list */ |
c5d77517 |
51 | |
dc877563 |
52 | unsigned lttv_hooks_number(LttvHooks *h); |
1b82f325 |
53 | |
1b82f325 |
54 | |
dc877563 |
55 | /* Return the hook at the specified position in the list */ |
1b82f325 |
56 | |
dc877563 |
57 | void lttv_hooks_get(LttvHooks *h, unsigned i, LttvHook *f, void **hook_data); |
1b82f325 |
58 | |
1b82f325 |
59 | |
dc877563 |
60 | /* Remove the specified hook. The position of the following hooks may change */ |
61 | |
62 | void lttv_hooks_remove_by_position(LttvHooks *h, unsigned i); |
63 | |
64 | |
65 | /* Call all the hooks in the list, each with its hook data, |
66 | with the specified call data. Return TRUE is one hook returned TRUE. */ |
67 | |
68 | gboolean lttv_hooks_call(LttvHooks *h, void *call_data); |
69 | |
70 | |
71 | /* Call the hooks in the list until one returns true, in which case TRUE is |
72 | returned. */ |
73 | |
74 | gboolean lttv_hooks_call_check(LttvHooks *h, void *call_data); |
c5d77517 |
75 | |
76 | |
77 | /* Sometimes different hooks need to be called based on the case. The |
dc877563 |
78 | case is represented by an unsigned integer id */ |
79 | |
ffd54a90 |
80 | typedef GPtrArray LttvHooksById; |
dc877563 |
81 | |
82 | |
83 | /* Create and destroy a hooks by id list */ |
84 | |
85 | LttvHooksById *lttv_hooks_by_id_new(); |
86 | |
87 | void lttv_hooks_by_id_destroy(LttvHooksById *h); |
88 | |
89 | |
90 | /* Obtain the hooks for a given id, creating a list if needed */ |
91 | |
92 | LttvHooks *lttv_hooks_by_id_find(LttvHooksById *h, unsigned id); |
93 | |
94 | |
95 | /* Return an id larger than any for which a list exists. */ |
96 | |
97 | unsigned lttv_hooks_by_id_max_id(LttvHooksById *h); |
98 | |
c5d77517 |
99 | |
dc877563 |
100 | /* Get the list of hooks for an id, NULL if none exists */ |
c5d77517 |
101 | |
dc877563 |
102 | LttvHooks *lttv_hooks_by_id_get(LttvHooksById *h, unsigned id); |
c5d77517 |
103 | |
c5d77517 |
104 | |
dc877563 |
105 | /* Remove the list of hooks associated with an id */ |
c5d77517 |
106 | |
dc877563 |
107 | void lttv_hooks_by_id_remove(LttvHooksById *h, unsigned id); |
c5d77517 |
108 | |
109 | #endif // HOOK_H |