2005-06-22 11:20:32 -07:00
|
|
|
/*
|
2005-11-19 19:59:01 -08:00
|
|
|
* mooclosure.h
|
2005-06-22 11:20:32 -07:00
|
|
|
*
|
2007-06-24 10:56:20 -07:00
|
|
|
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
2005-06-22 11:20:32 -07:00
|
|
|
*
|
2007-06-24 10:56:20 -07:00
|
|
|
* This library 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 11:20:32 -07:00
|
|
|
*
|
|
|
|
* See COPYING file that comes with this distribution.
|
|
|
|
*/
|
|
|
|
|
2007-04-12 08:31:28 -07:00
|
|
|
#ifndef MOO_CLOSURE_H
|
|
|
|
#define MOO_CLOSURE_H
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-11-19 19:59:01 -08:00
|
|
|
#include <glib-object.h>
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
|
2005-11-19 19:59:01 -08:00
|
|
|
#define MOO_TYPE_CLOSURE (moo_closure_get_type ())
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-11-19 19:59:01 -08:00
|
|
|
typedef struct _MooClosure MooClosure;
|
|
|
|
typedef struct _MooObjectPtr MooObjectPtr;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-11-19 19:59:01 -08:00
|
|
|
typedef void (*MooClosureCall) (MooClosure *closure);
|
|
|
|
typedef void (*MooClosureDestroy) (MooClosure *closure);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
struct _MooClosure
|
|
|
|
{
|
2005-11-19 19:59:01 -08:00
|
|
|
MooClosureCall call;
|
|
|
|
MooClosureDestroy destroy;
|
|
|
|
guint ref_count : 16;
|
|
|
|
guint valid : 1;
|
|
|
|
guint floating : 1;
|
|
|
|
guint in_call : 1;
|
2005-06-22 11:20:32 -07:00
|
|
|
};
|
|
|
|
|
2005-11-19 19:59:01 -08:00
|
|
|
struct _MooObjectPtr
|
2005-06-22 11:20:32 -07:00
|
|
|
{
|
2005-11-19 19:59:01 -08:00
|
|
|
GObject *target;
|
|
|
|
GWeakNotify notify;
|
|
|
|
gpointer notify_data;
|
2005-06-22 11:20:32 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-11-19 19:59:01 -08:00
|
|
|
GType moo_closure_get_type (void) G_GNUC_CONST;
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-11-19 19:59:01 -08: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 11:20:32 -07:00
|
|
|
|
2005-11-19 19:59:01 -08:00
|
|
|
MooClosure *moo_closure_ref (MooClosure *closure);
|
2006-05-08 21:57:16 -07:00
|
|
|
MooClosure *moo_closure_ref_sink (MooClosure *closure);
|
2005-11-19 19:59:01 -08:00
|
|
|
void moo_closure_unref (MooClosure *closure);
|
|
|
|
void moo_closure_sink (MooClosure *closure);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2005-11-19 19:59:01 -08:00
|
|
|
void moo_closure_invoke (MooClosure *closure);
|
|
|
|
void moo_closure_invalidate (MooClosure *closure);
|
2005-06-22 11:20:32 -07:00
|
|
|
|
|
|
|
|
2005-11-19 19:59:01 -08:00
|
|
|
#define MOO_OBJECT_PTR_GET(ptr_) ((ptr_) && (ptr_)->target ? (ptr_)->target : NULL)
|
|
|
|
|
2006-11-03 23:03:45 -08:00
|
|
|
MooObjectPtr *_moo_object_ptr_new (GObject *object,
|
2005-11-19 19:59:01 -08:00
|
|
|
GWeakNotify notify,
|
|
|
|
gpointer data);
|
2006-11-03 23:03:45 -08:00
|
|
|
void _moo_object_ptr_free (MooObjectPtr *ptr);
|
2005-11-19 19:59:01 -08:00
|
|
|
|
|
|
|
|
2006-11-03 23:03:45 -08:00
|
|
|
MooClosure *_moo_closure_new_simple (gpointer object,
|
2005-11-19 19:59:01 -08:00
|
|
|
const char *signal,
|
|
|
|
GCallback callback,
|
|
|
|
GCallback proxy_func);
|
|
|
|
|
|
|
|
|
|
|
|
G_END_DECLS
|
2005-06-22 11:20:32 -07:00
|
|
|
|
2007-04-12 08:31:28 -07:00
|
|
|
#endif /* MOO_CLOSURE_H */
|