MafwCallbas

MafwCallbas — put together a function call and invoke it later

Synopsis

#define             MAFW_CBAS_BOOLEAN                   (val)
#define             MAFW_CBAS_DOUBLE                    (val)
#define             MAFW_CBAS_END
#define             MAFW_CBAS_HASH                      (val)
#define             MAFW_CBAS_INT                       (val)
#define             MAFW_CBAS_INT64                     (val)
#define             MAFW_CBAS_LONG                      (val)
#define             MAFW_CBAS_NULL
#define             MAFW_CBAS_POINTER                   (val)
#define             MAFW_CBAS_STRING                    (val)
#define             MAFW_CBAS_UINT                      (val)
#define             MAFW_CBAS_UINT64                    (val)
#define             MAFW_CBAS_ULONG                     (val)
                    MafwCallbas;
MafwCallbas*        mafw_callbas_new                    (GCallback cb,
                                                         GClosureMarshal mars,
                                                         gpointer self,
                                                         ...);
void                mafw_callbas_argv2gval              (GValue *value,
                                                         GType type,
                                                         va_list *args);
gint                mafw_callbas_defer                  (MafwCallbas *cbas);
void                mafw_callbas_free                   (MafwCallbas *cbas);
void                mafw_callbas_invoke                 (MafwCallbas *cbas);

Description

Primarily these functions help you in the construction of deferred function calls, ie. when you at some point know how and what you want to invoke (such as a user-supplied callback), but you need to do it later in execution time. Then you need to create a `callbas', an object binding a C function (callback) to some C arguments you want it to be called with. This is done with mafw_callbas_new(). You can invoke a callbas with mafw_callbas_invoke() any number of times before releasing it with mafw_callbas_free(). This happens automatically if you mafw_callbas_defer() the activisation until idle time.

mafw_callbas_argv2gval() is also useful as a standalone function when you need to create a GValue out of some arbitrary C values.

Details

MAFW_CBAS_BOOLEAN()

#define MAFW_CBAS_BOOLEAN(val)	G_TYPE_BOOLEAN,		(val)

boolean parameter.

val : value

MAFW_CBAS_DOUBLE()

#define MAFW_CBAS_DOUBLE(val)	G_TYPE_DOUBLE,		(val)

A double floating pointer parameter.

val : value

MAFW_CBAS_END

#define MAFW_CBAS_END		G_TYPE_INVALID

End of parameters


MAFW_CBAS_HASH()

#define MAFW_CBAS_HASH(val)	G_TYPE_HASH_TABLE,	(val)

A hash table parameter.

val : value

MAFW_CBAS_INT()

#define MAFW_CBAS_INT(val)	G_TYPE_INT,		(val)

An integer parameter.

val : value

MAFW_CBAS_INT64()

#define MAFW_CBAS_INT64(val)	G_TYPE_INT64,		(val)

An 64bit integer parameter.

val : value

MAFW_CBAS_LONG()

#define MAFW_CBAS_LONG(val)	G_TYPE_LONG,		(val)

A long parameter.

val : value

MAFW_CBAS_NULL

#define MAFW_CBAS_NULL		MAFW_CBAS_POINTER(NULL)

A NULL pointer parameter.

val : value

MAFW_CBAS_POINTER()

#define MAFW_CBAS_POINTER(val)	G_TYPE_POINTER, 	(val)

A pointer parameter.

val : value

MAFW_CBAS_STRING()

#define MAFW_CBAS_STRING(val)	G_TYPE_STRING,		(val)

A string parameter.

val : value

MAFW_CBAS_UINT()

#define MAFW_CBAS_UINT(val)	G_TYPE_UINT,		(val)

An unsigned integer parameter.

val : value

MAFW_CBAS_UINT64()

#define MAFW_CBAS_UINT64(val)	G_TYPE_UINT64,		(val)

An unsigned 64bits integer parameter.

val : value

MAFW_CBAS_ULONG()

#define MAFW_CBAS_ULONG(val)	G_TYPE_ULONG,		(val)

An unsigned long parameter.

val : value

MafwCallbas

typedef struct {
	GClosure *closure;
	GArray *gvargs;
} MafwCallbas;

This structure is meant to represent a function call

GClosure *closure; function's closure
GArray *gvargs; is an array of "s" holding the actual arguments of closure.

mafw_callbas_new ()

MafwCallbas*        mafw_callbas_new                    (GCallback cb,
                                                         GClosureMarshal mars,
                                                         gpointer self,
                                                         ...);

Creates a callbas with which you can eventually invoke cb. self is passed as the first argument to cb. The rest of the arguments are given in the varadic list as GType0--value pairs, closed with MAFW_CBAS_END. You are advised to use the MAFW_CBAS_*() macros for that. mars is the marshaller function created by `glib-marshal'; it should NOT account for the first self parameter.

cb : a callback
mars : the closure
self : self
... : parameters
Returns : a new instance of MafwCallbas with the constructed with the given parameters.

mafw_callbas_argv2gval ()

void                mafw_callbas_argv2gval              (GValue *value,
                                                         GType type,
                                                         va_list *args);

Decodes the next argument from args having type and encodes it into value, a reset GValue. Since args is passed as a pointer it is modified, so subsequent calls to this function will decode subsequent varadic arguments.

In general the value is copied, except for hash tables.

value : a GValue to place the result
type : the GType of the value
args : arguments list

mafw_callbas_defer ()

gint                mafw_callbas_defer                  (MafwCallbas *cbas);

Arranges for the invocation of cbas when you enter (return to) the main loop and returns the GLib source ID with which you can cancel its activation.

cbas : a MafwCallbas instance
Returns : the event id

mafw_callbas_free ()

void                mafw_callbas_free                   (MafwCallbas *cbas);

Releases a callbas and everything therein.

cbas : a MafwCallbas instance

mafw_callbas_invoke ()

void                mafw_callbas_invoke                 (MafwCallbas *cbas);

Invokes the C function represented by cbas, ignoring its return value.

cbas : a MafwCallbas instance