Use the correct fields for enums and flags. (#145015,Tommi Komulainen)
[glib.git] / gobject / gclosure.h
blobecb5e3f2af00666bf81e1709a9d11cd2aa72cb77
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 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
20 #error "Only <glib-object.h> can be included directly."
21 #endif
23 #ifndef __G_CLOSURE_H__
24 #define __G_CLOSURE_H__
26 #include <gobject/gtype.h>
28 G_BEGIN_DECLS
30 /* --- defines --- */
31 #define G_CLOSURE_NEEDS_MARSHAL(closure) (((GClosure*) (closure))->marshal == NULL)
32 #define G_CLOSURE_N_NOTIFIERS(cl) ((cl)->meta_marshal + ((cl)->n_guards << 1L) + \
33 (cl)->n_fnotifiers + (cl)->n_inotifiers)
34 #define G_CCLOSURE_SWAP_DATA(cclosure) (((GClosure*) (closure))->derivative_flag)
35 #define G_CALLBACK(f) ((GCallback) (f))
38 /* -- typedefs --- */
39 typedef struct _GClosure GClosure;
40 typedef struct _GClosureNotifyData GClosureNotifyData;
41 typedef void (*GCallback) (void);
42 typedef void (*GClosureNotify) (gpointer data,
43 GClosure *closure);
44 typedef void (*GClosureMarshal) (GClosure *closure,
45 GValue *return_value,
46 guint n_param_values,
47 const GValue *param_values,
48 gpointer invocation_hint,
49 gpointer marshal_data);
50 typedef struct _GCClosure GCClosure;
53 /* --- structures --- */
54 struct _GClosureNotifyData
56 gpointer data;
57 GClosureNotify notify;
59 struct _GClosure
61 /*< private >*/ guint ref_count : 15;
62 /*< private >*/ guint meta_marshal : 1;
63 /*< private >*/ guint n_guards : 1;
64 /*< private >*/ guint n_fnotifiers : 2; /* finalization notifiers */
65 /*< private >*/ guint n_inotifiers : 8; /* invalidation notifiers */
66 /*< private >*/ guint in_inotify : 1;
67 /*< private >*/ guint floating : 1;
68 /*< protected >*/ guint derivative_flag : 1;
69 /*< public >*/ guint in_marshal : 1;
70 /*< public >*/ guint is_invalid : 1;
72 /*< private >*/ void (*marshal) (GClosure *closure,
73 GValue /*out*/ *return_value,
74 guint n_param_values,
75 const GValue *param_values,
76 gpointer invocation_hint,
77 gpointer marshal_data);
78 /*< protected >*/ gpointer data;
80 /*< private >*/ GClosureNotifyData *notifiers;
82 /* invariants/constrains:
83 * - ->marshal and ->data are _invalid_ as soon as ->is_invalid==TRUE
84 * - invocation of all inotifiers occours prior to fnotifiers
85 * - order of inotifiers is random
86 * inotifiers may _not_ free/invalidate parameter values (e.g. ->data)
87 * - order of fnotifiers is random
88 * - each notifier may only be removed before or during its invocation
89 * - reference counting may only happen prior to fnotify invocation
90 * (in that sense, fnotifiers are really finalization handlers)
93 /* closure for C function calls, callback() is the user function
95 struct _GCClosure
97 GClosure closure;
98 gpointer callback;
102 /* --- prototypes --- */
103 GClosure* g_cclosure_new (GCallback callback_func,
104 gpointer user_data,
105 GClosureNotify destroy_data);
106 GClosure* g_cclosure_new_swap (GCallback callback_func,
107 gpointer user_data,
108 GClosureNotify destroy_data);
109 GClosure* g_signal_type_cclosure_new (GType itype,
110 guint struct_offset);
113 /* --- prototypes --- */
114 GClosure* g_closure_ref (GClosure *closure);
115 void g_closure_sink (GClosure *closure);
116 void g_closure_unref (GClosure *closure);
117 /* intimidating */
118 GClosure* g_closure_new_simple (guint sizeof_closure,
119 gpointer data);
120 void g_closure_add_finalize_notifier (GClosure *closure,
121 gpointer notify_data,
122 GClosureNotify notify_func);
123 void g_closure_remove_finalize_notifier (GClosure *closure,
124 gpointer notify_data,
125 GClosureNotify notify_func);
126 void g_closure_add_invalidate_notifier (GClosure *closure,
127 gpointer notify_data,
128 GClosureNotify notify_func);
129 void g_closure_remove_invalidate_notifier (GClosure *closure,
130 gpointer notify_data,
131 GClosureNotify notify_func);
132 void g_closure_add_marshal_guards (GClosure *closure,
133 gpointer pre_marshal_data,
134 GClosureNotify pre_marshal_notify,
135 gpointer post_marshal_data,
136 GClosureNotify post_marshal_notify);
137 void g_closure_set_marshal (GClosure *closure,
138 GClosureMarshal marshal);
139 void g_closure_set_meta_marshal (GClosure *closure,
140 gpointer marshal_data,
141 GClosureMarshal meta_marshal);
142 void g_closure_invalidate (GClosure *closure);
143 void g_closure_invoke (GClosure *closure,
144 GValue /*out*/ *return_value,
145 guint n_param_values,
146 const GValue *param_values,
147 gpointer invocation_hint);
149 /* FIXME:
150 OK: data_object::destroy -> closure_invalidate();
151 MIS: closure_invalidate() -> disconnect(closure);
152 MIS: disconnect(closure) -> (unlink) closure_unref();
153 OK: closure_finalize() -> g_free (data_string);
155 random remarks:
156 - need marshaller repo with decent aliasing to base types
157 - provide marshaller collection, virtually covering anything out there
160 G_END_DECLS
162 #endif /* __G_CLOSURE_H__ */