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>
74 <!-- ##### STRUCT GHook ##### -->
77 <informaltable pgwide=1 frame="none" role="struct">
78 <tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*">
82 <entry>#gpointer data;</entry>
87 <entry>#GHook *next;</entry>
92 <entry>#GHook *prev;</entry>
97 <entry>#guint ref_count;</entry>
102 <entry>#guint hook_id;</entry>
107 <entry>#guint flags;</entry>
112 <entry>#gpointer data;</entry>
117 <entry>#GDestroyNotify destroy;</entry>
121 </tbody></tgroup></informaltable>
133 <!-- ##### USER_FUNCTION GHookFunc ##### -->
141 <!-- ##### USER_FUNCTION GHookCheckFunc ##### -->
150 <!-- ##### USER_FUNCTION GHookMarshaller ##### -->
159 <!-- ##### USER_FUNCTION GHookCheckMarshaller ##### -->
169 <!-- ##### USER_FUNCTION GHookFreeFunc ##### -->
178 <!-- ##### MACRO G_HOOK_DEFERRED_DESTROY ##### -->
185 <!-- ##### FUNCTION g_hook_list_init ##### -->
187 Initializes a #GHookList.
188 This must be called before the #GHookList is used.
191 @hook_list: a #GHookList.
192 @hook_size: the size of each element in the #GHookList, typically
196 <!-- ##### FUNCTION g_hook_list_invoke ##### -->
198 Calls all of the #GHook functions in a #GHookList.
201 @hook_list: a #GHookList.
202 @may_recurse: TRUE if functions which are already running (e.g. in another
203 thread) can be called. If set to FALSE, these are skipped.
206 <!-- ##### FUNCTION g_hook_list_invoke_check ##### -->
208 Calls all of the #GHook functions in a #GHookList.
209 Any function which returns TRUE is removed from the #GHookList.
212 @hook_list: a #GHookList.
213 @may_recurse: TRUE if functions which are already running (e.g. in another
214 thread) can be called. If set to FALSE, these are skipped.
217 <!-- ##### FUNCTION g_hook_list_marshal ##### -->
222 @hook_list: a #GHookList.
228 <!-- ##### FUNCTION g_hook_list_marshal_check ##### -->
233 @hook_list: a #GHookList.
239 <!-- ##### FUNCTION g_hook_list_clear ##### -->
241 Removes all the #GHook elements from a #GHookList.
244 @hook_list: a #GHookList.
247 <!-- ##### FUNCTION g_hook_alloc ##### -->
249 Allocates space for a #GHook and initializes it.
252 @hook_list: a #GHookList.
253 @Returns: a new #GHook.
256 <!-- ##### MACRO g_hook_append ##### -->
258 Appends a #GHook onto the end of a #GHookList.
261 @hook_list: a #GHookList.
262 @hook: the #GHook to add to the end of @hook_list.
265 <!-- ##### FUNCTION g_hook_prepend ##### -->
267 Prepends a #GHook on the start of a #GHookList.
270 @hook_list: a #GHookList.
271 @hook: the #GHook to add to the start of @hook_list.
274 <!-- ##### FUNCTION g_hook_insert_before ##### -->
276 Inserts a #GHook into a #GHookList, before a given #GHook.
279 @hook_list: a #GHookList.
280 @sibling: the #GHook to insert the new #GHook before.
281 @hook: the #GHook to insert.
284 <!-- ##### FUNCTION g_hook_insert_sorted ##### -->
286 Inserts a #GHook into a #GHookList, sorted by the given function.
289 @hook_list: a #GHookList.
290 @hook: the #GHook to insert.
291 @func: the comparison function used to sort the #GHook elements.
294 <!-- ##### USER_FUNCTION GHookCompareFunc ##### -->
296 Defines the type of function used to compare #GHook elements in
297 g_hook_insert_sorted().
300 @new_hook: the #GHook being inserted.
301 @sibling: the #GHook to compare with @new_hook.
302 @Returns: a value <= 0 if @new_hook should be before @sibling.
305 <!-- ##### FUNCTION g_hook_compare_ids ##### -->
307 Compares the ids of two #GHook elements, returning a negative value
308 if the second id is greater than the first.
312 @sibling: a #GHook to compare with @new_hook.
313 @Returns: a value <= 0 if the id of @sibling is >= the id of @new_hook.
316 <!-- ##### FUNCTION g_hook_get ##### -->
318 Returns the #GHook with the given id, or NULL if it is not found.
321 @hook_list: a #GHookList.
323 @Returns: the #GHook with the given id, or NULL if it is not found.
326 <!-- ##### FUNCTION g_hook_find ##### -->
328 Finds a #GHook in a #GHookList using the given function to test for a match.
331 @hook_list: a #GHookList.
332 @need_valids: TRUE if #GHook elements which have been destroyed should be
334 @func: the function to call for each #GHook, which should return TRUE when
335 the #GHook has been found.
336 @data: the data passed to @func.
337 @Returns: the found #GHook or NULL if no matching #GHook is found.
340 <!-- ##### FUNCTION g_hook_find_data ##### -->
342 Finds a #GHook in a #GHookList with the given data.
345 @hook_list: a #GHookList.
346 @need_valids: TRUE if #GHook elements which have been destroyed should be
348 @data: the data to find.
349 @Returns: the #GHook with the given @data or NULL if no matching
353 <!-- ##### FUNCTION g_hook_find_func ##### -->
355 Finds a #GHook in a #GHookList with the given function.
358 @hook_list: a #GHookList.
359 @need_valids: TRUE if #GHook elements which have been destroyed should be
361 @func: the function to find.
362 @Returns: the #GHook with the given @func or NULL if no matching
366 <!-- ##### USER_FUNCTION GHookFindFunc ##### -->
368 Defines the type of the function passed to g_hooK_find_func().
372 @data: user data passed to g_hook_find_func().
373 @Returns: TRUE if the required #GHook has been found.
376 <!-- ##### FUNCTION g_hook_find_func_data ##### -->
378 Finds a #GHook in a #GHookList with the given function and data.
381 @hook_list: a #GHookList.
382 @need_valids: TRUE if #GHook elements which have been destroyed should be
384 @func: the function to find.
385 @data: the data to find.
386 @Returns: the #GHook with the given @func and @data or NULL if no matching
390 <!-- ##### FUNCTION g_hook_first_valid ##### -->
392 Returns the first #GHook in a #GHookList which has not been destroyed.
393 The reference count for the #GHook is incremented, so you must call
394 g_hook_unref() to restore it when no longer needed. (Or call
395 g_hook_next_valid() if you are stepping through the #GHookList.)
398 @hook_list: a #GHookList.
399 @may_be_in_call: TRUE if hooks which are currently running (e.g. in another
400 thread) are considered valid. If set to FALSE, these are skipped.
401 @Returns: the first valid #GHook, or NULL if none are valid.
404 <!-- ##### FUNCTION g_hook_next_valid ##### -->
406 Returns the next #GHook in a #GHookList which has not been destroyed.
407 The reference count for the #GHook is incremented, so you must call
408 g_hook_unref() to restore it when no longer needed. (Or continue to call
409 g_hook_next_valid() until NULL is returned.)
413 @hook_list: a #GHookList.
414 @hook: the current #GHook.
415 @may_be_in_call: TRUE if hooks which are currently running (e.g. in another
416 thread) are considered valid. If set to FALSE, these are skipped.
417 @Returns: the next valid #GHook, or NULL if none are valid.
420 <!-- ##### ENUM GHookFlagMask ##### -->
426 @G_HOOK_FLAG_IN_CALL:
429 <!-- ##### MACRO G_HOOK_FLAG_USER_SHIFT ##### -->
436 <!-- ##### MACRO G_HOOK_IS_VALID ##### -->
438 Returns TRUE if the #GHook is valid, i.e. it is in a #GHookList, it is active
439 and it has not been destroyed.
443 @Returns: TRUE if the #GHook is valid.
446 <!-- ##### MACRO G_HOOK_ACTIVE ##### -->
448 Returns TRUE if the #GHook is active, which is normally TRUE until the #GHook
453 @Returns: TRUE if the #GHook is active.
456 <!-- ##### MACRO G_HOOK_IN_CALL ##### -->
458 Returns TRUE if the #GHook function is currently executing.
462 @Returns: TRUE if the #GHook function is currently executing.
465 <!-- ##### MACRO G_HOOK_IS_UNLINKED ##### -->
467 Returns TRUE if the #GHook is not in a #GHookList.
472 @Returns: TRUE if the #GHook is not in a #GHookList.
475 <!-- ##### FUNCTION g_hook_ref ##### -->
477 Increments the reference count for a #GHook.
480 @hook_list: a #GHookList.
481 @hook: the #GHook to increment the reference count of.
484 <!-- ##### FUNCTION g_hook_unref ##### -->
486 Decrements the reference count of a #GHook.
487 If the reference count falls to 0, the #GHook is removed from the #GHookList
488 and g_hook_free() is called to free it.
491 @hook_list: a #GHookList.
495 <!-- ##### FUNCTION g_hook_free ##### -->
497 Calls the #GHookList @hook_free function if it exists, and frees the memory
498 allocated for the #GHook.
501 @hook_list: a #GHookList.
502 @hook: the #GHook to free.
505 <!-- ##### FUNCTION g_hook_destroy ##### -->
507 Destroys a #GHook, given its ID.
510 @hook_list: a #GHookList.
512 @Returns: TRUE if the #GHook was found in the #GHookList and destroyed.
515 <!-- ##### FUNCTION g_hook_destroy_link ##### -->
517 Removes one #GHook from a #GHookList, calling the @hook_destroy function in
518 the #GHookList, and the @destroy function of the #GHook, if they exist.
521 @hook_list: a #GHookList.
522 @hook: the #GHook to remove.