1998-09-30 10:56:00 +02: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 13:02:02 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1998-09-30 10:56:00 +02: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 13:02:02 +02:00
|
|
|
* Lesser General Public License for more details.
|
1998-09-30 10:56:00 +02:00
|
|
|
*
|
2000-07-26 13:02:02 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1998-09-30 10:56:00 +02:00
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
1998-12-15 06:28:02 +01:00
|
|
|
|
1999-02-24 07:14:27 +01:00
|
|
|
/*
|
2000-07-26 13:02:02 +02:00
|
|
|
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
1999-02-24 07:14:27 +01: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
|
|
|
|
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
*/
|
|
|
|
|
1998-12-15 06:28:02 +01:00
|
|
|
/*
|
|
|
|
* MT safe
|
|
|
|
*/
|
|
|
|
|
1998-09-30 10:56:00 +02:00
|
|
|
#include "glib.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* --- defines --- */
|
|
|
|
#define G_HOOKS_PREALLOC (16)
|
|
|
|
|
|
|
|
|
|
|
|
/* --- 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 17:34:59 +01:00
|
|
|
static void
|
|
|
|
default_finalize_hook (GHookList *hook_list,
|
|
|
|
GHook *hook)
|
|
|
|
{
|
|
|
|
GDestroyNotify destroy = hook->destroy;
|
|
|
|
|
|
|
|
if (destroy)
|
|
|
|
{
|
|
|
|
hook->destroy = NULL;
|
|
|
|
destroy (hook->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-30 10:56:00 +02: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));
|
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 17:34:59 +01:00
|
|
|
g_return_if_fail (hook_size < 65536);
|
1998-09-30 10:56:00 +02:00
|
|
|
|
|
|
|
hook_list->seq_id = 1;
|
|
|
|
hook_list->hook_size = hook_size;
|
|
|
|
hook_list->is_setup = TRUE;
|
|
|
|
hook_list->hooks = NULL;
|
|
|
|
hook_list->hook_memchunk = g_mem_chunk_new ("GHook Memchunk",
|
|
|
|
hook_size,
|
|
|
|
hook_size * G_HOOKS_PREALLOC,
|
|
|
|
G_ALLOC_AND_FREE);
|
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 17:34:59 +01:00
|
|
|
hook_list->finalize_hook = default_finalize_hook;
|
1998-09-30 10:56:00 +02: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)
|
|
|
|
{
|
|
|
|
g_mem_chunk_destroy (hook_list->hook_memchunk);
|
|
|
|
hook_list->hook_memchunk = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
do
|
|
|
|
{
|
1998-10-07 06:19:14 +02:00
|
|
|
GHook *tmp;
|
1998-09-30 10:56:00 +02: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);
|
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 17:34:59 +01:00
|
|
|
if (hook_list->hook_memchunk)
|
|
|
|
g_warning (G_STRLOC ": failed to clear hooklist, unconsolidated references on hooks left");
|
1998-09-30 10:56:00 +02: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);
|
|
|
|
|
|
|
|
hook = g_chunk_new0 (GHook, hook_list->hook_memchunk);
|
|
|
|
hook->data = NULL;
|
|
|
|
hook->next = NULL;
|
|
|
|
hook->prev = NULL;
|
1998-10-07 06:19:14 +02:00
|
|
|
hook->flags = G_HOOK_FLAG_ACTIVE;
|
1998-09-30 10:56:00 +02:00
|
|
|
hook->ref_count = 0;
|
1998-10-03 01:21:58 +02:00
|
|
|
hook->hook_id = 0;
|
1998-09-30 10:56:00 +02:00
|
|
|
hook->func = NULL;
|
|
|
|
hook->destroy = NULL;
|
|
|
|
|
|
|
|
return hook;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 17:34:59 +01:00
|
|
|
g_return_if_fail (!G_HOOK_IN_CALL (hook));
|
1998-10-31 19:57:36 +01:00
|
|
|
|
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 17:34:59 +01:00
|
|
|
hook_list->finalize_hook (hook_list, hook);
|
1998-09-30 10:56:00 +02:00
|
|
|
g_chunk_free (hook, hook_list->hook_memchunk);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 17:34:59 +01:00
|
|
|
|
|
|
|
hook->flags &= ~G_HOOK_FLAG_ACTIVE;
|
1998-10-03 01:21:58 +02:00
|
|
|
if (hook->hook_id)
|
1998-09-30 10:56:00 +02:00
|
|
|
{
|
1998-10-03 01:21:58 +02:00
|
|
|
hook->hook_id = 0;
|
1998-09-30 10:56:00 +02:00
|
|
|
g_hook_unref (hook_list, hook); /* counterpart to g_hook_insert_before */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
g_hook_destroy (GHookList *hook_list,
|
2001-04-29 05:04:27 +02:00
|
|
|
gulong hook_id)
|
1998-09-30 10:56:00 +02:00
|
|
|
{
|
|
|
|
GHook *hook;
|
|
|
|
|
|
|
|
g_return_val_if_fail (hook_list != NULL, FALSE);
|
1998-10-03 01:21:58 +02:00
|
|
|
g_return_val_if_fail (hook_id > 0, FALSE);
|
1998-09-30 10:56:00 +02:00
|
|
|
|
1998-10-03 01:21:58 +02:00
|
|
|
hook = g_hook_get (hook_list, hook_id);
|
1998-09-30 10:56:00 +02:00
|
|
|
if (hook)
|
|
|
|
{
|
|
|
|
g_hook_destroy_link (hook_list, hook);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_hook_unref (GHookList *hook_list,
|
|
|
|
GHook *hook)
|
|
|
|
{
|
|
|
|
g_return_if_fail (hook_list != NULL);
|
1999-03-17 02:05:49 +01:00
|
|
|
g_return_if_fail (hook_list->hook_memchunk != NULL);
|
1998-09-30 10:56:00 +02:00
|
|
|
g_return_if_fail (hook != NULL);
|
|
|
|
g_return_if_fail (hook->ref_count > 0);
|
|
|
|
|
|
|
|
hook->ref_count--;
|
|
|
|
if (!hook->ref_count)
|
|
|
|
{
|
1998-10-03 01:21:58 +02:00
|
|
|
g_return_if_fail (hook->hook_id == 0);
|
1998-10-07 06:19:14 +02: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 17:34:59 +01:00
|
|
|
|
1998-09-30 10:56:00 +02: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 02:05:49 +01:00
|
|
|
|
|
|
|
if (!hook_list->is_setup)
|
1998-09-30 10:56:00 +02:00
|
|
|
{
|
1999-03-17 02:05:49 +01:00
|
|
|
hook_list->is_setup = TRUE;
|
|
|
|
g_hook_free (hook_list, hook);
|
|
|
|
hook_list->is_setup = FALSE;
|
|
|
|
|
|
|
|
if (!hook_list->hooks)
|
|
|
|
{
|
|
|
|
g_mem_chunk_destroy (hook_list->hook_memchunk);
|
|
|
|
hook_list->hook_memchunk = NULL;
|
|
|
|
}
|
1998-09-30 10:56:00 +02:00
|
|
|
}
|
1999-03-17 02:05:49 +01:00
|
|
|
else
|
|
|
|
g_hook_free (hook_list, hook);
|
1998-09-30 10:56:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_hook_ref (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++;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 17:34:59 +01:00
|
|
|
g_return_if_fail (hook->ref_count == 0);
|
1998-09-30 10:56:00 +02:00
|
|
|
|
1998-10-03 01:21:58 +02:00
|
|
|
hook->hook_id = hook_list->seq_id++;
|
1998-09-30 10:56:00 +02: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-03 01:21:58 +02:00
|
|
|
|
1998-10-07 06:19:14 +02:00
|
|
|
hook = g_hook_first_valid (hook_list, may_recurse);
|
1998-09-30 10:56:00 +02:00
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-07 06:19:14 +02:00
|
|
|
GHookFunc func;
|
1998-09-30 10:56:00 +02:00
|
|
|
gboolean was_in_call;
|
|
|
|
|
1998-11-02 08:04:38 +01:00
|
|
|
func = (GHookFunc) hook->func;
|
1998-09-30 10:56:00 +02:00
|
|
|
|
1998-10-07 06:19:14 +02:00
|
|
|
was_in_call = G_HOOK_IN_CALL (hook);
|
|
|
|
hook->flags |= G_HOOK_FLAG_IN_CALL;
|
1998-09-30 10:56:00 +02:00
|
|
|
func (hook->data);
|
|
|
|
if (!was_in_call)
|
1998-10-07 06:19:14 +02:00
|
|
|
hook->flags &= ~G_HOOK_FLAG_IN_CALL;
|
1998-09-30 10:56:00 +02:00
|
|
|
|
1999-01-02 02:32:37 +01:00
|
|
|
hook = g_hook_next_valid (hook_list, hook, may_recurse);
|
1998-09-30 10:56:00 +02: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 06:19:14 +02:00
|
|
|
hook = g_hook_first_valid (hook_list, may_recurse);
|
1998-09-30 10:56:00 +02:00
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-07 06:19:14 +02:00
|
|
|
GHookCheckFunc func;
|
1998-09-30 10:56:00 +02:00
|
|
|
gboolean was_in_call;
|
1998-10-07 06:19:14 +02:00
|
|
|
gboolean need_destroy;
|
1998-09-30 10:56:00 +02:00
|
|
|
|
1998-11-02 08:04:38 +01:00
|
|
|
func = (GHookCheckFunc) hook->func;
|
1998-09-30 10:56:00 +02:00
|
|
|
|
1998-10-07 06:19:14 +02:00
|
|
|
was_in_call = G_HOOK_IN_CALL (hook);
|
|
|
|
hook->flags |= G_HOOK_FLAG_IN_CALL;
|
1998-09-30 10:56:00 +02:00
|
|
|
need_destroy = !func (hook->data);
|
|
|
|
if (!was_in_call)
|
1998-10-07 06:19:14 +02:00
|
|
|
hook->flags &= ~G_HOOK_FLAG_IN_CALL;
|
1998-09-30 10:56:00 +02:00
|
|
|
if (need_destroy)
|
|
|
|
g_hook_destroy_link (hook_list, hook);
|
|
|
|
|
1999-01-02 02:32:37 +01:00
|
|
|
hook = g_hook_next_valid (hook_list, hook, may_recurse);
|
1998-11-30 08:08:54 +01: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 02:32:37 +01:00
|
|
|
hook = g_hook_next_valid (hook_list, hook, may_recurse);
|
1998-09-30 10:56:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-10-03 01:21:58 +02:00
|
|
|
g_hook_list_marshal (GHookList *hook_list,
|
|
|
|
gboolean may_recurse,
|
|
|
|
GHookMarshaller marshaller,
|
|
|
|
gpointer data)
|
1998-09-30 10:56:00 +02: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 06:19:14 +02:00
|
|
|
hook = g_hook_first_valid (hook_list, may_recurse);
|
1998-09-30 10:56:00 +02:00
|
|
|
while (hook)
|
|
|
|
{
|
|
|
|
gboolean was_in_call;
|
|
|
|
|
1998-10-07 06:19:14 +02:00
|
|
|
was_in_call = G_HOOK_IN_CALL (hook);
|
|
|
|
hook->flags |= G_HOOK_FLAG_IN_CALL;
|
1998-09-30 10:56:00 +02:00
|
|
|
marshaller (hook, data);
|
|
|
|
if (!was_in_call)
|
1998-10-07 06:19:14 +02:00
|
|
|
hook->flags &= ~G_HOOK_FLAG_IN_CALL;
|
1998-09-30 10:56:00 +02:00
|
|
|
|
1999-01-02 02:32:37 +01:00
|
|
|
hook = g_hook_next_valid (hook_list, hook, may_recurse);
|
1998-09-30 10:56:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GHook*
|
1998-10-07 06:19:14 +02:00
|
|
|
g_hook_first_valid (GHookList *hook_list,
|
|
|
|
gboolean may_be_in_call)
|
1998-09-30 10:56:00 +02: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 11:09:28 +01:00
|
|
|
g_hook_ref (hook_list, hook);
|
1998-10-07 06:19:14 +02:00
|
|
|
if (G_HOOK_IS_VALID (hook) && (may_be_in_call || !G_HOOK_IN_CALL (hook)))
|
1998-09-30 10:56:00 +02:00
|
|
|
return hook;
|
|
|
|
else
|
1998-12-21 22:43:00 +01:00
|
|
|
return g_hook_next_valid (hook_list, hook, may_be_in_call);
|
1998-09-30 10:56:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GHook*
|
1998-12-21 22:43:00 +01:00
|
|
|
g_hook_next_valid (GHookList *hook_list,
|
|
|
|
GHook *hook,
|
|
|
|
gboolean may_be_in_call)
|
1998-09-30 10:56:00 +02:00
|
|
|
{
|
1998-12-21 22:43:00 +01:00
|
|
|
GHook *ohook = hook;
|
|
|
|
|
|
|
|
g_return_val_if_fail (hook_list != NULL, NULL);
|
|
|
|
|
1998-09-30 10:56:00 +02:00
|
|
|
if (!hook)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
hook = hook->next;
|
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-07 06:19:14 +02:00
|
|
|
if (G_HOOK_IS_VALID (hook) && (may_be_in_call || !G_HOOK_IN_CALL (hook)))
|
1998-12-21 22:43:00 +01:00
|
|
|
{
|
|
|
|
g_hook_ref (hook_list, hook);
|
|
|
|
g_hook_unref (hook_list, ohook);
|
|
|
|
|
|
|
|
return hook;
|
|
|
|
}
|
1998-09-30 10:56:00 +02:00
|
|
|
hook = hook->next;
|
|
|
|
}
|
1998-12-21 22:43:00 +01:00
|
|
|
g_hook_unref (hook_list, ohook);
|
|
|
|
|
1998-09-30 10:56:00 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GHook*
|
|
|
|
g_hook_get (GHookList *hook_list,
|
2001-04-29 05:04:27 +02:00
|
|
|
gulong hook_id)
|
1998-09-30 10:56:00 +02:00
|
|
|
{
|
|
|
|
GHook *hook;
|
|
|
|
|
|
|
|
g_return_val_if_fail (hook_list != NULL, NULL);
|
1998-10-03 01:21:58 +02:00
|
|
|
g_return_val_if_fail (hook_id > 0, NULL);
|
1998-09-30 10:56:00 +02:00
|
|
|
|
|
|
|
hook = hook_list->hooks;
|
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-03 01:21:58 +02:00
|
|
|
if (hook->hook_id == hook_id)
|
1998-09-30 10:56:00 +02:00
|
|
|
return hook;
|
|
|
|
hook = hook->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 06:19:14 +02:00
|
|
|
hook = hook_list->hooks;
|
1998-09-30 10:56:00 +02:00
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-07 06:19:14 +02:00
|
|
|
GHook *tmp;
|
|
|
|
|
|
|
|
/* test only non-destroyed hooks */
|
|
|
|
if (!hook->hook_id)
|
|
|
|
{
|
|
|
|
hook = hook->next;
|
|
|
|
continue;
|
|
|
|
}
|
1998-09-30 10:56:00 +02:00
|
|
|
|
|
|
|
g_hook_ref (hook_list, hook);
|
|
|
|
|
1998-10-07 06:19:14 +02:00
|
|
|
if (func (hook, data) && hook->hook_id && (!need_valids || G_HOOK_ACTIVE (hook)))
|
1998-09-30 10:56:00 +02:00
|
|
|
{
|
|
|
|
g_hook_unref (hook_list, hook);
|
|
|
|
|
|
|
|
return hook;
|
|
|
|
}
|
1998-10-07 06:19:14 +02:00
|
|
|
|
|
|
|
tmp = hook->next;
|
1998-09-30 10:56:00 +02:00
|
|
|
g_hook_unref (hook_list, hook);
|
|
|
|
hook = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GHook*
|
|
|
|
g_hook_find_data (GHookList *hook_list,
|
|
|
|
gboolean need_valids,
|
|
|
|
gpointer data)
|
|
|
|
{
|
1998-10-07 06:19:14 +02:00
|
|
|
GHook *hook;
|
1998-09-30 10:56:00 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail (hook_list != NULL, NULL);
|
|
|
|
|
1998-10-07 06:19:14 +02:00
|
|
|
hook = hook_list->hooks;
|
1998-09-30 10:56:00 +02:00
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-07 06:19:14 +02:00
|
|
|
/* test only non-destroyed hooks */
|
|
|
|
if (hook->data == data &&
|
|
|
|
hook->hook_id &&
|
|
|
|
(!need_valids || G_HOOK_ACTIVE (hook)))
|
1998-09-30 10:56:00 +02:00
|
|
|
return hook;
|
1998-10-07 06:19:14 +02:00
|
|
|
|
|
|
|
hook = hook->next;
|
1998-09-30 10:56:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GHook*
|
|
|
|
g_hook_find_func (GHookList *hook_list,
|
|
|
|
gboolean need_valids,
|
|
|
|
gpointer func)
|
|
|
|
{
|
1998-10-07 06:19:14 +02:00
|
|
|
GHook *hook;
|
1998-09-30 10:56:00 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail (hook_list != NULL, NULL);
|
|
|
|
g_return_val_if_fail (func != NULL, NULL);
|
|
|
|
|
1998-10-07 06:19:14 +02:00
|
|
|
hook = hook_list->hooks;
|
1998-09-30 10:56:00 +02:00
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-07 06:19:14 +02:00
|
|
|
/* test only non-destroyed hooks */
|
|
|
|
if (hook->func == func &&
|
|
|
|
hook->hook_id &&
|
|
|
|
(!need_valids || G_HOOK_ACTIVE (hook)))
|
1998-09-30 10:56:00 +02:00
|
|
|
return hook;
|
1998-10-07 06:19:14 +02:00
|
|
|
|
|
|
|
hook = hook->next;
|
1998-09-30 10:56:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GHook*
|
|
|
|
g_hook_find_func_data (GHookList *hook_list,
|
|
|
|
gboolean need_valids,
|
|
|
|
gpointer func,
|
|
|
|
gpointer data)
|
|
|
|
{
|
1998-10-07 06:19:14 +02:00
|
|
|
GHook *hook;
|
1998-09-30 10:56:00 +02:00
|
|
|
|
|
|
|
g_return_val_if_fail (hook_list != NULL, NULL);
|
|
|
|
g_return_val_if_fail (func != NULL, NULL);
|
|
|
|
|
1998-10-07 06:19:14 +02:00
|
|
|
hook = hook_list->hooks;
|
1998-09-30 10:56:00 +02:00
|
|
|
while (hook)
|
|
|
|
{
|
1998-10-07 06:19:14 +02: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 10:56:00 +02:00
|
|
|
return hook;
|
1998-10-07 06:19:14 +02:00
|
|
|
|
|
|
|
hook = hook->next;
|
1998-09-30 10:56:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 06:19:14 +02:00
|
|
|
|
|
|
|
/* first non-destroyed hook */
|
|
|
|
sibling = hook_list->hooks;
|
|
|
|
while (sibling && !sibling->hook_id)
|
|
|
|
sibling = sibling->next;
|
1998-09-30 10:56:00 +02:00
|
|
|
|
|
|
|
while (sibling)
|
|
|
|
{
|
1998-10-07 06:19:14 +02:00
|
|
|
GHook *tmp;
|
1998-09-30 10:56:00 +02:00
|
|
|
|
|
|
|
g_hook_ref (hook_list, sibling);
|
1998-10-03 01:21:58 +02:00
|
|
|
if (func (hook, sibling) <= 0 && sibling->hook_id)
|
1998-09-30 10:56:00 +02:00
|
|
|
{
|
|
|
|
g_hook_unref (hook_list, sibling);
|
|
|
|
break;
|
|
|
|
}
|
1998-10-07 06:19:14 +02:00
|
|
|
|
|
|
|
/* next non-destroyed hook */
|
|
|
|
tmp = sibling->next;
|
|
|
|
while (tmp && !tmp->hook_id)
|
|
|
|
tmp = tmp->next;
|
|
|
|
|
1998-09-30 10:56:00 +02:00
|
|
|
g_hook_unref (hook_list, sibling);
|
|
|
|
sibling = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hook_insert_before (hook_list, sibling, hook);
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
g_hook_compare_ids (GHook *new_hook,
|
|
|
|
GHook *sibling)
|
|
|
|
{
|
1998-10-03 01:21:58 +02:00
|
|
|
return ((glong) new_hook->hook_id) - ((glong) sibling->hook_id);
|
1998-09-30 10:56:00 +02:00
|
|
|
}
|