GDBus: Use GVariant instead of GHashTable for GDBusProxy::g-properties-changed
authorDavid Zeuthen <davidz@redhat.com>
Mon, 10 May 2010 17:31:54 +0000 (13:31 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Mon, 10 May 2010 17:31:54 +0000 (13:31 -0400)
gio/gdbusconnection.c
gio/gdbusproxy.c
gio/gdbusproxy.h
gio/tests/gdbus-example-watch-proxy.c

index 2de63821a0d39db8c76aba04827070bcd9f14fba..f26d48eee2d5d23c91b6a8a477d7315ee491e61c 100644 (file)
  * - Need to rewrite GDBusAuth and rework GDBusAuthMechanism. In particular
  *   the mechanism VFuncs need to be able to set an error.
  *
- * - The GDBusProxy::g-properties-changed signal currently looks like this
- *
- *      void user_function (GDBusProxy *proxy,
- *                          GHashTable *changed_properties,
- *                          gpointer    user_data);
- *
- *   which is problematic because some people frown upon GHashTable
- *   usage in public API (in particular some of the JS people). Maybe we
- *   need to rework it, maybe it doesn't matter since GDBusProxy is
- *   a low-level API and, for C code, we expect code generators to
- *   spit out subclasses that automatically hook up to this signal
- *   and does g_object_notify() anyway? Hmm...
- *
  * - probably want a G_DBUS_NONCE_TCP_TMPDIR environment variable
  *   to specify where the nonce is stored. This will allow people to use
  *   G_DBUS_NONCE_TCP_TMPDIR=/mnt/secure.company.server/dbus-nonce-dir
index c851cc168a68382ccae9f97f1b5b1b1c6f8477fe..cb0a2f47b372d61eb890c7093783828639ad2e22 100644 (file)
@@ -387,7 +387,7 @@ g_dbus_proxy_class_init (GDBusProxyClass *klass)
   /**
    * GDBusProxy::g-properties-changed:
    * @proxy: The #GDBusProxy emitting the signal.
-   * @changed_properties: A #GHashTable containing the properties that changed.
+   * @changed_properties: A #GVariant containing the properties that changed.
    *
    * Emitted when one or more D-Bus properties on @proxy changes. The cached properties
    * are already replaced when this signal fires.
@@ -403,7 +403,7 @@ g_dbus_proxy_class_init (GDBusProxyClass *klass)
                                                      g_cclosure_marshal_VOID__BOXED,
                                                      G_TYPE_NONE,
                                                      1,
-                                                     G_TYPE_HASH_TABLE);
+                                                     G_TYPE_VARIANT);
 
   /**
    * GDBusProxy::g-signal:
@@ -587,7 +587,8 @@ on_properties_changed (GDBusConnection *connection,
   const gchar *interface_name_for_signal;
   GVariantIter *iter;
   GVariant *item;
-  GHashTable *changed_properties;
+  GVariant *changed_properties;
+  GVariantBuilder *builder;
 
   error = NULL;
   iter = NULL;
@@ -617,11 +618,7 @@ on_properties_changed (GDBusConnection *connection,
   if (g_strcmp0 (interface_name_for_signal, proxy->priv->interface_name) != 0)
     goto out;
 
-  changed_properties = g_hash_table_new_full (g_str_hash,
-                                              g_str_equal,
-                                              g_free,
-                                              (GDestroyNotify) g_variant_unref);
-
+  builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
   while ((item = g_variant_iter_next_value (iter)))
     {
       const gchar *key;
@@ -636,16 +633,17 @@ on_properties_changed (GDBusConnection *connection,
                            g_strdup (key),
                            value); /* steals value */
 
-      g_hash_table_insert (changed_properties,
-                           g_strdup (key),
-                           g_variant_ref (value));
+      g_variant_builder_add (builder,
+                             "{sv}",
+                             g_strdup (key),
+                             g_variant_ref (value));
     }
-
+  changed_properties = g_variant_builder_end (builder);
 
   /* emit signal */
   g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL], 0, changed_properties);
 
-  g_hash_table_unref (changed_properties);
+  g_variant_unref (changed_properties);
 
  out:
   if (iter != NULL)
index 9b65e27f0a6af9b73716320ffb4e85fbd5e1d888..ee9f62eda997585ac5933dfd23f7d206f02d2fc1 100644 (file)
@@ -70,7 +70,7 @@ struct _GDBusProxyClass
   /*< public >*/
   /* Signals */
   void (*g_properties_changed) (GDBusProxy   *proxy,
-                                GHashTable   *changed_properties);
+                                GVariant     *changed_properties);
   void (*g_signal)             (GDBusProxy   *proxy,
                                 const gchar  *sender_name,
                                 const gchar  *signal_name,
index 9a6176ea57652eccdef98703df57a619626b361c..7060b21aefb7eea315e2333f8aa692a830380a08 100644 (file)
@@ -56,19 +56,28 @@ print_properties (GDBusProxy *proxy)
 
 static void
 on_properties_changed (GDBusProxy *proxy,
-                       GHashTable *changed_properties,
+                       GVariant   *changed_properties,
                        gpointer    user_data)
 {
-  GHashTableIter iter;
-  const gchar *key;
-  GVariant *value;
+  GVariantIter *iter;
+  GVariant *item;
 
   g_print (" *** Properties Changed:\n");
 
-  g_hash_table_iter_init (&iter, changed_properties);
-  while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value))
+  g_variant_get (changed_properties,
+                 "a{sv}",
+                 &iter);
+  while ((item = g_variant_iter_next_value (iter)))
     {
+      const gchar *key;
+      GVariant *value;
       gchar *value_str;
+
+      g_variant_get (item,
+                     "{sv}",
+                     &key,
+                     &value);
+
       value_str = g_variant_print (value, TRUE);
       g_print ("      %s -> %s\n", key, value_str);
       g_free (value_str);