9c312311 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Michel Dagenais |
3 | * |
47e76340 |
4 | * 25/05/2004 Mathieu Desnoyers : Hook priorities |
5 | * |
9c312311 |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License Version 2 as |
8 | * published by the Free Software Foundation; |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program; if not, write to the Free Software |
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
18 | * MA 02111-1307, USA. |
19 | */ |
20 | |
c5d77517 |
21 | #ifndef HOOK_H |
22 | #define HOOK_H |
23 | |
858bd80a |
24 | #include <glib.h> |
c5d77517 |
25 | |
26 | /* A hook is a function to call with the supplied hook data, and with |
27 | call site specific data (e.g., hooks for events are called with a |
28 | pointer to the current event). */ |
dc877563 |
29 | |
30 | typedef gboolean (*LttvHook)(void *hook_data, void *call_data); |
c5d77517 |
31 | |
32 | |
33 | /* A list of hooks allows registering hooks to be called later. */ |
34 | |
996acd92 |
35 | typedef GArray LttvHooks; |
dc877563 |
36 | |
47e76340 |
37 | /* A priority associated with each hook, from -19 (high prio) to 20 (low prio) |
38 | * 0 being the default priority. |
39 | * |
40 | * Priority ordering is done in the lttv_hooks_add and lttv_hooks_add_list |
41 | * functions. Hook removal does not change list order. |
42 | */ |
43 | |
bb545b3c |
44 | #define LTTV_PRIO_DEFAULT 50 |
45 | #define LTTV_PRIO_HIGH 0 |
46 | #define LTTV_PRIO_LOW 99 |
47 | |
47e76340 |
48 | typedef gint LttvHookPrio; |
dc877563 |
49 | |
50 | /* Create and destroy a list of hooks */ |
51 | |
52 | LttvHooks *lttv_hooks_new(); |
53 | |
54 | void lttv_hooks_destroy(LttvHooks *h); |
55 | |
56 | |
57 | /* Add a hook and its hook data to the list */ |
58 | |
47e76340 |
59 | void lttv_hooks_add(LttvHooks *h, LttvHook f, void *hook_data, LttvHookPrio p); |
dc877563 |
60 | |
61 | |
62 | /* Add a list of hooks to the list h */ |
63 | |
bb545b3c |
64 | void lttv_hooks_add_list(LttvHooks *h, const LttvHooks *list); |
dc877563 |
65 | |
66 | |
67 | /* Remove a hook from the list. Return the hook data. */ |
68 | |
69 | void *lttv_hooks_remove(LttvHooks *h, LttvHook f); |
70 | |
71 | |
72 | /* Remove a hook from the list checking that the hook data match. */ |
73 | |
74 | void lttv_hooks_remove_data(LttvHooks *h, LttvHook f, void *hook_data); |
75 | |
76 | |
77 | /* Remove a list of hooks from the hooks list in h. */ |
c5d77517 |
78 | |
3f328da1 |
79 | void lttv_hooks_remove_list(LttvHooks *h, LttvHooks *list); |
c5d77517 |
80 | |
c5d77517 |
81 | |
dc877563 |
82 | /* Return the number of hooks in the list */ |
c5d77517 |
83 | |
dc877563 |
84 | unsigned lttv_hooks_number(LttvHooks *h); |
1b82f325 |
85 | |
1b82f325 |
86 | |
47e76340 |
87 | /* Return the hook at the specified position in the list. |
88 | * *f and *hook_data are NULL if no hook exists at that position. */ |
1b82f325 |
89 | |
47e76340 |
90 | void lttv_hooks_get(LttvHooks *h, unsigned i, LttvHook *f, void **hook_data, |
91 | LttvHookPrio *p); |
1b82f325 |
92 | |
1b82f325 |
93 | |
dc877563 |
94 | /* Remove the specified hook. The position of the following hooks may change */ |
8436038a |
95 | /* The hook is removed from the list event if its ref_count is higher than 1 */ |
dc877563 |
96 | |
97 | void lttv_hooks_remove_by_position(LttvHooks *h, unsigned i); |
98 | |
99 | |
100 | /* Call all the hooks in the list, each with its hook data, |
47e76340 |
101 | with the specified call data, in priority order. Return TRUE if one hook |
102 | returned TRUE. */ |
dc877563 |
103 | |
104 | gboolean lttv_hooks_call(LttvHooks *h, void *call_data); |
105 | |
106 | |
47e76340 |
107 | /* Call the hooks in the list in priority order until one returns true, |
108 | * in which case TRUE is returned. */ |
dc877563 |
109 | |
110 | gboolean lttv_hooks_call_check(LttvHooks *h, void *call_data); |
c5d77517 |
111 | |
112 | |
47e76340 |
113 | /* Call hooks from two lists in priority order. If priority is the same, |
114 | * hooks from h1 are called first. */ |
115 | |
116 | gboolean lttv_hooks_call_merge(LttvHooks *h1, void *call_data1, |
117 | LttvHooks *h2, void *call_data2); |
118 | |
119 | gboolean lttv_hooks_call_check_merge(LttvHooks *h1, void *call_data1, |
120 | LttvHooks *h2, void *call_data2); |
121 | |
c5d77517 |
122 | /* Sometimes different hooks need to be called based on the case. The |
dc877563 |
123 | case is represented by an unsigned integer id */ |
124 | |
ffd54a90 |
125 | typedef GPtrArray LttvHooksById; |
dc877563 |
126 | |
127 | |
128 | /* Create and destroy a hooks by id list */ |
129 | |
130 | LttvHooksById *lttv_hooks_by_id_new(); |
131 | |
132 | void lttv_hooks_by_id_destroy(LttvHooksById *h); |
133 | |
134 | |
135 | /* Obtain the hooks for a given id, creating a list if needed */ |
136 | |
137 | LttvHooks *lttv_hooks_by_id_find(LttvHooksById *h, unsigned id); |
138 | |
139 | |
140 | /* Return an id larger than any for which a list exists. */ |
141 | |
142 | unsigned lttv_hooks_by_id_max_id(LttvHooksById *h); |
143 | |
c5d77517 |
144 | |
dc877563 |
145 | /* Get the list of hooks for an id, NULL if none exists */ |
c5d77517 |
146 | |
dc877563 |
147 | LttvHooks *lttv_hooks_by_id_get(LttvHooksById *h, unsigned id); |
c5d77517 |
148 | |
c5d77517 |
149 | |
dc877563 |
150 | /* Remove the list of hooks associated with an id */ |
c5d77517 |
151 | |
dc877563 |
152 | void lttv_hooks_by_id_remove(LttvHooksById *h, unsigned id); |
c5d77517 |
153 | |
154 | #endif // HOOK_H |