2005-06-22 18:20:32 +00:00
|
|
|
/*
|
2005-11-20 03:59:01 +00:00
|
|
|
* mooclosure.h
|
2005-06-22 18:20:32 +00:00
|
|
|
*
|
2010-12-21 20:15:45 -08:00
|
|
|
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
|
2005-06-22 18:20:32 +00:00
|
|
|
*
|
2008-09-05 17:20:50 -05:00
|
|
|
* This file is part of medit. medit is free software; you can
|
|
|
|
* redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2.1 of the License,
|
|
|
|
* or (at your option) any later version.
|
2005-06-22 18:20:32 +00:00
|
|
|
*
|
2008-09-05 17:20:50 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
2005-06-22 18:20:32 +00:00
|
|
|
*/
|
|
|
|
|
2007-04-12 10:31:28 -05:00
|
|
|
#ifndef MOO_CLOSURE_H
|
|
|
|
#define MOO_CLOSURE_H
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2005-11-20 03:59:01 +00:00
|
|
|
#include <glib-object.h>
|
2005-06-22 18:20:32 +00:00
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
|
2005-11-20 03:59:01 +00:00
|
|
|
#define MOO_TYPE_CLOSURE (moo_closure_get_type ())
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2005-11-20 03:59:01 +00:00
|
|
|
typedef struct _MooClosure MooClosure;
|
|
|
|
typedef struct _MooObjectPtr MooObjectPtr;
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2005-11-20 03:59:01 +00:00
|
|
|
typedef void (*MooClosureCall) (MooClosure *closure);
|
|
|
|
typedef void (*MooClosureDestroy) (MooClosure *closure);
|
2005-06-22 18:20:32 +00:00
|
|
|
|
|
|
|
struct _MooClosure
|
|
|
|
{
|
2005-11-20 03:59:01 +00:00
|
|
|
MooClosureCall call;
|
|
|
|
MooClosureDestroy destroy;
|
|
|
|
guint ref_count : 16;
|
|
|
|
guint valid : 1;
|
|
|
|
guint floating : 1;
|
|
|
|
guint in_call : 1;
|
2005-06-22 18:20:32 +00:00
|
|
|
};
|
|
|
|
|
2005-11-20 03:59:01 +00:00
|
|
|
struct _MooObjectPtr
|
2005-06-22 18:20:32 +00:00
|
|
|
{
|
2005-11-20 03:59:01 +00:00
|
|
|
GObject *target;
|
|
|
|
GWeakNotify notify;
|
|
|
|
gpointer notify_data;
|
2005-06-22 18:20:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-11-20 03:59:01 +00:00
|
|
|
GType moo_closure_get_type (void) G_GNUC_CONST;
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2005-11-20 03:59:01 +00:00
|
|
|
MooClosure *moo_closure_alloc (gsize size,
|
|
|
|
MooClosureCall call,
|
|
|
|
MooClosureDestroy destroy);
|
|
|
|
#define moo_closure_new(Type__,call__,destroy__) \
|
|
|
|
((Type__*)moo_closure_alloc (sizeof(Type__), call__, destroy__))
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2005-11-20 03:59:01 +00:00
|
|
|
MooClosure *moo_closure_ref (MooClosure *closure);
|
2006-05-08 23:57:16 -05:00
|
|
|
MooClosure *moo_closure_ref_sink (MooClosure *closure);
|
2005-11-20 03:59:01 +00:00
|
|
|
void moo_closure_unref (MooClosure *closure);
|
|
|
|
void moo_closure_sink (MooClosure *closure);
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2005-11-20 03:59:01 +00:00
|
|
|
void moo_closure_invoke (MooClosure *closure);
|
|
|
|
void moo_closure_invalidate (MooClosure *closure);
|
2005-06-22 18:20:32 +00:00
|
|
|
|
|
|
|
|
2005-11-20 03:59:01 +00:00
|
|
|
#define MOO_OBJECT_PTR_GET(ptr_) ((ptr_) && (ptr_)->target ? (ptr_)->target : NULL)
|
|
|
|
|
2006-11-04 01:03:45 -06:00
|
|
|
MooObjectPtr *_moo_object_ptr_new (GObject *object,
|
2005-11-20 03:59:01 +00:00
|
|
|
GWeakNotify notify,
|
|
|
|
gpointer data);
|
2006-11-04 01:03:45 -06:00
|
|
|
void _moo_object_ptr_free (MooObjectPtr *ptr);
|
2005-11-20 03:59:01 +00:00
|
|
|
|
|
|
|
|
2006-11-04 01:03:45 -06:00
|
|
|
MooClosure *_moo_closure_new_simple (gpointer object,
|
2005-11-20 03:59:01 +00:00
|
|
|
const char *signal,
|
|
|
|
GCallback callback,
|
|
|
|
GCallback proxy_func);
|
|
|
|
|
|
|
|
|
|
|
|
G_END_DECLS
|
2005-06-22 18:20:32 +00:00
|
|
|
|
2007-04-12 10:31:28 -05:00
|
|
|
#endif /* MOO_CLOSURE_H */
|