Add test case for the g_qsort_with_data func. It works. This fixes bug
[glib.git] / gobject / gclosure.h
blobab8974de96b1ec33329bd190cef32b878e98ac02
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>
25 G_BEGIN_DECLS
27 /* --- defines --- */
28 #define G_CLOSURE_NEEDS_MARSHAL(closure) (((GClosure*) (closure))->marshal == NULL)
29 #define G_CCLOSURE_SWAP_DATA(cclosure) (((GClosure*) (closure))->derivative_flag)
30 #define G_CALLBACK(f) ((GCallback) (f))
33 /* -- typedefs --- */
34 typedef struct _GClosure GClosure;
35 typedef struct _GClosureNotifyData GClosureNotifyData;
36 typedef void (*GCallback) (void);
37 typedef void (*GClosureNotify) (gpointer data,
38 GClosure *closure);
39 typedef void (*GClosureMarshal) (GClosure *closure,
40 GValue *return_value,
41 guint n_param_values,
42 const GValue *param_values,
43 gpointer invocation_hint,
44 gpointer marshal_data);
45 typedef struct _GCClosure GCClosure;
48 /* --- structures --- */
49 struct _GClosureNotifyData
51 gpointer data;
52 GClosureNotify notify;
54 struct _GClosure
56 /*< private >*/ guint ref_count : 15;
57 /*< private >*/ guint meta_marshal : 1;
58 /*< private >*/ guint n_guards : 1;
59 /*< private >*/ guint n_fnotifiers : 2; /* finalization notifiers */
60 /*< private >*/ guint n_inotifiers : 8; /* invalidation notifiers */
61 /*< private >*/ guint in_inotify : 1;
62 /*< private >*/ guint floating : 1;
63 /*< protected >*/ guint derivative_flag : 1;
64 /*< puplic >*/ guint in_marshal : 1;
65 /*< public >*/ guint is_invalid : 1;
67 /*< private >*/ void (*marshal) (GClosure *closure,
68 GValue /*out*/ *return_value,
69 guint n_param_values,
70 const GValue *param_values,
71 gpointer invocation_hint,
72 gpointer marshal_data);
73 /*< protected >*/ gpointer data;
75 /*< private >*/ GClosureNotifyData *notifiers;
77 /* invariants/constrains:
78 * - ->marshal and ->data are _invalid_ as soon as ->is_invalid==TRUE
79 * - invocation of all inotifiers occours prior to fnotifiers
80 * - order of inotifiers is random
81 * inotifiers may _not_ free/invalidate parameter values (e.g. ->data)
82 * - order of fnotifiers is random
83 * - each notifier may only be removed before or during its invocation
84 * - reference counting may only happen prior to fnotify invocation
85 * (in that sense, fnotifiers are really finalization handlers)
88 /* closure for C function calls, callback() is the user function
90 struct _GCClosure
92 GClosure closure;
93 gpointer callback;
97 /* --- prototypes --- */
98 GClosure* g_cclosure_new (GCallback callback_func,
99 gpointer user_data,
100 GClosureNotify destroy_data);
101 GClosure* g_cclosure_new_swap (GCallback callback_func,
102 gpointer user_data,
103 GClosureNotify destroy_data);
104 GClosure* g_signal_type_cclosure_new (GType itype,
105 guint struct_offset);
108 /* --- prototypes --- */
109 GClosure* g_closure_ref (GClosure *closure);
110 void g_closure_sink (GClosure *closure);
111 void g_closure_unref (GClosure *closure);
112 /* intimidating */
113 GClosure* g_closure_new_simple (guint sizeof_closure,
114 gpointer data);
115 void g_closure_add_finalize_notifier (GClosure *closure,
116 gpointer notify_data,
117 GClosureNotify notify_func);
118 void g_closure_remove_finalize_notifier (GClosure *closure,
119 gpointer notify_data,
120 GClosureNotify notify_func);
121 void g_closure_add_invalidate_notifier (GClosure *closure,
122 gpointer notify_data,
123 GClosureNotify notify_func);
124 void g_closure_remove_invalidate_notifier (GClosure *closure,
125 gpointer notify_data,
126 GClosureNotify notify_func);
127 void g_closure_add_marshal_guards (GClosure *closure,
128 gpointer pre_marshal_data,
129 GClosureNotify pre_marshal_notify,
130 gpointer post_marshal_data,
131 GClosureNotify post_marshal_notify);
132 void g_closure_set_marshal (GClosure *closure,
133 GClosureMarshal marshal);
134 void g_closure_set_meta_marshal (GClosure *closure,
135 gpointer marshal_data,
136 GClosureMarshal meta_marshal);
137 void g_closure_invalidate (GClosure *closure);
138 void g_closure_invoke (GClosure *closure,
139 GValue /*out*/ *return_value,
140 guint n_param_values,
141 const GValue *param_values,
142 gpointer invocation_hint);
145 /* FIXME:
146 OK: data_object::destroy -> closure_invalidate();
147 MIS: closure_invalidate() -> disconnect(closure);
148 MIS: disconnect(closure) -> (unlink) closure_unref();
149 OK: closure_finalize() -> g_free (data_string);
151 random remarks:
152 - need marshaller repo with decent aliasing to base types
153 - provide marshaller collection, virtually covering anything out there
156 G_END_DECLS
158 #endif /* __G_CLOSURE_H__ */