diff options
author | Emmanuele Bassi <ebassi@linux.intel.com> | 2010-08-04 00:57:52 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@linux.intel.com> | 2010-08-04 01:09:28 +0100 |
commit | 4bc9654c63feee596de5aa214d7cbd8fc293cd9d (patch) | |
tree | 954ba78b9e8fe91151f35d4d4723b31cf5dfacaa | |
parent | f5cd8ddeaac7e6df484629b7ae54a86ffa155a05 (diff) |
binding: Add a default marshaller for the closure API
The g_object_bind_property_with_closures() function should set a
marshaller if the two GClosures don't have one already. This simplifies
the caller code and avoids duplication.
We need to add a new marshaller to the gmarshal.list matching the
signature of the GBindingTransformFunc function.
-rw-r--r-- | gobject/gbinding.c | 7 | ||||
-rw-r--r-- | gobject/gclosure.c | 15 | ||||
-rw-r--r-- | gobject/gmarshal.list | 1 | ||||
-rw-r--r-- | gobject/gobject.symbols | 1 | ||||
-rw-r--r-- | gobject/tests/binding.c | 39 |
5 files changed, 24 insertions, 39 deletions
diff --git a/gobject/gbinding.c b/gobject/gbinding.c index 06273acb8..c73c4e654 100644 --- a/gobject/gbinding.c +++ b/gobject/gbinding.c @@ -105,6 +105,7 @@ #include "gbinding.h" #include "genums.h" +#include "gmarshal.h" #include "gobject.h" #include "gsignal.h" #include "gparamspecs.h" @@ -1161,12 +1162,18 @@ g_object_bind_property_with_closures (gpointer source, if (transform_to != NULL) { + if (G_CLOSURE_NEEDS_MARSHAL (transform_to)) + g_closure_set_marshal (transform_to, g_cclosure_marshal_BOOLEAN__BOXED_BOXED); + data->transform_to_closure = g_closure_ref (transform_to); g_closure_sink (data->transform_to_closure); } if (transform_from != NULL) { + if (G_CLOSURE_NEEDS_MARSHAL (transform_from)) + g_closure_set_marshal (transform_from, g_cclosure_marshal_BOOLEAN__BOXED_BOXED); + data->transform_from_closure = g_closure_ref (transform_from); g_closure_sink (data->transform_from_closure); } diff --git a/gobject/gclosure.c b/gobject/gclosure.c index 1c5af30dd..8a6b0f7ab 100644 --- a/gobject/gclosure.c +++ b/gobject/gclosure.c @@ -1236,3 +1236,18 @@ g_signal_type_cclosure_new (GType itype, * A marshaller for a #GCClosure with a callback of type * <literal>gchar* (*callback) (gpointer instance, GObject *arg1, gpointer arg2, gpointer user_data)</literal>. */ +/** + * g_cclosure_marshal_BOOLEAN__OBJECT_BOXED_BOXED: + * @closure: the #GClosure to which the marshaller belongs + * @return_value: a #GValue, which can store the returned string + * @n_param_values: 3 + * @param_values: a #GValue array holding instance, arg1 and arg2 + * @invocation_hint: the invocation hint given as the last argument + * to g_closure_invoke() + * @marshal_data: additional data specified when registering the marshaller + * + * A marshaller for a #GCClosure with a callback of type + * <literal>gboolean (*callback) (gpointer instance, GBoxed *arg1, GBoxed *arg2, gpointer user_data)</literal>. + * + * Since: 2.26 + */ diff --git a/gobject/gmarshal.list b/gobject/gmarshal.list index 533307be8..41cf74aec 100644 --- a/gobject/gmarshal.list +++ b/gobject/gmarshal.list @@ -47,3 +47,4 @@ VOID:VARIANT VOID:UINT,POINTER BOOL:FLAGS STRING:OBJECT,POINTER +BOOL:BOXED,BOXED diff --git a/gobject/gobject.symbols b/gobject/gobject.symbols index 0eca5e71b..9d1a021a0 100644 --- a/gobject/gobject.symbols +++ b/gobject/gobject.symbols @@ -58,6 +58,7 @@ g_variant_get_gtype G_GNUC_CONST #if IN_HEADER(__G_MARSHAL_H__) #if IN_FILE(__G_SIGNAL_C__) g_cclosure_marshal_BOOLEAN__FLAGS +g_cclosure_marshal_BOOLEAN__BOXED_BOXED g_cclosure_marshal_STRING__OBJECT_POINTER g_cclosure_marshal_VOID__BOOLEAN g_cclosure_marshal_VOID__BOXED diff --git a/gobject/tests/binding.c b/gobject/tests/binding.c index 979a6812e..dc3b83c0c 100644 --- a/gobject/tests/binding.c +++ b/gobject/tests/binding.c @@ -356,43 +356,6 @@ binding_transform (void) } static void -binding_transform_marshal (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint G_GNUC_UNUSED, - gpointer marshal_data) -{ - typedef gboolean (* GMarshalFunc_BOOLEAN__VALUE_VALUE) (gpointer data1, - gpointer arg_2, - gpointer arg_3, - gpointer data2); - register GMarshalFunc_BOOLEAN__VALUE_VALUE callback; - register GCClosure *cc = (GCClosure *) closure; - register gpointer data1, data2; - gboolean v_return; - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - - callback = (GMarshalFunc_BOOLEAN__VALUE_VALUE) (marshal_data ? marshal_data : cc->callback); - v_return = callback (data1, - g_value_get_boxed (param_values + 1), - g_value_get_boxed (param_values + 2), - data2); - - g_value_set_boolean (return_value, v_return); -} - -static void binding_transform_closure (void) { BindingSource *source = g_object_new (binding_source_get_type (), NULL); @@ -402,10 +365,8 @@ binding_transform_closure (void) GClosure *c2f_clos, *f2c_clos; c2f_clos = g_cclosure_new (G_CALLBACK (celsius_to_fahrenheit), &unused_data_1, (GClosureNotify) data_free); - g_closure_set_marshal (c2f_clos, binding_transform_marshal); f2c_clos = g_cclosure_new (G_CALLBACK (fahrenheit_to_celsius), &unused_data_2, (GClosureNotify) data_free); - g_closure_set_marshal (f2c_clos, binding_transform_marshal); binding = g_object_bind_property_with_closures (source, "value", target, "value", |