[glib/gdbus-merge] GDBus: Use GVariant instead of GHashTable for GDBusProxy::g-properties-changed
- From: David Zeuthen <davidz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/gdbus-merge] GDBus: Use GVariant instead of GHashTable for GDBusProxy::g-properties-changed
- Date: Mon, 10 May 2010 17:34:04 +0000 (UTC)
commit 7e8b07ae3be5ce63ba17183a410ac8512a29cb13
Author: David Zeuthen <davidz redhat com>
Date: Mon May 10 13:31:54 2010 -0400
GDBus: Use GVariant instead of GHashTable for GDBusProxy::g-properties-changed
gio/gdbusconnection.c | 13 -------------
gio/gdbusproxy.c | 24 +++++++++++-------------
gio/gdbusproxy.h | 2 +-
gio/tests/gdbus-example-watch-proxy.c | 21 +++++++++++++++------
4 files changed, 27 insertions(+), 33 deletions(-)
---
diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c
index 2de6382..f26d48e 100644
--- a/gio/gdbusconnection.c
+++ b/gio/gdbusconnection.c
@@ -28,19 +28,6 @@
* - 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
diff --git a/gio/gdbusproxy.c b/gio/gdbusproxy.c
index c851cc1..cb0a2f4 100644
--- a/gio/gdbusproxy.c
+++ b/gio/gdbusproxy.c
@@ -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)
diff --git a/gio/gdbusproxy.h b/gio/gdbusproxy.h
index 9b65e27..ee9f62e 100644
--- a/gio/gdbusproxy.h
+++ b/gio/gdbusproxy.h
@@ -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,
diff --git a/gio/tests/gdbus-example-watch-proxy.c b/gio/tests/gdbus-example-watch-proxy.c
index 9a6176e..7060b21 100644
--- a/gio/tests/gdbus-example-watch-proxy.c
+++ b/gio/tests/gdbus-example-watch-proxy.c
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]