1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 support for manipulating lists of hook functions.
7 <!-- ##### SECTION Long_Description ##### -->
9 The #GHookList, #GHook and their related functions provide support for
10 lists of hook functions. Functions can be added and removed from the lists,
11 and the list of hook functions can be invoked.
15 <!-- ##### SECTION See_Also ##### -->
20 <!-- ##### SECTION Stability_Level ##### -->
23 <!-- ##### STRUCT GHookList ##### -->
25 The <structname>GHookList</structname> struct represents a
26 list of hook functions.
29 @seq_id: the next free #GHook id.
30 @hook_size: the size of the #GHookList elements, in bytes.
31 @is_setup: 1 if the #GHookList has been initialized.
32 @hooks: the first #GHook element in the list.
34 @finalize_hook: the function to call to finalize a #GHook element. The
35 default behaviour is to call the hooks <function>destroy</function> function.
38 <!-- ##### USER_FUNCTION GHookFinalizeFunc ##### -->
40 Defines the type of function to be called when a hook in a
41 list of hooks gets finalized.
44 @hook_list: a #GHookList.
45 @hook: the hook in @hook_list that gets finalized.
48 <!-- ##### STRUCT GHook ##### -->
50 The <structname>GHook</structname> struct represents a single hook
51 function in a #GHookList.
54 @data: data which is passed to func when this hook is invoked.
55 @next: pointer to the next hook in the list.
56 @prev: pointer to the previous hook in the list.
57 @ref_count: the reference count of this hook.
58 @hook_id: the id of this hook, which is unique within its list.
59 @flags: flags which are set for this hook. See #GHookFlagMask for
61 @func: the function to call when this hook is invoked. The possible
62 signatures for this function are #GHookFunc and #GHookCheckFunc.
63 @destroy: the default <function>finalize_hook</function> function of a
64 #GHookList calls this member of the hook that is being finalized.
66 <!-- ##### USER_FUNCTION GHookFunc ##### -->
68 Defines the type of a hook function that can be invoked
69 by g_hook_list_invoke().
72 @data: the data field of the #GHook is passed to the hook function here.
75 <!-- ##### USER_FUNCTION GHookCheckFunc ##### -->
77 Defines the type of a hook function that can be invoked
78 by g_hook_list_invoke_check().
81 @data: the data field of the #GHook is passed to the hook function here.
82 @Returns: %FALSE if the #GHook should be destroyed.
85 <!-- ##### FUNCTION g_hook_list_init ##### -->
87 Initializes a #GHookList.
88 This must be called before the #GHookList is used.
91 @hook_list: a #GHookList.
92 @hook_size: the size of each element in the #GHookList, typically
93 <literal>sizeof (GHook)</literal>.
96 <!-- ##### FUNCTION g_hook_list_invoke ##### -->
98 Calls all of the #GHook functions in a #GHookList.
101 @hook_list: a #GHookList.
102 @may_recurse: %TRUE if functions which are already running (e.g. in another
103 thread) can be called. If set to %FALSE, these are skipped.
106 <!-- ##### FUNCTION g_hook_list_invoke_check ##### -->
108 Calls all of the #GHook functions in a #GHookList.
109 Any function which returns %TRUE is removed from the #GHookList.
112 @hook_list: a #GHookList.
113 @may_recurse: %TRUE if functions which are already running (e.g. in another
114 thread) can be called. If set to %FALSE, these are skipped.
117 <!-- ##### FUNCTION g_hook_list_marshal ##### -->
119 Calls a function on each valid #GHook.
122 @hook_list: a #GHookList.
123 @may_recurse: %TRUE if hooks which are currently running (e.g. in another
124 thread) are considered valid. If set to %FALSE, these are skipped.
125 @marshaller: the function to call for each #GHook.
126 @marshal_data: data to pass to @marshaller.
129 <!-- ##### USER_FUNCTION GHookMarshaller ##### -->
131 Defines the type of function used by g_hook_list_marshal().
135 @marshal_data: user data.
138 <!-- ##### FUNCTION g_hook_list_marshal_check ##### -->
140 Calls a function on each valid #GHook and destroys it if the
141 function returns %FALSE.
144 @hook_list: a #GHookList.
145 @may_recurse: %TRUE if hooks which are currently running (e.g. in another
146 thread) are considered valid. If set to %FALSE, these are skipped.
147 @marshaller: the function to call for each #GHook.
148 @marshal_data: data to pass to @marshaller.
151 <!-- ##### USER_FUNCTION GHookCheckMarshaller ##### -->
153 Defines the type of function used by g_hook_list_marshal_check().
157 @marshal_data: user data.
158 @Returns: %FALSE if @hook should be destroyed.
161 <!-- ##### FUNCTION g_hook_list_clear ##### -->
163 Removes all the #GHook elements from a #GHookList.
166 @hook_list: a #GHookList.
169 <!-- ##### FUNCTION g_hook_alloc ##### -->
171 Allocates space for a #GHook and initializes it.
174 @hook_list: a #GHookList.
175 @Returns: a new #GHook.
178 <!-- ##### MACRO g_hook_append ##### -->
180 Appends a #GHook onto the end of a #GHookList.
183 @hook_list: a #GHookList.
184 @hook: the #GHook to add to the end of @hook_list.
187 <!-- ##### FUNCTION g_hook_prepend ##### -->
189 Prepends a #GHook on the start of a #GHookList.
192 @hook_list: a #GHookList.
193 @hook: the #GHook to add to the start of @hook_list.
196 <!-- ##### FUNCTION g_hook_insert_before ##### -->
198 Inserts a #GHook into a #GHookList, before a given #GHook.
201 @hook_list: a #GHookList.
202 @sibling: the #GHook to insert the new #GHook before.
203 @hook: the #GHook to insert.
206 <!-- ##### FUNCTION g_hook_insert_sorted ##### -->
208 Inserts a #GHook into a #GHookList, sorted by the given function.
211 @hook_list: a #GHookList.
212 @hook: the #GHook to insert.
213 @func: the comparison function used to sort the #GHook elements.
216 <!-- ##### USER_FUNCTION GHookCompareFunc ##### -->
218 Defines the type of function used to compare #GHook elements in
219 g_hook_insert_sorted().
222 @new_hook: the #GHook being inserted.
223 @sibling: the #GHook to compare with @new_hook.
224 @Returns: a value <= 0 if @new_hook should be before @sibling.
227 <!-- ##### FUNCTION g_hook_compare_ids ##### -->
229 Compares the ids of two #GHook elements, returning a negative value
230 if the second id is greater than the first.
234 @sibling: a #GHook to compare with @new_hook.
235 @Returns: a value <= 0 if the id of @sibling is >= the id of @new_hook.
238 <!-- ##### FUNCTION g_hook_get ##### -->
240 Returns the #GHook with the given id, or %NULL if it is not found.
243 @hook_list: a #GHookList.
245 @Returns: the #GHook with the given id, or %NULL if it is not found.
248 <!-- ##### FUNCTION g_hook_find ##### -->
250 Finds a #GHook in a #GHookList using the given function to test for a match.
253 @hook_list: a #GHookList.
254 @need_valids: %TRUE if #GHook elements which have been destroyed should be
256 @func: the function to call for each #GHook, which should return %TRUE when
257 the #GHook has been found.
258 @data: the data to pass to @func.
259 @Returns: the found #GHook or %NULL if no matching #GHook is found.
262 <!-- ##### USER_FUNCTION GHookFindFunc ##### -->
264 Defines the type of the function passed to g_hook_find().
268 @data: user data passed to g_hook_find_func().
269 @Returns: %TRUE if the required #GHook has been found.
272 <!-- ##### FUNCTION g_hook_find_data ##### -->
274 Finds a #GHook in a #GHookList with the given data.
277 @hook_list: a #GHookList.
278 @need_valids: %TRUE if #GHook elements which have been destroyed should be
280 @data: the data to find.
281 @Returns: the #GHook with the given @data or %NULL if no matching
285 <!-- ##### FUNCTION g_hook_find_func ##### -->
287 Finds a #GHook in a #GHookList with the given function.
290 @hook_list: a #GHookList.
291 @need_valids: %TRUE if #GHook elements which have been destroyed should be
293 @func: the function to find.
294 @Returns: the #GHook with the given @func or %NULL if no matching
298 <!-- ##### FUNCTION g_hook_find_func_data ##### -->
300 Finds a #GHook in a #GHookList with the given function and data.
303 @hook_list: a #GHookList.
304 @need_valids: %TRUE if #GHook elements which have been destroyed should be
306 @func: the function to find.
307 @data: the data to find.
308 @Returns: the #GHook with the given @func and @data or %NULL if no matching
312 <!-- ##### FUNCTION g_hook_first_valid ##### -->
314 Returns the first #GHook in a #GHookList which has not been destroyed.
315 The reference count for the #GHook is incremented, so you must call
316 g_hook_unref() to restore it when no longer needed. (Or call
317 g_hook_next_valid() if you are stepping through the #GHookList.)
320 @hook_list: a #GHookList.
321 @may_be_in_call: %TRUE if hooks which are currently running (e.g. in another
322 thread) are considered valid. If set to %FALSE, these are skipped.
323 @Returns: the first valid #GHook, or %NULL if none are valid.
326 <!-- ##### FUNCTION g_hook_next_valid ##### -->
328 Returns the next #GHook in a #GHookList which has not been destroyed.
329 The reference count for the #GHook is incremented, so you must call
330 g_hook_unref() to restore it when no longer needed. (Or continue to call
331 g_hook_next_valid() until %NULL is returned.)
335 @hook_list: a #GHookList.
336 @hook: the current #GHook.
337 @may_be_in_call: %TRUE if hooks which are currently running (e.g. in another
338 thread) are considered valid. If set to %FALSE, these are skipped.
339 @Returns: the next valid #GHook, or %NULL if none are valid.
342 <!-- ##### ENUM GHookFlagMask ##### -->
344 Flags used internally in the #GHook implementation.
347 @G_HOOK_FLAG_ACTIVE: set if the hook has not been destroyed.
348 @G_HOOK_FLAG_IN_CALL: set if the hook is currently being run.
349 @G_HOOK_FLAG_MASK: A mask covering all bits reserved for
350 hook flags; see #G_HOOK_FLAGS_USER_SHIFT
352 <!-- ##### MACRO G_HOOK_FLAGS ##### -->
354 Returns the flags of a hook.
360 <!-- ##### MACRO G_HOOK_FLAG_USER_SHIFT ##### -->
362 The position of the first bit which is not reserved for internal
363 use be the #GHook implementation, i.e.
364 <literal>1 << G_HOOK_FLAG_USER_SHIFT</literal> is the first bit
365 which can be used for application-defined flags.
370 <!-- ##### MACRO G_HOOK ##### -->
372 Casts a pointer to a <literal>GHook*</literal>.
378 <!-- ##### MACRO G_HOOK_IS_VALID ##### -->
380 Returns %TRUE if the #GHook is valid, i.e. it is in a #GHookList, it is active
381 and it has not been destroyed.
385 @Returns: %TRUE if the #GHook is valid.
388 <!-- ##### MACRO G_HOOK_ACTIVE ##### -->
390 Returns %TRUE if the #GHook is active, which is normally %TRUE until the #GHook
395 @Returns: %TRUE if the #GHook is active.
398 <!-- ##### MACRO G_HOOK_IN_CALL ##### -->
400 Returns %TRUE if the #GHook function is currently executing.
404 @Returns: %TRUE if the #GHook function is currently executing.
407 <!-- ##### MACRO G_HOOK_IS_UNLINKED ##### -->
409 Returns %TRUE if the #GHook is not in a #GHookList.
414 @Returns: %TRUE if the #GHook is not in a #GHookList.
417 <!-- ##### FUNCTION g_hook_ref ##### -->
419 Increments the reference count for a #GHook.
422 @hook_list: a #GHookList.
423 @hook: the #GHook to increment the reference count of.
424 @Returns: the @hook that was passed in (since 2.6)
427 <!-- ##### FUNCTION g_hook_unref ##### -->
429 Decrements the reference count of a #GHook.
430 If the reference count falls to 0, the #GHook is removed from the #GHookList
431 and g_hook_free() is called to free it.
434 @hook_list: a #GHookList.
435 @hook: the #GHook to unref.
438 <!-- ##### FUNCTION g_hook_free ##### -->
440 Calls the #GHookList @hook_free function if it exists, and frees the memory
441 allocated for the #GHook.
444 @hook_list: a #GHookList.
445 @hook: the #GHook to free.
448 <!-- ##### FUNCTION g_hook_destroy ##### -->
450 Destroys a #GHook, given its ID.
453 @hook_list: a #GHookList.
455 @Returns: %TRUE if the #GHook was found in the #GHookList and destroyed.
458 <!-- ##### FUNCTION g_hook_destroy_link ##### -->
460 Removes one #GHook from a #GHookList, marking it inactive and calling
461 g_hook_unref() on it.
464 @hook_list: a #GHookList.
465 @hook: the #GHook to remove.