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