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 gobject.gclosure; 7 8 import gobject.gtype; 9 import gobject.gvalue; 10 import glib.gtypes; 11 import core.stdc.stdarg; 12 13 //#define G_CLOSURE_NEEDS_MARSHAL(closure) (((GClosure*) (closure))->marshal == NULL) 14 //#define G_CLOSURE_N_NOTIFIERS(cl) (((cl)->n_guards << 1L) + \ 15 // (cl)->n_fnotifiers + (cl)->n_inotifiers) 16 // #define G_CCLOSURE_SWAP_DATA(cclosure) (((GClosure*) (cclosure))->derivative_flag) 17 // #define G_CALLBACK(f) ((GCallback) (f)) 18 19 extern (C) { 20 21 alias GCallback = void function(); 22 alias GClosureNotify = void function (gpointer data, 23 GClosure *closure); 24 alias GClosureMarshal = void function (GClosure *closure, 25 GValue *return_value, 26 guint n_param_values, 27 const GValue *param_values, 28 gpointer invocation_hint, 29 gpointer marshal_data); 30 alias GVaClosureMarshal = void function (GClosure *closure, 31 GValue *return_value, 32 gpointer instance, 33 va_list args, 34 gpointer marshal_data, 35 int n_params, 36 GType *param_types); 37 38 struct GClosureNotifyData 39 { 40 gpointer data; 41 GClosureNotify notify; 42 } 43 44 struct GClosure; 45 // struct GClosure 46 // { 47 // /*< private >*/ 48 // guint ref_count : 15; 49 // /* meta_marshal is not used anymore but must be zero for historical reasons 50 // as it was exposed in the G_CLOSURE_N_NOTIFIERS macro */ 51 // guint meta_marshal_nouse : 1; 52 // guint n_guards : 1; 53 // guint n_fnotifiers : 2; /* finalization notifiers */ 54 // guint n_inotifiers : 8; /* invalidation notifiers */ 55 // guint in_inotify : 1; 56 // guint floating : 1; 57 // /*< protected >*/ 58 // guint derivative_flag : 1; 59 // /*< public >*/ 60 // guint in_marshal : 1; 61 // guint is_invalid : 1; 62 63 // /*< private >*/ void (*marshal) (GClosure *closure, 64 // GValue /*out*/ *return_value, 65 // guint n_param_values, 66 // const GValue *param_values, 67 // gpointer invocation_hint, 68 // gpointer marshal_data); 69 // /*< protected >*/ gpointer data; 70 71 // /*< private >*/ GClosureNotifyData *notifiers; 72 73 // /* invariants/constrains: 74 // * - ->marshal and ->data are _invalid_ as soon as ->is_invalid==TRUE 75 // * - invocation of all inotifiers occours prior to fnotifiers 76 // * - order of inotifiers is random 77 // * inotifiers may _not_ free/invalidate parameter values (e.g. ->data) 78 // * - order of fnotifiers is random 79 // * - each notifier may only be removed before or during its invocation 80 // * - reference counting may only happen prior to fnotify invocation 81 // * (in that sense, fnotifiers are really finalization handlers) 82 // */ 83 // } 84 85 struct GCClosure; 86 //struct GCClosure 87 //{ 88 // GClosure closure; 89 // gpointer callback; 90 //} 91 92 93 /* --- prototypes --- */ 94 95 GClosure* g_cclosure_new (GCallback callback_func, 96 gpointer user_data, 97 GClosureNotify destroy_data); 98 99 GClosure* g_cclosure_new_swap (GCallback callback_func, 100 gpointer user_data, 101 GClosureNotify destroy_data); 102 103 GClosure* g_signal_type_cclosure_new (GType itype, 104 guint struct_offset); 105 106 107 /* --- prototypes --- */ 108 109 GClosure* g_closure_ref (GClosure *closure); 110 111 void g_closure_sink (GClosure *closure); 112 113 void g_closure_unref (GClosure *closure); 114 /* intimidating */ 115 116 GClosure* g_closure_new_simple (guint sizeof_closure, 117 gpointer data); 118 119 void g_closure_add_finalize_notifier (GClosure *closure, 120 gpointer notify_data, 121 GClosureNotify notify_func); 122 123 void g_closure_remove_finalize_notifier (GClosure *closure, 124 gpointer notify_data, 125 GClosureNotify notify_func); 126 127 void g_closure_add_invalidate_notifier (GClosure *closure, 128 gpointer notify_data, 129 GClosureNotify notify_func); 130 131 void g_closure_remove_invalidate_notifier (GClosure *closure, 132 gpointer notify_data, 133 GClosureNotify notify_func); 134 135 void g_closure_add_marshal_guards (GClosure *closure, 136 gpointer pre_marshal_data, 137 GClosureNotify pre_marshal_notify, 138 gpointer post_marshal_data, 139 GClosureNotify post_marshal_notify); 140 141 void g_closure_set_marshal (GClosure *closure, 142 GClosureMarshal marshal); 143 144 void g_closure_set_meta_marshal (GClosure *closure, 145 gpointer marshal_data, 146 GClosureMarshal meta_marshal); 147 148 void g_closure_invalidate (GClosure *closure); 149 150 void g_closure_invoke (GClosure *closure, 151 GValue /*out*/ *return_value, 152 guint n_param_values, 153 const(GValue) *param_values, 154 gpointer invocation_hint); 155 156 /* FIXME: 157 OK: data_object::destroy -> closure_invalidate(); 158 MIS: closure_invalidate() -> disconnect(closure); 159 MIS: disconnect(closure) -> (unlink) closure_unref(); 160 OK: closure_finalize() -> g_free (data_string); 161 162 random remarks: 163 - need marshaller repo with decent aliasing to base types 164 - provide marshaller collection, virtually covering anything out there 165 */ 166 167 168 void g_cclosure_marshal_generic (GClosure *closure, 169 GValue *return_gvalue, 170 guint n_param_values, 171 const(GValue) *param_values, 172 gpointer invocation_hint, 173 gpointer marshal_data); 174 175 176 void g_cclosure_marshal_generic_va (GClosure *closure, 177 GValue *return_value, 178 gpointer instance, 179 va_list args_list, 180 gpointer marshal_data, 181 int n_params, 182 GType *param_types); 183 184 } 185