1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 2000-2001 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
19 #ifndef __G_CLOSURE_H__
20 #define __G_CLOSURE_H__
23 #include <gobject/gtype.h>
28 #define G_CLOSURE_NEEDS_MARSHAL(closure) (((GClosure*) (closure))->marshal == NULL)
29 #define G_CLOSURE_N_NOTIFIERS(cl) ((cl)->meta_marshal + ((cl)->n_guards << 1L) + \
30 (cl)->n_fnotifiers + (cl)->n_inotifiers)
31 #define G_CCLOSURE_SWAP_DATA(cclosure) (((GClosure*) (closure))->derivative_flag)
32 #define G_CALLBACK(f) ((GCallback) (f))
36 typedef struct _GClosure GClosure;
37 typedef struct _GClosureNotifyData GClosureNotifyData;
38 typedef void (*GCallback) (void);
39 typedef void (*GClosureNotify) (gpointer data,
41 typedef void (*GClosureMarshal) (GClosure *closure,
44 const GValue *param_values,
45 gpointer invocation_hint,
46 gpointer marshal_data);
47 typedef struct _GCClosure GCClosure;
50 /* --- structures --- */
51 struct _GClosureNotifyData
54 GClosureNotify notify;
58 /*< private >*/ guint ref_count : 15;
59 /*< private >*/ guint meta_marshal : 1;
60 /*< private >*/ guint n_guards : 1;
61 /*< private >*/ guint n_fnotifiers : 2; /* finalization notifiers */
62 /*< private >*/ guint n_inotifiers : 8; /* invalidation notifiers */
63 /*< private >*/ guint in_inotify : 1;
64 /*< private >*/ guint floating : 1;
65 /*< protected >*/ guint derivative_flag : 1;
66 /*< puplic >*/ guint in_marshal : 1;
67 /*< public >*/ guint is_invalid : 1;
69 /*< private >*/ void (*marshal) (GClosure *closure,
70 GValue /*out*/ *return_value,
72 const GValue *param_values,
73 gpointer invocation_hint,
74 gpointer marshal_data);
75 /*< protected >*/ gpointer data;
77 /*< private >*/ GClosureNotifyData *notifiers;
79 /* invariants/constrains:
80 * - ->marshal and ->data are _invalid_ as soon as ->is_invalid==TRUE
81 * - invocation of all inotifiers occours prior to fnotifiers
82 * - order of inotifiers is random
83 * inotifiers may _not_ free/invalidate parameter values (e.g. ->data)
84 * - order of fnotifiers is random
85 * - each notifier may only be removed before or during its invocation
86 * - reference counting may only happen prior to fnotify invocation
87 * (in that sense, fnotifiers are really finalization handlers)
90 /* closure for C function calls, callback() is the user function
99 /* --- prototypes --- */
100 GClosure* g_cclosure_new (GCallback callback_func,
102 GClosureNotify destroy_data);
103 GClosure* g_cclosure_new_swap (GCallback callback_func,
105 GClosureNotify destroy_data);
106 GClosure* g_signal_type_cclosure_new (GType itype,
107 guint struct_offset);
110 /* --- prototypes --- */
111 GClosure* g_closure_ref (GClosure *closure);
112 void g_closure_sink (GClosure *closure);
113 void g_closure_unref (GClosure *closure);
115 GClosure* g_closure_new_simple (guint sizeof_closure,
117 void g_closure_add_finalize_notifier (GClosure *closure,
118 gpointer notify_data,
119 GClosureNotify notify_func);
120 void g_closure_remove_finalize_notifier (GClosure *closure,
121 gpointer notify_data,
122 GClosureNotify notify_func);
123 void g_closure_add_invalidate_notifier (GClosure *closure,
124 gpointer notify_data,
125 GClosureNotify notify_func);
126 void g_closure_remove_invalidate_notifier (GClosure *closure,
127 gpointer notify_data,
128 GClosureNotify notify_func);
129 void g_closure_add_marshal_guards (GClosure *closure,
130 gpointer pre_marshal_data,
131 GClosureNotify pre_marshal_notify,
132 gpointer post_marshal_data,
133 GClosureNotify post_marshal_notify);
134 void g_closure_set_marshal (GClosure *closure,
135 GClosureMarshal marshal);
136 void g_closure_set_meta_marshal (GClosure *closure,
137 gpointer marshal_data,
138 GClosureMarshal meta_marshal);
139 void g_closure_invalidate (GClosure *closure);
140 void g_closure_invoke (GClosure *closure,
141 GValue /*out*/ *return_value,
142 guint n_param_values,
143 const GValue *param_values,
144 gpointer invocation_hint);
147 OK: data_object::destroy -> closure_invalidate();
148 MIS: closure_invalidate() -> disconnect(closure);
149 MIS: disconnect(closure) -> (unlink) closure_unref();
150 OK: closure_finalize() -> g_free (data_string);
153 - need marshaller repo with decent aliasing to base types
154 - provide marshaller collection, virtually covering anything out there
159 #endif /* __G_CLOSURE_H__ */