From 4a3d68bb35a2f371708568e199bdb0fc92af4ef5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 9 Jan 2011 17:06:45 -0600 Subject: Using the GCancellable to detect if we're already creating a proxy so that we don't do it twice. --- libindicator/indicator-service-manager.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index 4f98a5c..34b6baa 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -417,14 +417,17 @@ start_service (IndicatorServiceManager * service) g_return_if_fail(priv->name != NULL); + if (priv->service_proxy_cancel != NULL) { + /* A service proxy is being gotten currently */ + return; + } + if (priv->service_proxy != NULL) { g_object_unref(priv->service_proxy); priv->service_proxy = NULL; } - if (priv->service_proxy_cancel == NULL) { - priv->service_proxy_cancel = g_cancellable_new(); - } + priv->service_proxy_cancel = g_cancellable_new(); g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, @@ -446,13 +449,24 @@ static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) { GError * error = NULL; + + IndicatorServiceManager * service = INDICATOR_SERVICE_MANAGER(user_data); + g_return_if_fail(service != NULL); + GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); + IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(user_data); + + if (priv->service_proxy_cancel != NULL) { + g_object_unref(priv->service_proxy_cancel); + priv->service_proxy_cancel = NULL; + } + if (error != NULL) { /* Unable to create the proxy, eh, let's try again in a bit */ g_error_free(error); - start_service_again(INDICATOR_SERVICE_MANAGER(user_data)); + start_service_again(service); return; } @@ -462,12 +476,13 @@ service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) odd that it wouldn't have an owner at this point. But, all we can do is try again. */ g_object_unref(proxy); - start_service_again(INDICATOR_SERVICE_MANAGER(user_data)); + start_service_again(service); return; } g_free(name); - IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(user_data); + /* Okay, we're good to grab the proxy at this point, we're + sure that it's ours. */ priv->service_proxy = proxy; /* Signal for drop */ -- cgit v1.2.3