ossrv_pub/glib_hook_functions/inc/stdapis/glib-2.0/glib/ghook.h
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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 Nokia Corporation.  All rights reserved.
       
     4  *
       
     5  * This library is free software; you can redistribute it and/or
       
     6  * modify it under the terms of the GNU Lesser General Public
       
     7  * License as published by the Free Software Foundation; either
       
     8  * version 2 of the License, or (at your option) any later version.
       
     9  *
       
    10  * This library is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
       
    13  * Lesser General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU Lesser General Public
       
    16  * License along with this library; if not, write to the
       
    17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    18  * Boston, MA 02111-1307, USA.
       
    19  */
       
    20 
       
    21 /*
       
    22  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
       
    23  * file for a list of people on the GLib Team.  See the ChangeLog
       
    24  * files for a list of changes.  These files are distributed with
       
    25  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
       
    26  */
       
    27 
       
    28 #ifndef __G_HOOK_H__
       
    29 #define __G_HOOK_H__
       
    30 
       
    31 #include <_ansi.h>
       
    32 #include <glib/gmem.h>
       
    33 
       
    34 G_BEGIN_DECLS
       
    35 
       
    36 
       
    37 /* --- typedefs --- */
       
    38 typedef struct _GHook		GHook;
       
    39 typedef struct _GHookList	GHookList;
       
    40 
       
    41 typedef gint		(*GHookCompareFunc)	(GHook		*new_hook,
       
    42 						 GHook		*sibling);
       
    43 typedef gboolean	(*GHookFindFunc)	(GHook		*hook,
       
    44 						 gpointer	 data);
       
    45 typedef void		(*GHookMarshaller)	(GHook		*hook,
       
    46 						 gpointer	 marshal_data);
       
    47 typedef gboolean	(*GHookCheckMarshaller)	(GHook		*hook,
       
    48 						 gpointer	 marshal_data);
       
    49 typedef void		(*GHookFunc)		(gpointer	 data);
       
    50 typedef gboolean	(*GHookCheckFunc)	(gpointer	 data);
       
    51 typedef void		(*GHookFinalizeFunc)	(GHookList      *hook_list,
       
    52 						 GHook          *hook);
       
    53 typedef enum
       
    54 {
       
    55   G_HOOK_FLAG_ACTIVE	    = 1 << 0,
       
    56   G_HOOK_FLAG_IN_CALL	    = 1 << 1,
       
    57   G_HOOK_FLAG_MASK	    = 0x0f
       
    58 } GHookFlagMask;
       
    59 #define G_HOOK_FLAG_USER_SHIFT	(4)
       
    60 
       
    61 
       
    62 /* --- structures --- */
       
    63 struct _GHookList
       
    64 {
       
    65   gulong	    seq_id;
       
    66   guint		    hook_size : 16;
       
    67   guint		    is_setup : 1;
       
    68   GHook		   *hooks;
       
    69   gpointer	    dummy3;
       
    70   GHookFinalizeFunc finalize_hook;
       
    71   gpointer	    dummy[2];
       
    72 };
       
    73 struct _GHook
       
    74 {
       
    75   gpointer	 data;
       
    76   GHook		*next;
       
    77   GHook		*prev;
       
    78   guint		 ref_count;
       
    79   gulong	 hook_id;
       
    80   guint		 flags;
       
    81   gpointer	 func;
       
    82   GDestroyNotify destroy;
       
    83 };
       
    84 
       
    85 
       
    86 /* --- macros --- */
       
    87 #define	G_HOOK(hook)			((GHook*) (hook))
       
    88 #define	G_HOOK_FLAGS(hook)		(G_HOOK (hook)->flags)
       
    89 #define	G_HOOK_ACTIVE(hook)		((G_HOOK_FLAGS (hook) & \
       
    90 					  G_HOOK_FLAG_ACTIVE) != 0)
       
    91 #define	G_HOOK_IN_CALL(hook)		((G_HOOK_FLAGS (hook) & \
       
    92 					  G_HOOK_FLAG_IN_CALL) != 0)
       
    93 #define G_HOOK_IS_VALID(hook)		(G_HOOK (hook)->hook_id != 0 && \
       
    94 					 (G_HOOK_FLAGS (hook) & \
       
    95                                           G_HOOK_FLAG_ACTIVE))
       
    96 #define G_HOOK_IS_UNLINKED(hook)	(G_HOOK (hook)->next == NULL && \
       
    97 					 G_HOOK (hook)->prev == NULL && \
       
    98 					 G_HOOK (hook)->hook_id == 0 && \
       
    99 					 G_HOOK (hook)->ref_count == 0)
       
   100 
       
   101 
       
   102 /* --- prototypes --- */
       
   103 /* callback maintenance functions */
       
   104 IMPORT_C void	 g_hook_list_init		(GHookList		*hook_list,
       
   105 					 guint			 hook_size);
       
   106 IMPORT_C void	 g_hook_list_clear		(GHookList		*hook_list);
       
   107 IMPORT_C GHook*	 g_hook_alloc			(GHookList		*hook_list);
       
   108 IMPORT_C void	 g_hook_free			(GHookList		*hook_list,
       
   109 					 GHook			*hook);
       
   110 IMPORT_C GHook *	 g_hook_ref			(GHookList		*hook_list,
       
   111 					 GHook			*hook);
       
   112 IMPORT_C void	 g_hook_unref			(GHookList		*hook_list,
       
   113 					 GHook			*hook);
       
   114 IMPORT_C gboolean g_hook_destroy			(GHookList		*hook_list,
       
   115 					 gulong			 hook_id);
       
   116 IMPORT_C void	 g_hook_destroy_link		(GHookList		*hook_list,
       
   117 					 GHook			*hook);
       
   118 IMPORT_C void	 g_hook_prepend			(GHookList		*hook_list,
       
   119 					 GHook			*hook);
       
   120 IMPORT_C void	 g_hook_insert_before		(GHookList		*hook_list,
       
   121 					 GHook			*sibling,
       
   122 					 GHook			*hook);
       
   123 IMPORT_C void	 g_hook_insert_sorted		(GHookList		*hook_list,
       
   124 					 GHook			*hook,
       
   125 					 GHookCompareFunc	 func);
       
   126 IMPORT_C GHook*	 g_hook_get			(GHookList		*hook_list,
       
   127 					 gulong			 hook_id);
       
   128 IMPORT_C GHook*	 g_hook_find			(GHookList		*hook_list,
       
   129 					 gboolean		 need_valids,
       
   130 					 GHookFindFunc		 func,
       
   131 					 gpointer		 data);
       
   132 IMPORT_C GHook*	 g_hook_find_data		(GHookList		*hook_list,
       
   133 					 gboolean		 need_valids,
       
   134 					 gpointer		 data);
       
   135 IMPORT_C GHook*	 g_hook_find_func		(GHookList		*hook_list,
       
   136 					 gboolean		 need_valids,
       
   137 					 gpointer		 func);
       
   138 IMPORT_C GHook*	 g_hook_find_func_data		(GHookList		*hook_list,
       
   139 					 gboolean		 need_valids,
       
   140 					 gpointer		 func,
       
   141 					 gpointer		 data);
       
   142 /* return the first valid hook, and increment its reference count */
       
   143 IMPORT_C GHook*	 g_hook_first_valid		(GHookList		*hook_list,
       
   144 					 gboolean		 may_be_in_call);
       
   145 /* return the next valid hook with incremented reference count, and
       
   146  * decrement the reference count of the original hook
       
   147  */
       
   148 IMPORT_C GHook*	 g_hook_next_valid		(GHookList		*hook_list,
       
   149 					 GHook			*hook,
       
   150 					 gboolean		 may_be_in_call);
       
   151 /* GHookCompareFunc implementation to insert hooks sorted by their id */
       
   152 IMPORT_C gint	 g_hook_compare_ids		(GHook			*new_hook,
       
   153 					 GHook			*sibling);
       
   154 /* convenience macros */
       
   155 #define	 g_hook_append( hook_list, hook )  \
       
   156      g_hook_insert_before ((hook_list), NULL, (hook))
       
   157 /* invoke all valid hooks with the (*GHookFunc) signature.
       
   158  */
       
   159 IMPORT_C void	 g_hook_list_invoke		(GHookList		*hook_list,
       
   160 					 gboolean		 may_recurse);
       
   161 /* invoke all valid hooks with the (*GHookCheckFunc) signature,
       
   162  * and destroy the hook if FALSE is returned.
       
   163  */
       
   164 IMPORT_C void	 g_hook_list_invoke_check	(GHookList		*hook_list,
       
   165 					 gboolean		 may_recurse);
       
   166 /* invoke a marshaller on all valid hooks.
       
   167  */
       
   168 IMPORT_C void	 g_hook_list_marshal		(GHookList		*hook_list,
       
   169 					 gboolean		 may_recurse,
       
   170 					 GHookMarshaller	 marshaller,
       
   171 					 gpointer		 marshal_data);
       
   172 IMPORT_C void	 g_hook_list_marshal_check	(GHookList		*hook_list,
       
   173 					 gboolean		 may_recurse,
       
   174 					 GHookCheckMarshaller	 marshaller,
       
   175 					 gpointer		 marshal_data);
       
   176 
       
   177 G_END_DECLS
       
   178 
       
   179 #endif /* __G_HOOK_H__ */
       
   180