gdbusproxy could provide some g_dbus_proxy_reload_properties_sync call or so
Submitted by Ray Strode [halfline]
Assigned to David Zeuthen
Link to original bug (#739317)
Description
I'm currently facing a situation where I'm on a worker thread and I make a call to another process that causes that process to, as a side-effect, update some properties on one of the objects managed by an object manager.
My worker thread has a proxy to the object, and the properties on the proxy are cached. The updated properties in the cache will get refreshed when the PropertiesChanged signal comes in, but the thread needs to know the updated values before it can proceed. I think it really only has a few options:
- Wait until g-properties-changed is emitted and then proceed. This has the problem that if no properties are updated, that the thread will block forever.
- call Get() or GetAll() itself manually. Then it doesn't get to use the nice generated accessor functions provided by gdbuscodegen.
- call Get() or GetAll() manually and then feed the result back into the cache with set_cached_property. This solves all the problems but it really feels like this functionality should be part of the GDBusProxy api.
So, concretely, my proposal here is something along the lines of:
static gboolean g_dbus_proxy_reload_properties_sync (GDBusProxy *proxy, GCancellable *cancellable, GError **error) { GVariant *result; char *name; GVariant *value; GVariantIter *iter;
result = g_dbus_connection_call_sync (g_dbus_proxy_get_connection (proxy), g_dbus_proxy_get_name_owner (proxy), g_dbus_proxy_get_object_path (proxy), "org.freedesktop.DBus.Properties", "GetAll", g_variant_new ("(s)", g_dbus_proxy_get_interface_name (proxy)), G_VARIANT_TYPE ("(a{sv})"), G_DBUS_CALL_FLAGS_NONE, -1, cancellable, error); if (result == NULL) return FALSE;
g_variant_get (result, "(a{sv})", &iter); while (g_variant_iter_next (iter, "{sv}", &name, &value)) { g_dbus_proxy_set_cached_property (proxy, name, value); g_free (name); g_variant_unref (value); } g_variant_iter_free (iter); return TRUE; }
Make sense?