[gnome-software] trivial: Use a blocking delay in the dummy plugin
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Use a blocking delay in the dummy plugin
- Date: Thu, 21 Apr 2016 22:07:12 +0000 (UTC)
commit 30cff91a20775793e95d51f17944cb864ca2a1f9
Author: Richard Hughes <richard hughsie com>
Date: Thu Apr 21 22:28:33 2016 +0100
trivial: Use a blocking delay in the dummy plugin
src/plugins/gs-plugin-dummy.c | 83 ++++++++---------------------------------
1 files changed, 16 insertions(+), 67 deletions(-)
---
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
index fafdd44..4c8c497 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -81,52 +81,6 @@ gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
}
-typedef struct {
- GsPlugin *plugin;
- GsApp *app;
- GMainLoop *loop;
- GCancellable *cancellable;
- GError **error;
- guint percentage;
-} GsPluginDummyHelper;
-
-/**
- * gs_plugin_dummy_delay_cb:
- */
-static gboolean
-gs_plugin_dummy_delay_cb (gpointer user_data)
-{
- GsPluginDummyHelper *helper = (GsPluginDummyHelper *) user_data;
- helper->percentage += 10;
- if (helper->percentage >= 100) {
- g_main_loop_quit (helper->loop);
- return FALSE;
- }
- if (helper->error != NULL && *(helper->error) != NULL) {
- g_main_loop_quit (helper->loop);
- return FALSE;
- }
- g_debug ("dummy percentage=%i%%", helper->percentage);
- if (helper->app != NULL) {
- gs_app_set_progress (helper->app, helper->percentage);
- gs_plugin_status_update (helper->plugin,
- helper->app,
- GS_PLUGIN_STATUS_DOWNLOADING);
- }
- return TRUE;
-}
-
-/**
- * gs_plugin_dummy_delay_cancel_cb:
- */
-static void
-gs_plugin_dummy_delay_cancel_cb (GCancellable *cancellable,
- GsPluginDummyHelper *helper)
-{
- g_debug ("dummy delay cancelled");
- g_cancellable_set_error_if_cancelled (cancellable, helper->error);
-}
-
/**
* gs_plugin_dummy_delay:
*/
@@ -137,28 +91,23 @@ gs_plugin_dummy_delay (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- g_autofree GsPluginDummyHelper *helper = g_new0 (GsPluginDummyHelper, 1);
- g_autoptr(GMainLoop) loop = g_main_loop_new (NULL, FALSE);
-
- /* cancel the delay on cancellation */
- if (cancellable != NULL) {
- g_cancellable_connect (cancellable,
- G_CALLBACK (gs_plugin_dummy_delay_cancel_cb),
- helper, NULL);
+ gboolean ret = TRUE;
+ guint i;
+ guint timeout_us = timeout_ms * 10;
+
+ /* do blocking delay in 1% increments */
+ for (i = 0; i < 100; i++) {
+ g_usleep (timeout_us);
+ if (g_cancellable_set_error_if_cancelled (cancellable, error)) {
+ ret = FALSE;
+ break;
+ }
+ if (app != NULL)
+ gs_app_set_progress (app, i);
+ gs_plugin_status_update (plugin, app,
+ GS_PLUGIN_STATUS_DOWNLOADING);
}
-
- /* set up callbacks */
- helper->app = app;
- helper->cancellable = cancellable;
- helper->error = error;
- helper->loop = loop;
- helper->percentage = 0;
- helper->plugin = plugin;
- g_debug ("dummy waiting for %ims", timeout_ms);
- g_timeout_add (timeout_ms / 10, gs_plugin_dummy_delay_cb, helper);
- g_main_loop_run (loop);
- g_debug ("dummy done");
- return helper->error != NULL;
+ return ret;
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]