GDBus: subscribe to PropertiesChanged() before calling GetAll()

Otherwise there's a slight chance of a race.
This commit is contained in:
David Zeuthen 2010-05-13 17:20:39 -04:00
parent 0e2c708bb2
commit 51446baa52

View File

@ -71,6 +71,8 @@ struct _GDBusProxyPrivate
guint properties_changed_subscriber_id; guint properties_changed_subscriber_id;
guint signals_subscriber_id; guint signals_subscriber_id;
gboolean initialized;
}; };
enum enum
@ -648,12 +650,17 @@ on_signal_received (GDBusConnection *connection,
{ {
GDBusProxy *proxy = G_DBUS_PROXY (user_data); GDBusProxy *proxy = G_DBUS_PROXY (user_data);
if (!proxy->priv->initialized)
goto out;
g_signal_emit (proxy, g_signal_emit (proxy,
signals[SIGNAL_SIGNAL], signals[SIGNAL_SIGNAL],
0, 0,
sender_name, sender_name,
signal_name, signal_name,
parameters); parameters);
out:
;
} }
/* ---------------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------------- */
@ -677,22 +684,17 @@ on_properties_changed (GDBusConnection *connection,
GVariant *value; GVariant *value;
error = NULL; error = NULL;
changed_properties = NULL;
invalidated_properties = NULL;
#if 0 // TODO! if (!proxy->priv->initialized)
/* Ignore this signal if properties are not yet available goto out;
*
* (can happen in the window between subscribing to PropertiesChanged() and until
* org.freedesktop.DBus.Properties.GetAll() returns)
*/
if (!proxy->priv->properties_available)
return;
#endif
if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sa{sv}as)"))) if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sa{sv}as)")))
{ {
g_warning ("Value for PropertiesChanged signal with type `%s' does not match `(sa{sv}as)'", g_warning ("Value for PropertiesChanged signal with type `%s' does not match `(sa{sv}as)'",
g_variant_get_type_string (parameters)); g_variant_get_type_string (parameters));
return; goto out;
} }
g_variant_get (parameters, g_variant_get (parameters,
@ -719,7 +721,8 @@ on_properties_changed (GDBusConnection *connection,
invalidated_properties); invalidated_properties);
out: out:
g_variant_unref (changed_properties); if (changed_properties != NULL)
g_variant_unref (changed_properties);
g_free (invalidated_properties); g_free (invalidated_properties);
} }
@ -815,6 +818,8 @@ initable_init (GInitable *initable,
ret = FALSE; ret = FALSE;
subscribe_to_signals (proxy);
if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES)) if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES))
{ {
/* load all properties synchronously */ /* load all properties synchronously */
@ -836,11 +841,10 @@ initable_init (GInitable *initable,
g_variant_unref (result); g_variant_unref (result);
} }
subscribe_to_signals (proxy);
ret = TRUE; ret = TRUE;
out: out:
proxy->priv->initialized = TRUE;
return ret; return ret;
} }
@ -896,6 +900,8 @@ async_initable_init_async (GAsyncInitable *initable,
user_data, user_data,
NULL); NULL);
subscribe_to_signals (proxy);
if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES)) if (!(proxy->priv->flags & G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES))
{ {
/* load all properties asynchronously */ /* load all properties asynchronously */
@ -944,11 +950,10 @@ async_initable_init_finish (GAsyncInitable *initable,
process_get_all_reply (proxy, result); process_get_all_reply (proxy, result);
} }
subscribe_to_signals (proxy);
ret = TRUE; ret = TRUE;
out: out:
proxy->priv->initialized = TRUE;
return ret; return ret;
} }