From c6313acb0861e4861a160f6866e42995cd50f062 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 11 Mar 2011 14:50:18 -0600 Subject: Add a cancellable object for the GetApplications call --- src/indicator-application.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/indicator-application.c b/src/indicator-application.c index f7ce391..1d074d6 100644 --- a/src/indicator-application.c +++ b/src/indicator-application.c @@ -86,6 +86,7 @@ struct _IndicatorApplicationPrivate { GList * applications; GHashTable * theme_dirs; guint disconnect_kill; + GCancellable * get_apps_cancel; }; typedef struct _ApplicationEntry ApplicationEntry; @@ -166,6 +167,8 @@ indicator_application_init (IndicatorApplication *self) priv->theme_dirs = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + priv->get_apps_cancel = NULL; + return; } @@ -178,6 +181,12 @@ indicator_application_dispose (GObject *object) g_source_remove(priv->disconnect_kill); } + if (priv->get_apps_cancel != NULL) { + g_cancellable_cancel(priv->get_apps_cancel); + /* The callback should clear the cancelable */ + g_warn_if_fail(priv->get_apps_cancel == NULL); + } + while (priv->applications != NULL) { application_removed(INDICATOR_APPLICATION(object), 0); @@ -290,10 +299,20 @@ service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) g_signal_connect(proxy, "g-signal", G_CALLBACK(receive_signal), self); + /* We shouldn't be in a situation where we've already + called this function. It doesn't *hurt* anything, but + man we should look into it more. */ + if (priv->get_apps_cancel != NULL) { + g_warning("Already getting applications? Odd."); + return; + } + + priv->get_apps_cancel = g_cancellable_new(); + /* Query it for existing applications */ g_debug("Request current apps"); g_dbus_proxy_call(priv->service_proxy, "GetApplications", NULL, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, + G_DBUS_CALL_FLAGS_NONE, -1, priv->get_apps_cancel, get_applications, self); return; @@ -789,6 +808,12 @@ get_applications (GObject * obj, GAsyncResult * res, gpointer user_data) GVariant * child; GVariantIter * iter; + /* No one can cancel us anymore, we've completed! */ + if (priv->get_apps_cancel != NULL) { + g_object_unref(priv->get_apps_cancel); + priv->get_apps_cancel = NULL; + } + result = g_dbus_proxy_call_finish(priv->service_proxy, res, &error); if (error != NULL) { -- cgit v1.2.3 From a4e9c0bf6ee2b628dac8655cacd2841c87aae702 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 11 Mar 2011 15:42:22 -0600 Subject: If we're in the middle of a GetApplications and we get another signal, let's try again. --- src/indicator-application.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/indicator-application.c b/src/indicator-application.c index 1d074d6..73e8341 100644 --- a/src/indicator-application.c +++ b/src/indicator-application.c @@ -749,6 +749,21 @@ receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data) { IndicatorApplication * self = INDICATOR_APPLICATION(user_data); + IndicatorApplicationPrivate * priv = INDICATOR_APPLICATION_GET_PRIVATE(self); + + /* If we're in the middle of a GetApplications call and we get + any of these our state is probably going to just be confused. Let's + cancel the call we had and try again to try and get a clear answer */ + if (priv->get_apps_cancel != NULL) { + g_cancelable_cancel(priv->get_apps_cancel); + g_object_unref(priv->get_apps_cancel); + + priv->get_apps_cancel = g_cancellable_new(); + + g_dbus_proxy_call(priv->service_proxy, "GetApplications", NULL, + G_DBUS_CALL_FLAGS_NONE, -1, priv->get_apps_cancel, + get_applications, self); + } if (g_strcmp0(signal_name, "ApplicationAdded") == 0) { const gchar * iconname; -- cgit v1.2.3 From bc6a7d9b4fd1dd9edc477edfdba39a34069ec53d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 11 Mar 2011 15:43:47 -0600 Subject: Unrefing the object, it might not happen right away, so let's clear it ourselves. --- src/indicator-application.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/indicator-application.c b/src/indicator-application.c index 73e8341..c2dd16a 100644 --- a/src/indicator-application.c +++ b/src/indicator-application.c @@ -183,8 +183,8 @@ indicator_application_dispose (GObject *object) if (priv->get_apps_cancel != NULL) { g_cancellable_cancel(priv->get_apps_cancel); - /* The callback should clear the cancelable */ - g_warn_if_fail(priv->get_apps_cancel == NULL); + g_object_unref(priv->get_apps_cancel); + priv->get_apps_cancel = NULL; } while (priv->applications != NULL) { @@ -755,7 +755,7 @@ receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, any of these our state is probably going to just be confused. Let's cancel the call we had and try again to try and get a clear answer */ if (priv->get_apps_cancel != NULL) { - g_cancelable_cancel(priv->get_apps_cancel); + g_cancellable_cancel(priv->get_apps_cancel); g_object_unref(priv->get_apps_cancel); priv->get_apps_cancel = g_cancellable_new(); -- cgit v1.2.3 From c892f84845aeb7367c9246a679a21da09ebafd2c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 11 Mar 2011 15:49:21 -0600 Subject: Only clear the cancel if we're not being cancelled --- src/indicator-application.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/indicator-application.c b/src/indicator-application.c index c2dd16a..f9b200b 100644 --- a/src/indicator-application.c +++ b/src/indicator-application.c @@ -823,14 +823,16 @@ get_applications (GObject * obj, GAsyncResult * res, gpointer user_data) GVariant * child; GVariantIter * iter; + result = g_dbus_proxy_call_finish(priv->service_proxy, res, &error); + /* No one can cancel us anymore, we've completed! */ if (priv->get_apps_cancel != NULL) { - g_object_unref(priv->get_apps_cancel); - priv->get_apps_cancel = NULL; + if (error == NULL || error->domain != G_IO_ERROR || error->code != G_IO_ERROR_CANCELLED) { + g_object_unref(priv->get_apps_cancel); + priv->get_apps_cancel = NULL; + } } - result = g_dbus_proxy_call_finish(priv->service_proxy, res, &error); - if (error != NULL) { g_warning("Unable to get application list: %s", error->message); return; -- cgit v1.2.3 From d3c5e2540937720b15b542092cfccf924c7487aa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 11 Mar 2011 15:53:30 -0600 Subject: A couple memory leaks --- src/indicator-application.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/indicator-application.c b/src/indicator-application.c index f9b200b..eabbf54 100644 --- a/src/indicator-application.c +++ b/src/indicator-application.c @@ -835,13 +835,17 @@ get_applications (GObject * obj, GAsyncResult * res, gpointer user_data) if (error != NULL) { g_warning("Unable to get application list: %s", error->message); + g_error_free(error); return; } g_variant_get(result, "(a(sisossss))", &iter); - while ((child = g_variant_iter_next_value (iter))) + while ((child = g_variant_iter_next_value (iter))) { get_applications_helper(self, child); + g_variant_unref(child); + } g_variant_iter_free (iter); + g_variant_unref(result); return; } -- cgit v1.2.3 From a11d8f16f4939353926b3cbf35217746fb488803 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 11 Mar 2011 16:19:02 -0600 Subject: Removing applications before adding new ones. --- src/indicator-application.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/indicator-application.c b/src/indicator-application.c index eabbf54..f59ffd7 100644 --- a/src/indicator-application.c +++ b/src/indicator-application.c @@ -833,12 +833,20 @@ get_applications (GObject * obj, GAsyncResult * res, gpointer user_data) } } + /* If we got an error, print it and exit out */ if (error != NULL) { g_warning("Unable to get application list: %s", error->message); g_error_free(error); return; } + /* Remove all applications that we previously had + as we're going to repopulate the list. */ + while (priv->applications != NULL) { + application_removed(self, 0); + } + + /* Get our new applications that we got in the request */ g_variant_get(result, "(a(sisossss))", &iter); while ((child = g_variant_iter_next_value (iter))) { get_applications_helper(self, child); -- cgit v1.2.3 From 00a8865d92f45049e9f2485ff6825506a2561197 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 11 Mar 2011 16:28:20 -0600 Subject: If we're requeuing we don't really want to continue to process the signal --- src/indicator-application.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/indicator-application.c b/src/indicator-application.c index f59ffd7..2b26c92 100644 --- a/src/indicator-application.c +++ b/src/indicator-application.c @@ -763,6 +763,7 @@ receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, g_dbus_proxy_call(priv->service_proxy, "GetApplications", NULL, G_DBUS_CALL_FLAGS_NONE, -1, priv->get_apps_cancel, get_applications, self); + return; } if (g_strcmp0(signal_name, "ApplicationAdded") == 0) { -- cgit v1.2.3 -- cgit v1.2.3