GDBus: Catch up with new PropertiesChanged signal

After a long discussion, this has finally been standardized in the
D-Bus spec. See

 http://lists.freedesktop.org/archives/dbus/2010-May/012667.html
 http://lists.freedesktop.org/archives/dbus/2010-May/012712.html

Signed-off-by: David Zeuthen <davidz@redhat.com>
This commit is contained in:
David Zeuthen
2010-05-13 11:56:15 -04:00
parent 2d75583fb2
commit 82158afdad
9 changed files with 136 additions and 62 deletions

View File

@@ -233,9 +233,11 @@ send_property_change (GObject *obj,
GDBusConnection *connection)
{
GVariantBuilder *builder;
GVariantBuilder *invalidated_builder;
MyObject *myobj = (MyObject *)obj;
builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
invalidated_builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
if (g_strcmp0 (pspec->name, "count") == 0)
g_variant_builder_add (builder,
@@ -251,9 +253,10 @@ send_property_change (GObject *obj,
"/org/myorg/MyObject",
"org.freedesktop.DBus.Properties",
"PropertiesChanged",
g_variant_new ("(sa{sv})",
g_variant_new ("(sa{sv}as)",
"org.myorg.MyObject",
builder),
builder,
invalidated_builder),
NULL);
}

View File

@@ -202,27 +202,31 @@ accounts_user_g_signal (GDBusProxy *proxy,
}
static void
accounts_user_g_properties_changed (GDBusProxy *proxy,
GVariant *changed_properties)
accounts_user_g_properties_changed (GDBusProxy *proxy,
GVariant *changed_properties,
const gchar* const *invalidated_properties)
{
AccountsUser *user = ACCOUNTS_USER (proxy);
GVariantIter *iter;
GVariant *item;
g_variant_get (changed_properties, "a{sv}", &iter);
while ((item = g_variant_iter_next_value (iter)) != NULL)
if (changed_properties != NULL)
{
const gchar *key;
g_variant_get (item,
"{sv}",
&key,
NULL);
if (g_strcmp0 (key, "AutomaticLogin") == 0)
g_object_notify (G_OBJECT (user), "automatic-login");
else if (g_strcmp0 (key, "RealName") == 0)
g_object_notify (G_OBJECT (user), "real-name");
else if (g_strcmp0 (key, "UserName") == 0)
g_object_notify (G_OBJECT (user), "user-name");
g_variant_get (changed_properties, "a{sv}", &iter);
while ((item = g_variant_iter_next_value (iter)) != NULL)
{
const gchar *key;
g_variant_get (item,
"{sv}",
&key,
NULL);
if (g_strcmp0 (key, "AutomaticLogin") == 0)
g_object_notify (G_OBJECT (user), "automatic-login");
else if (g_strcmp0 (key, "RealName") == 0)
g_object_notify (G_OBJECT (user), "real-name");
else if (g_strcmp0 (key, "UserName") == 0)
g_object_notify (G_OBJECT (user), "user-name");
}
}
}

View File

@@ -243,9 +243,10 @@ handle_set_property (GDBusConnection *connection,
object_path,
"org.freedesktop.DBus.Properties",
"PropertiesChanged",
g_variant_new ("(sa{sv})",
g_variant_new ("(sa{sv}as)",
interface_name,
builder),
builder,
NULL),
&local_error);
g_assert_no_error (local_error);
}
@@ -283,12 +284,14 @@ on_timeout_cb (gpointer user_data)
{
GDBusConnection *connection = G_DBUS_CONNECTION (user_data);
GVariantBuilder *builder;
GVariantBuilder *invalidated_builder;
GError *error;
swap_a_and_b = !swap_a_and_b;
error = NULL;
builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
invalidated_builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
g_variant_builder_add (builder,
"{sv}",
"Foo",
@@ -302,9 +305,10 @@ on_timeout_cb (gpointer user_data)
"/org/gtk/GDBus/TestObject",
"org.freedesktop.DBus.Properties",
"PropertiesChanged",
g_variant_new ("(sa{sv})",
g_variant_new ("(sa{sv}as)",
"org.gtk.GDBus.TestInterface",
builder),
builder,
invalidated_builder),
&error);
g_assert_no_error (error);

View File

@@ -42,32 +42,45 @@ print_properties (GDBusProxy *proxy)
}
static void
on_properties_changed (GDBusProxy *proxy,
GVariant *changed_properties,
gpointer user_data)
on_properties_changed (GDBusProxy *proxy,
GVariant *changed_properties,
const gchar* const *invalidated_properties,
gpointer user_data)
{
GVariantIter *iter;
GVariant *item;
g_print (" *** Properties Changed:\n");
g_variant_get (changed_properties,
"a{sv}",
&iter);
while ((item = g_variant_iter_next_value (iter)))
if (changed_properties != NULL)
{
const gchar *key;
GVariant *value;
gchar *value_str;
GVariantIter *iter;
GVariant *item;
g_variant_get (item,
"{sv}",
&key,
&value);
g_print (" *** Properties Changed:\n");
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);
}
}
value_str = g_variant_print (value, TRUE);
g_print (" %s -> %s\n", key, value_str);
g_free (value_str);
if (invalidated_properties != NULL)
{
guint n;
g_print (" *** Properties Invalidated:\n");
for (n = 0; invalidated_properties[n] != NULL; n++)
{
const gchar *key = invalidated_properties[n];
g_print (" %s\n", key);
}
}
}

View File

@@ -187,6 +187,7 @@ class TestService(dbus.service.Object):
"PropertiesChanged")
message.append("com.example.Frob")
message.append({prop_name : prop_value})
message.append([], signature="as")
session_bus.send_message(message)
# ----------------------------------------------------------------------------------------------------