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 <!-- ##### STRUCT GHookList ##### -->
23 <informaltable pgwide=1 frame="none" role="struct">
24 <tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*">
28 <entry>#guint seq_id;</entry>
29 <entry>the next free #GHook id.</entry>
33 <entry>#guint hook_size;</entry>
34 <entry>the size of the #GHookList elements, in bytes.</entry>
38 <entry>#guint is_setup : 1;</entry>
39 <entry>1 if the #GHookList has been initialized.</entry>
43 <entry>#GHook *hooks;</entry>
44 <entry>the first #GHook element in the list.</entry>
48 <entry>#GMemChunk *hook_memchunk;</entry>
49 <entry>the #GMemChunk used for allocating the #GHook elements.</entry>
53 <entry>#GHookFreeFunc hook_free;</entry>
54 <entry>the function to call to free a #GHook element.</entry>
58 <entry>#GHookFreeFunc hook_destroy;</entry>
59 <entry>the function to call to destory a #GHook element.</entry>
62 </tbody></tgroup></informaltable>
73 <!-- ##### STRUCT GHook ##### -->
76 <informaltable pgwide=1 frame="none" role="struct">
77 <tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*">
81 <entry>#gpointer data;</entry>
86 <entry>#GHook *next;</entry>
91 <entry>#GHook *prev;</entry>
96 <entry>#guint ref_count;</entry>
101 <entry>#guint hook_id;</entry>
106 <entry>#guint flags;</entry>
111 <entry>#gpointer data;</entry>
116 <entry>#GDestroyNotify destroy;</entry>
120 </tbody></tgroup></informaltable>
132 <!-- ##### USER_FUNCTION GHookFunc ##### -->
140 <!-- ##### USER_FUNCTION GHookCheckFunc ##### -->
149 <!-- ##### USER_FUNCTION GHookMarshaller ##### -->
156 <!-- # Unused Parameters # -->
160 <!-- ##### USER_FUNCTION GHookCheckMarshaller ##### -->
168 <!-- # Unused Parameters # -->
172 <!-- ##### FUNCTION g_hook_list_init ##### -->
174 Initializes a #GHookList.
175 This must be called before the #GHookList is used.
178 @hook_list: a #GHookList.
179 @hook_size: the size of each element in the #GHookList, typically
183 <!-- ##### FUNCTION g_hook_list_invoke ##### -->
185 Calls all of the #GHook functions in a #GHookList.
188 @hook_list: a #GHookList.
189 @may_recurse: TRUE if functions which are already running (e.g. in another
190 thread) can be called. If set to FALSE, these are skipped.
193 <!-- ##### FUNCTION g_hook_list_invoke_check ##### -->
195 Calls all of the #GHook functions in a #GHookList.
196 Any function which returns TRUE is removed from the #GHookList.
199 @hook_list: a #GHookList.
200 @may_recurse: TRUE if functions which are already running (e.g. in another
201 thread) can be called. If set to FALSE, these are skipped.
204 <!-- ##### FUNCTION g_hook_list_marshal ##### -->
209 @hook_list: a #GHookList.
213 <!-- # Unused Parameters # -->
217 <!-- ##### FUNCTION g_hook_list_marshal_check ##### -->
222 @hook_list: a #GHookList.
226 <!-- # Unused Parameters # -->
230 <!-- ##### FUNCTION g_hook_list_clear ##### -->
232 Removes all the #GHook elements from a #GHookList.
235 @hook_list: a #GHookList.
238 <!-- ##### FUNCTION g_hook_alloc ##### -->
240 Allocates space for a #GHook and initializes it.
243 @hook_list: a #GHookList.
244 @Returns: a new #GHook.
247 <!-- ##### MACRO g_hook_append ##### -->
249 Appends a #GHook onto the end of a #GHookList.
252 @hook_list: a #GHookList.
253 @hook: the #GHook to add to the end of @hook_list.
256 <!-- ##### FUNCTION g_hook_prepend ##### -->
258 Prepends a #GHook on the start of a #GHookList.
261 @hook_list: a #GHookList.
262 @hook: the #GHook to add to the start of @hook_list.
265 <!-- ##### FUNCTION g_hook_insert_before ##### -->
267 Inserts a #GHook into a #GHookList, before a given #GHook.
270 @hook_list: a #GHookList.
271 @sibling: the #GHook to insert the new #GHook before.
272 @hook: the #GHook to insert.
275 <!-- ##### FUNCTION g_hook_insert_sorted ##### -->
277 Inserts a #GHook into a #GHookList, sorted by the given function.
280 @hook_list: a #GHookList.
281 @hook: the #GHook to insert.
282 @func: the comparison function used to sort the #GHook elements.
285 <!-- ##### USER_FUNCTION GHookCompareFunc ##### -->
287 Defines the type of function used to compare #GHook elements in
288 g_hook_insert_sorted().
291 @new_hook: the #GHook being inserted.
292 @sibling: the #GHook to compare with @new_hook.
293 @Returns: a value <= 0 if @new_hook should be before @sibling.
296 <!-- ##### FUNCTION g_hook_compare_ids ##### -->
298 Compares the ids of two #GHook elements, returning a negative value
299 if the second id is greater than the first.
303 @sibling: a #GHook to compare with @new_hook.
304 @Returns: a value <= 0 if the id of @sibling is >= the id of @new_hook.
307 <!-- ##### FUNCTION g_hook_get ##### -->
309 Returns the #GHook with the given id, or NULL if it is not found.
312 @hook_list: a #GHookList.
314 @Returns: the #GHook with the given id, or NULL if it is not found.
317 <!-- ##### FUNCTION g_hook_find ##### -->
319 Finds a #GHook in a #GHookList using the given function to test for a match.
322 @hook_list: a #GHookList.
323 @need_valids: TRUE if #GHook elements which have been destroyed should be
325 @func: the function to call for each #GHook, which should return TRUE when
326 the #GHook has been found.
327 @data: the data passed to @func.
328 @Returns: the found #GHook or NULL if no matching #GHook is found.
331 <!-- ##### FUNCTION g_hook_find_data ##### -->
333 Finds a #GHook in a #GHookList with the given data.
336 @hook_list: a #GHookList.
337 @need_valids: TRUE if #GHook elements which have been destroyed should be
339 @data: the data to find.
340 @Returns: the #GHook with the given @data or NULL if no matching
344 <!-- ##### FUNCTION g_hook_find_func ##### -->
346 Finds a #GHook in a #GHookList with the given function.
349 @hook_list: a #GHookList.
350 @need_valids: TRUE if #GHook elements which have been destroyed should be
352 @func: the function to find.
353 @Returns: the #GHook with the given @func or NULL if no matching
357 <!-- ##### USER_FUNCTION GHookFindFunc ##### -->
359 Defines the type of the function passed to g_hooK_find_func().
363 @data: user data passed to g_hook_find_func().
364 @Returns: TRUE if the required #GHook has been found.
367 <!-- ##### FUNCTION g_hook_find_func_data ##### -->
369 Finds a #GHook in a #GHookList with the given function and data.
372 @hook_list: a #GHookList.
373 @need_valids: TRUE if #GHook elements which have been destroyed should be
375 @func: the function to find.
376 @data: the data to find.
377 @Returns: the #GHook with the given @func and @data or NULL if no matching
381 <!-- ##### FUNCTION g_hook_first_valid ##### -->
383 Returns the first #GHook in a #GHookList which has not been destroyed.
384 The reference count for the #GHook is incremented, so you must call
385 g_hook_unref() to restore it when no longer needed. (Or call
386 g_hook_next_valid() if you are stepping through the #GHookList.)
389 @hook_list: a #GHookList.
390 @may_be_in_call: TRUE if hooks which are currently running (e.g. in another
391 thread) are considered valid. If set to FALSE, these are skipped.
392 @Returns: the first valid #GHook, or NULL if none are valid.
395 <!-- ##### FUNCTION g_hook_next_valid ##### -->
397 Returns the next #GHook in a #GHookList which has not been destroyed.
398 The reference count for the #GHook is incremented, so you must call
399 g_hook_unref() to restore it when no longer needed. (Or continue to call
400 g_hook_next_valid() until NULL is returned.)
404 @hook_list: a #GHookList.
405 @hook: the current #GHook.
406 @may_be_in_call: TRUE if hooks which are currently running (e.g. in another
407 thread) are considered valid. If set to FALSE, these are skipped.
408 @Returns: the next valid #GHook, or NULL if none are valid.
411 <!-- ##### ENUM GHookFlagMask ##### -->
417 @G_HOOK_FLAG_IN_CALL:
420 <!-- ##### MACRO G_HOOK_FLAG_USER_SHIFT ##### -->
427 <!-- ##### MACRO G_HOOK_IS_VALID ##### -->
429 Returns TRUE if the #GHook is valid, i.e. it is in a #GHookList, it is active
430 and it has not been destroyed.
434 @Returns: TRUE if the #GHook is valid.
437 <!-- ##### MACRO G_HOOK_ACTIVE ##### -->
439 Returns TRUE if the #GHook is active, which is normally TRUE until the #GHook
444 @Returns: TRUE if the #GHook is active.
447 <!-- ##### MACRO G_HOOK_IN_CALL ##### -->
449 Returns TRUE if the #GHook function is currently executing.
453 @Returns: TRUE if the #GHook function is currently executing.
456 <!-- ##### MACRO G_HOOK_IS_UNLINKED ##### -->
458 Returns TRUE if the #GHook is not in a #GHookList.
463 @Returns: TRUE if the #GHook is not in a #GHookList.
466 <!-- ##### FUNCTION g_hook_ref ##### -->
468 Increments the reference count for a #GHook.
471 @hook_list: a #GHookList.
472 @hook: the #GHook to increment the reference count of.
475 <!-- ##### FUNCTION g_hook_unref ##### -->
477 Decrements the reference count of a #GHook.
478 If the reference count falls to 0, the #GHook is removed from the #GHookList
479 and g_hook_free() is called to free it.
482 @hook_list: a #GHookList.
486 <!-- ##### FUNCTION g_hook_free ##### -->
488 Calls the #GHookList @hook_free function if it exists, and frees the memory
489 allocated for the #GHook.
492 @hook_list: a #GHookList.
493 @hook: the #GHook to free.
496 <!-- ##### FUNCTION g_hook_destroy ##### -->
498 Destroys a #GHook, given its ID.
501 @hook_list: a #GHookList.
503 @Returns: TRUE if the #GHook was found in the #GHookList and destroyed.
506 <!-- ##### FUNCTION g_hook_destroy_link ##### -->
508 Removes one #GHook from a #GHookList, calling the @hook_destroy function in
509 the #GHookList, and the @destroy function of the #GHook, if they exist.
512 @hook_list: a #GHookList.
513 @hook: the #GHook to remove.