From 9ec73cc6e59da8471740c8614fa5a5cdfdf368e3 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lureau Date: Tue, 30 Sep 2008 02:13:08 +0300 Subject: [PATCH] Marshall flags & enum --- dbus/dbus-gvalue.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 files changed, 39 insertions(+), 2 deletions(-) diff --git a/dbus/dbus-gvalue.c b/dbus/dbus-gvalue.c index a18067c..877f32d 100644 --- a/dbus/dbus-gvalue.c +++ b/dbus/dbus-gvalue.c @@ -273,6 +273,20 @@ _dbus_g_value_types_init (void) }; set_type_metadata (G_TYPE_FLOAT, &typedata); } + { + static const DBusGTypeMarshalData typedata = { + DBUS_TYPE_STRING_AS_STRING, + &basic_vtable, + }; + set_type_metadata (G_TYPE_ENUM, &typedata); + } + { + static const DBusGTypeMarshalData typedata = { + DBUS_TYPE_STRING_AS_STRING, + &basic_vtable, + }; + set_type_metadata (G_TYPE_FLAGS, &typedata); + } /* Register complex types with builtin GType mappings */ { @@ -1337,15 +1351,38 @@ marshal_basic (DBusMessageIter *iter, const GValue *value) } return TRUE; case G_TYPE_STRING: + case G_TYPE_ENUM: + case G_TYPE_FLAGS: /* FIXME, the GValue string may not be valid UTF-8 */ { - const char *v = g_value_get_string (value); + const char *v = NULL; + GValue xform = { 0, }; + + if (G_VALUE_HOLDS_STRING (value)) + v = g_value_get_string (value); + + else if (G_VALUE_HOLDS_ENUM (value) || G_VALUE_HOLDS_FLAGS (value)) + { + g_value_init (&xform, G_TYPE_STRING); + + if (!g_value_transform (value, &xform)) + g_warning ("Could not transform enum/flags to string"); + else + v = g_value_get_string (&xform); + } + if (!v) v = ""; if (!dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, - &v)) + &v)) { + if (G_IS_VALUE (&xform)) + g_value_unset (&xform); goto nomem; + } + + if (G_IS_VALUE (&xform)) + g_value_unset (&xform); } return TRUE; -- 1.5.6.5