[gnome-software/wip/william/update-all: 70/75] Refactor gs_plugin_loader_offline_update_async/finish()
- From: William Hua <williamhua src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/william/update-all: 70/75] Refactor gs_plugin_loader_offline_update_async/finish()
- Date: Wed, 6 Apr 2016 17:33:39 +0000 (UTC)
commit 31b6d684d256b9a2d3aeb0eecb292e9d78e8a03d
Author: William Hua <william hua canonical com>
Date: Wed Apr 6 12:20:47 2016 +0100
Refactor gs_plugin_loader_offline_update_async/finish()
src/gs-plugin-loader.c | 83 +++++++++++++++++++++++++++++++++++++-----------
1 files changed, 64 insertions(+), 19 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 8d3425c..bb3e07e 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -3741,17 +3741,16 @@ gs_plugin_loader_filename_to_app_finish (GsPluginLoader *plugin_loader,
/******************************************************************************/
/**
- * gs_plugin_loader_offline_update_thread_cb:
+ * gs_plugin_loader_iterate_app_list_thread_cb:
**/
static void
-gs_plugin_loader_offline_update_thread_cb (GTask *task,
- gpointer object,
- gpointer task_data,
- GCancellable *cancellable)
+gs_plugin_loader_iterate_app_list_thread_cb (GTask *task,
+ gpointer object,
+ gpointer task_data,
+ GCancellable *cancellable)
{
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (object);
GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
- const gchar *function_name = "gs_plugin_offline_update";
gboolean ret = TRUE;
GsPluginLoaderAsyncState *state = (GsPluginLoaderAsyncState *) task_data;
GsPlugin *plugin;
@@ -3769,18 +3768,18 @@ gs_plugin_loader_offline_update_thread_cb (GTask *task,
if (ret)
return;
ret = g_module_symbol (plugin->module,
- function_name,
+ state->function_name,
(gpointer *) &plugin_func);
if (!ret)
continue;
ptask = as_profile_start (priv->profile,
"GsPlugin::%s(%s)",
plugin->name,
- function_name);
+ state->function_name);
ret = plugin_func (plugin, state->list, cancellable, &error_local);
if (!ret) {
g_warning ("failed to call %s on %s: %s",
- function_name, plugin->name,
+ state->function_name, plugin->name,
error_local->message);
continue;
}
@@ -3791,17 +3790,18 @@ gs_plugin_loader_offline_update_thread_cb (GTask *task,
}
/**
- * gs_plugin_loader_offline_update_async:
+ * gs_plugin_loader_iterate_app_list_async:
*
- * This method calls all plugins that implement the gs_plugin_add_offline_update()
+ * This method calls all plugins that implement the specified
* function.
**/
-void
-gs_plugin_loader_offline_update_async (GsPluginLoader *plugin_loader,
- GList *apps,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+static void
+gs_plugin_loader_iterate_app_list_async (GsPluginLoader *plugin_loader,
+ const gchar *function_name,
+ GList *apps,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
GsPluginLoaderAsyncState *state;
g_autoptr(GTask) task = NULL;
@@ -3811,13 +3811,56 @@ gs_plugin_loader_offline_update_async (GsPluginLoader *plugin_loader,
/* save state */
state = g_slice_new0 (GsPluginLoaderAsyncState);
+ state->function_name = function_name;
state->list = g_list_copy_deep (apps, (GCopyFunc) g_object_ref, NULL);
/* run in a thread */
task = g_task_new (plugin_loader, cancellable, callback, user_data);
g_task_set_task_data (task, state, (GDestroyNotify) gs_plugin_loader_free_async_state);
g_task_set_return_on_cancel (task, TRUE);
- g_task_run_in_thread (task, gs_plugin_loader_offline_update_thread_cb);
+ g_task_run_in_thread (task, gs_plugin_loader_iterate_app_list_thread_cb);
+}
+
+/**
+ * gs_plugin_loader_iterate_app_list_finish:
+ **/
+static gboolean
+gs_plugin_loader_iterate_app_list_finish (GsPluginLoader *plugin_loader,
+ GAsyncResult *res,
+ GError **error)
+{
+ g_return_val_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader), FALSE);
+ g_return_val_if_fail (G_IS_TASK (res), FALSE);
+ g_return_val_if_fail (g_task_is_valid (res, plugin_loader), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ return g_task_propagate_boolean (G_TASK (res), error);
+}
+
+/******************************************************************************/
+
+/**
+ * gs_plugin_loader_offline_update_async:
+ *
+ * This method calls all plugins that implement the gs_plugin_offline_update()
+ * function.
+ **/
+void
+gs_plugin_loader_offline_update_async (GsPluginLoader *plugin_loader,
+ GList *apps,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader));
+ g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+
+ gs_plugin_loader_iterate_app_list_async (plugin_loader,
+ "gs_plugin_offline_update",
+ apps,
+ cancellable,
+ callback,
+ user_data);
}
/**
@@ -3833,9 +3876,11 @@ gs_plugin_loader_offline_update_finish (GsPluginLoader *plugin_loader,
g_return_val_if_fail (g_task_is_valid (res, plugin_loader), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- return g_task_propagate_boolean (G_TASK (res), error);
+ return gs_plugin_loader_iterate_app_list_finish (plugin_loader, res, error);
}
+/******************************************************************************/
+
/**
* gs_plugin_loader_get_plugin_supported:
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]