Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
gclosure.h
Go to the documentation of this file.
1/* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 2000-2001 Red Hat, Inc.
3 * Copyright (C) 2005 Imendio AB
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 */
20#ifndef __G_CLOSURE_H__
21#define __G_CLOSURE_H__
22
23#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
24#error "Only <glib-object.h> can be included directly."
25#endif
26
27#include <gobject/gtype.h>
28
30
31/* --- defines --- */
32/**
33 * G_CLOSURE_NEEDS_MARSHAL:
34 * @closure: a #GClosure
35 *
36 * Check if the closure still needs a marshaller. See g_closure_set_marshal().
37 *
38 * Returns: %TRUE if a #GClosureMarshal marshaller has not yet been set on
39 * @closure.
40 */
41#define G_CLOSURE_NEEDS_MARSHAL(closure) (((GClosure*) (closure))->marshal == NULL)
42/**
43 * G_CLOSURE_N_NOTIFIERS:
44 * @cl: a #GClosure
45 *
46 * Get the total number of notifiers connected with the closure @cl.
47 *
48 * The count includes the meta marshaller, the finalize and invalidate notifiers
49 * and the marshal guards. Note that each guard counts as two notifiers.
50 * See g_closure_set_meta_marshal(), g_closure_add_finalize_notifier(),
51 * g_closure_add_invalidate_notifier() and g_closure_add_marshal_guards().
52 *
53 * Returns: number of notifiers
54 */
55#define G_CLOSURE_N_NOTIFIERS(cl) (((cl)->n_guards << 1L) + \
56 (cl)->n_fnotifiers + (cl)->n_inotifiers)
57/**
58 * G_CCLOSURE_SWAP_DATA:
59 * @cclosure: a #GCClosure
60 *
61 * Checks whether the user data of the #GCClosure should be passed as the
62 * first parameter to the callback. See g_cclosure_new_swap().
63 *
64 * Returns: %TRUE if data has to be swapped.
65 */
66#define G_CCLOSURE_SWAP_DATA(cclosure) (((GClosure*) (cclosure))->derivative_flag)
67/**
68 * G_CALLBACK:
69 * @f: a function pointer.
70 *
71 * Cast a function pointer to a #GCallback.
72 */
73#define G_CALLBACK(f) ((GCallback) (f))
74
75
76/* -- typedefs --- */
77typedef struct _GClosure GClosure;
79
80/**
81 * GCallback:
82 *
83 * The type used for callback functions in structure definitions and function
84 * signatures.
85 *
86 * This doesn't mean that all callback functions must take no parameters and
87 * return void. The required signature of a callback function is determined by
88 * the context in which is used (e.g. the signal to which it is connected).
89 *
90 * Use G_CALLBACK() to cast the callback function to a #GCallback.
91 */
92typedef void (*GCallback) (void);
93/**
94 * GClosureNotify:
95 * @data: data specified when registering the notification callback
96 * @closure: the #GClosure on which the notification is emitted
97 *
98 * The type used for the various notification callbacks which can be registered
99 * on closures.
100 */
101typedef void (*GClosureNotify) (gpointer data,
102 GClosure *closure);
103/**
104 * GClosureMarshal:
105 * @closure: the #GClosure to which the marshaller belongs
106 * @return_value: (nullable): a #GValue to store the return
107 * value. May be %NULL if the callback of @closure doesn't return a
108 * value.
109 * @n_param_values: the length of the @param_values array
110 * @param_values: (array length=n_param_values): an array of
111 * #GValues holding the arguments on which to invoke the
112 * callback of @closure
113 * @invocation_hint: (nullable): the invocation hint given as the
114 * last argument to g_closure_invoke()
115 * @marshal_data: (nullable): additional data specified when
116 * registering the marshaller, see g_closure_set_marshal() and
117 * g_closure_set_meta_marshal()
118 *
119 * The type used for marshaller functions.
120 */
121typedef void (*GClosureMarshal) (GClosure *closure,
122 GValue *return_value,
123 guint n_param_values,
124 const GValue *param_values,
125 gpointer invocation_hint,
126 gpointer marshal_data);
127
128/**
129 * GVaClosureMarshal:
130 * @closure: the #GClosure to which the marshaller belongs
131 * @return_value: (nullable): a #GValue to store the return
132 * value. May be %NULL if the callback of @closure doesn't return a
133 * value.
134 * @instance: (type GObject.TypeInstance): the instance on which the closure is
135 * invoked.
136 * @args: va_list of arguments to be passed to the closure.
137 * @marshal_data: (nullable): additional data specified when
138 * registering the marshaller, see g_closure_set_marshal() and
139 * g_closure_set_meta_marshal()
140 * @n_params: the length of the @param_types array
141 * @param_types: (array length=n_params): the #GType of each argument from
142 * @args.
143 *
144 * This is the signature of va_list marshaller functions, an optional
145 * marshaller that can be used in some situations to avoid
146 * marshalling the signal argument into GValues.
147 */
148typedef void (* GVaClosureMarshal) (GClosure *closure,
149 GValue *return_value,
150 gpointer instance,
151 va_list args,
152 gpointer marshal_data,
153 int n_params,
154 GType *param_types);
155
156/**
157 * GCClosure:
158 * @closure: the #GClosure
159 * @callback: the callback function
160 *
161 * A #GCClosure is a specialization of #GClosure for C function callbacks.
162 */
163typedef struct _GCClosure GCClosure;
164
165
166/* --- structures --- */
172
174{
175 /*< private >*/
176 guint ref_count : 15; /* (atomic) */
177 /* meta_marshal is not used anymore but must be zero for historical reasons
178 as it was exposed in the G_CLOSURE_N_NOTIFIERS macro */
179 guint meta_marshal_nouse : 1; /* (atomic) */
180 guint n_guards : 1; /* (atomic) */
181 guint n_fnotifiers : 2; /* finalization notifiers (atomic) */
182 guint n_inotifiers : 8; /* invalidation notifiers (atomic) */
183 guint in_inotify : 1; /* (atomic) */
184 guint floating : 1; /* (atomic) */
185 /*< protected >*/
186 guint derivative_flag : 1; /* (atomic) */
187 /*< public >*/
188 guint in_marshal : 1; /* (atomic) */
189 guint is_invalid : 1; /* (atomic) */
190
191 /*< private >*/ void (*marshal) (GClosure *closure,
192 GValue /*out*/ *return_value,
193 guint n_param_values,
194 const GValue *param_values,
195 gpointer invocation_hint,
196 gpointer marshal_data);
197 /*< protected >*/ gpointer data;
198
200
201 /* invariants/constraints:
202 * - ->marshal and ->data are _invalid_ as soon as ->is_invalid==TRUE
203 * - invocation of all inotifiers occurs prior to fnotifiers
204 * - order of inotifiers is random
205 * inotifiers may _not_ free/invalidate parameter values (e.g. ->data)
206 * - order of fnotifiers is random
207 * - each notifier may only be removed before or during its invocation
208 * - reference counting may only happen prior to fnotify invocation
209 * (in that sense, fnotifiers are really finalization handlers)
210 */
211};
212/* closure for C function calls, callback() is the user function
213 */
219
220
221/* --- prototypes --- */
224 gpointer user_data,
225 GClosureNotify destroy_data);
228 gpointer user_data,
229 GClosureNotify destroy_data);
232 guint struct_offset);
233
234
235/* --- prototypes --- */
239void g_closure_sink (GClosure *closure);
241void g_closure_unref (GClosure *closure);
242/* intimidating */
245 gpointer data);
248 gpointer notify_data,
249 GClosureNotify notify_func);
252 gpointer notify_data,
253 GClosureNotify notify_func);
256 gpointer notify_data,
257 GClosureNotify notify_func);
260 gpointer notify_data,
261 GClosureNotify notify_func);
264 gpointer pre_marshal_data,
265 GClosureNotify pre_marshal_notify,
266 gpointer post_marshal_data,
267 GClosureNotify post_marshal_notify);
270 GClosureMarshal marshal);
273 gpointer marshal_data,
274 GClosureMarshal meta_marshal);
279 GValue /*out*/ *return_value,
280 guint n_param_values,
281 const GValue *param_values,
282 gpointer invocation_hint);
283
284/* FIXME:
285 OK: data_object::destroy -> closure_invalidate();
286 MIS: closure_invalidate() -> disconnect(closure);
287 MIS: disconnect(closure) -> (unlink) closure_unref();
288 OK: closure_finalize() -> g_free (data_string);
289
290 random remarks:
291 - need marshaller repo with decent aliasing to base types
292 - provide marshaller collection, virtually covering anything out there
293*/
294
297 GValue *return_gvalue,
298 guint n_param_values,
299 const GValue *param_values,
300 gpointer invocation_hint,
301 gpointer marshal_data);
302
305 GValue *return_value,
306 gpointer instance,
307 va_list args_list,
308 gpointer marshal_data,
309 int n_params,
310 GType *param_types);
311
312
314
315#endif /* __G_CLOSURE_H__ */
void(* GCallback)(void)
Definition gclosure.h:92
void(* GClosureNotify)(gpointer data, GClosure *closure)
Definition gclosure.h:101
GOBJECT_AVAILABLE_IN_ALL void g_closure_unref(GClosure *closure)
GOBJECT_AVAILABLE_IN_ALL void g_closure_invalidate(GClosure *closure)
void(* GVaClosureMarshal)(GClosure *closure, GValue *return_value, gpointer instance, va_list args, gpointer marshal_data, int n_params, GType *param_types)
Definition gclosure.h:148
GOBJECT_AVAILABLE_IN_ALL void g_closure_add_marshal_guards(GClosure *closure, gpointer pre_marshal_data, GClosureNotify pre_marshal_notify, gpointer post_marshal_data, GClosureNotify post_marshal_notify)
GOBJECT_AVAILABLE_IN_ALL GClosure * g_cclosure_new_swap(GCallback callback_func, gpointer user_data, GClosureNotify destroy_data)
GOBJECT_AVAILABLE_IN_ALL void g_closure_remove_invalidate_notifier(GClosure *closure, gpointer notify_data, GClosureNotify notify_func)
GOBJECT_AVAILABLE_IN_ALL void g_cclosure_marshal_generic_va(GClosure *closure, GValue *return_value, gpointer instance, va_list args_list, gpointer marshal_data, int n_params, GType *param_types)
GOBJECT_AVAILABLE_IN_ALL GClosure * g_closure_ref(GClosure *closure)
GOBJECT_AVAILABLE_IN_ALL GClosure * g_signal_type_cclosure_new(GType itype, guint struct_offset)
GOBJECT_AVAILABLE_IN_ALL void g_closure_set_meta_marshal(GClosure *closure, gpointer marshal_data, GClosureMarshal meta_marshal)
GOBJECT_AVAILABLE_IN_ALL void g_closure_add_invalidate_notifier(GClosure *closure, gpointer notify_data, GClosureNotify notify_func)
GOBJECT_AVAILABLE_IN_ALL void g_closure_set_marshal(GClosure *closure, GClosureMarshal marshal)
GOBJECT_AVAILABLE_IN_ALL void g_closure_invoke(GClosure *closure, GValue *return_value, guint n_param_values, const GValue *param_values, gpointer invocation_hint)
GOBJECT_AVAILABLE_IN_ALL void g_closure_add_finalize_notifier(GClosure *closure, gpointer notify_data, GClosureNotify notify_func)
GOBJECT_AVAILABLE_IN_ALL GClosure * g_closure_new_simple(guint sizeof_closure, gpointer data)
GOBJECT_AVAILABLE_IN_ALL void g_closure_remove_finalize_notifier(GClosure *closure, gpointer notify_data, GClosureNotify notify_func)
void(* GClosureMarshal)(GClosure *closure, GValue *return_value, guint n_param_values, const GValue *param_values, gpointer invocation_hint, gpointer marshal_data)
Definition gclosure.h:121
GOBJECT_AVAILABLE_IN_ALL void g_cclosure_marshal_generic(GClosure *closure, GValue *return_gvalue, guint n_param_values, const GValue *param_values, gpointer invocation_hint, gpointer marshal_data)
GOBJECT_AVAILABLE_IN_ALL void g_closure_sink(GClosure *closure)
GOBJECT_AVAILABLE_IN_ALL GClosure * g_cclosure_new(GCallback callback_func, gpointer user_data, GClosureNotify destroy_data)
#define G_END_DECLS
Definition gmacros.h:910
#define G_BEGIN_DECLS
Definition gmacros.h:909
#define GOBJECT_AVAILABLE_IN_ALL
gsize GType
Definition gtype.h:427
void * gpointer
Definition gtypes.h:109
unsigned int guint
Definition gtypes.h:61
gpointer callback
Definition gclosure.h:217
GClosure closure
Definition gclosure.h:216
GClosureNotify notify
Definition gclosure.h:170
void(* marshal)(GClosure *closure, GValue *return_value, guint n_param_values, const GValue *param_values, gpointer invocation_hint, gpointer marshal_data)
Definition gclosure.h:191
gpointer data
Definition gclosure.h:197
guint in_marshal
Definition gclosure.h:188
guint n_fnotifiers
Definition gclosure.h:181
guint floating
Definition gclosure.h:184
guint is_invalid
Definition gclosure.h:189
guint meta_marshal_nouse
Definition gclosure.h:179
GClosureNotifyData * notifiers
Definition gclosure.h:199
guint ref_count
Definition gclosure.h:176
guint n_guards
Definition gclosure.h:180
guint in_inotify
Definition gclosure.h:183
guint derivative_flag
Definition gclosure.h:186
guint n_inotifiers
Definition gclosure.h:182