1998-09-30 08:56:00 +00:00
|
|
|
/* GLIB - Library of useful routines for C programming
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
|
|
|
* GHook: Callback maintenance functions
|
|
|
|
* Copyright (C) 1998 Tim Janik
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 11:02:02 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1998-09-30 08:56:00 +00:00
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2000-07-26 11:02:02 +00:00
|
|
|
* Lesser General Public License for more details.
|
1998-09-30 08:56:00 +00:00
|
|
|
*
|
2000-07-26 11:02:02 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2014-01-23 12:58:29 +01:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
1998-09-30 08:56:00 +00:00
|
|
|
*/
|
1998-12-15 05:28:02 +00:00
|
|
|
|
1999-02-24 06:14:27 +00:00
|
|
|
/*
|
2000-07-26 11:02:02 +00:00
|
|
|
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
1999-02-24 06:14:27 +00:00
|
|
|
* file for a list of people on the GLib Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
2010-09-03 23:03:14 -04:00
|
|
|
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
1999-02-24 06:14:27 +00:00
|
|
|
*/
|
|
|
|
|
2010-09-03 23:03:14 -04:00
|
|
|
/*
|
1998-12-15 05:28:02 +00:00
|
|
|
* MT safe
|
|
|
|
*/
|
|
|
|
|
2002-12-04 01:27:44 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-09-03 23:03:14 -04:00
|
|
|
#include "ghook.h"
|
|
|
|
|
|
|
|
#include "gtestutils.h"
|
2011-09-18 18:59:20 -04:00
|
|
|
#include "gslice.h"
|
1998-09-30 08:56:00 +00:00
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* SECTION:hooks
|
|
|
|
* @title: Hook Functions
|
|
|
|
* @short_description: support for manipulating lists of hook functions
|
|
|
|
*
|
|
|
|
* The #GHookList, #GHook and their related functions provide support for
|
|
|
|
* lists of hook functions. Functions can be added and removed from the lists,
|
|
|
|
* and the list of hook functions can be invoked.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GHookList:
|
|
|
|
* @seq_id: the next free #GHook id
|
|
|
|
* @hook_size: the size of the #GHookList elements, in bytes
|
|
|
|
* @is_setup: 1 if the #GHookList has been initialized
|
|
|
|
* @hooks: the first #GHook element in the list
|
|
|
|
* @dummy3: unused
|
|
|
|
* @finalize_hook: the function to call to finalize a #GHook element.
|
|
|
|
* The default behaviour is to call the hooks @destroy function
|
|
|
|
* @dummy: unused
|
|
|
|
*
|
2014-02-01 20:47:23 -05:00
|
|
|
* The #GHookList struct represents a list of hook functions.
|
2011-11-13 00:26:57 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GHookFinalizeFunc:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @hook: the hook in @hook_list that gets finalized
|
|
|
|
*
|
|
|
|
* Defines the type of function to be called when a hook in a
|
|
|
|
* list of hooks gets finalized.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GHookFlagMask:
|
|
|
|
* @G_HOOK_FLAG_ACTIVE: set if the hook has not been destroyed
|
|
|
|
* @G_HOOK_FLAG_IN_CALL: set if the hook is currently being run
|
|
|
|
* @G_HOOK_FLAG_MASK: A mask covering all bits reserved for
|
2011-12-13 23:00:16 -05:00
|
|
|
* hook flags; see %G_HOOK_FLAG_USER_SHIFT
|
2011-11-13 00:26:57 -05:00
|
|
|
*
|
|
|
|
* Flags used internally in the #GHook implementation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* G_HOOK_FLAGS:
|
|
|
|
* @hook: a #GHook
|
|
|
|
*
|
2011-12-13 23:00:16 -05:00
|
|
|
* Gets the flags of a hook.
|
2011-11-13 00:26:57 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* G_HOOK_FLAG_USER_SHIFT:
|
|
|
|
*
|
|
|
|
* The position of the first bit which is not reserved for internal
|
|
|
|
* use be the #GHook implementation, i.e.
|
2014-02-09 02:07:26 -05:00
|
|
|
* `1 << G_HOOK_FLAG_USER_SHIFT` is the first
|
2011-11-13 00:26:57 -05:00
|
|
|
* bit which can be used for application-defined flags.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* G_HOOK:
|
|
|
|
* @hook: a pointer
|
|
|
|
*
|
2014-02-06 08:04:52 -05:00
|
|
|
* Casts a pointer to a `GHook*`.
|
2011-11-13 00:26:57 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* G_HOOK_IS_VALID:
|
|
|
|
* @hook: a #GHook
|
|
|
|
*
|
|
|
|
* Returns %TRUE if the #GHook is valid, i.e. it is in a #GHookList,
|
|
|
|
* it is active and it has not been destroyed.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the #GHook is valid
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* G_HOOK_ACTIVE:
|
|
|
|
* @hook: a #GHook
|
|
|
|
*
|
|
|
|
* Returns %TRUE if the #GHook is active, which is normally the case
|
|
|
|
* until the #GHook is destroyed.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the #GHook is active
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* G_HOOK_IN_CALL:
|
|
|
|
* @hook: a #GHook
|
|
|
|
*
|
|
|
|
* Returns %TRUE if the #GHook function is currently executing.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the #GHook function is currently executing
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* G_HOOK_IS_UNLINKED:
|
|
|
|
* @hook: a #GHook
|
|
|
|
*
|
|
|
|
* Returns %TRUE if the #GHook is not in a #GHookList.
|
|
|
|
|
|
|
|
* Returns: %TRUE if the #GHook is not in a #GHookList
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GHook:
|
|
|
|
* @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
|
|
|
|
*
|
2014-02-01 20:47:23 -05:00
|
|
|
* The #GHook struct represents a single hook function in a #GHookList.
|
2011-11-13 00:26:57 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GHookFunc:
|
|
|
|
* @data: the data field of the #GHook is passed to the hook function here
|
|
|
|
*
|
|
|
|
* Defines the type of a hook function that can be invoked
|
|
|
|
* by g_hook_list_invoke().
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GHookCheckFunc:
|
|
|
|
* @data: the data field of the #GHook is passed to the hook function here
|
|
|
|
*
|
|
|
|
* Defines the type of a hook function that can be invoked
|
|
|
|
* by g_hook_list_invoke_check().
|
|
|
|
*
|
|
|
|
* Returns: %FALSE if the #GHook should be destroyed
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
|
|
|
|
/* --- functions --- */
|
destruction cleanup. there's one ->finalize_hook member in the hooklist
Thu Mar 8 16:23:34 2001 Tim Janik <timj@gtk.org>
* ghook.[hc]: destruction cleanup. there's one
->finalize_hook member in the hooklist now that gets
called when a hook should be destroyed, that's it.
that function is guarranteed to be called only when
all ref_counts to the hook vanished, thus also when
the hook is not in call.
Thu Mar 8 16:35:48 2001 Tim Janik <timj@gtk.org>
* gparamspecs.[hc]: s/g_param_spec_string_c/g_param_spec_stringc/.
* gsignal.[hc]: fixed accumulator invocation, implemented emission
hooks. and no, neither of these callbacks are called via a closure,
language bindings can wrap the accumulator and emission hook
interface, they already get parameters marshalled into a GValue array.
(g_signal_connect): removed this function as its C specific, doesn't
cover the swapped argument, is too close to its broken original
gtk_signal_connect() and creates demand for _swapped, _after and
_swapped_after variants <brrr>.
(g_signal_connectc): convenience macro to connect a C handler
func with data, like the old g_signal_connect() plus swapped
argument.
* gtype.h:
* gboxed.c: added G_TYPE_VALUE boxed type.
2001-03-08 16:34:59 +00:00
|
|
|
static void
|
|
|
|
default_finalize_hook (GHookList *hook_list,
|
|
|
|
GHook *hook)
|
|
|
|
{
|
|
|
|
GDestroyNotify destroy = hook->destroy;
|
|
|
|
|
|
|
|
if (destroy)
|
|
|
|
{
|
|
|
|
hook->destroy = NULL;
|
|
|
|
destroy (hook->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_list_init:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @hook_size: the size of each element in the #GHookList,
|
2014-02-06 08:04:52 -05:00
|
|
|
* typically `sizeof (GHook)`.
|
2011-11-13 00:26:57 -05:00
|
|
|
*
|
|
|
|
* Initializes a #GHookList.
|
|
|
|
* This must be called before the #GHookList is used.
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
void
|
|
|
|
g_hook_list_init (GHookList *hook_list,
|
|
|
|
guint hook_size)
|
|
|
|
{
|
|
|
|
g_return_if_fail (hook_list != NULL);
|
|
|
|
g_return_if_fail (hook_size >= sizeof (GHook));
|
|
|
|
|
|
|
|
hook_list->seq_id = 1;
|
|
|
|
hook_list->hook_size = hook_size;
|
|
|
|
hook_list->is_setup = TRUE;
|
|
|
|
hook_list->hooks = NULL;
|
2005-11-01 18:10:31 +00:00
|
|
|
hook_list->dummy3 = NULL;
|
destruction cleanup. there's one ->finalize_hook member in the hooklist
Thu Mar 8 16:23:34 2001 Tim Janik <timj@gtk.org>
* ghook.[hc]: destruction cleanup. there's one
->finalize_hook member in the hooklist now that gets
called when a hook should be destroyed, that's it.
that function is guarranteed to be called only when
all ref_counts to the hook vanished, thus also when
the hook is not in call.
Thu Mar 8 16:35:48 2001 Tim Janik <timj@gtk.org>
* gparamspecs.[hc]: s/g_param_spec_string_c/g_param_spec_stringc/.
* gsignal.[hc]: fixed accumulator invocation, implemented emission
hooks. and no, neither of these callbacks are called via a closure,
language bindings can wrap the accumulator and emission hook
interface, they already get parameters marshalled into a GValue array.
(g_signal_connect): removed this function as its C specific, doesn't
cover the swapped argument, is too close to its broken original
gtk_signal_connect() and creates demand for _swapped, _after and
_swapped_after variants <brrr>.
(g_signal_connectc): convenience macro to connect a C handler
func with data, like the old g_signal_connect() plus swapped
argument.
* gtype.h:
* gboxed.c: added G_TYPE_VALUE boxed type.
2001-03-08 16:34:59 +00:00
|
|
|
hook_list->finalize_hook = default_finalize_hook;
|
2002-03-03 03:15:10 +00:00
|
|
|
hook_list->dummy[0] = NULL;
|
|
|
|
hook_list->dummy[1] = NULL;
|
1998-09-30 08:56:00 +00:00
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_list_clear:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
*
|
|
|
|
* Removes all the #GHook elements from a #GHookList.
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
void
|
|
|
|
g_hook_list_clear (GHookList *hook_list)
|
|
|
|
{
|
|
|
|
g_return_if_fail (hook_list != NULL);
|
|
|
|
|
|
|
|
if (hook_list->is_setup)
|
|
|
|
{
|
|
|
|
GHook *hook;
|
|
|
|
|
|
|
|
hook_list->is_setup = FALSE;
|
|
|
|
|
|
|
|
hook = hook_list->hooks;
|
|
|
|
if (!hook)
|
|
|
|
{
|
2005-11-01 18:10:31 +00:00
|
|
|
/* destroy hook_list->hook_memchunk */
|
1998-09-30 08:56:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
do
|
|
|
|
{
|
1998-10-07 04:19:14 +00:00
|
|
|
GHook *tmp;
|
1998-09-30 08:56:00 +00:00
|
|
|
|
|
|
|
g_hook_ref (hook_list, hook);
|
|
|
|
g_hook_destroy_link (hook_list, hook);
|
|
|
|
tmp = hook->next;
|
|
|
|
g_hook_unref (hook_list, hook);
|
|
|
|
hook = tmp;
|
|
|
|
}
|
|
|
|
while (hook);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_alloc:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
*
|
|
|
|
* Allocates space for a #GHook and initializes it.
|
|
|
|
*
|
|
|
|
* Returns: a new #GHook
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
GHook*
|
|
|
|
g_hook_alloc (GHookList *hook_list)
|
|
|
|
{
|
|
|
|
GHook *hook;
|
|
|
|
|
|
|
|
g_return_val_if_fail (hook_list != NULL, NULL);
|
|
|
|
g_return_val_if_fail (hook_list->is_setup, NULL);
|
|
|
|
|
2005-11-01 18:10:31 +00:00
|
|
|
hook = g_slice_alloc0 (hook_list->hook_size);
|
1998-09-30 08:56:00 +00:00
|
|
|
hook->data = NULL;
|
|
|
|
hook->next = NULL;
|
|
|
|
hook->prev = NULL;
|
1998-10-07 04:19:14 +00:00
|
|
|
hook->flags = G_HOOK_FLAG_ACTIVE;
|
1998-09-30 08:56:00 +00:00
|
|
|
hook->ref_count = 0;
|
1998-10-02 23:21:58 +00:00
|
|
|
hook->hook_id = 0;
|
1998-09-30 08:56:00 +00:00
|
|
|
hook->func = NULL;
|
|
|
|
hook->destroy = NULL;
|
|
|
|
|
|
|
|
return hook;
|
|
|
|
}
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_free:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @hook: the #GHook to free
|
|
|
|
*
|
|
|
|
* Calls the #GHookList @finalize_hook function if it exists,
|
|
|
|
* and frees the memory allocated for the #GHook.
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
void
|
|
|
|
g_hook_free (GHookList *hook_list,
|
|
|
|
GHook *hook)
|
|
|
|
{
|
|
|
|
g_return_if_fail (hook_list != NULL);
|
|
|
|
g_return_if_fail (hook_list->is_setup);
|
|
|
|
g_return_if_fail (hook != NULL);
|
|
|
|
g_return_if_fail (G_HOOK_IS_UNLINKED (hook));
|
destruction cleanup. there's one ->finalize_hook member in the hooklist
Thu Mar 8 16:23:34 2001 Tim Janik <timj@gtk.org>
* ghook.[hc]: destruction cleanup. there's one
->finalize_hook member in the hooklist now that gets
called when a hook should be destroyed, that's it.
that function is guarranteed to be called only when
all ref_counts to the hook vanished, thus also when
the hook is not in call.
Thu Mar 8 16:35:48 2001 Tim Janik <timj@gtk.org>
* gparamspecs.[hc]: s/g_param_spec_string_c/g_param_spec_stringc/.
* gsignal.[hc]: fixed accumulator invocation, implemented emission
hooks. and no, neither of these callbacks are called via a closure,
language bindings can wrap the accumulator and emission hook
interface, they already get parameters marshalled into a GValue array.
(g_signal_connect): removed this function as its C specific, doesn't
cover the swapped argument, is too close to its broken original
gtk_signal_connect() and creates demand for _swapped, _after and
_swapped_after variants <brrr>.
(g_signal_connectc): convenience macro to connect a C handler
func with data, like the old g_signal_connect() plus swapped
argument.
* gtype.h:
* gboxed.c: added G_TYPE_VALUE boxed type.
2001-03-08 16:34:59 +00:00
|
|
|
g_return_if_fail (!G_HOOK_IN_CALL (hook));
|
1998-10-31 18:57:36 +00:00
|
|
|
|
2007-09-19 20:36:53 +00:00
|
|
|
if(hook_list->finalize_hook != NULL)
|
|
|
|
hook_list->finalize_hook (hook_list, hook);
|
2005-11-01 18:10:31 +00:00
|
|
|
g_slice_free1 (hook_list->hook_size, hook);
|
1998-09-30 08:56:00 +00:00
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_destroy_link:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @hook: the #GHook to remove
|
|
|
|
*
|
|
|
|
* Removes one #GHook from a #GHookList, marking it
|
|
|
|
* inactive and calling g_hook_unref() on it.
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
void
|
|
|
|
g_hook_destroy_link (GHookList *hook_list,
|
|
|
|
GHook *hook)
|
|
|
|
{
|
|
|
|
g_return_if_fail (hook_list != NULL);
|
|
|
|
g_return_if_fail (hook != NULL);
|
destruction cleanup. there's one ->finalize_hook member in the hooklist
Thu Mar 8 16:23:34 2001 Tim Janik <timj@gtk.org>
* ghook.[hc]: destruction cleanup. there's one
->finalize_hook member in the hooklist now that gets
called when a hook should be destroyed, that's it.
that function is guarranteed to be called only when
all ref_counts to the hook vanished, thus also when
the hook is not in call.
Thu Mar 8 16:35:48 2001 Tim Janik <timj@gtk.org>
* gparamspecs.[hc]: s/g_param_spec_string_c/g_param_spec_stringc/.
* gsignal.[hc]: fixed accumulator invocation, implemented emission
hooks. and no, neither of these callbacks are called via a closure,
language bindings can wrap the accumulator and emission hook
interface, they already get parameters marshalled into a GValue array.
(g_signal_connect): removed this function as its C specific, doesn't
cover the swapped argument, is too close to its broken original
gtk_signal_connect() and creates demand for _swapped, _after and
_swapped_after variants <brrr>.
(g_signal_connectc): convenience macro to connect a C handler
func with data, like the old g_signal_connect() plus swapped
argument.
* gtype.h:
* gboxed.c: added G_TYPE_VALUE boxed type.
2001-03-08 16:34:59 +00:00
|
|
|
|
|
|
|
hook->flags &= ~G_HOOK_FLAG_ACTIVE;
|
1998-10-02 23:21:58 +00:00
|
|
|
if (hook->hook_id)
|
1998-09-30 08:56:00 +00:00
|
|
|
{
|
1998-10-02 23:21:58 +00:00
|
|
|
hook->hook_id = 0;
|
1998-09-30 08:56:00 +00:00
|
|
|
g_hook_unref (hook_list, hook); /* counterpart to g_hook_insert_before */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_destroy:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @hook_id: a hook ID
|
|
|
|
*
|
|
|
|
* Destroys a #GHook, given its ID.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the #GHook was found in the #GHookList and destroyed
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
gboolean
|
|
|
|
g_hook_destroy (GHookList *hook_list,
|
2001-04-29 03:04:27 +00:00
|
|
|
gulong hook_id)
|
1998-09-30 08:56:00 +00:00
|
|
|
{
|
|
|
|
GHook *hook;
|
|
|
|
|
|
|
|
g_return_val_if_fail (hook_list != NULL, FALSE);
|
1998-10-02 23:21:58 +00:00
|
|
|
g_return_val_if_fail (hook_id > 0, FALSE);
|
1998-09-30 08:56:00 +00:00
|
|
|
|
1998-10-02 23:21:58 +00:00
|
|
|
hook = g_hook_get (hook_list, hook_id);
|
1998-09-30 08:56:00 +00:00
|
|
|
if (hook)
|
|
|
|
{
|
|
|
|
g_hook_destroy_link (hook_list, hook);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_unref:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @hook: the #GHook to 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.
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
void
|
|
|
|
g_hook_unref (GHookList *hook_list,
|
|
|
|
GHook *hook)
|
|
|
|
{
|
|
|
|
g_return_if_fail (hook_list != NULL);
|
|
|
|
g_return_if_fail (hook != NULL);
|
|
|
|
g_return_if_fail (hook->ref_count > 0);
|
|
|
|
|
|
|
|
hook->ref_count--;
|
|
|
|
if (!hook->ref_count)
|
|
|
|
{
|
1998-10-02 23:21:58 +00:00
|
|
|
g_return_if_fail (hook->hook_id == 0);
|
1998-10-07 04:19:14 +00:00
|
|
|
g_return_if_fail (!G_HOOK_IN_CALL (hook));
|
destruction cleanup. there's one ->finalize_hook member in the hooklist
Thu Mar 8 16:23:34 2001 Tim Janik <timj@gtk.org>
* ghook.[hc]: destruction cleanup. there's one
->finalize_hook member in the hooklist now that gets
called when a hook should be destroyed, that's it.
that function is guarranteed to be called only when
all ref_counts to the hook vanished, thus also when
the hook is not in call.
Thu Mar 8 16:35:48 2001 Tim Janik <timj@gtk.org>
* gparamspecs.[hc]: s/g_param_spec_string_c/g_param_spec_stringc/.
* gsignal.[hc]: fixed accumulator invocation, implemented emission
hooks. and no, neither of these callbacks are called via a closure,
language bindings can wrap the accumulator and emission hook
interface, they already get parameters marshalled into a GValue array.
(g_signal_connect): removed this function as its C specific, doesn't
cover the swapped argument, is too close to its broken original
gtk_signal_connect() and creates demand for _swapped, _after and
_swapped_after variants <brrr>.
(g_signal_connectc): convenience macro to connect a C handler
func with data, like the old g_signal_connect() plus swapped
argument.
* gtype.h:
* gboxed.c: added G_TYPE_VALUE boxed type.
2001-03-08 16:34:59 +00:00
|
|
|
|
1998-09-30 08:56:00 +00:00
|
|
|
if (hook->prev)
|
|
|
|
hook->prev->next = hook->next;
|
|
|
|
else
|
|
|
|
hook_list->hooks = hook->next;
|
|
|
|
if (hook->next)
|
|
|
|
{
|
|
|
|
hook->next->prev = hook->prev;
|
|
|
|
hook->next = NULL;
|
|
|
|
}
|
|
|
|
hook->prev = NULL;
|
1999-03-17 01:05:49 +00:00
|
|
|
|
|
|
|
if (!hook_list->is_setup)
|
1998-09-30 08:56:00 +00:00
|
|
|
{
|
1999-03-17 01:05:49 +00:00
|
|
|
hook_list->is_setup = TRUE;
|
|
|
|
g_hook_free (hook_list, hook);
|
|
|
|
hook_list->is_setup = FALSE;
|
|
|
|
|
|
|
|
if (!hook_list->hooks)
|
|
|
|
{
|
2005-11-01 18:10:31 +00:00
|
|
|
/* destroy hook_list->hook_memchunk */
|
1999-03-17 01:05:49 +00:00
|
|
|
}
|
1998-09-30 08:56:00 +00:00
|
|
|
}
|
1999-03-17 01:05:49 +00:00
|
|
|
else
|
|
|
|
g_hook_free (hook_list, hook);
|
1998-09-30 08:56:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_ref:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @hook: the #GHook to increment the reference count of
|
|
|
|
*
|
|
|
|
* Increments the reference count for a #GHook.
|
|
|
|
*
|
|
|
|
* Returns: the @hook that was passed in (since 2.6)
|
|
|
|
*/
|
2004-11-08 18:26:56 +00:00
|
|
|
GHook *
|
1998-09-30 08:56:00 +00:00
|
|
|
g_hook_ref (GHookList *hook_list,
|
|
|
|
GHook *hook)
|
|
|
|
{
|
2004-11-08 18:49:35 +00:00
|
|
|
g_return_val_if_fail (hook_list != NULL, NULL);
|
|
|
|
g_return_val_if_fail (hook != NULL, NULL);
|
|
|
|
g_return_val_if_fail (hook->ref_count > 0, NULL);
|
1998-09-30 08:56:00 +00:00
|
|
|
|
|
|
|
hook->ref_count++;
|
2004-11-08 18:26:56 +00:00
|
|
|
|
|
|
|
return hook;
|
1998-09-30 08:56:00 +00:00
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_append:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @hook: the #GHook to add to the end of @hook_list
|
|
|
|
*
|
|
|
|
* Appends a #GHook onto the end of a #GHookList.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_hook_prepend:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @hook: the #GHook to add to the start of @hook_list
|
|
|
|
*
|
|
|
|
* Prepends a #GHook on the start of a #GHookList.
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
void
|
|
|
|
g_hook_prepend (GHookList *hook_list,
|
|
|
|
GHook *hook)
|
|
|
|
{
|
|
|
|
g_return_if_fail (hook_list != NULL);
|
|
|
|
|
|
|
|
g_hook_insert_before (hook_list, hook_list->hooks, hook);
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_insert_before:
|
|
|
|
* @hook_list: a #GHookList
|
2013-12-06 12:23:09 +00:00
|
|
|
* @sibling: (nullable): the #GHook to insert the new #GHook before
|
2011-11-13 00:26:57 -05:00
|
|
|
* @hook: the #GHook to insert
|
|
|
|
*
|
|
|
|
* Inserts a #GHook into a #GHookList, before a given #GHook.
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
void
|
|
|
|
g_hook_insert_before (GHookList *hook_list,
|
|
|
|
GHook *sibling,
|
|
|
|
GHook *hook)
|
|
|
|
{
|
|
|
|
g_return_if_fail (hook_list != NULL);
|
|
|
|
g_return_if_fail (hook_list->is_setup);
|
|
|
|
g_return_if_fail (hook != NULL);
|
|
|
|
g_return_if_fail (G_HOOK_IS_UNLINKED (hook));
|
destruction cleanup. there's one ->finalize_hook member in the hooklist
Thu Mar 8 16:23:34 2001 Tim Janik <timj@gtk.org>
* ghook.[hc]: destruction cleanup. there's one
->finalize_hook member in the hooklist now that gets
called when a hook should be destroyed, that's it.
that function is guarranteed to be called only when
all ref_counts to the hook vanished, thus also when
the hook is not in call.
Thu Mar 8 16:35:48 2001 Tim Janik <timj@gtk.org>
* gparamspecs.[hc]: s/g_param_spec_string_c/g_param_spec_stringc/.
* gsignal.[hc]: fixed accumulator invocation, implemented emission
hooks. and no, neither of these callbacks are called via a closure,
language bindings can wrap the accumulator and emission hook
interface, they already get parameters marshalled into a GValue array.
(g_signal_connect): removed this function as its C specific, doesn't
cover the swapped argument, is too close to its broken original
gtk_signal_connect() and creates demand for _swapped, _after and
_swapped_after variants <brrr>.
(g_signal_connectc): convenience macro to connect a C handler
func with data, like the old g_signal_connect() plus swapped
argument.
* gtype.h:
* gboxed.c: added G_TYPE_VALUE boxed type.
2001-03-08 16:34:59 +00:00
|
|
|
g_return_if_fail (hook->ref_count == 0);
|
1998-09-30 08:56:00 +00:00
|
|
|
|
1998-10-02 23:21:58 +00:00
|
|
|
hook->hook_id = hook_list->seq_id++;
|
1998-09-30 08:56:00 +00:00
|
|
|
hook->ref_count = 1; /* counterpart to g_hook_destroy_link */
|
|
|
|
|
|
|
|
if (sibling)
|
|
|
|
{
|
|
|
|
if (sibling->prev)
|
|
|
|
{
|
|
|
|
hook->prev = sibling->prev;
|
|
|
|
hook->prev->next = hook;
|
|
|
|
hook->next = sibling;
|
|
|
|
sibling->prev = hook;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hook_list->hooks = hook;
|
|
|
|
hook->next = sibling;
|
|
|
|
sibling->prev = hook;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (hook_list->hooks)
|
|
|
|
{
|
|
|
|
sibling = hook_list->hooks;
|
|
|
|
while (sibling->next)
|
|
|
|
sibling = sibling->next;
|
|
|
|
hook->prev = sibling;
|
|
|
|
sibling->next = hook;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hook_list->hooks = hook;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_list_invoke:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @may_recurse: %TRUE if functions which are already running
|
|
|
|
* (e.g. in another thread) can be called. If set to %FALSE,
|
|
|
|
* these are skipped
|
|
|
|
*
|
|
|
|
* Calls all of the #GHook functions in a #GHookList.
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
void
|
|
|
|
g_hook_list_invoke (GHookList *hook_list,
|
|
|
|
gboolean may_recurse)
|
|
|
|
{
|
|
|
|
GHook *hook;
|
|
|
|
|
|
|
|
g_return_if_fail (hook_list != NULL);
|
|
|
|
g_return_if_fail (hook_list->is_setup);
|
1998-10-02 23:21:58 +00:00
|
|
|
|
1998-10-07 04:19:14 +00:00
|
|
|
hook = g_hook_first_valid (hook_list, may_recurse);
|
1998-09-30 08:56:00 +00:00
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-07 04:19:14 +00:00
|
|
|
GHookFunc func;
|
1998-09-30 08:56:00 +00:00
|
|
|
gboolean was_in_call;
|
|
|
|
|
1998-11-02 07:04:38 +00:00
|
|
|
func = (GHookFunc) hook->func;
|
1998-09-30 08:56:00 +00:00
|
|
|
|
1998-10-07 04:19:14 +00:00
|
|
|
was_in_call = G_HOOK_IN_CALL (hook);
|
|
|
|
hook->flags |= G_HOOK_FLAG_IN_CALL;
|
1998-09-30 08:56:00 +00:00
|
|
|
func (hook->data);
|
|
|
|
if (!was_in_call)
|
1998-10-07 04:19:14 +00:00
|
|
|
hook->flags &= ~G_HOOK_FLAG_IN_CALL;
|
1998-09-30 08:56:00 +00:00
|
|
|
|
1999-01-02 01:32:37 +00:00
|
|
|
hook = g_hook_next_valid (hook_list, hook, may_recurse);
|
1998-09-30 08:56:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_list_invoke_check:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @may_recurse: %TRUE if functions which are already running
|
|
|
|
* (e.g. in another thread) can be called. If set to %FALSE,
|
|
|
|
* these are skipped
|
|
|
|
*
|
|
|
|
* Calls all of the #GHook functions in a #GHookList.
|
|
|
|
* Any function which returns %FALSE is removed from the #GHookList.
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
void
|
|
|
|
g_hook_list_invoke_check (GHookList *hook_list,
|
|
|
|
gboolean may_recurse)
|
|
|
|
{
|
|
|
|
GHook *hook;
|
|
|
|
|
|
|
|
g_return_if_fail (hook_list != NULL);
|
|
|
|
g_return_if_fail (hook_list->is_setup);
|
|
|
|
|
1998-10-07 04:19:14 +00:00
|
|
|
hook = g_hook_first_valid (hook_list, may_recurse);
|
1998-09-30 08:56:00 +00:00
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-07 04:19:14 +00:00
|
|
|
GHookCheckFunc func;
|
1998-09-30 08:56:00 +00:00
|
|
|
gboolean was_in_call;
|
1998-10-07 04:19:14 +00:00
|
|
|
gboolean need_destroy;
|
1998-09-30 08:56:00 +00:00
|
|
|
|
1998-11-02 07:04:38 +00:00
|
|
|
func = (GHookCheckFunc) hook->func;
|
1998-09-30 08:56:00 +00:00
|
|
|
|
1998-10-07 04:19:14 +00:00
|
|
|
was_in_call = G_HOOK_IN_CALL (hook);
|
|
|
|
hook->flags |= G_HOOK_FLAG_IN_CALL;
|
1998-09-30 08:56:00 +00:00
|
|
|
need_destroy = !func (hook->data);
|
|
|
|
if (!was_in_call)
|
1998-10-07 04:19:14 +00:00
|
|
|
hook->flags &= ~G_HOOK_FLAG_IN_CALL;
|
1998-09-30 08:56:00 +00:00
|
|
|
if (need_destroy)
|
|
|
|
g_hook_destroy_link (hook_list, hook);
|
|
|
|
|
1999-01-02 01:32:37 +00:00
|
|
|
hook = g_hook_next_valid (hook_list, hook, may_recurse);
|
1998-11-30 07:08:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* GHookCheckMarshaller:
|
|
|
|
* @hook: a #GHook
|
|
|
|
* @marshal_data: user data
|
|
|
|
*
|
|
|
|
* Defines the type of function used by g_hook_list_marshal_check().
|
|
|
|
*
|
|
|
|
* Returns: %FALSE if @hook should be destroyed
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_hook_list_marshal_check:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @may_recurse: %TRUE if hooks which are currently running
|
|
|
|
* (e.g. in another thread) are considered valid. If set to %FALSE,
|
|
|
|
* these are skipped
|
|
|
|
* @marshaller: the function to call for each #GHook
|
|
|
|
* @marshal_data: data to pass to @marshaller
|
|
|
|
*
|
|
|
|
* Calls a function on each valid #GHook and destroys it if the
|
|
|
|
* function returns %FALSE.
|
|
|
|
*/
|
1998-11-30 07:08:54 +00:00
|
|
|
void
|
|
|
|
g_hook_list_marshal_check (GHookList *hook_list,
|
|
|
|
gboolean may_recurse,
|
|
|
|
GHookCheckMarshaller marshaller,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GHook *hook;
|
|
|
|
|
|
|
|
g_return_if_fail (hook_list != NULL);
|
|
|
|
g_return_if_fail (hook_list->is_setup);
|
|
|
|
g_return_if_fail (marshaller != NULL);
|
|
|
|
|
|
|
|
hook = g_hook_first_valid (hook_list, may_recurse);
|
|
|
|
while (hook)
|
|
|
|
{
|
|
|
|
gboolean was_in_call;
|
|
|
|
gboolean need_destroy;
|
|
|
|
|
|
|
|
was_in_call = G_HOOK_IN_CALL (hook);
|
|
|
|
hook->flags |= G_HOOK_FLAG_IN_CALL;
|
|
|
|
need_destroy = !marshaller (hook, data);
|
|
|
|
if (!was_in_call)
|
|
|
|
hook->flags &= ~G_HOOK_FLAG_IN_CALL;
|
|
|
|
if (need_destroy)
|
|
|
|
g_hook_destroy_link (hook_list, hook);
|
|
|
|
|
1999-01-02 01:32:37 +00:00
|
|
|
hook = g_hook_next_valid (hook_list, hook, may_recurse);
|
1998-09-30 08:56:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* GHookMarshaller:
|
|
|
|
* @hook: a #GHook
|
|
|
|
* @marshal_data: user data
|
|
|
|
*
|
|
|
|
* Defines the type of function used by g_hook_list_marshal().
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_hook_list_marshal:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @may_recurse: %TRUE if hooks which are currently running
|
|
|
|
* (e.g. in another thread) are considered valid. If set to %FALSE,
|
|
|
|
* these are skipped
|
|
|
|
* @marshaller: the function to call for each #GHook
|
|
|
|
* @marshal_data: data to pass to @marshaller
|
|
|
|
*
|
|
|
|
* Calls a function on each valid #GHook.
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
void
|
1998-10-02 23:21:58 +00:00
|
|
|
g_hook_list_marshal (GHookList *hook_list,
|
|
|
|
gboolean may_recurse,
|
|
|
|
GHookMarshaller marshaller,
|
|
|
|
gpointer data)
|
1998-09-30 08:56:00 +00:00
|
|
|
{
|
|
|
|
GHook *hook;
|
|
|
|
|
|
|
|
g_return_if_fail (hook_list != NULL);
|
|
|
|
g_return_if_fail (hook_list->is_setup);
|
|
|
|
g_return_if_fail (marshaller != NULL);
|
|
|
|
|
1998-10-07 04:19:14 +00:00
|
|
|
hook = g_hook_first_valid (hook_list, may_recurse);
|
1998-09-30 08:56:00 +00:00
|
|
|
while (hook)
|
|
|
|
{
|
|
|
|
gboolean was_in_call;
|
|
|
|
|
1998-10-07 04:19:14 +00:00
|
|
|
was_in_call = G_HOOK_IN_CALL (hook);
|
|
|
|
hook->flags |= G_HOOK_FLAG_IN_CALL;
|
1998-09-30 08:56:00 +00:00
|
|
|
marshaller (hook, data);
|
|
|
|
if (!was_in_call)
|
1998-10-07 04:19:14 +00:00
|
|
|
hook->flags &= ~G_HOOK_FLAG_IN_CALL;
|
1998-09-30 08:56:00 +00:00
|
|
|
|
1999-01-02 01:32:37 +00:00
|
|
|
hook = g_hook_next_valid (hook_list, hook, may_recurse);
|
1998-09-30 08:56:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_first_valid:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @may_be_in_call: %TRUE if hooks which are currently running
|
|
|
|
* (e.g. in another thread) are considered valid. If set to %FALSE,
|
|
|
|
* these are skipped
|
|
|
|
*
|
|
|
|
* 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.)
|
|
|
|
*
|
|
|
|
* Returns: the first valid #GHook, or %NULL if none are valid
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
GHook*
|
1998-10-07 04:19:14 +00:00
|
|
|
g_hook_first_valid (GHookList *hook_list,
|
|
|
|
gboolean may_be_in_call)
|
1998-09-30 08:56:00 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (hook_list != NULL, NULL);
|
|
|
|
|
|
|
|
if (hook_list->is_setup)
|
|
|
|
{
|
|
|
|
GHook *hook;
|
|
|
|
|
|
|
|
hook = hook_list->hooks;
|
|
|
|
if (hook)
|
|
|
|
{
|
1998-12-22 10:09:28 +00:00
|
|
|
g_hook_ref (hook_list, hook);
|
1998-10-07 04:19:14 +00:00
|
|
|
if (G_HOOK_IS_VALID (hook) && (may_be_in_call || !G_HOOK_IN_CALL (hook)))
|
1998-09-30 08:56:00 +00:00
|
|
|
return hook;
|
|
|
|
else
|
1998-12-21 21:43:00 +00:00
|
|
|
return g_hook_next_valid (hook_list, hook, may_be_in_call);
|
1998-09-30 08:56:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_next_valid:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @hook: the current #GHook
|
|
|
|
* @may_be_in_call: %TRUE if hooks which are currently running
|
|
|
|
* (e.g. in another thread) are considered valid. If set to %FALSE,
|
|
|
|
* these are skipped
|
|
|
|
*
|
|
|
|
* 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.)
|
|
|
|
*
|
|
|
|
* Returns: the next valid #GHook, or %NULL if none are valid
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
GHook*
|
1998-12-21 21:43:00 +00:00
|
|
|
g_hook_next_valid (GHookList *hook_list,
|
|
|
|
GHook *hook,
|
|
|
|
gboolean may_be_in_call)
|
1998-09-30 08:56:00 +00:00
|
|
|
{
|
1998-12-21 21:43:00 +00:00
|
|
|
GHook *ohook = hook;
|
|
|
|
|
|
|
|
g_return_val_if_fail (hook_list != NULL, NULL);
|
|
|
|
|
1998-09-30 08:56:00 +00:00
|
|
|
if (!hook)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
hook = hook->next;
|
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-07 04:19:14 +00:00
|
|
|
if (G_HOOK_IS_VALID (hook) && (may_be_in_call || !G_HOOK_IN_CALL (hook)))
|
1998-12-21 21:43:00 +00:00
|
|
|
{
|
|
|
|
g_hook_ref (hook_list, hook);
|
|
|
|
g_hook_unref (hook_list, ohook);
|
|
|
|
|
|
|
|
return hook;
|
|
|
|
}
|
1998-09-30 08:56:00 +00:00
|
|
|
hook = hook->next;
|
|
|
|
}
|
1998-12-21 21:43:00 +00:00
|
|
|
g_hook_unref (hook_list, ohook);
|
|
|
|
|
1998-09-30 08:56:00 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_get:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @hook_id: a hook id
|
|
|
|
*
|
|
|
|
* Returns the #GHook with the given id, or %NULL if it is not found.
|
|
|
|
*
|
|
|
|
* Returns: the #GHook with the given id, or %NULL if it is not found
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
GHook*
|
|
|
|
g_hook_get (GHookList *hook_list,
|
2001-04-29 03:04:27 +00:00
|
|
|
gulong hook_id)
|
1998-09-30 08:56:00 +00:00
|
|
|
{
|
|
|
|
GHook *hook;
|
|
|
|
|
|
|
|
g_return_val_if_fail (hook_list != NULL, NULL);
|
1998-10-02 23:21:58 +00:00
|
|
|
g_return_val_if_fail (hook_id > 0, NULL);
|
1998-09-30 08:56:00 +00:00
|
|
|
|
|
|
|
hook = hook_list->hooks;
|
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-02 23:21:58 +00:00
|
|
|
if (hook->hook_id == hook_id)
|
1998-09-30 08:56:00 +00:00
|
|
|
return hook;
|
|
|
|
hook = hook->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* GHookFindFunc:
|
|
|
|
* @hook: a #GHook
|
|
|
|
* @data: user data passed to g_hook_find_func()
|
|
|
|
*
|
|
|
|
* Defines the type of the function passed to g_hook_find().
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the required #GHook has been found
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_hook_find:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @need_valids: %TRUE if #GHook elements which have been destroyed
|
|
|
|
* should be skipped
|
|
|
|
* @func: the function to call for each #GHook, which should return
|
|
|
|
* %TRUE when the #GHook has been found
|
|
|
|
* @data: the data to pass to @func
|
|
|
|
*
|
|
|
|
* Finds a #GHook in a #GHookList using the given function to
|
|
|
|
* test for a match.
|
|
|
|
*
|
|
|
|
* Returns: the found #GHook or %NULL if no matching #GHook is found
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
GHook*
|
|
|
|
g_hook_find (GHookList *hook_list,
|
|
|
|
gboolean need_valids,
|
|
|
|
GHookFindFunc func,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GHook *hook;
|
|
|
|
|
|
|
|
g_return_val_if_fail (hook_list != NULL, NULL);
|
|
|
|
g_return_val_if_fail (func != NULL, NULL);
|
|
|
|
|
1998-10-07 04:19:14 +00:00
|
|
|
hook = hook_list->hooks;
|
1998-09-30 08:56:00 +00:00
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-07 04:19:14 +00:00
|
|
|
GHook *tmp;
|
|
|
|
|
|
|
|
/* test only non-destroyed hooks */
|
|
|
|
if (!hook->hook_id)
|
|
|
|
{
|
|
|
|
hook = hook->next;
|
|
|
|
continue;
|
|
|
|
}
|
1998-09-30 08:56:00 +00:00
|
|
|
|
|
|
|
g_hook_ref (hook_list, hook);
|
|
|
|
|
1998-10-07 04:19:14 +00:00
|
|
|
if (func (hook, data) && hook->hook_id && (!need_valids || G_HOOK_ACTIVE (hook)))
|
1998-09-30 08:56:00 +00:00
|
|
|
{
|
|
|
|
g_hook_unref (hook_list, hook);
|
|
|
|
|
|
|
|
return hook;
|
|
|
|
}
|
1998-10-07 04:19:14 +00:00
|
|
|
|
|
|
|
tmp = hook->next;
|
1998-09-30 08:56:00 +00:00
|
|
|
g_hook_unref (hook_list, hook);
|
|
|
|
hook = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_find_data:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @need_valids: %TRUE if #GHook elements which have been destroyed
|
|
|
|
* should be skipped
|
|
|
|
* @data: the data to find
|
|
|
|
*
|
|
|
|
* Finds a #GHook in a #GHookList with the given data.
|
|
|
|
*
|
|
|
|
* Returns: the #GHook with the given @data or %NULL if no matching
|
|
|
|
* #GHook is found
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
GHook*
|
|
|
|
g_hook_find_data (GHookList *hook_list,
|
|
|
|
gboolean need_valids,
|
|
|
|
gpointer data)
|
|
|
|
{
|
1998-10-07 04:19:14 +00:00
|
|
|
GHook *hook;
|
1998-09-30 08:56:00 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (hook_list != NULL, NULL);
|
|
|
|
|
1998-10-07 04:19:14 +00:00
|
|
|
hook = hook_list->hooks;
|
1998-09-30 08:56:00 +00:00
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-07 04:19:14 +00:00
|
|
|
/* test only non-destroyed hooks */
|
|
|
|
if (hook->data == data &&
|
|
|
|
hook->hook_id &&
|
|
|
|
(!need_valids || G_HOOK_ACTIVE (hook)))
|
1998-09-30 08:56:00 +00:00
|
|
|
return hook;
|
1998-10-07 04:19:14 +00:00
|
|
|
|
|
|
|
hook = hook->next;
|
1998-09-30 08:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_find_func:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @need_valids: %TRUE if #GHook elements which have been destroyed
|
|
|
|
* should be skipped
|
|
|
|
* @func: the function to find
|
|
|
|
*
|
|
|
|
* Finds a #GHook in a #GHookList with the given function.
|
|
|
|
*
|
|
|
|
* Returns: the #GHook with the given @func or %NULL if no matching
|
|
|
|
* #GHook is found
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
GHook*
|
|
|
|
g_hook_find_func (GHookList *hook_list,
|
|
|
|
gboolean need_valids,
|
|
|
|
gpointer func)
|
|
|
|
{
|
1998-10-07 04:19:14 +00:00
|
|
|
GHook *hook;
|
1998-09-30 08:56:00 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (hook_list != NULL, NULL);
|
|
|
|
g_return_val_if_fail (func != NULL, NULL);
|
|
|
|
|
1998-10-07 04:19:14 +00:00
|
|
|
hook = hook_list->hooks;
|
1998-09-30 08:56:00 +00:00
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-07 04:19:14 +00:00
|
|
|
/* test only non-destroyed hooks */
|
|
|
|
if (hook->func == func &&
|
|
|
|
hook->hook_id &&
|
|
|
|
(!need_valids || G_HOOK_ACTIVE (hook)))
|
1998-09-30 08:56:00 +00:00
|
|
|
return hook;
|
1998-10-07 04:19:14 +00:00
|
|
|
|
|
|
|
hook = hook->next;
|
1998-09-30 08:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_find_func_data:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @need_valids: %TRUE if #GHook elements which have been destroyed
|
|
|
|
* should be skipped
|
2013-12-06 12:23:09 +00:00
|
|
|
* @func: (not nullable): the function to find
|
2011-11-13 00:26:57 -05:00
|
|
|
* @data: the data to find
|
|
|
|
*
|
|
|
|
* Finds a #GHook in a #GHookList with the given function and data.
|
|
|
|
*
|
|
|
|
* Returns: the #GHook with the given @func and @data or %NULL if
|
|
|
|
* no matching #GHook is found
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
GHook*
|
|
|
|
g_hook_find_func_data (GHookList *hook_list,
|
|
|
|
gboolean need_valids,
|
|
|
|
gpointer func,
|
|
|
|
gpointer data)
|
|
|
|
{
|
1998-10-07 04:19:14 +00:00
|
|
|
GHook *hook;
|
1998-09-30 08:56:00 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (hook_list != NULL, NULL);
|
|
|
|
g_return_val_if_fail (func != NULL, NULL);
|
|
|
|
|
1998-10-07 04:19:14 +00:00
|
|
|
hook = hook_list->hooks;
|
1998-09-30 08:56:00 +00:00
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-07 04:19:14 +00:00
|
|
|
/* test only non-destroyed hooks */
|
|
|
|
if (hook->data == data &&
|
|
|
|
hook->func == func &&
|
|
|
|
hook->hook_id &&
|
|
|
|
(!need_valids || G_HOOK_ACTIVE (hook)))
|
1998-09-30 08:56:00 +00:00
|
|
|
return hook;
|
1998-10-07 04:19:14 +00:00
|
|
|
|
|
|
|
hook = hook->next;
|
1998-09-30 08:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* GHookCompareFunc:
|
|
|
|
* @new_hook: the #GHook being inserted
|
|
|
|
* @sibling: the #GHook to compare with @new_hook
|
|
|
|
*
|
|
|
|
* Defines the type of function used to compare #GHook elements in
|
|
|
|
* g_hook_insert_sorted().
|
|
|
|
*
|
2014-02-09 02:07:26 -05:00
|
|
|
* Returns: a value <= 0 if @new_hook should be before @sibling
|
2011-11-13 00:26:57 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_hook_insert_sorted:
|
|
|
|
* @hook_list: a #GHookList
|
|
|
|
* @hook: the #GHook to insert
|
|
|
|
* @func: the comparison function used to sort the #GHook elements
|
|
|
|
*
|
|
|
|
* Inserts a #GHook into a #GHookList, sorted by the given function.
|
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
void
|
|
|
|
g_hook_insert_sorted (GHookList *hook_list,
|
|
|
|
GHook *hook,
|
|
|
|
GHookCompareFunc func)
|
|
|
|
{
|
|
|
|
GHook *sibling;
|
|
|
|
|
|
|
|
g_return_if_fail (hook_list != NULL);
|
|
|
|
g_return_if_fail (hook_list->is_setup);
|
|
|
|
g_return_if_fail (hook != NULL);
|
|
|
|
g_return_if_fail (G_HOOK_IS_UNLINKED (hook));
|
|
|
|
g_return_if_fail (hook->func != NULL);
|
|
|
|
g_return_if_fail (func != NULL);
|
1998-10-07 04:19:14 +00:00
|
|
|
|
|
|
|
/* first non-destroyed hook */
|
|
|
|
sibling = hook_list->hooks;
|
|
|
|
while (sibling && !sibling->hook_id)
|
|
|
|
sibling = sibling->next;
|
1998-09-30 08:56:00 +00:00
|
|
|
|
|
|
|
while (sibling)
|
|
|
|
{
|
1998-10-07 04:19:14 +00:00
|
|
|
GHook *tmp;
|
1998-09-30 08:56:00 +00:00
|
|
|
|
|
|
|
g_hook_ref (hook_list, sibling);
|
1998-10-02 23:21:58 +00:00
|
|
|
if (func (hook, sibling) <= 0 && sibling->hook_id)
|
1998-09-30 08:56:00 +00:00
|
|
|
{
|
|
|
|
g_hook_unref (hook_list, sibling);
|
|
|
|
break;
|
|
|
|
}
|
1998-10-07 04:19:14 +00:00
|
|
|
|
|
|
|
/* next non-destroyed hook */
|
|
|
|
tmp = sibling->next;
|
|
|
|
while (tmp && !tmp->hook_id)
|
|
|
|
tmp = tmp->next;
|
|
|
|
|
1998-09-30 08:56:00 +00:00
|
|
|
g_hook_unref (hook_list, sibling);
|
|
|
|
sibling = tmp;
|
2011-11-13 00:26:57 -05:00
|
|
|
|
|
|
|
}
|
1998-09-30 08:56:00 +00:00
|
|
|
|
|
|
|
g_hook_insert_before (hook_list, sibling, hook);
|
|
|
|
}
|
|
|
|
|
2011-11-13 00:26:57 -05:00
|
|
|
/**
|
|
|
|
* g_hook_compare_ids:
|
|
|
|
* @new_hook: a #GHook
|
|
|
|
* @sibling: a #GHook to compare with @new_hook
|
|
|
|
*
|
|
|
|
* Compares the ids of two #GHook elements, returning a negative value
|
|
|
|
* if the second id is greater than the first.
|
|
|
|
*
|
2014-02-09 02:07:26 -05:00
|
|
|
* Returns: a value <= 0 if the id of @sibling is >= the id of @new_hook
|
2011-11-13 00:26:57 -05:00
|
|
|
*/
|
1998-09-30 08:56:00 +00:00
|
|
|
gint
|
|
|
|
g_hook_compare_ids (GHook *new_hook,
|
|
|
|
GHook *sibling)
|
|
|
|
{
|
Changes for 64-bit cleanliness, loosely based on patch from Mark Murnane.
Wed Jun 20 12:00:54 2001 Owen Taylor <otaylor@redhat.com>
Changes for 64-bit cleanliness, loosely based on patch
from Mark Murnane.
* gconvert.c (g_convert/g_convert_with_fallback): Remove
workarounds for since-fixed GNU libc bugs. Minor
doc fix.
* gconvert.[ch]: Change gint to gsize/gssize as
appropriate.
* gconvert.c (g_locale/filename_to/from_utf8): Fix incorrect
computation of bytes_read / bytes_written.
* gfileutils.[ch] (g_file_get_contents): Make length
out parameter 'gsize *len'.
* ghook.c (g_hook_compare_ids): Don't compare a
and b as 'a - b'.
* gmacros.h (GSIZE_TO_POINTER): Add GPOINTER_TO_SIZE,
GSIZE_TO_POINTER.
* gmain.c (g_timeout_prepare): Rewrite to avoid
overflows. (Fixes bug when system clock skews
backwards more than 24 days.)
* gmarkup.[ch]: Make lengths passed to callbacks
gsize, length for g_markup_parse-context_parse(),
g_markup_escape_text() gssize.
* gmessages.[ch] (g_printf_string_upper_bound): Change
return value to gsize.
* gmessages.c (printf_string_upper_bound): Remove
a ridiculous use of 'inline' on a 300 line function.
* gstring.[ch]: Represent size of string as a gsize,
not gint. Make parameters to functions take gsize,
or gssize where -1 is allowed.
* gstring.c (g_string_erase): Make
g_string_erase (string, pos, -1) a synonym for
g_string_truncate for consistency with other G*
APIs.
* gstrfuncs.[ch]: Make all functions taking a string
length, take a gsize, or gssize if -1 is allowed.
(g_strstr_len, g_strrstr_len). Also fix some boundary
conditions in g_str[r]str[_len].
* gutf8.c tests/unicode-encoding.c: Make parameters that
are byte lengths gsize, gssize as appropriate. Make
character offsets, other counts, glong.
* gasyncqueue.c gcompletion.c
timeloop.c timeloop-basic.c gutils.c gspawn.c.
Small 64 bit cleanliness fixups.
* glist.c (g_list_sort2, g_list_sort_real): Fix functions
that should have been static.
* gdate.c (g_date_fill_parse_tokens): Fix extra
declaration that was shadowing another.
* tests/module-test.c: Include string.h
Mon Jun 18 15:43:29 2001 Owen Taylor <otaylor@redhat.com>
* gutf8.c (g_get_charset): Make argument
G_CONST_RETURN char **.
2001-06-23 13:55:09 +00:00
|
|
|
if (new_hook->hook_id < sibling->hook_id)
|
|
|
|
return -1;
|
|
|
|
else if (new_hook->hook_id > sibling->hook_id)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
1998-09-30 08:56:00 +00:00
|
|
|
}
|