gclosure.h

Go to the documentation of this file.
00001 /* GObject - GLib Type, Object, Parameter and Signal Library
00002  * Copyright (C) 2000-2001 Red Hat, Inc.
00003  * Copyright (C) 2005 Imendio AB
00004  * Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General
00017  * Public License along with this library; if not, write to the
00018  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00019  * Boston, MA 02111-1307, USA.
00020  */
00021 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
00022 #error "Only <glib-object.h> can be included directly."
00023 #endif
00024 
00025 #ifndef __G_CLOSURE_H__
00026 #define __G_CLOSURE_H__
00027 
00028 #include <_ansi.h>
00029 #include        <gobject/gtype.h>
00030 
00031 G_BEGIN_DECLS
00032 
00033 /* --- defines --- */
00034 #define G_CLOSURE_NEEDS_MARSHAL(closure) (((GClosure*) (closure))->marshal == NULL)
00035 #define G_CLOSURE_N_NOTIFIERS(cl)        ((cl)->meta_marshal + ((cl)->n_guards << 1L) + \
00036                                           (cl)->n_fnotifiers + (cl)->n_inotifiers)
00037 #define G_CCLOSURE_SWAP_DATA(cclosure)   (((GClosure*) (closure))->derivative_flag)
00038 #define G_CALLBACK(f)                    ((GCallback) (f))
00039 
00040 
00041 /* -- typedefs --- */
00042 typedef struct _GClosure                 GClosure;
00043 typedef struct _GClosureNotifyData       GClosureNotifyData;
00044 typedef void  (*GCallback)              (void);
00045 typedef void  (*GClosureNotify)         (gpointer        data,
00046                                          GClosure       *closure);
00047 typedef void  (*GClosureMarshal)        (GClosure       *closure,
00048                                          GValue         *return_value,
00049                                          guint           n_param_values,
00050                                          const GValue   *param_values,
00051                                          gpointer        invocation_hint,
00052                                          gpointer        marshal_data);
00053 typedef struct _GCClosure                GCClosure;
00054 
00055 
00056 /* --- structures --- */
00057 struct _GClosureNotifyData
00058 {
00059   gpointer       data;
00060   GClosureNotify notify;
00061 };
00062 struct _GClosure
00063 {
00064   /*< private >*/
00065   volatile              guint    ref_count : 15;
00066   volatile              guint    meta_marshal : 1;
00067   volatile              guint    n_guards : 1;
00068   volatile              guint    n_fnotifiers : 2;      /* finalization notifiers */
00069   volatile              guint    n_inotifiers : 8;      /* invalidation notifiers */
00070   volatile              guint    in_inotify : 1;
00071   volatile              guint    floating : 1;
00072   /*< protected >*/
00073   volatile              guint    derivative_flag : 1;
00074   /*< public >*/
00075   volatile              guint    in_marshal : 1;
00076   volatile              guint    is_invalid : 1;
00077 
00078   /*< private >*/       void   (*marshal)  (GClosure       *closure,
00079                                             GValue /*out*/ *return_value,
00080                                             guint           n_param_values,
00081                                             const GValue   *param_values,
00082                                             gpointer        invocation_hint,
00083                                             gpointer        marshal_data);
00084   /*< protected >*/     gpointer data;
00085 
00086   /*< private >*/       GClosureNotifyData *notifiers;
00087 
00088   /* invariants/constrains:
00089    * - ->marshal and ->data are _invalid_ as soon as ->is_invalid==TRUE
00090    * - invocation of all inotifiers occours prior to fnotifiers
00091    * - order of inotifiers is random
00092    *   inotifiers may _not_ free/invalidate parameter values (e.g. ->data)
00093    * - order of fnotifiers is random
00094    * - each notifier may only be removed before or during its invocation
00095    * - reference counting may only happen prior to fnotify invocation
00096    *   (in that sense, fnotifiers are really finalization handlers)
00097    */
00098 };
00099 /* closure for C function calls, callback() is the user function
00100  */
00101 struct _GCClosure
00102 {
00103   GClosure      closure;
00104   gpointer      callback;
00105 };
00106 
00107 
00108 /* --- prototypes --- */
00109 IMPORT_C GClosure* g_cclosure_new                       (GCallback      callback_func,
00110                                                  gpointer       user_data,
00111                                                  GClosureNotify destroy_data);
00112 IMPORT_C GClosure* g_cclosure_new_swap                  (GCallback      callback_func,
00113                                                  gpointer       user_data,
00114                                                  GClosureNotify destroy_data);
00115 IMPORT_C GClosure* g_signal_type_cclosure_new           (GType          itype,
00116                                                  guint          struct_offset);
00117 
00118 
00119 /* --- prototypes --- */
00120 IMPORT_C GClosure* g_closure_ref                                (GClosure       *closure);
00121 IMPORT_C void     g_closure_sink                        (GClosure       *closure);
00122 IMPORT_C void     g_closure_unref                       (GClosure       *closure);
00123 /* intimidating */
00124 IMPORT_C GClosure* g_closure_new_simple                 (guint           sizeof_closure,
00125                                                  gpointer        data);
00126 IMPORT_C void     g_closure_add_finalize_notifier       (GClosure       *closure,
00127                                                  gpointer        notify_data,
00128                                                  GClosureNotify  notify_func);
00129 IMPORT_C void     g_closure_remove_finalize_notifier    (GClosure       *closure,
00130                                                  gpointer        notify_data,
00131                                                  GClosureNotify  notify_func);
00132 IMPORT_C void     g_closure_add_invalidate_notifier     (GClosure       *closure,
00133                                                  gpointer        notify_data,
00134                                                  GClosureNotify  notify_func);
00135 IMPORT_C void     g_closure_remove_invalidate_notifier  (GClosure       *closure,
00136                                                  gpointer        notify_data,
00137                                                  GClosureNotify  notify_func);
00138 IMPORT_C void     g_closure_add_marshal_guards          (GClosure       *closure,
00139                                                  gpointer        pre_marshal_data,
00140                                                  GClosureNotify  pre_marshal_notify,
00141                                                  gpointer        post_marshal_data,
00142                                                  GClosureNotify  post_marshal_notify);
00143 IMPORT_C void     g_closure_set_marshal                 (GClosure       *closure,
00144                                                  GClosureMarshal marshal);
00145 IMPORT_C void     g_closure_set_meta_marshal            (GClosure       *closure,
00146                                                  gpointer        marshal_data,
00147                                                  GClosureMarshal meta_marshal);
00148 IMPORT_C void     g_closure_invalidate                  (GClosure       *closure);
00149 IMPORT_C void     g_closure_invoke                      (GClosure       *closure,
00150                                                  GValue /*out*/ *return_value,
00151                                                  guint           n_param_values,
00152                                                  const GValue   *param_values,
00153                                                  gpointer        invocation_hint);
00154 
00155 /* FIXME:
00156    OK:  data_object::destroy            -> closure_invalidate();
00157    MIS: closure_invalidate()            -> disconnect(closure);
00158    MIS: disconnect(closure)             -> (unlink) closure_unref();
00159    OK:  closure_finalize()              -> g_free (data_string);
00160 
00161    random remarks:
00162    - need marshaller repo with decent aliasing to base types
00163    - provide marshaller collection, virtually covering anything out there
00164 */
00165 
00166 G_END_DECLS
00167 
00168 #endif /* __G_CLOSURE_H__ */

Copyright © Nokia Corporation 2001-2008
Back to top