Signal Marshallers

Name

Signal Marshallers -- Functions to adapt C structures to native calling convention.

Synopsis


#include <gtk/gtk.h>


#define     gtk_signal_default_marshaller

Description

What are Signal Marshallers?

Marshals are functions which all have the same prototype: they take a GtkObject, a GtkSignalFunc, a gpointer, and an array of argument values. The functions are names gtk_marshall_RETURNTYPE__PARAMTYPE1_PARAMTYPE2....

They then call a native function: the GtkObject is the first parameter passed in. The arguments are passed in the native calling convention: chars, shorts, ints, longs may be packed on the stack, or tucked in registers: it doesn't matter because the same calling convention will be generated inside the gtkmarshal code as is expected where you define your handlers.

So the function named:
gtk_marshal_BOOL__POINTER_INT_INT_UINT(GtkObject*, GtkSignalFunc, gpointer, GtkArg*);
will call the GtkSignalFunc assuming it was a function with signature:
gboolean sigfunc(gpointer,gint,gint,guint);


Writing Custom Marshals

Marshals are primarily used as arguments to gtk_signal_new(). Sometimes, you may find that a marshaller you need isn't available in the standard list. Then you have to write your own.

If you wish to define a signal with a new type of argument list. Suppose you want 2 pointers and 2 integers. You would write:
typedef int (*GtkSignal_INT__POINTER_POINTER_INT_INT)(
			gpointer, gpointer, gint, gint
);

void marshal_INT__POINTER_POINTER_INT_INT(GtkObject*    object,
					   GtkSignalFunc func,
					   gpointer      func_data,
                                           GtkArg*       args)
{
	GtkSignal_NONE__POINTER_POINTER_INT_INT rfunc;
	gint* return_val;
	return_val = GTK_RETLOC_INT(args[4]);
	rfunc = (GtkSignal_INT__POINTER_POINTER_INT_INT)func;
	*return_val = (*rfunc)(object,
                               GTK_VALUE_POINTER(args[0]),
                               GTK_VALUE_POINTER(args[1]),
                               GTK_VALUE_INT(args[2]),
                               GTK_VALUE_INT(args[3]),
                               func_data);
}

Details

gtk_signal_default_marshaller

#define gtk_signal_default_marshaller gtk_marshal_NONE__NONE

A marshaller that returns void and takes no extra parameters.

See Also

GtkSignal

The signal handling functions (of which marshallers are really an implementation detail).