GLib.Hook
Description: Reference for GLib.Hook

### Struct

# GLibHook

since: 2.0

#### Description

    struct GHook {
      gpointer data;
      GHook* next;
      GHook* prev;
      guint ref_count;
      gulong hook_id;
      guint flags;
      gpointer func;
      GDestroyNotify destroy;
    }

The `GHook` struct represents a single hook function in a `GHookList`.

###### Structure members

`data`

  Data which is passed to func when this hook is invoked.

`next`

  Pointer to the next hook in the list.

`prev`

  Pointer to the previous hook in the list.

`ref_count`

  The reference count of this hook.

`hook_id`

  The id of this hook, which is unique within its list.

`flags`

  Flags which are set for this hook. See `GHookFlagMask` for predefined flags.

`func`

  The function to call when this hook is invoked. The possible signatures for this function are `GHookFunc` and `GHookCheckFunc`.

`destroy`

  The default `finalize_hook` function of a `GHookList` calls this member of the hook that is being finalized.

Available since: 2.0

#### Functions

###### g_hook_alloc

Allocates space for a `GHook` and initializes it.

since: 2.0

###### g_hook_destroy

Destroys a `GHook`, given its ID.

since: 2.0

###### g_hook_destroy_link

Removes one `GHook` from a `GHookList`, marking it inactive and calling `g_hook_unref()` on it.

since: 2.0

###### g_hook_find

Finds a `GHook` in a `GHookList` using the given function to test for a match.

since: 2.0

###### g_hook_find_data

Finds a `GHook` in a `GHookList` with the given data.

since: 2.0

###### g_hook_find_func

Finds a `GHook` in a `GHookList` with the given function.

since: 2.0

###### g_hook_find_func_data

Finds a `GHook` in a `GHookList` with the given function and data.

since: 2.0

###### g_hook_first_valid

Returns the first `GHook` in a `GHookList` which has not been destroyed. The reference count for the `GHook` is incremented, so you must call `g_hook_unref()` to restore it when no longer needed. (Or call `g_hook_next_valid()` if you are stepping through the `GHookList`.)

since: 2.0

###### g_hook_free

Calls the `GHookList` `finalize_hook` function if it exists, and frees the memory allocated for the `GHook`.

since: 2.0

###### g_hook_get

Returns the `GHook` with the given id, or `NULL` if it is not found.

since: 2.0

###### g_hook_insert_before

Inserts a `GHook` into a `GHookList`, before a given `GHook`.

since: 2.0

###### g_hook_insert_sorted

Inserts a `GHook` into a `GHookList`, sorted by the given function.

since: 2.0

###### g_hook_next_valid

Returns the next `GHook` in a `GHookList` which has not been destroyed. The reference count for the `GHook` is incremented, so you must call `g_hook_unref()` to restore it when no longer needed. (Or continue to call `g_hook_next_valid()` until `NULL` is returned.)

since: 2.0

###### g_hook_prepend

Prepends a `GHook` on the start of a `GHookList`.

since: 2.0

###### g_hook_ref

Increments the reference count for a `GHook`.

since: 2.0

###### g_hook_unref

Decrements the reference count of a `GHook`. If the reference count falls to 0, the `GHook` is removed from the `GHookList` and `g_hook_free()` is called to free it.

since: 2.0

#### Instance methods

###### g_hook_compare_ids

Compares the ids of two `GHook` elements, returning a negative value if the second id is greater than the first.

since: 2.0