|
|
|||
File indexing completed on 2025-12-16 10:17:39
0001 /* GObject - GLib Type, Object, Parameter and Signal Library 0002 * Copyright (C) 2000-2001 Red Hat, Inc. 0003 * Copyright (C) 2005 Imendio AB 0004 * 0005 * SPDX-License-Identifier: LGPL-2.1-or-later 0006 * 0007 * This library is free software; you can redistribute it and/or 0008 * modify it under the terms of the GNU Lesser General Public 0009 * License as published by the Free Software Foundation; either 0010 * version 2.1 of the License, or (at your option) any later version. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General 0018 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 #ifndef __G_CLOSURE_H__ 0021 #define __G_CLOSURE_H__ 0022 0023 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) 0024 #error "Only <glib-object.h> can be included directly." 0025 #endif 0026 0027 #include <gobject/gtype.h> 0028 0029 G_BEGIN_DECLS 0030 0031 /* --- defines --- */ 0032 /** 0033 * G_CLOSURE_NEEDS_MARSHAL: 0034 * @closure: a #GClosure 0035 * 0036 * Check if the closure still needs a marshaller. See g_closure_set_marshal(). 0037 * 0038 * Returns: %TRUE if a #GClosureMarshal marshaller has not yet been set on 0039 * @closure. 0040 */ 0041 #define G_CLOSURE_NEEDS_MARSHAL(closure) (((GClosure*) (closure))->marshal == NULL) 0042 /** 0043 * G_CLOSURE_N_NOTIFIERS: 0044 * @cl: a #GClosure 0045 * 0046 * Get the total number of notifiers connected with the closure @cl. 0047 * 0048 * The count includes the meta marshaller, the finalize and invalidate notifiers 0049 * and the marshal guards. Note that each guard counts as two notifiers. 0050 * See g_closure_set_meta_marshal(), g_closure_add_finalize_notifier(), 0051 * g_closure_add_invalidate_notifier() and g_closure_add_marshal_guards(). 0052 * 0053 * Returns: number of notifiers 0054 */ 0055 #define G_CLOSURE_N_NOTIFIERS(cl) (((cl)->n_guards << 1L) + \ 0056 (cl)->n_fnotifiers + (cl)->n_inotifiers) 0057 /** 0058 * G_CCLOSURE_SWAP_DATA: 0059 * @cclosure: a #GCClosure 0060 * 0061 * Checks whether the user data of the #GCClosure should be passed as the 0062 * first parameter to the callback. See g_cclosure_new_swap(). 0063 * 0064 * Returns: %TRUE if data has to be swapped. 0065 */ 0066 #define G_CCLOSURE_SWAP_DATA(cclosure) (((GClosure*) (cclosure))->derivative_flag) 0067 /** 0068 * G_CALLBACK: 0069 * @f: a function pointer. 0070 * 0071 * Cast a function pointer to a #GCallback. 0072 */ 0073 #define G_CALLBACK(f) ((GCallback) (f)) 0074 0075 0076 /* -- typedefs --- */ 0077 typedef struct _GClosure GClosure; 0078 typedef struct _GClosureNotifyData GClosureNotifyData; 0079 0080 /** 0081 * GCallback: 0082 * 0083 * The type used for callback functions in structure definitions and function 0084 * signatures. 0085 * 0086 * This doesn't mean that all callback functions must take no parameters and 0087 * return void. The required signature of a callback function is determined by 0088 * the context in which is used (e.g. the signal to which it is connected). 0089 * 0090 * Use G_CALLBACK() to cast the callback function to a #GCallback. 0091 */ 0092 typedef void (*GCallback) (void); 0093 /** 0094 * GClosureNotify: 0095 * @data: data specified when registering the notification callback 0096 * @closure: the #GClosure on which the notification is emitted 0097 * 0098 * The type used for the various notification callbacks which can be registered 0099 * on closures. 0100 */ 0101 typedef void (*GClosureNotify) (gpointer data, 0102 GClosure *closure); 0103 /** 0104 * GClosureMarshal: 0105 * @closure: the #GClosure to which the marshaller belongs 0106 * @return_value: (nullable): a #GValue to store the return 0107 * value. May be %NULL if the callback of @closure doesn't return a 0108 * value. 0109 * @n_param_values: the length of the @param_values array 0110 * @param_values: (array length=n_param_values): an array of 0111 * #GValues holding the arguments on which to invoke the 0112 * callback of @closure 0113 * @invocation_hint: (nullable): the invocation hint given as the 0114 * last argument to g_closure_invoke() 0115 * @marshal_data: (nullable): additional data specified when 0116 * registering the marshaller, see g_closure_set_marshal() and 0117 * g_closure_set_meta_marshal() 0118 * 0119 * The type used for marshaller functions. 0120 */ 0121 typedef void (*GClosureMarshal) (GClosure *closure, 0122 GValue *return_value, 0123 guint n_param_values, 0124 const GValue *param_values, 0125 gpointer invocation_hint, 0126 gpointer marshal_data); 0127 0128 /** 0129 * GVaClosureMarshal: 0130 * @closure: the #GClosure to which the marshaller belongs 0131 * @return_value: (nullable): a #GValue to store the return 0132 * value. May be %NULL if the callback of @closure doesn't return a 0133 * value. 0134 * @instance: (type GObject.TypeInstance): the instance on which the closure is 0135 * invoked. 0136 * @args: va_list of arguments to be passed to the closure. 0137 * @marshal_data: (nullable): additional data specified when 0138 * registering the marshaller, see g_closure_set_marshal() and 0139 * g_closure_set_meta_marshal() 0140 * @n_params: the length of the @param_types array 0141 * @param_types: (array length=n_params): the #GType of each argument from 0142 * @args. 0143 * 0144 * This is the signature of va_list marshaller functions, an optional 0145 * marshaller that can be used in some situations to avoid 0146 * marshalling the signal argument into GValues. 0147 */ 0148 typedef void (* GVaClosureMarshal) (GClosure *closure, 0149 GValue *return_value, 0150 gpointer instance, 0151 va_list args, 0152 gpointer marshal_data, 0153 int n_params, 0154 GType *param_types); 0155 0156 /** 0157 * GCClosure: 0158 * @closure: the #GClosure 0159 * @callback: the callback function 0160 * 0161 * A #GCClosure is a specialization of #GClosure for C function callbacks. 0162 */ 0163 typedef struct _GCClosure GCClosure; 0164 0165 0166 /* --- structures --- */ 0167 struct _GClosureNotifyData 0168 { 0169 gpointer data; 0170 GClosureNotify notify; 0171 }; 0172 0173 struct _GClosure 0174 { 0175 /*< private >*/ 0176 guint ref_count : 15; /* (atomic) */ 0177 /* meta_marshal is not used anymore but must be zero for historical reasons 0178 as it was exposed in the G_CLOSURE_N_NOTIFIERS macro */ 0179 guint meta_marshal_nouse : 1; /* (atomic) */ 0180 guint n_guards : 1; /* (atomic) */ 0181 guint n_fnotifiers : 2; /* finalization notifiers (atomic) */ 0182 guint n_inotifiers : 8; /* invalidation notifiers (atomic) */ 0183 guint in_inotify : 1; /* (atomic) */ 0184 guint floating : 1; /* (atomic) */ 0185 /*< protected >*/ 0186 guint derivative_flag : 1; /* (atomic) */ 0187 /*< public >*/ 0188 guint in_marshal : 1; /* (atomic) */ 0189 guint is_invalid : 1; /* (atomic) */ 0190 0191 /*< private >*/ void (*marshal) (GClosure *closure, 0192 GValue /*out*/ *return_value, 0193 guint n_param_values, 0194 const GValue *param_values, 0195 gpointer invocation_hint, 0196 gpointer marshal_data); 0197 /*< protected >*/ gpointer data; 0198 0199 /*< private >*/ GClosureNotifyData *notifiers; 0200 0201 /* invariants/constraints: 0202 * - ->marshal and ->data are _invalid_ as soon as ->is_invalid==TRUE 0203 * - invocation of all inotifiers occurs prior to fnotifiers 0204 * - order of inotifiers is random 0205 * inotifiers may _not_ free/invalidate parameter values (e.g. ->data) 0206 * - order of fnotifiers is random 0207 * - each notifier may only be removed before or during its invocation 0208 * - reference counting may only happen prior to fnotify invocation 0209 * (in that sense, fnotifiers are really finalization handlers) 0210 */ 0211 }; 0212 /* closure for C function calls, callback() is the user function 0213 */ 0214 struct _GCClosure 0215 { 0216 GClosure closure; 0217 gpointer callback; 0218 }; 0219 0220 0221 /* --- prototypes --- */ 0222 GOBJECT_AVAILABLE_IN_ALL 0223 GClosure* g_cclosure_new (GCallback callback_func, 0224 gpointer user_data, 0225 GClosureNotify destroy_data); 0226 GOBJECT_AVAILABLE_IN_ALL 0227 GClosure* g_cclosure_new_swap (GCallback callback_func, 0228 gpointer user_data, 0229 GClosureNotify destroy_data); 0230 GOBJECT_AVAILABLE_IN_ALL 0231 GClosure* g_signal_type_cclosure_new (GType itype, 0232 guint struct_offset); 0233 0234 0235 /* --- prototypes --- */ 0236 GOBJECT_AVAILABLE_IN_ALL 0237 GClosure* g_closure_ref (GClosure *closure); 0238 GOBJECT_AVAILABLE_IN_ALL 0239 void g_closure_sink (GClosure *closure); 0240 GOBJECT_AVAILABLE_IN_ALL 0241 void g_closure_unref (GClosure *closure); 0242 /* intimidating */ 0243 GOBJECT_AVAILABLE_IN_ALL 0244 GClosure* g_closure_new_simple (guint sizeof_closure, 0245 gpointer data); 0246 GOBJECT_AVAILABLE_IN_ALL 0247 void g_closure_add_finalize_notifier (GClosure *closure, 0248 gpointer notify_data, 0249 GClosureNotify notify_func); 0250 GOBJECT_AVAILABLE_IN_ALL 0251 void g_closure_remove_finalize_notifier (GClosure *closure, 0252 gpointer notify_data, 0253 GClosureNotify notify_func); 0254 GOBJECT_AVAILABLE_IN_ALL 0255 void g_closure_add_invalidate_notifier (GClosure *closure, 0256 gpointer notify_data, 0257 GClosureNotify notify_func); 0258 GOBJECT_AVAILABLE_IN_ALL 0259 void g_closure_remove_invalidate_notifier (GClosure *closure, 0260 gpointer notify_data, 0261 GClosureNotify notify_func); 0262 GOBJECT_AVAILABLE_IN_ALL 0263 void g_closure_add_marshal_guards (GClosure *closure, 0264 gpointer pre_marshal_data, 0265 GClosureNotify pre_marshal_notify, 0266 gpointer post_marshal_data, 0267 GClosureNotify post_marshal_notify); 0268 GOBJECT_AVAILABLE_IN_ALL 0269 void g_closure_set_marshal (GClosure *closure, 0270 GClosureMarshal marshal); 0271 GOBJECT_AVAILABLE_IN_ALL 0272 void g_closure_set_meta_marshal (GClosure *closure, 0273 gpointer marshal_data, 0274 GClosureMarshal meta_marshal); 0275 GOBJECT_AVAILABLE_IN_ALL 0276 void g_closure_invalidate (GClosure *closure); 0277 GOBJECT_AVAILABLE_IN_ALL 0278 void g_closure_invoke (GClosure *closure, 0279 GValue /*out*/ *return_value, 0280 guint n_param_values, 0281 const GValue *param_values, 0282 gpointer invocation_hint); 0283 0284 /* FIXME: 0285 OK: data_object::destroy -> closure_invalidate(); 0286 MIS: closure_invalidate() -> disconnect(closure); 0287 MIS: disconnect(closure) -> (unlink) closure_unref(); 0288 OK: closure_finalize() -> g_free (data_string); 0289 0290 random remarks: 0291 - need marshaller repo with decent aliasing to base types 0292 - provide marshaller collection, virtually covering anything out there 0293 */ 0294 0295 GOBJECT_AVAILABLE_IN_ALL 0296 void g_cclosure_marshal_generic (GClosure *closure, 0297 GValue *return_gvalue, 0298 guint n_param_values, 0299 const GValue *param_values, 0300 gpointer invocation_hint, 0301 gpointer marshal_data); 0302 0303 GOBJECT_AVAILABLE_IN_ALL 0304 void g_cclosure_marshal_generic_va (GClosure *closure, 0305 GValue *return_value, 0306 gpointer instance, 0307 va_list args_list, 0308 gpointer marshal_data, 0309 int n_params, 0310 GType *param_types); 0311 0312 0313 G_END_DECLS 0314 0315 #endif /* __G_CLOSURE_H__ */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|