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