turned all modifications to the first 32 integer bits in a closure into
[platform/upstream/glib.git] / gobject / gclosure.h
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 2000-2001 Red Hat, Inc.
3  * Copyright (C) 2005 Imendio AB
4  *
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.
9  *
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.
14  *
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.
19  */
20 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
21 #error "Only <glib-object.h> can be included directly."
22 #endif
23
24 #ifndef __G_CLOSURE_H__
25 #define __G_CLOSURE_H__
26
27 #include        <gobject/gtype.h>
28
29 G_BEGIN_DECLS
30
31 /* --- defines --- */
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))
37
38
39 /* -- typedefs --- */
40 typedef struct _GClosure                 GClosure;
41 typedef struct _GClosureNotifyData       GClosureNotifyData;
42 typedef void  (*GCallback)              (void);
43 typedef void  (*GClosureNotify)         (gpointer        data,
44                                          GClosure       *closure);
45 typedef void  (*GClosureMarshal)        (GClosure       *closure,
46                                          GValue         *return_value,
47                                          guint           n_param_values,
48                                          const GValue   *param_values,
49                                          gpointer        invocation_hint,
50                                          gpointer        marshal_data);
51 typedef struct _GCClosure                GCClosure;
52
53
54 /* --- structures --- */
55 struct _GClosureNotifyData
56 {
57   gpointer       data;
58   GClosureNotify notify;
59 };
60 struct _GClosure
61 {
62   /*< private >*/
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;
70   /*< protected >*/
71   volatile              guint    derivative_flag : 1;
72   /*< public >*/
73   volatile              guint    in_marshal : 1;
74   volatile              guint    is_invalid : 1;
75
76   /*< private >*/       void   (*marshal)  (GClosure       *closure,
77                                             GValue /*out*/ *return_value,
78                                             guint           n_param_values,
79                                             const GValue   *param_values,
80                                             gpointer        invocation_hint,
81                                             gpointer        marshal_data);
82   /*< protected >*/     gpointer data;
83
84   /*< private >*/       GClosureNotifyData *notifiers;
85
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)
95    */
96 };
97 /* closure for C function calls, callback() is the user function
98  */
99 struct _GCClosure
100 {
101   GClosure      closure;
102   gpointer      callback;
103 };
104
105
106 /* --- prototypes --- */
107 GClosure* g_cclosure_new                        (GCallback      callback_func,
108                                                  gpointer       user_data,
109                                                  GClosureNotify destroy_data);
110 GClosure* g_cclosure_new_swap                   (GCallback      callback_func,
111                                                  gpointer       user_data,
112                                                  GClosureNotify destroy_data);
113 GClosure* g_signal_type_cclosure_new            (GType          itype,
114                                                  guint          struct_offset);
115
116
117 /* --- prototypes --- */
118 GClosure* g_closure_ref                         (GClosure       *closure);
119 void      g_closure_sink                        (GClosure       *closure);
120 void      g_closure_unref                       (GClosure       *closure);
121 /* intimidating */
122 GClosure* g_closure_new_simple                  (guint           sizeof_closure,
123                                                  gpointer        data);
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);
152
153 /* FIXME:
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);
158
159    random remarks:
160    - need marshaller repo with decent aliasing to base types
161    - provide marshaller collection, virtually covering anything out there
162 */
163
164 G_END_DECLS
165
166 #endif /* __G_CLOSURE_H__ */