mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-05-29 00:40:07 +02:00
GDBus: Remove cached value if a property is invalidated
Also add a test case to catch this. Signed-off-by: David Zeuthen <davidz@redhat.com>
This commit is contained in:
parent
bb6530eb34
commit
ddc94bd0a6
@ -696,6 +696,7 @@ on_properties_changed (GDBusConnection *connection,
|
|||||||
GVariantIter iter;
|
GVariantIter iter;
|
||||||
gchar *key;
|
gchar *key;
|
||||||
GVariant *value;
|
GVariant *value;
|
||||||
|
guint n;
|
||||||
|
|
||||||
error = NULL;
|
error = NULL;
|
||||||
changed_properties = NULL;
|
changed_properties = NULL;
|
||||||
@ -728,6 +729,11 @@ on_properties_changed (GDBusConnection *connection,
|
|||||||
value); /* adopts value */
|
value); /* adopts value */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (n = 0; invalidated_properties[n] != NULL; n++)
|
||||||
|
{
|
||||||
|
g_hash_table_remove (proxy->priv->properties, invalidated_properties[n]);
|
||||||
|
}
|
||||||
|
|
||||||
/* emit signal */
|
/* emit signal */
|
||||||
g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
|
g_signal_emit (proxy, signals[PROPERTIES_CHANGED_SIGNAL],
|
||||||
0,
|
0,
|
||||||
|
@ -192,6 +192,42 @@ test_properties (GDBusConnection *connection,
|
|||||||
g_dbus_proxy_set_cached_property (proxy, "y", NULL);
|
g_dbus_proxy_set_cached_property (proxy, "y", NULL);
|
||||||
variant = g_dbus_proxy_get_cached_property (proxy, "y");
|
variant = g_dbus_proxy_get_cached_property (proxy, "y");
|
||||||
g_assert (variant == NULL);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
|
@ -189,6 +189,21 @@ class TestService(dbus.service.Object):
|
|||||||
message.append({prop_name : prop_value})
|
message.append({prop_name : prop_value})
|
||||||
message.append([], signature="as")
|
message.append([], signature="as")
|
||||||
session_bus.send_message(message)
|
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",
|
@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["as"] = [dbus.String("a string"), dbus.String("another string")]
|
||||||
obj.frob_props["ao"] = [dbus.ObjectPath("/some/path"), dbus.ObjectPath("/another/path")]
|
obj.frob_props["ao"] = [dbus.ObjectPath("/some/path"), dbus.ObjectPath("/another/path")]
|
||||||
obj.frob_props["foo"] = "a frobbed string"
|
obj.frob_props["foo"] = "a frobbed string"
|
||||||
|
obj.frob_props["PropertyThatWillBeInvalidated"] = "InitialValue"
|
||||||
|
|
||||||
mainloop = gobject.MainLoop()
|
mainloop = gobject.MainLoop()
|
||||||
mainloop.run()
|
mainloop.run()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user