mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
GDBus: Use GVariant instead of GHashTable for GDBusProxy::g-properties-changed
This commit is contained in:
parent
869b4c6833
commit
7e8b07ae3b
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user