diff options
| author | Robert McQueen <robot101@debian.org> | 2005-11-27 16:55:09 +0000 | 
|---|---|---|
| committer | Robert McQueen <robot101@debian.org> | 2005-11-27 16:55:09 +0000 | 
| commit | 75d6182c05309031371ddf9e9103f5921afa0031 (patch) | |
| tree | 51e3527328e202e006fccaca26ed757d89bfa34a | |
| parent | c77c7e343b73bb9c14319679063a55e5cf1ee1d6 (diff) | |
2005-11-27  Carlos Garcia Campos  <carlosgc@gnome.org>
	* glib/dbus-gobject.c: Append a GValue instead of a basic type in
	method return message for property getters
| -rw-r--r-- | ChangeLog | 5 | ||||
| -rw-r--r-- | glib/dbus-gobject.c | 41 | ||||
| -rw-r--r-- | glib/dbus-gvalue.c | 8 | ||||
| -rw-r--r-- | glib/dbus-gvalue.h | 1 | ||||
| -rw-r--r-- | python/dbus_bindings.pyx | 8 | 
5 files changed, 43 insertions, 20 deletions
| @@ -1,3 +1,8 @@ +2005-11-27  Carlos Garcia Campos  <carlosgc@gnome.org> + +	* glib/dbus-gobject.c: Append a GValue instead of a basic type in +	method return message for property getters +  2005-11-27  Robert McQueen  <robot101@debian.org>  	* python/dbus_bindings.pyx: Fix a bug where doing a strict append diff --git a/glib/dbus-gobject.c b/glib/dbus-gobject.c index 0a019cc2..3e30dc2e 100644 --- a/glib/dbus-gobject.c +++ b/glib/dbus-gobject.c @@ -690,25 +690,41 @@ get_object_property (DBusConnection *connection,                       GObject        *object,                       GParamSpec     *pspec)  { -  GType value_type; +  GType value_gtype;    GValue value = {0, }; +  gchar *variant_sig;    DBusMessage *ret; -  DBusMessageIter iter; - -  value_type = G_PARAM_SPEC_VALUE_TYPE (pspec); +  DBusMessageIter iter, subiter;    ret = dbus_message_new_method_return (message);    if (ret == NULL)      g_error ("out of memory"); -  g_value_init (&value, value_type); + +  g_value_init (&value, pspec->value_type);    g_object_get_property (object, pspec->name, &value); -  value_type = G_VALUE_TYPE (&value); +  variant_sig = _dbus_gvalue_to_signature (&value); +  if (variant_sig == NULL) +    { +      value_gtype = G_VALUE_TYPE (&value); +      g_warning ("Cannot marshal type \"%s\" in variant", g_type_name (value_gtype)); +      g_value_unset (&value); +      return ret; +    } -  dbus_message_iter_init_append (message, &iter); +  dbus_message_iter_init_append (ret, &iter); +  if (!dbus_message_iter_open_container (&iter, +					 DBUS_TYPE_VARIANT, +					 variant_sig, +					 &subiter)) +    { +      g_free (variant_sig); +      g_value_unset (&value); +      return ret; +    } -  if (!_dbus_gvalue_marshal (&iter, &value)) +  if (!_dbus_gvalue_marshal (&subiter, &value))      {        dbus_message_unref (ret);        ret = dbus_message_new_error (message, @@ -716,6 +732,11 @@ get_object_property (DBusConnection *connection,                                      "Can't convert GType of object property to a D-BUS type");      } +  dbus_message_iter_close_container (&iter, &subiter); + +  g_value_unset (&value); +  g_free (variant_sig); +    return ret;  } @@ -1307,7 +1328,7 @@ gobject_message_function (DBusConnection  *connection,            dbus_message_iter_next (&iter);          }        else if (getter) -        {      +        {            ret = get_object_property (connection, message,                                       object, pspec);          } @@ -1321,7 +1342,7 @@ gobject_message_function (DBusConnection  *connection,        if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID)          g_warning ("Property get or set had too many arguments\n"); -       +        dbus_connection_send (connection, ret, NULL);        dbus_message_unref (ret);        return DBUS_HANDLER_RESULT_HANDLED; diff --git a/glib/dbus-gvalue.c b/glib/dbus-gvalue.c index 2f6371e3..7f4e822f 100644 --- a/glib/dbus-gvalue.c +++ b/glib/dbus-gvalue.c @@ -388,8 +388,8 @@ _dbus_gtype_to_signature (GType gtype)    return ret;  } -static char * -dbus_gvalue_to_signature (const GValue *val) +char * +_dbus_gvalue_to_signature (const GValue *val)  {    GType gtype; @@ -406,7 +406,7 @@ dbus_gvalue_to_signature (const GValue *val)        for (i = 0; i < array->n_values; i++)  	{  	  char *sig; -	  sig = dbus_gvalue_to_signature (g_value_array_get_nth (array, i)); +	  sig = _dbus_gvalue_to_signature (g_value_array_get_nth (array, i));  	  g_string_append (str, sig);  	  g_free (sig);  	} @@ -1465,7 +1465,7 @@ marshal_variant (DBusMessageIter          *iter,    real_value = g_value_get_boxed (value);    value_gtype = G_VALUE_TYPE (real_value); -  variant_sig = dbus_gvalue_to_signature (real_value); +  variant_sig = _dbus_gvalue_to_signature (real_value);    if (variant_sig == NULL)      {        g_warning ("Cannot marshal type \"%s\" in variant", g_type_name (value_gtype)); diff --git a/glib/dbus-gvalue.h b/glib/dbus-gvalue.h index 3b41747e..1bfd719d 100644 --- a/glib/dbus-gvalue.h +++ b/glib/dbus-gvalue.h @@ -17,6 +17,7 @@ typedef struct {  void           _dbus_g_value_types_init        (void);  char *         _dbus_gtype_to_signature        (GType                    type); +char *         _dbus_gvalue_to_signature       (const GValue            *val);  gboolean       _dbus_gvalue_demarshal          (DBusGValueMarshalCtx    *context,  					       DBusMessageIter         *iter, diff --git a/python/dbus_bindings.pyx b/python/dbus_bindings.pyx index 21adc87a..8b1b221b 100644 --- a/python/dbus_bindings.pyx +++ b/python/dbus_bindings.pyx @@ -1053,10 +1053,7 @@ cdef class MessageIter:              tmp_sig = sig[1:-1]              retval = self.append_struct(value, signature = tmp_sig)          elif sig_type == TYPE_VARIANT: -            if isinstance(value, Variant): -                retval = self.append_variant(value) -            else: -                retval = self.append_variant(Variant(value)) +            retval = self.append_variant(Variant(value))          elif sig_type == DICT_ENTRY_BEGIN:              raise TypeError, "Signiture is invalid in append_strict. A dict entry must be part of an array."           else: @@ -1751,9 +1748,8 @@ def bus_register(Connection connection):      return retval -NAME_FLAG_ALLOW_REPLACEMENT    = 0x1 +NAME_FLAG_PROHIBIT_REPLACEMENT = 0x1  NAME_FLAG_REPLACE_EXISTING     = 0x2 -NAME_FLAG_DO_NOT_QUEUE         = 0x4  REQUEST_NAME_REPLY_PRIMARY_OWNER = 1  REQUEST_NAME_REPLY_IN_QUEUE      = 2 | 
