00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __G_HOOK_H__
00029 #define __G_HOOK_H__
00030
00031 #include <_ansi.h>
00032 #include <glib/gmem.h>
00033
00034 G_BEGIN_DECLS
00035
00036
00037
00038 typedef struct _GHook GHook;
00039 typedef struct _GHookList GHookList;
00040
00041 typedef gint (*GHookCompareFunc) (GHook *new_hook,
00042 GHook *sibling);
00043 typedef gboolean (*GHookFindFunc) (GHook *hook,
00044 gpointer data);
00045 typedef void (*GHookMarshaller) (GHook *hook,
00046 gpointer marshal_data);
00047 typedef gboolean (*GHookCheckMarshaller) (GHook *hook,
00048 gpointer marshal_data);
00049 typedef void (*GHookFunc) (gpointer data);
00050 typedef gboolean (*GHookCheckFunc) (gpointer data);
00051 typedef void (*GHookFinalizeFunc) (GHookList *hook_list,
00052 GHook *hook);
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 #define G_HOOK_FLAG_USER_SHIFT (4)
00060
00061
00062
00063 struct _GHookList
00064 {
00065 gulong seq_id;
00066 guint hook_size : 16;
00067 guint is_setup : 1;
00068 GHook *hooks;
00069 gpointer dummy3;
00070 GHookFinalizeFunc finalize_hook;
00071 gpointer dummy[2];
00072 };
00073 struct _GHook
00074 {
00075 gpointer data;
00076 GHook *next;
00077 GHook *prev;
00078 guint ref_count;
00079 gulong hook_id;
00080 guint flags;
00081 gpointer func;
00082 GDestroyNotify destroy;
00083 };
00084
00085
00086
00087 #define G_HOOK(hook) ((GHook*) (hook))
00088 #define G_HOOK_FLAGS(hook) (G_HOOK (hook)->flags)
00089 #define G_HOOK_ACTIVE(hook) ((G_HOOK_FLAGS (hook) & \
00090 G_HOOK_FLAG_ACTIVE) != 0)
00091 #define G_HOOK_IN_CALL(hook) ((G_HOOK_FLAGS (hook) & \
00092 G_HOOK_FLAG_IN_CALL) != 0)
00093 #define G_HOOK_IS_VALID(hook) (G_HOOK (hook)->hook_id != 0 && \
00094 (G_HOOK_FLAGS (hook) & \
00095 G_HOOK_FLAG_ACTIVE))
00096 #define G_HOOK_IS_UNLINKED(hook) (G_HOOK (hook)->next == NULL && \
00097 G_HOOK (hook)->prev == NULL && \
00098 G_HOOK (hook)->hook_id == 0 && \
00099 G_HOOK (hook)->ref_count == 0)
00100
00101
00102
00103
00104 IMPORT_C void g_hook_list_init (GHookList *hook_list,
00105 guint hook_size);
00106 IMPORT_C void g_hook_list_clear (GHookList *hook_list);
00107 IMPORT_C GHook* g_hook_alloc (GHookList *hook_list);
00108 IMPORT_C void g_hook_free (GHookList *hook_list,
00109 GHook *hook);
00110 IMPORT_C GHook * g_hook_ref (GHookList *hook_list,
00111 GHook *hook);
00112 IMPORT_C void g_hook_unref (GHookList *hook_list,
00113 GHook *hook);
00114 IMPORT_C gboolean g_hook_destroy (GHookList *hook_list,
00115 gulong hook_id);
00116 IMPORT_C void g_hook_destroy_link (GHookList *hook_list,
00117 GHook *hook);
00118 IMPORT_C void g_hook_prepend (GHookList *hook_list,
00119 GHook *hook);
00120 IMPORT_C void g_hook_insert_before (GHookList *hook_list,
00121 GHook *sibling,
00122 GHook *hook);
00123 IMPORT_C void g_hook_insert_sorted (GHookList *hook_list,
00124 GHook *hook,
00125 GHookCompareFunc func);
00126 IMPORT_C GHook* g_hook_get (GHookList *hook_list,
00127 gulong hook_id);
00128 IMPORT_C GHook* g_hook_find (GHookList *hook_list,
00129 gboolean need_valids,
00130 GHookFindFunc func,
00131 gpointer data);
00132 IMPORT_C GHook* g_hook_find_data (GHookList *hook_list,
00133 gboolean need_valids,
00134 gpointer data);
00135 IMPORT_C GHook* g_hook_find_func (GHookList *hook_list,
00136 gboolean need_valids,
00137 gpointer func);
00138 IMPORT_C GHook* g_hook_find_func_data (GHookList *hook_list,
00139 gboolean need_valids,
00140 gpointer func,
00141 gpointer data);
00142
00143 IMPORT_C GHook* g_hook_first_valid (GHookList *hook_list,
00144 gboolean may_be_in_call);
00145
00146
00147
00148 IMPORT_C GHook* g_hook_next_valid (GHookList *hook_list,
00149 GHook *hook,
00150 gboolean may_be_in_call);
00151
00152 IMPORT_C gint g_hook_compare_ids (GHook *new_hook,
00153 GHook *sibling);
00154
00155 #define g_hook_append( hook_list, hook ) \
00156 g_hook_insert_before ((hook_list), NULL, (hook))
00157
00158
00159 IMPORT_C void g_hook_list_invoke (GHookList *hook_list,
00160 gboolean may_recurse);
00161
00162
00163
00164 IMPORT_C void g_hook_list_invoke_check (GHookList *hook_list,
00165 gboolean may_recurse);
00166
00167
00168 IMPORT_C void g_hook_list_marshal (GHookList *hook_list,
00169 gboolean may_recurse,
00170 GHookMarshaller marshaller,
00171 gpointer marshal_data);
00172 IMPORT_C void g_hook_list_marshal_check (GHookList *hook_list,
00173 gboolean may_recurse,
00174 GHookCheckMarshaller marshaller,
00175 gpointer marshal_data);
00176
00177 G_END_DECLS
00178
00179 #endif
00180