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>#GHookFinalizeFunc finalize_hook;</entry>
54 <entry>the function to call to finalize a #GHook element.
55 The default behaviour is to call the hooks <function>destroy</function>
59 </tbody></tgroup></informaltable>
71 <!-- ##### USER_FUNCTION GHookFinalizeFunc ##### -->
73 Defines the type of function to be called when a hook in a
74 list of hooks gets finalized.
77 @hook_list: a #GHookList.
78 @hook: the hook in @hook_list that gets finalized.
81 <!-- ##### STRUCT GHook ##### -->
84 <informaltable pgwide=1 frame="none" role="struct">
85 <tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*">
89 <entry>#gpointer data;</entry>
90 <entry>data which is passed to func when this hook is invoked.</entry>
94 <entry>#GHook *next;</entry>
95 <entry>pointer to the next hook in the list.</entry>
99 <entry>#GHook *prev;</entry>
100 <entry>pointer to the previous hook in the list.</entry>
104 <entry>#guint ref_count;</entry>
105 <entry>the reference count of this hook.</entry>
109 <entry>#guint hook_id;</entry>
110 <entry>the id of this hook, which is unique within its list.</entry>
114 <entry>#guint flags;</entry>
115 <entry>flags which are set for this hook. See #GHookFlagMask for
116 predefined flags.</entry>
120 <entry>#gpointer func;</entry>
121 <entry>the function to call when this hook is invoked. The possible
122 signatures for this function are #GHookFunc and #GHookCheckFunc.</entry>
126 <entry>#GDestroyNotify destroy;</entry>
127 <entry>the default <function>finalize_hook</function> function of a
128 #GHookList calls this member of the hook that is being finalized.</entry>
131 </tbody></tgroup></informaltable>
143 <!-- ##### USER_FUNCTION GHookFunc ##### -->
145 Defines the type of a hook function that can be invoked
146 by g_hook_list_invoke().
149 @data: the data field of the #GHook is passed to the hook function here.
152 <!-- ##### USER_FUNCTION GHookCheckFunc ##### -->
154 Defines the type of a hook function that can be invoked
155 by g_hook_list_invoke_check().
158 @data: the data field of the #GHook is passed to the hook function here.
159 @Returns: %FALSE if the #GHook should be destroyed.
162 <!-- ##### FUNCTION g_hook_list_init ##### -->
164 Initializes a #GHookList.
165 This must be called before the #GHookList is used.
168 @hook_list: a #GHookList.
169 @hook_size: the size of each element in the #GHookList, typically
170 <literal>sizeof (GHook)</literal>.
173 <!-- ##### FUNCTION g_hook_list_invoke ##### -->
175 Calls all of the #GHook functions in a #GHookList.
178 @hook_list: a #GHookList.
179 @may_recurse: %TRUE if functions which are already running (e.g. in another
180 thread) can be called. If set to %FALSE, these are skipped.
183 <!-- ##### FUNCTION g_hook_list_invoke_check ##### -->
185 Calls all of the #GHook functions in a #GHookList.
186 Any function which returns %TRUE is removed from the #GHookList.
189 @hook_list: a #GHookList.
190 @may_recurse: %TRUE if functions which are already running (e.g. in another
191 thread) can be called. If set to %FALSE, these are skipped.
194 <!-- ##### FUNCTION g_hook_list_marshal ##### -->
196 Calls a function on each valid #GHook.
199 @hook_list: a #GHookList.
200 @may_recurse: %TRUE if hooks which are currently running (e.g. in another
201 thread) are considered valid. If set to %FALSE, these are skipped.
202 @marshaller: the function to call for each #GHook.
203 @marshal_data: data to pass to @marshaller.
206 <!-- ##### USER_FUNCTION GHookMarshaller ##### -->
208 Defines the type of function used by g_hook_list_marshal().
212 @marshal_data: user data.
215 <!-- ##### FUNCTION g_hook_list_marshal_check ##### -->
217 Calls a function on each valid #GHook and destroys it if the
218 function returns %FALSE.
221 @hook_list: a #GHookList.
222 @may_recurse: %TRUE if hooks which are currently running (e.g. in another
223 thread) are considered valid. If set to %FALSE, these are skipped.
224 @marshaller: the function to call for each #GHook.
225 @marshal_data: data to pass to @marshaller.
228 <!-- ##### USER_FUNCTION GHookCheckMarshaller ##### -->
230 Defines the type of function used by g_hook_list_marshal_check().
234 @marshal_data: user data.
235 @Returns: %FALSE if @hook should be destroyed.
238 <!-- ##### FUNCTION g_hook_list_clear ##### -->
240 Removes all the #GHook elements from a #GHookList.
243 @hook_list: a #GHookList.
246 <!-- ##### FUNCTION g_hook_alloc ##### -->
248 Allocates space for a #GHook and initializes it.
251 @hook_list: a #GHookList.
252 @Returns: a new #GHook.
255 <!-- ##### MACRO g_hook_append ##### -->
257 Appends a #GHook onto the end of a #GHookList.
260 @hook_list: a #GHookList.
261 @hook: the #GHook to add to the end of @hook_list.
264 <!-- ##### FUNCTION g_hook_prepend ##### -->
266 Prepends a #GHook on the start of a #GHookList.
269 @hook_list: a #GHookList.
270 @hook: the #GHook to add to the start of @hook_list.
273 <!-- ##### FUNCTION g_hook_insert_before ##### -->
275 Inserts a #GHook into a #GHookList, before a given #GHook.
278 @hook_list: a #GHookList.
279 @sibling: the #GHook to insert the new #GHook before.
280 @hook: the #GHook to insert.
283 <!-- ##### FUNCTION g_hook_insert_sorted ##### -->
285 Inserts a #GHook into a #GHookList, sorted by the given function.
288 @hook_list: a #GHookList.
289 @hook: the #GHook to insert.
290 @func: the comparison function used to sort the #GHook elements.
293 <!-- ##### USER_FUNCTION GHookCompareFunc ##### -->
295 Defines the type of function used to compare #GHook elements in
296 g_hook_insert_sorted().
299 @new_hook: the #GHook being inserted.
300 @sibling: the #GHook to compare with @new_hook.
301 @Returns: a value <= 0 if @new_hook should be before @sibling.
304 <!-- ##### FUNCTION g_hook_compare_ids ##### -->
306 Compares the ids of two #GHook elements, returning a negative value
307 if the second id is greater than the first.
311 @sibling: a #GHook to compare with @new_hook.
312 @Returns: a value <= 0 if the id of @sibling is >= the id of @new_hook.
315 <!-- ##### FUNCTION g_hook_get ##### -->
317 Returns the #GHook with the given id, or %NULL if it is not found.
320 @hook_list: a #GHookList.
322 @Returns: the #GHook with the given id, or %NULL if it is not found.
325 <!-- ##### FUNCTION g_hook_find ##### -->
327 Finds a #GHook in a #GHookList using the given function to test for a match.
330 @hook_list: a #GHookList.
331 @need_valids: %TRUE if #GHook elements which have been destroyed should be
333 @func: the function to call for each #GHook, which should return %TRUE when
334 the #GHook has been found.
335 @data: the data to pass to @func.
336 @Returns: the found #GHook or %NULL if no matching #GHook is found.
339 <!-- ##### USER_FUNCTION GHookFindFunc ##### -->
341 Defines the type of the function passed to g_hook_find().
345 @data: user data passed to g_hook_find_func().
346 @Returns: %TRUE if the required #GHook has been found.
349 <!-- ##### FUNCTION g_hook_find_data ##### -->
351 Finds a #GHook in a #GHookList with the given data.
354 @hook_list: a #GHookList.
355 @need_valids: %TRUE if #GHook elements which have been destroyed should be
357 @data: the data to find.
358 @Returns: the #GHook with the given @data or %NULL if no matching
362 <!-- ##### FUNCTION g_hook_find_func ##### -->
364 Finds a #GHook in a #GHookList with the given function.
367 @hook_list: a #GHookList.
368 @need_valids: %TRUE if #GHook elements which have been destroyed should be
370 @func: the function to find.
371 @Returns: the #GHook with the given @func or %NULL if no matching
375 <!-- ##### FUNCTION g_hook_find_func_data ##### -->
377 Finds a #GHook in a #GHookList with the given function and data.
380 @hook_list: a #GHookList.
381 @need_valids: %TRUE if #GHook elements which have been destroyed should be
383 @func: the function to find.
384 @data: the data to find.
385 @Returns: the #GHook with the given @func and @data or %NULL if no matching
389 <!-- ##### FUNCTION g_hook_first_valid ##### -->
391 Returns the first #GHook in a #GHookList which has not been destroyed.
392 The reference count for the #GHook is incremented, so you must call
393 g_hook_unref() to restore it when no longer needed. (Or call
394 g_hook_next_valid() if you are stepping through the #GHookList.)
397 @hook_list: a #GHookList.
398 @may_be_in_call: %TRUE if hooks which are currently running (e.g. in another
399 thread) are considered valid. If set to %FALSE, these are skipped.
400 @Returns: the first valid #GHook, or %NULL if none are valid.
403 <!-- ##### FUNCTION g_hook_next_valid ##### -->
405 Returns the next #GHook in a #GHookList which has not been destroyed.
406 The reference count for the #GHook is incremented, so you must call
407 g_hook_unref() to restore it when no longer needed. (Or continue to call
408 g_hook_next_valid() until %NULL is returned.)
412 @hook_list: a #GHookList.
413 @hook: the current #GHook.
414 @may_be_in_call: %TRUE if hooks which are currently running (e.g. in another
415 thread) are considered valid. If set to %FALSE, these are skipped.
416 @Returns: the next valid #GHook, or %NULL if none are valid.
419 <!-- ##### ENUM GHookFlagMask ##### -->
421 Flags used internally in the #GHook implementation.
424 @G_HOOK_FLAG_ACTIVE: set if the hook has not been destroyed.
425 @G_HOOK_FLAG_IN_CALL: set if the hook is currently being run.
428 <!-- ##### MACRO G_HOOK_FLAGS ##### -->
430 Returns the flags of a hook.
436 <!-- ##### MACRO G_HOOK_FLAG_USER_SHIFT ##### -->
443 <!-- ##### MACRO G_HOOK ##### -->
445 Casts a pointer to a <literal>GHook*</literal>.
451 <!-- ##### MACRO G_HOOK_IS_VALID ##### -->
453 Returns %TRUE if the #GHook is valid, i.e. it is in a #GHookList, it is active
454 and it has not been destroyed.
458 @Returns: %TRUE if the #GHook is valid.
461 <!-- ##### MACRO G_HOOK_ACTIVE ##### -->
463 Returns %TRUE if the #GHook is active, which is normally %TRUE until the #GHook
468 @Returns: %TRUE if the #GHook is active.
471 <!-- ##### MACRO G_HOOK_IN_CALL ##### -->
473 Returns %TRUE if the #GHook function is currently executing.
477 @Returns: %TRUE if the #GHook function is currently executing.
480 <!-- ##### MACRO G_HOOK_IS_UNLINKED ##### -->
482 Returns %TRUE if the #GHook is not in a #GHookList.
487 @Returns: %TRUE if the #GHook is not in a #GHookList.
490 <!-- ##### FUNCTION g_hook_ref ##### -->
492 Increments the reference count for a #GHook.
495 @hook_list: a #GHookList.
496 @hook: the #GHook to increment the reference count of.
499 <!-- ##### FUNCTION g_hook_unref ##### -->
501 Decrements the reference count of a #GHook.
502 If the reference count falls to 0, the #GHook is removed from the #GHookList
503 and g_hook_free() is called to free it.
506 @hook_list: a #GHookList.
507 @hook: the #GHook to unref.
510 <!-- ##### FUNCTION g_hook_free ##### -->
512 Calls the #GHookList @hook_free function if it exists, and frees the memory
513 allocated for the #GHook.
516 @hook_list: a #GHookList.
517 @hook: the #GHook to free.
520 <!-- ##### FUNCTION g_hook_destroy ##### -->
522 Destroys a #GHook, given its ID.
525 @hook_list: a #GHookList.
527 @Returns: %TRUE if the #GHook was found in the #GHookList and destroyed.
530 <!-- ##### FUNCTION g_hook_destroy_link ##### -->
532 Removes one #GHook from a #GHookList, marking it inactive and calling
533 g_hook_unref() on it.
536 @hook_list: a #GHookList.
537 @hook: the #GHook to remove.