1 /* 2 * Distributed under the Boost Software License, Version 1.0. 3 * (See accompanying file LICENSE_1_0.txt or copy at 4 * http://www.boost.org/LICENSE_1_0.txt) 5 */ 6 module glib.ghook; 7 8 import glib.gtypes; 9 import glib.gmem; 10 11 12 enum GHookFlagMask 13 { 14 G_HOOK_FLAG_ACTIVE = 1 << 0, 15 G_HOOK_FLAG_IN_CALL = 1 << 1, 16 G_HOOK_FLAG_MASK = 0x0f 17 } 18 enum G_HOOK_FLAG_USER_SHIFT = 4; 19 20 21 // struct _GHookList 22 // { 23 // gulong seq_id; 24 // guint hook_size : 16; 25 // guint is_setup : 1; 26 // GHook *hooks; 27 // gpointer dummy3; 28 // GHookFinalizeFunc finalize_hook; 29 // gpointer dummy[2]; 30 // }; 31 32 // TODO: define struct with bitfields 33 struct GHookList; 34 35 struct GHook 36 { 37 gpointer data; 38 GHook *next; 39 GHook *prev; 40 guint ref_count; 41 gulong hook_id; 42 guint flags; 43 gpointer func; 44 GDestroyNotify destroy; 45 } 46 47 48 // TODO: impl following macros 49 // #define G_HOOK(hook) ((GHook*) (hook)) 50 // #define G_HOOK_FLAGS(hook) (G_HOOK (hook)->flags) 51 // #define G_HOOK_ACTIVE(hook) ((G_HOOK_FLAGS (hook) & \ 52 // G_HOOK_FLAG_ACTIVE) != 0) 53 // #define G_HOOK_IN_CALL(hook) ((G_HOOK_FLAGS (hook) & \ 54 // G_HOOK_FLAG_IN_CALL) != 0) 55 // #define G_HOOK_IS_VALID(hook) (G_HOOK (hook)->hook_id != 0 && \ 56 // (G_HOOK_FLAGS (hook) & \ 57 // G_HOOK_FLAG_ACTIVE)) 58 // #define G_HOOK_IS_UNLINKED(hook) (G_HOOK (hook)->next == NULL && \ 59 // G_HOOK (hook)->prev == NULL && \ 60 // G_HOOK (hook)->hook_id == 0 && \ 61 // G_HOOK (hook)->ref_count == 0) 62 // 63 64 extern (C) { 65 66 alias GHookCompareFunc = gint function (GHook *new_hook, GHook *sibling); 67 alias GHookFindFunc = gboolean function (GHook *hook, gpointer data); 68 alias GHookMarshaller = void function (GHook *hook, gpointer marshal_data); 69 alias GHookCheckMarshaller = gboolean function (GHook *hook, gpointer marshal_data); 70 alias GHookFunc = void function (gpointer data); 71 alias GHookCheckFunc = gboolean function (gpointer data); 72 alias GHookFinalizeFunc = void function (GHookList *hook_list, GHook *hook); 73 74 75 void g_hook_list_init (GHookList *hook_list, 76 guint hook_size); 77 78 void g_hook_list_clear (GHookList *hook_list); 79 80 GHook* g_hook_alloc (GHookList *hook_list); 81 82 void g_hook_free (GHookList *hook_list, 83 GHook *hook); 84 85 GHook * g_hook_ref (GHookList *hook_list, 86 GHook *hook); 87 88 void g_hook_unref (GHookList *hook_list, 89 GHook *hook); 90 91 gboolean g_hook_destroy (GHookList *hook_list, 92 gulong hook_id); 93 94 void g_hook_destroy_link (GHookList *hook_list, 95 GHook *hook); 96 97 void g_hook_prepend (GHookList *hook_list, 98 GHook *hook); 99 100 void g_hook_insert_before (GHookList *hook_list, 101 GHook *sibling, 102 GHook *hook); 103 104 void g_hook_insert_sorted (GHookList *hook_list, 105 GHook *hook, 106 GHookCompareFunc func); 107 108 GHook* g_hook_get (GHookList *hook_list, 109 gulong hook_id); 110 111 GHook* g_hook_find (GHookList *hook_list, 112 gboolean need_valids, 113 GHookFindFunc func, 114 gpointer data); 115 116 GHook* g_hook_find_data (GHookList *hook_list, 117 gboolean need_valids, 118 gpointer data); 119 120 GHook* g_hook_find_func (GHookList *hook_list, 121 gboolean need_valids, 122 gpointer func); 123 124 GHook* g_hook_find_func_data (GHookList *hook_list, 125 gboolean need_valids, 126 gpointer func, 127 gpointer data); 128 129 GHook* g_hook_first_valid (GHookList *hook_list, 130 gboolean may_be_in_call); 131 132 GHook* g_hook_next_valid (GHookList *hook_list, 133 GHook *hook, 134 gboolean may_be_in_call); 135 136 gint g_hook_compare_ids (GHook *new_hook, 137 GHook *sibling); 138 139 extern (D) { 140 auto g_hook_append(HL, H)(HL hook_list, H hook) { 141 return g_hook_insert_before(hook_list, null, hook); 142 } 143 } 144 145 void g_hook_list_invoke (GHookList *hook_list, 146 gboolean may_recurse); 147 148 void g_hook_list_invoke_check (GHookList *hook_list, 149 gboolean may_recurse); 150 151 void g_hook_list_marshal (GHookList *hook_list, 152 gboolean may_recurse, 153 GHookMarshaller marshaller, 154 gpointer marshal_data); 155 156 void g_hook_list_marshal_check (GHookList *hook_list, 157 gboolean may_recurse, 158 GHookCheckMarshaller marshaller, 159 gpointer marshal_data); 160 } 161