1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 2000-2001 Red Hat, Inc.
3 * Copyright (C) 2005 Imendio AB
4 * Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 * Boston, MA 02111-1307, USA.
21 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
22 #error "Only <glib-object.h> can be included directly."
25 #ifndef __G_CLOSURE_H__
26 #define __G_CLOSURE_H__
29 #include <gobject/gtype.h>
34 #define G_CLOSURE_NEEDS_MARSHAL(closure) (((GClosure*) (closure))->marshal == NULL)
35 #define G_CLOSURE_N_NOTIFIERS(cl) ((cl)->meta_marshal + ((cl)->n_guards << 1L) + \
36 (cl)->n_fnotifiers + (cl)->n_inotifiers)
37 #define G_CCLOSURE_SWAP_DATA(cclosure) (((GClosure*) (closure))->derivative_flag)
38 #define G_CALLBACK(f) ((GCallback) (f))
42 typedef struct _GClosure GClosure;
43 typedef struct _GClosureNotifyData GClosureNotifyData;
44 typedef void (*GCallback) (void);
45 typedef void (*GClosureNotify) (gpointer data,
47 typedef void (*GClosureMarshal) (GClosure *closure,
50 const GValue *param_values,
51 gpointer invocation_hint,
52 gpointer marshal_data);
53 typedef struct _GCClosure GCClosure;
56 /* --- structures --- */
57 struct _GClosureNotifyData
60 GClosureNotify notify;
65 volatile guint ref_count : 15;
66 volatile guint meta_marshal : 1;
67 volatile guint n_guards : 1;
68 volatile guint n_fnotifiers : 2; /* finalization notifiers */
69 volatile guint n_inotifiers : 8; /* invalidation notifiers */
70 volatile guint in_inotify : 1;
71 volatile guint floating : 1;
73 volatile guint derivative_flag : 1;
75 volatile guint in_marshal : 1;
76 volatile guint is_invalid : 1;
78 /*< private >*/ void (*marshal) (GClosure *closure,
79 GValue /*out*/ *return_value,
81 const GValue *param_values,
82 gpointer invocation_hint,
83 gpointer marshal_data);
84 /*< protected >*/ gpointer data;
86 /*< private >*/ GClosureNotifyData *notifiers;
88 /* invariants/constrains:
89 * - ->marshal and ->data are _invalid_ as soon as ->is_invalid==TRUE
90 * - invocation of all inotifiers occours prior to fnotifiers
91 * - order of inotifiers is random
92 * inotifiers may _not_ free/invalidate parameter values (e.g. ->data)
93 * - order of fnotifiers is random
94 * - each notifier may only be removed before or during its invocation
95 * - reference counting may only happen prior to fnotify invocation
96 * (in that sense, fnotifiers are really finalization handlers)
99 /* closure for C function calls, callback() is the user function
108 /* --- prototypes --- */
109 IMPORT_C GClosure* g_cclosure_new (GCallback callback_func,
111 GClosureNotify destroy_data);
112 IMPORT_C GClosure* g_cclosure_new_swap (GCallback callback_func,
114 GClosureNotify destroy_data);
115 IMPORT_C GClosure* g_signal_type_cclosure_new (GType itype,
116 guint struct_offset);
119 /* --- prototypes --- */
120 IMPORT_C GClosure* g_closure_ref (GClosure *closure);
121 IMPORT_C void g_closure_sink (GClosure *closure);
122 IMPORT_C void g_closure_unref (GClosure *closure);
124 IMPORT_C GClosure* g_closure_new_simple (guint sizeof_closure,
126 IMPORT_C void g_closure_add_finalize_notifier (GClosure *closure,
127 gpointer notify_data,
128 GClosureNotify notify_func);
129 IMPORT_C void g_closure_remove_finalize_notifier (GClosure *closure,
130 gpointer notify_data,
131 GClosureNotify notify_func);
132 IMPORT_C void g_closure_add_invalidate_notifier (GClosure *closure,
133 gpointer notify_data,
134 GClosureNotify notify_func);
135 IMPORT_C void g_closure_remove_invalidate_notifier (GClosure *closure,
136 gpointer notify_data,
137 GClosureNotify notify_func);
138 IMPORT_C void g_closure_add_marshal_guards (GClosure *closure,
139 gpointer pre_marshal_data,
140 GClosureNotify pre_marshal_notify,
141 gpointer post_marshal_data,
142 GClosureNotify post_marshal_notify);
143 IMPORT_C void g_closure_set_marshal (GClosure *closure,
144 GClosureMarshal marshal);
145 IMPORT_C void g_closure_set_meta_marshal (GClosure *closure,
146 gpointer marshal_data,
147 GClosureMarshal meta_marshal);
148 IMPORT_C void g_closure_invalidate (GClosure *closure);
149 IMPORT_C void g_closure_invoke (GClosure *closure,
150 GValue /*out*/ *return_value,
151 guint n_param_values,
152 const GValue *param_values,
153 gpointer invocation_hint);
156 OK: data_object::destroy -> closure_invalidate();
157 MIS: closure_invalidate() -> disconnect(closure);
158 MIS: disconnect(closure) -> (unlink) closure_unref();
159 OK: closure_finalize() -> g_free (data_string);
162 - need marshaller repo with decent aliasing to base types
163 - provide marshaller collection, virtually covering anything out there
168 #endif /* __G_CLOSURE_H__ */