ghook.h

Go to the documentation of this file.
00001 /* GLIB - Library of useful routines for C programming
00002  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00020 /*
00021  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
00022  * file for a list of people on the GLib Team.  See the ChangeLog
00023  * files for a list of changes.  These files are distributed with
00024  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
00025  */
00026 
00027 #ifndef __G_HOOK_H__
00028 #define __G_HOOK_H__
00029 
00030 #include <gmem.h>
00031 
00032 G_BEGIN_DECLS
00033 
00034 typedef struct _GHook           GHook;
00035 typedef struct _GHookList       GHookList;
00036 
00037 typedef gint            (*GHookCompareFunc)     (GHook          *new_hook,
00038                                                  GHook          *sibling);
00039 typedef gboolean        (*GHookFindFunc)        (GHook          *hook,
00040                                                  gpointer        data);
00041 typedef void            (*GHookMarshaller)      (GHook          *hook,
00042                                                  gpointer        data);
00043 typedef gboolean        (*GHookCheckMarshaller) (GHook          *hook,
00044                                                  gpointer        data);
00045 typedef void            (*GHookFunc)            (gpointer        data);
00046 typedef gboolean        (*GHookCheckFunc)       (gpointer        data);
00047 typedef void            (*GHookFreeFunc)        (GHookList      *hook_list,
00048                                                  GHook          *hook);
00049 
00050 /* Callback maintenance functions
00051  */
00052 #define G_HOOK_FLAG_USER_SHIFT  (4)
00053 typedef enum
00054 {
00055   G_HOOK_FLAG_ACTIVE    = 1 << 0,
00056   G_HOOK_FLAG_IN_CALL   = 1 << 1,
00057   G_HOOK_FLAG_MASK      = 0x0f
00058 } GHookFlagMask;
00059 
00060 #define G_HOOK_DEFERRED_DESTROY ((GHookFreeFunc) 0x01)
00061 
00062 struct _GHookList
00063 {
00064   guint          seq_id;
00065   guint          hook_size;
00066   guint          is_setup : 1;
00067   GHook         *hooks;
00068   GMemChunk     *hook_memchunk;
00069   GHookFreeFunc  hook_free; /* virtual function */
00070   GHookFreeFunc  hook_destroy; /* virtual function */
00071 };
00072 
00073 struct _GHook
00074 {
00075   gpointer       data;
00076   GHook         *next;
00077   GHook         *prev;
00078   guint          ref_count;
00079   guint          hook_id;
00080   guint          flags;
00081   gpointer       func;
00082   GDestroyNotify destroy;
00083 };
00084 
00085 #define G_HOOK_ACTIVE(hook)             ((((GHook*) hook)->flags & \
00086                                           G_HOOK_FLAG_ACTIVE) != 0)
00087 #define G_HOOK_IN_CALL(hook)            ((((GHook*) hook)->flags & \
00088                                           G_HOOK_FLAG_IN_CALL) != 0)
00089 #define G_HOOK_IS_VALID(hook)           (((GHook*) hook)->hook_id != 0 && \
00090                                          G_HOOK_ACTIVE (hook))
00091 #define G_HOOK_IS_UNLINKED(hook)        (((GHook*) hook)->next == NULL && \
00092                                          ((GHook*) hook)->prev == NULL && \
00093                                          ((GHook*) hook)->hook_id == 0 && \
00094                                          ((GHook*) hook)->ref_count == 0)
00095 
00096 void     g_hook_list_init               (GHookList              *hook_list,
00097                                          guint                   hook_size);
00098 void     g_hook_list_clear              (GHookList              *hook_list);
00099 GHook*   g_hook_alloc                   (GHookList              *hook_list);
00100 void     g_hook_free                    (GHookList              *hook_list,
00101                                          GHook                  *hook);
00102 void     g_hook_ref                     (GHookList              *hook_list,
00103                                          GHook                  *hook);
00104 void     g_hook_unref                   (GHookList              *hook_list,
00105                                          GHook                  *hook);
00106 gboolean g_hook_destroy                 (GHookList              *hook_list,
00107                                          guint                   hook_id);
00108 void     g_hook_destroy_link            (GHookList              *hook_list,
00109                                          GHook                  *hook);
00110 void     g_hook_prepend                 (GHookList              *hook_list,
00111                                          GHook                  *hook);
00112 void     g_hook_insert_before           (GHookList              *hook_list,
00113                                          GHook                  *sibling,
00114                                          GHook                  *hook);
00115 void     g_hook_insert_sorted           (GHookList              *hook_list,
00116                                          GHook                  *hook,
00117                                          GHookCompareFunc        func);
00118 GHook*   g_hook_get                     (GHookList              *hook_list,
00119                                          guint                   hook_id);
00120 GHook*   g_hook_find                    (GHookList              *hook_list,
00121                                          gboolean                need_valids,
00122                                          GHookFindFunc           func,
00123                                          gpointer                data);
00124 GHook*   g_hook_find_data               (GHookList              *hook_list,
00125                                          gboolean                need_valids,
00126                                          gpointer                data);
00127 GHook*   g_hook_find_func               (GHookList              *hook_list,
00128                                          gboolean                need_valids,
00129                                          gpointer                func);
00130 GHook*   g_hook_find_func_data          (GHookList              *hook_list,
00131                                          gboolean                need_valids,
00132                                          gpointer                func,
00133                                          gpointer                data);
00134 /* return the first valid hook, and increment its reference count */
00135 GHook*   g_hook_first_valid             (GHookList              *hook_list,
00136                                          gboolean                may_be_in_call);
00137 /* return the next valid hook with incremented reference count, and
00138  * decrement the reference count of the original hook
00139  */
00140 GHook*   g_hook_next_valid              (GHookList              *hook_list,
00141                                          GHook                  *hook,
00142                                          gboolean                may_be_in_call);
00143 
00144 /* GHookCompareFunc implementation to insert hooks sorted by their id */
00145 gint     g_hook_compare_ids             (GHook                  *new_hook,
00146                                          GHook                  *sibling);
00147 
00148 /* convenience macros */
00149 #define  g_hook_append( hook_list, hook )  \
00150      g_hook_insert_before ((hook_list), NULL, (hook))
00151 
00152 /* invoke all valid hooks with the (*GHookFunc) signature.
00153  */
00154 void     g_hook_list_invoke             (GHookList              *hook_list,
00155                                          gboolean                may_recurse);
00156 /* invoke all valid hooks with the (*GHookCheckFunc) signature,
00157  * and destroy the hook if FALSE is returned.
00158  */
00159 void     g_hook_list_invoke_check       (GHookList              *hook_list,
00160                                          gboolean                may_recurse);
00161 /* invoke a marshaller on all valid hooks.
00162  */
00163 void     g_hook_list_marshal            (GHookList              *hook_list,
00164                                          gboolean                may_recurse,
00165                                          GHookMarshaller         marshaller,
00166                                          gpointer                data);
00167 void     g_hook_list_marshal_check      (GHookList              *hook_list,
00168                                          gboolean                may_recurse,
00169                                          GHookCheckMarshaller    marshaller,
00170                                          gpointer                data);
00171 
00172 G_END_DECLS
00173 
00174 #endif /* __G_HOOK_H__ */
00175 

Generated on Tue Jul 5 14:14:41 2011 for ROOT_528-00b_version by  doxygen 1.5.1