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