williamr@2: /* GObject - GLib Type, Object, Parameter and Signal Library williamr@2: * Copyright (C) 2000-2001 Red Hat, Inc. williamr@2: * Copyright (C) 2005 Imendio AB williamr@2: * Portions copyright (c) 2006 Nokia Corporation. All rights reserved. williamr@2: * williamr@2: * This library is free software; you can redistribute it and/or williamr@2: * modify it under the terms of the GNU Lesser General Public williamr@2: * License as published by the Free Software Foundation; either williamr@2: * version 2 of the License, or (at your option) any later version. williamr@2: * williamr@2: * This library is distributed in the hope that it will be useful, williamr@2: * but WITHOUT ANY WARRANTY; without even the implied warranty of williamr@2: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU williamr@2: * Lesser General Public License for more details. williamr@2: * williamr@2: * You should have received a copy of the GNU Lesser General williamr@2: * Public License along with this library; if not, write to the williamr@2: * Free Software Foundation, Inc., 59 Temple Place, Suite 330, williamr@2: * Boston, MA 02111-1307, USA. williamr@2: */ williamr@2: #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION) williamr@2: #error "Only can be included directly." williamr@2: #endif williamr@2: williamr@2: #ifndef __G_CLOSURE_H__ williamr@2: #define __G_CLOSURE_H__ williamr@2: williamr@2: #include <_ansi.h> williamr@2: #include williamr@2: williamr@2: G_BEGIN_DECLS williamr@2: williamr@2: /* --- defines --- */ williamr@2: #define G_CLOSURE_NEEDS_MARSHAL(closure) (((GClosure*) (closure))->marshal == NULL) williamr@2: #define G_CLOSURE_N_NOTIFIERS(cl) ((cl)->meta_marshal + ((cl)->n_guards << 1L) + \ williamr@2: (cl)->n_fnotifiers + (cl)->n_inotifiers) williamr@2: #define G_CCLOSURE_SWAP_DATA(cclosure) (((GClosure*) (closure))->derivative_flag) williamr@2: #define G_CALLBACK(f) ((GCallback) (f)) williamr@2: williamr@2: williamr@2: /* -- typedefs --- */ williamr@2: typedef struct _GClosure GClosure; williamr@2: typedef struct _GClosureNotifyData GClosureNotifyData; williamr@2: typedef void (*GCallback) (void); williamr@2: typedef void (*GClosureNotify) (gpointer data, williamr@2: GClosure *closure); williamr@2: typedef void (*GClosureMarshal) (GClosure *closure, williamr@2: GValue *return_value, williamr@2: guint n_param_values, williamr@2: const GValue *param_values, williamr@2: gpointer invocation_hint, williamr@2: gpointer marshal_data); williamr@2: typedef struct _GCClosure GCClosure; williamr@2: williamr@2: williamr@2: /* --- structures --- */ williamr@2: struct _GClosureNotifyData williamr@2: { williamr@2: gpointer data; williamr@2: GClosureNotify notify; williamr@2: }; williamr@2: struct _GClosure williamr@2: { williamr@2: /*< private >*/ williamr@2: volatile guint ref_count : 15; williamr@2: volatile guint meta_marshal : 1; williamr@2: volatile guint n_guards : 1; williamr@2: volatile guint n_fnotifiers : 2; /* finalization notifiers */ williamr@2: volatile guint n_inotifiers : 8; /* invalidation notifiers */ williamr@2: volatile guint in_inotify : 1; williamr@2: volatile guint floating : 1; williamr@2: /*< protected >*/ williamr@2: volatile guint derivative_flag : 1; williamr@2: /*< public >*/ williamr@2: volatile guint in_marshal : 1; williamr@2: volatile guint is_invalid : 1; williamr@2: williamr@2: /*< private >*/ void (*marshal) (GClosure *closure, williamr@2: GValue /*out*/ *return_value, williamr@2: guint n_param_values, williamr@2: const GValue *param_values, williamr@2: gpointer invocation_hint, williamr@2: gpointer marshal_data); williamr@2: /*< protected >*/ gpointer data; williamr@2: williamr@2: /*< private >*/ GClosureNotifyData *notifiers; williamr@2: williamr@2: /* invariants/constrains: williamr@2: * - ->marshal and ->data are _invalid_ as soon as ->is_invalid==TRUE williamr@2: * - invocation of all inotifiers occours prior to fnotifiers williamr@2: * - order of inotifiers is random williamr@2: * inotifiers may _not_ free/invalidate parameter values (e.g. ->data) williamr@2: * - order of fnotifiers is random williamr@2: * - each notifier may only be removed before or during its invocation williamr@2: * - reference counting may only happen prior to fnotify invocation williamr@2: * (in that sense, fnotifiers are really finalization handlers) williamr@2: */ williamr@2: }; williamr@2: /* closure for C function calls, callback() is the user function williamr@2: */ williamr@2: struct _GCClosure williamr@2: { williamr@2: GClosure closure; williamr@2: gpointer callback; williamr@2: }; williamr@2: williamr@2: williamr@2: /* --- prototypes --- */ williamr@2: IMPORT_C GClosure* g_cclosure_new (GCallback callback_func, williamr@2: gpointer user_data, williamr@2: GClosureNotify destroy_data); williamr@2: IMPORT_C GClosure* g_cclosure_new_swap (GCallback callback_func, williamr@2: gpointer user_data, williamr@2: GClosureNotify destroy_data); williamr@2: IMPORT_C GClosure* g_signal_type_cclosure_new (GType itype, williamr@2: guint struct_offset); williamr@2: williamr@2: williamr@2: /* --- prototypes --- */ williamr@2: IMPORT_C GClosure* g_closure_ref (GClosure *closure); williamr@2: IMPORT_C void g_closure_sink (GClosure *closure); williamr@2: IMPORT_C void g_closure_unref (GClosure *closure); williamr@2: /* intimidating */ williamr@2: IMPORT_C GClosure* g_closure_new_simple (guint sizeof_closure, williamr@2: gpointer data); williamr@2: IMPORT_C void g_closure_add_finalize_notifier (GClosure *closure, williamr@2: gpointer notify_data, williamr@2: GClosureNotify notify_func); williamr@2: IMPORT_C void g_closure_remove_finalize_notifier (GClosure *closure, williamr@2: gpointer notify_data, williamr@2: GClosureNotify notify_func); williamr@2: IMPORT_C void g_closure_add_invalidate_notifier (GClosure *closure, williamr@2: gpointer notify_data, williamr@2: GClosureNotify notify_func); williamr@2: IMPORT_C void g_closure_remove_invalidate_notifier (GClosure *closure, williamr@2: gpointer notify_data, williamr@2: GClosureNotify notify_func); williamr@2: IMPORT_C void g_closure_add_marshal_guards (GClosure *closure, williamr@2: gpointer pre_marshal_data, williamr@2: GClosureNotify pre_marshal_notify, williamr@2: gpointer post_marshal_data, williamr@2: GClosureNotify post_marshal_notify); williamr@2: IMPORT_C void g_closure_set_marshal (GClosure *closure, williamr@2: GClosureMarshal marshal); williamr@2: IMPORT_C void g_closure_set_meta_marshal (GClosure *closure, williamr@2: gpointer marshal_data, williamr@2: GClosureMarshal meta_marshal); williamr@2: IMPORT_C void g_closure_invalidate (GClosure *closure); williamr@2: IMPORT_C void g_closure_invoke (GClosure *closure, williamr@2: GValue /*out*/ *return_value, williamr@2: guint n_param_values, williamr@2: const GValue *param_values, williamr@2: gpointer invocation_hint); williamr@2: williamr@2: /* FIXME: williamr@2: OK: data_object::destroy -> closure_invalidate(); williamr@2: MIS: closure_invalidate() -> disconnect(closure); williamr@2: MIS: disconnect(closure) -> (unlink) closure_unref(); williamr@2: OK: closure_finalize() -> g_free (data_string); williamr@2: williamr@2: random remarks: williamr@2: - need marshaller repo with decent aliasing to base types williamr@2: - provide marshaller collection, virtually covering anything out there williamr@2: */ williamr@2: williamr@2: G_END_DECLS williamr@2: williamr@2: #endif /* __G_CLOSURE_H__ */