Update contrib.
     1 /* GLIB - Library of useful routines for C programming
 
     2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
 
     3  * Portions copyright (c) 2006-2009 Nokia Corporation.  All rights reserved.
 
     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/.
 
    27 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
 
    28 #error "Only <glib.h> can be included directly."
 
    34 #include <glib/gmem.h>
 
    39 /* --- typedefs --- */
 
    40 typedef struct _GHook		GHook;
 
    41 typedef struct _GHookList	GHookList;
 
    43 typedef gint		(*GHookCompareFunc)	(GHook		*new_hook,
 
    45 typedef gboolean	(*GHookFindFunc)	(GHook		*hook,
 
    47 typedef void		(*GHookMarshaller)	(GHook		*hook,
 
    48 						 gpointer	 marshal_data);
 
    49 typedef gboolean	(*GHookCheckMarshaller)	(GHook		*hook,
 
    50 						 gpointer	 marshal_data);
 
    51 typedef void		(*GHookFunc)		(gpointer	 data);
 
    52 typedef gboolean	(*GHookCheckFunc)	(gpointer	 data);
 
    53 typedef void		(*GHookFinalizeFunc)	(GHookList      *hook_list,
 
    57   G_HOOK_FLAG_ACTIVE	    = 1 << 0,
 
    58   G_HOOK_FLAG_IN_CALL	    = 1 << 1,
 
    59   G_HOOK_FLAG_MASK	    = 0x0f
 
    61 #define G_HOOK_FLAG_USER_SHIFT	(4)
 
    64 /* --- structures --- */
 
    72   GHookFinalizeFunc finalize_hook;
 
    84   GDestroyNotify destroy;
 
    89 #define	G_HOOK(hook)			((GHook*) (hook))
 
    90 #define	G_HOOK_FLAGS(hook)		(G_HOOK (hook)->flags)
 
    91 #define	G_HOOK_ACTIVE(hook)		((G_HOOK_FLAGS (hook) & \
 
    92 					  G_HOOK_FLAG_ACTIVE) != 0)
 
    93 #define	G_HOOK_IN_CALL(hook)		((G_HOOK_FLAGS (hook) & \
 
    94 					  G_HOOK_FLAG_IN_CALL) != 0)
 
    95 #define G_HOOK_IS_VALID(hook)		(G_HOOK (hook)->hook_id != 0 && \
 
    96 					 (G_HOOK_FLAGS (hook) & \
 
    98 #define G_HOOK_IS_UNLINKED(hook)	(G_HOOK (hook)->next == NULL && \
 
    99 					 G_HOOK (hook)->prev == NULL && \
 
   100 					 G_HOOK (hook)->hook_id == 0 && \
 
   101 					 G_HOOK (hook)->ref_count == 0)
 
   104 /* --- prototypes --- */
 
   105 /* callback maintenance functions */
 
   106 IMPORT_C void	 g_hook_list_init		(GHookList		*hook_list,
 
   108 IMPORT_C void	 g_hook_list_clear		(GHookList		*hook_list);
 
   109 IMPORT_C GHook*	 g_hook_alloc			(GHookList		*hook_list);
 
   110 IMPORT_C void	 g_hook_free			(GHookList		*hook_list,
 
   112 IMPORT_C GHook *	 g_hook_ref			(GHookList		*hook_list,
 
   114 IMPORT_C void	 g_hook_unref			(GHookList		*hook_list,
 
   116 IMPORT_C gboolean g_hook_destroy			(GHookList		*hook_list,
 
   118 IMPORT_C void	 g_hook_destroy_link		(GHookList		*hook_list,
 
   120 IMPORT_C void	 g_hook_prepend			(GHookList		*hook_list,
 
   122 IMPORT_C void	 g_hook_insert_before		(GHookList		*hook_list,
 
   125 IMPORT_C void	 g_hook_insert_sorted		(GHookList		*hook_list,
 
   127 					 GHookCompareFunc	 func);
 
   128 IMPORT_C GHook*	 g_hook_get			(GHookList		*hook_list,
 
   130 IMPORT_C GHook*	 g_hook_find			(GHookList		*hook_list,
 
   131 					 gboolean		 need_valids,
 
   134 IMPORT_C GHook*	 g_hook_find_data		(GHookList		*hook_list,
 
   135 					 gboolean		 need_valids,
 
   137 IMPORT_C GHook*	 g_hook_find_func		(GHookList		*hook_list,
 
   138 					 gboolean		 need_valids,
 
   140 IMPORT_C GHook*	 g_hook_find_func_data		(GHookList		*hook_list,
 
   141 					 gboolean		 need_valids,
 
   144 /* return the first valid hook, and increment its reference count */
 
   145 IMPORT_C GHook*	 g_hook_first_valid		(GHookList		*hook_list,
 
   146 					 gboolean		 may_be_in_call);
 
   147 /* return the next valid hook with incremented reference count, and
 
   148  * decrement the reference count of the original hook
 
   150 IMPORT_C GHook*	 g_hook_next_valid		(GHookList		*hook_list,
 
   152 					 gboolean		 may_be_in_call);
 
   153 /* GHookCompareFunc implementation to insert hooks sorted by their id */
 
   154 IMPORT_C gint	 g_hook_compare_ids		(GHook			*new_hook,
 
   156 /* convenience macros */
 
   157 #define	 g_hook_append( hook_list, hook )  \
 
   158      g_hook_insert_before ((hook_list), NULL, (hook))
 
   159 /* invoke all valid hooks with the (*GHookFunc) signature.
 
   161 IMPORT_C void	 g_hook_list_invoke		(GHookList		*hook_list,
 
   162 					 gboolean		 may_recurse);
 
   163 /* invoke all valid hooks with the (*GHookCheckFunc) signature,
 
   164  * and destroy the hook if FALSE is returned.
 
   166 IMPORT_C void	 g_hook_list_invoke_check	(GHookList		*hook_list,
 
   167 					 gboolean		 may_recurse);
 
   168 /* invoke a marshaller on all valid hooks.
 
   170 IMPORT_C void	 g_hook_list_marshal		(GHookList		*hook_list,
 
   171 					 gboolean		 may_recurse,
 
   172 					 GHookMarshaller	 marshaller,
 
   173 					 gpointer		 marshal_data);
 
   174 IMPORT_C void	 g_hook_list_marshal_check	(GHookList		*hook_list,
 
   175 					 gboolean		 may_recurse,
 
   176 					 GHookCheckMarshaller	 marshaller,
 
   177 					 gpointer		 marshal_data);
 
   181 #endif /* __G_HOOK_H__ */