From ddc94bd0a65a17471e50d0c659d9c59a1804c3f1 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Fri, 14 May 2010 12:55:25 -0400 Subject: [PATCH] GDBus: Remove cached value if a property is invalidated Also add a test case to catch this. Signed-off-by: David Zeuthen --- gio/gdbusproxy.c | 6 ++++++ gio/tests/gdbus-proxy.c | 36 ++++++++++++++++++++++++++++++++++++ gio/tests/gdbus-testserver.py | 16 ++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/gio/gdbusproxy.c b/gio/gdbusproxy.c index 911c659..53ef06e 100644 --- a/gio/gdbusproxy.c +++ b/gio/gdbusproxy.c @@ -696,6 +696,7 @@ on_properties_changed (GDBusConnection *connection, GVariantIter iter; gchar *key; GVariant *value; + guint n; error = NULL; changed_properties = NULL; @@ -728,6 +729,11 @@ on_properties_changed (GDBusConnection *connection, value); /* adopts value */ } + for (n = 0; invalidated_properties[n] != NULL; n++) + { + g_hash_table_remove (proxy->priv->properties, invalidated_properties[n]); + } + /* emit signal */ g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL], 0, diff --git a/gio/tests/gdbus-proxy.c b/gio/tests/gdbus-proxy.c index bfd09c1..17752fe 100644 --- a/gio/tests/gdbus-proxy.c +++ b/gio/tests/gdbus-proxy.c @@ -192,6 +192,42 @@ test_properties (GDBusConnection *connection, g_dbus_proxy_set_cached_property (proxy, "y", NULL); variant = g_dbus_proxy_get_cached_property (proxy, "y"); g_assert (variant == NULL); + + /* Check that the invalidation feature of the PropertiesChanged() + * signal works... First, check that we have a cached value of the + * property (from the initial GetAll() call) + */ + variant = g_dbus_proxy_get_cached_property (proxy, "PropertyThatWillBeInvalidated"); + g_assert (variant != NULL); + g_assert_cmpstr (g_variant_get_string (variant, NULL), ==, "InitialValue"); + g_variant_unref (variant); + /* now ask to invalidate the property - this causes a + * + * PropertiesChanaged("com.example.Frob", + * {}, + * ["PropertyThatWillBeInvalidated") + * + * signal to be emitted. This is received before the method reply + * for FrobInvalidateProperty *but* since the proxy was created in + * the same thread as we're doing this synchronous call, we'll get + * the method reply before... + */ + result = g_dbus_proxy_call_sync (proxy, + "FrobInvalidateProperty", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + g_assert_no_error (error); + g_assert (result != NULL); + g_assert_cmpstr (g_variant_get_type_string (result), ==, "()"); + g_variant_unref (result); + /* ... hence we wait for the g-properties-changed signal to be delivered */ + _g_assert_signal_received (proxy, "g-properties-changed"); + /* ... and now we finally, check that the cached value has been invalidated */ + variant = g_dbus_proxy_get_cached_property (proxy, "PropertyThatWillBeInvalidated"); + g_assert (variant == NULL); } /* ---------------------------------------------------------------------------------------------------- */ diff --git a/gio/tests/gdbus-testserver.py b/gio/tests/gdbus-testserver.py index d31a493..f7be13e 100755 --- a/gio/tests/gdbus-testserver.py +++ b/gio/tests/gdbus-testserver.py @@ -189,6 +189,21 @@ class TestService(dbus.service.Object): message.append({prop_name : prop_value}) message.append([], signature="as") session_bus.send_message(message) + + # ---------------------------------------------------------------------------------------------------- + + @dbus.service.method("com.example.Frob", + in_signature='', out_signature='') + def FrobInvalidateProperty(self): + self.frob_props["PropertyThatWillBeInvalidated"] = "OMGInvalidated" + message = dbus.lowlevel.SignalMessage("/com/example/TestObject", + "org.freedesktop.DBus.Properties", + "PropertiesChanged") + message.append("com.example.Frob") + message.append({}, signature="a{sv}") + message.append(["PropertyThatWillBeInvalidated"]) + session_bus.send_message(message) + # ---------------------------------------------------------------------------------------------------- @dbus.service.signal("com.example.Frob", @@ -266,6 +281,7 @@ if __name__ == '__main__': obj.frob_props["as"] = [dbus.String("a string"), dbus.String("another string")] obj.frob_props["ao"] = [dbus.ObjectPath("/some/path"), dbus.ObjectPath("/another/path")] obj.frob_props["foo"] = "a frobbed string" + obj.frob_props["PropertyThatWillBeInvalidated"] = "InitialValue" mainloop = gobject.MainLoop() mainloop.run() -- 2.7.4