Hooks by priority
[lttv.git] / ltt / branches / poly / lttv / lttv / hook.h
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
3 *
4 * 25/05/2004 Mathieu Desnoyers : Hook priorities
5 *
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
21 #ifndef HOOK_H
22 #define HOOK_H
23
24 #include <glib.h>
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). */
29
30 typedef gboolean (*LttvHook)(void *hook_data, void *call_data);
31
32
33 /* A list of hooks allows registering hooks to be called later. */
34
35 typedef GArray LttvHooks;
36
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
44 #define LTTV_PRIO_DEFAULT 0
45 typedef gint LttvHookPrio;
46
47 /* Create and destroy a list of hooks */
48
49 LttvHooks *lttv_hooks_new();
50
51 void lttv_hooks_destroy(LttvHooks *h);
52
53
54 /* Add a hook and its hook data to the list */
55
56 void lttv_hooks_add(LttvHooks *h, LttvHook f, void *hook_data, LttvHookPrio p);
57
58
59 /* Add a list of hooks to the list h */
60
61 void lttv_hooks_add_list(LttvHooks *h, LttvHooks *list);
62
63
64 /* Remove a hook from the list. Return the hook data. */
65
66 void *lttv_hooks_remove(LttvHooks *h, LttvHook f);
67
68
69 /* Remove a hook from the list checking that the hook data match. */
70
71 void lttv_hooks_remove_data(LttvHooks *h, LttvHook f, void *hook_data);
72
73
74 /* Remove a list of hooks from the hooks list in h. */
75
76 void lttv_hooks_remove_data_list(LttvHooks *h, LttvHooks *list);
77
78
79 /* Return the number of hooks in the list */
80
81 unsigned lttv_hooks_number(LttvHooks *h);
82
83
84 /* Return the hook at the specified position in the list.
85 * *f and *hook_data are NULL if no hook exists at that position. */
86
87 void lttv_hooks_get(LttvHooks *h, unsigned i, LttvHook *f, void **hook_data,
88 LttvHookPrio *p);
89
90
91 /* Remove the specified hook. The position of the following hooks may change */
92
93 void lttv_hooks_remove_by_position(LttvHooks *h, unsigned i);
94
95
96 /* Call all the hooks in the list, each with its hook data,
97 with the specified call data, in priority order. Return TRUE if one hook
98 returned TRUE. */
99
100 gboolean lttv_hooks_call(LttvHooks *h, void *call_data);
101
102
103 /* Call the hooks in the list in priority order until one returns true,
104 * in which case TRUE is returned. */
105
106 gboolean lttv_hooks_call_check(LttvHooks *h, void *call_data);
107
108
109 /* Call hooks from two lists in priority order. If priority is the same,
110 * hooks from h1 are called first. */
111
112 gboolean lttv_hooks_call_merge(LttvHooks *h1, void *call_data1,
113 LttvHooks *h2, void *call_data2);
114
115 gboolean lttv_hooks_call_check_merge(LttvHooks *h1, void *call_data1,
116 LttvHooks *h2, void *call_data2);
117
118 /* Sometimes different hooks need to be called based on the case. The
119 case is represented by an unsigned integer id */
120
121 typedef GPtrArray LttvHooksById;
122
123
124 /* Create and destroy a hooks by id list */
125
126 LttvHooksById *lttv_hooks_by_id_new();
127
128 void lttv_hooks_by_id_destroy(LttvHooksById *h);
129
130
131 /* Obtain the hooks for a given id, creating a list if needed */
132
133 LttvHooks *lttv_hooks_by_id_find(LttvHooksById *h, unsigned id);
134
135
136 /* Return an id larger than any for which a list exists. */
137
138 unsigned lttv_hooks_by_id_max_id(LttvHooksById *h);
139
140
141 /* Get the list of hooks for an id, NULL if none exists */
142
143 LttvHooks *lttv_hooks_by_id_get(LttvHooksById *h, unsigned id);
144
145
146 /* Remove the list of hooks associated with an id */
147
148 void lttv_hooks_by_id_remove(LttvHooksById *h, unsigned id);
149
150 #endif // HOOK_H
This page took 0.032427 seconds and 4 git commands to generate.