1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
34 typedef struct _GHook GHook;
35 typedef struct _GHookList GHookList;
37 typedef gint (*GHookCompareFunc) (GHook *new_hook,
39 typedef gboolean (*GHookFindFunc) (GHook *hook,
41 typedef void (*GHookMarshaller) (GHook *hook,
43 typedef gboolean (*GHookCheckMarshaller) (GHook *hook,
45 typedef void (*GHookFunc) (gpointer data);
46 typedef gboolean (*GHookCheckFunc) (gpointer data);
47 typedef void (*GHookFreeFunc) (GHookList *hook_list,
50 /* Callback maintenance functions
52 #define G_HOOK_FLAG_USER_SHIFT (4)
55 G_HOOK_FLAG_ACTIVE = 1 << 0,
56 G_HOOK_FLAG_IN_CALL = 1 << 1,
57 G_HOOK_FLAG_MASK = 0x0f
60 #define G_HOOK_DEFERRED_DESTROY ((GHookFreeFunc) 0x01)
68 GMemChunk *hook_memchunk;
69 GHookFreeFunc hook_free; /* virtual function */
70 GHookFreeFunc hook_destroy; /* virtual function */
82 GDestroyNotify destroy;
85 #define G_HOOK_ACTIVE(hook) ((((GHook*) hook)->flags & \
86 G_HOOK_FLAG_ACTIVE) != 0)
87 #define G_HOOK_IN_CALL(hook) ((((GHook*) hook)->flags & \
88 G_HOOK_FLAG_IN_CALL) != 0)
89 #define G_HOOK_IS_VALID(hook) (((GHook*) hook)->hook_id != 0 && \
91 #define G_HOOK_IS_UNLINKED(hook) (((GHook*) hook)->next == NULL && \
92 ((GHook*) hook)->prev == NULL && \
93 ((GHook*) hook)->hook_id == 0 && \
94 ((GHook*) hook)->ref_count == 0)
96 void g_hook_list_init (GHookList *hook_list,
98 void g_hook_list_clear (GHookList *hook_list);
99 GHook* g_hook_alloc (GHookList *hook_list);
100 void g_hook_free (GHookList *hook_list,
102 void g_hook_ref (GHookList *hook_list,
104 void g_hook_unref (GHookList *hook_list,
106 gboolean g_hook_destroy (GHookList *hook_list,
108 void g_hook_destroy_link (GHookList *hook_list,
110 void g_hook_prepend (GHookList *hook_list,
112 void g_hook_insert_before (GHookList *hook_list,
115 void g_hook_insert_sorted (GHookList *hook_list,
117 GHookCompareFunc func);
118 GHook* g_hook_get (GHookList *hook_list,
120 GHook* g_hook_find (GHookList *hook_list,
121 gboolean need_valids,
124 GHook* g_hook_find_data (GHookList *hook_list,
125 gboolean need_valids,
127 GHook* g_hook_find_func (GHookList *hook_list,
128 gboolean need_valids,
130 GHook* g_hook_find_func_data (GHookList *hook_list,
131 gboolean need_valids,
134 /* return the first valid hook, and increment its reference count */
135 GHook* g_hook_first_valid (GHookList *hook_list,
136 gboolean may_be_in_call);
137 /* return the next valid hook with incremented reference count, and
138 * decrement the reference count of the original hook
140 GHook* g_hook_next_valid (GHookList *hook_list,
142 gboolean may_be_in_call);
144 /* GHookCompareFunc implementation to insert hooks sorted by their id */
145 gint g_hook_compare_ids (GHook *new_hook,
148 /* convenience macros */
149 #define g_hook_append( hook_list, hook ) \
150 g_hook_insert_before ((hook_list), NULL, (hook))
152 /* invoke all valid hooks with the (*GHookFunc) signature.
154 void g_hook_list_invoke (GHookList *hook_list,
155 gboolean may_recurse);
156 /* invoke all valid hooks with the (*GHookCheckFunc) signature,
157 * and destroy the hook if FALSE is returned.
159 void g_hook_list_invoke_check (GHookList *hook_list,
160 gboolean may_recurse);
161 /* invoke a marshaller on all valid hooks.
163 void g_hook_list_marshal (GHookList *hook_list,
164 gboolean may_recurse,
165 GHookMarshaller marshaller,
167 void g_hook_list_marshal_check (GHookList *hook_list,
168 gboolean may_recurse,
169 GHookCheckMarshaller marshaller,
174 #endif /* __G_HOOK_H__ */