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