[dconf] Remove workaround for GDBus bug



commit 29ecbdf6aaae6b06a5dd6bfdb86b9165be8fb046
Author: Ryan Lortie <desrt desrt ca>
Date:   Sun May 16 12:55:53 2010 +0200

    Remove workaround for GDBus bug
    
    GDBus is working quite nicely now :)

 gsettings/dconfdatabase.c |   37 ++++++++++++-------------
 service/service.c         |   67 +++++++++++++++++----------------------------
 2 files changed, 43 insertions(+), 61 deletions(-)
---
diff --git a/gsettings/dconfdatabase.c b/gsettings/dconfdatabase.c
index 0dd2b90..fcd2ba6 100644
--- a/gsettings/dconfdatabase.c
+++ b/gsettings/dconfdatabase.c
@@ -317,6 +317,19 @@ dconf_database_filter_function (GDBusConnection *connection,
     }
 }
 
+GVariant *
+fake_maybe (GVariant *value)
+{
+  GVariantBuilder builder;
+
+  g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
+
+  if (value != NULL)
+    g_variant_builder_add (&builder, "v", value);
+
+  return g_variant_builder_end (&builder);
+}
+
 void
 dconf_database_write_tree (DConfDatabase  *database,
                            GTree          *tree,
@@ -347,13 +360,12 @@ dconf_database_write_tree (DConfDatabase  *database,
       g_dbus_message_new_method_call ("ca.desrt.dconf", "/",
                                       "ca.desrt.dconf.Writer", "Write");
 
-    g_variant_builder_init (&args, G_VARIANT_TYPE ("(ssa{smv})"));
-    g_variant_builder_add (&args, "s", database->context);
+    g_variant_builder_init (&args, G_VARIANT_TYPE ("(sa(sav))"));
     g_variant_builder_add (&args, "s", path);
 
-    g_variant_builder_open (&args, G_VARIANT_TYPE ("a{smv}"));
+    g_variant_builder_open (&args, G_VARIANT_TYPE ("a(sav)"));
     for (i = 0; keys[i]; i++)
-      g_variant_builder_add (&args, "{smv}", keys[i], values[i]);
+      g_variant_builder_add (&args, "(s av)", keys[i], fake_maybe (values[i]));
 
     g_variant_builder_close (&args);
 
@@ -384,20 +396,6 @@ dconf_database_list (DConfDatabase *database,
   return result;
 }
 
-static void
-dconf__message_set_body (GDBusMessage *message,
-                         GVariant     *body)
-{
-  gchar *printed;
-
-  g_variant_ref_sink (body);
-  printed = g_variant_print (body, FALSE);
-  g_variant_unref (body);
-
-  g_dbus_message_set_body (message, g_variant_new ("(s)", printed));
-  g_free (printed);
-}
-
 void
 dconf_database_write (DConfDatabase *database,
                       const gchar   *path_or_key,
@@ -413,7 +411,8 @@ dconf_database_write (DConfDatabase *database,
 
   message = g_dbus_message_new_method_call ("ca.desrt.dconf", "/",
                                             "ca.desrt.dconf.Writer", "Write");
-  dconf__message_set_body (message, g_variant_new ("(smv)", path_or_key, value));
+  g_dbus_message_set_body (message, g_variant_new ("(s av)", path_or_key,
+                                                   fake_maybe (value)));
   g_dbus_connection_send_message (database->bus, message, serial, NULL);
   g_object_unref (message);
 
diff --git a/service/service.c b/service/service.c
index fe1fde2..05bc697 100644
--- a/service/service.c
+++ b/service/service.c
@@ -123,15 +123,31 @@ emit_notify_signal (GDBusConnection  *connection,
   g_free (path);
 }
 
+static GVariant *
+unwrap_maybe (GVariant **ptr)
+{
+  GVariant *array, *child;
+
+  array = *ptr;
+
+  if (g_variant_n_children (array))
+    child = g_variant_get_child_value (array, 0);
+  else
+    child = NULL;
+
+  g_variant_unref (array);
+  *ptr = child;
+}
+
 static void
 method_call (GDBusConnection       *connection,
-             gpointer               user_data,
              const gchar           *sender,
              const gchar           *object_path,
              const gchar           *interface_name,
              const gchar           *method_name,
              GVariant              *parameters,
-             GDBusMethodInvocation *invocation)
+             GDBusMethodInvocation *invocation,
+             gpointer               user_data)
 {
   DConfWriter *writer = user_data;
 
@@ -145,9 +161,10 @@ method_call (GDBusConnection       *connection,
       guint64 serial;
       GVariant *none;
 
-      g_variant_get (parameters, "(@smv)", &keyvalue, &value);
+      g_variant_get (parameters, "(@s av)", &keyvalue, &value);
       key = g_variant_get_string (keyvalue, &key_length);
       g_variant_unref (keyvalue);
+      unwrap_maybe (&value);
 
       if (key[0] != '/' || strstr (key, "//"))
         {
@@ -199,13 +216,15 @@ method_call (GDBusConnection       *connection,
       gint i = 0;
       gint j;
 
-      g_variant_get (parameters, "(&sa{smv})", &prefix, &iter);
+      g_variant_get (parameters, "(&sa(sav))", &prefix, &iter);
       length = g_variant_iter_n_children (iter);
 
       keys = g_new (const gchar *, length);
       values = g_new (GVariant *, length);
-      while (g_variant_iter_next (iter, "{&smv}", &keys[i], &values[i]))
+      while (g_variant_iter_next (iter, "(&s av)", &keys[i], &values[i]))
         {
+          unwrap_maybe (&values[i]);
+
           if (keys[i][0] == '/' || strstr (keys[i], "//") ||
               (i > 0 && !(strcmp (keys[i - 1], keys[i]) < 0)))
             {
@@ -254,47 +273,11 @@ method_call (GDBusConnection       *connection,
 }
 
 static void
-fake_method_call (GDBusConnection       *connection,
-                  const gchar           *sender,
-                  const gchar           *object_path,
-                  const gchar           *interface_name,
-                  const gchar           *method_name,
-                  GVariant              *parameters,
-                  GDBusMethodInvocation *invocation,
-                  gpointer               user_data)
-{
-  GVariant *real_parameters;
-  const GVariantType *type;
-  const gchar *printed;
-  GError *error = NULL;
-
-  if (strcmp (method_name, "Merge") == 0)
-    type = G_VARIANT_TYPE ("(sa{smv})");
-  else
-    type = G_VARIANT_TYPE ("(smv)");
-
-  g_variant_get (parameters, "(&s)", &printed);
-  real_parameters = g_variant_parse (type, printed, NULL, NULL, &error);
-
-  if (real_parameters == NULL)
-    {
-      g_dbus_method_invocation_return_gerror (invocation, error);
-      g_error_free (error);
-      return;
-    }
-
-  method_call (connection, user_data, sender, object_path,
-               interface_name, method_name, real_parameters, invocation);
-
-  g_variant_unref (real_parameters);
-}
-
-static void
 bus_acquired (GDBusConnection *connection,
               const gchar     *name,
               gpointer         user_data)
 {
-  static const GDBusInterfaceVTable interface_vtable = { fake_method_call };
+  static const GDBusInterfaceVTable interface_vtable = { method_call };
   DConfWriter *writer = user_data;
 
   g_dbus_connection_register_object (connection, "/",



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]