[gnome-software/wip/william/request-refresh: 1/2] Add a needs-refresh query function for plugins
- From: William Hua <williamhua src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/william/request-refresh: 1/2] Add a needs-refresh query function for plugins
- Date: Sat, 7 May 2016 23:57:55 +0000 (UTC)
commit 3cc31893acdcec3e3bc0ab2ecc8bdc115b900325
Author: William Hua <william hua canonical com>
Date: Sat May 7 12:50:17 2016 -0400
Add a needs-refresh query function for plugins
src/gs-plugin-loader.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++
src/gs-plugin-loader.h | 2 +
src/gs-plugin.h | 2 +
3 files changed, 63 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 7b8f2c2..91c78aa 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -117,6 +117,8 @@ typedef gboolean (*GsPluginUpdateFunc) (GsPlugin *plugin,
GError **error);
typedef void (*GsPluginAdoptAppFunc) (GsPlugin *plugin,
GsApp *app);
+typedef gboolean (*GsPluginNeedsRefreshFunc) (GsPlugin *plugin,
+ GsPluginRefreshFlags *out_flags);
/* async state */
typedef struct {
@@ -3789,6 +3791,63 @@ gs_plugin_loader_refresh_finish (GsPluginLoader *plugin_loader,
return g_task_propagate_boolean (G_TASK (res), error);
}
+/**
+ * gs_plugin_loader_needs_refresh:
+ * @plugin_loader: a #GsPluginLoader
+ * @out_flags: (out) (optional): the type of refresh needed
+ *
+ * Returns: %TRUE if any plugin is requesting a refresh
+ */
+gboolean
+gs_plugin_loader_needs_refresh (GsPluginLoader *plugin_loader,
+ GsPluginRefreshFlags *out_flags)
+{
+ GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
+ GsPlugin *plugin;
+ GsPluginNeedsRefreshFunc plugin_func = NULL;
+ const gchar *function_name = "gs_plugin_needs_refresh";
+ gboolean needs_refresh = FALSE;
+ GsPluginRefreshFlags all_flags = GS_PLUGIN_REFRESH_FLAGS_NONE;
+ GsPluginRefreshFlags flags;
+ gboolean exists;
+ gboolean ret;
+ guint i;
+
+ g_return_val_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader), FALSE);
+
+ /* run each plugin */
+ for (i = 0; i < priv->plugins->len; i++) {
+ g_autoptr(AsProfileTask) ptask = NULL;
+
+ plugin = g_ptr_array_index (priv->plugins, i);
+ if (!gs_plugin_get_enabled (plugin))
+ continue;
+
+ exists = g_module_symbol (gs_plugin_get_module (plugin),
+ function_name,
+ (gpointer *) &plugin_func);
+ if (!exists)
+ continue;
+ ptask = as_profile_start (priv->profile,
+ "GsPlugin::%s(%s)",
+ gs_plugin_get_name (plugin),
+ function_name);
+ gs_plugin_loader_action_start (plugin_loader, plugin, TRUE);
+ flags = GS_PLUGIN_REFRESH_FLAGS_NONE;
+ ret = plugin_func (plugin, &flags);
+ gs_plugin_loader_action_stop (plugin_loader, plugin);
+ if (ret) {
+ needs_refresh = TRUE;
+ all_flags |= flags;
+ }
+ }
+
+ if (out_flags != NULL)
+ *out_flags = all_flags;
+
+ return needs_refresh;
+}
+
/******************************************************************************/
/**
diff --git a/src/gs-plugin-loader.h b/src/gs-plugin-loader.h
index 7f656bd..ea4801b 100644
--- a/src/gs-plugin-loader.h
+++ b/src/gs-plugin-loader.h
@@ -240,6 +240,8 @@ void gs_plugin_loader_set_network_status (GsPluginLoader
*plugin_loader,
gboolean online);
gboolean gs_plugin_loader_get_plugin_supported (GsPluginLoader *plugin_loader,
const gchar *plugin_func);
+gboolean gs_plugin_loader_needs_refresh (GsPluginLoader *plugin_loader,
+ GsPluginRefreshFlags *out_flags);
G_END_DECLS
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index e48a9af..0c17a3f 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -338,6 +338,8 @@ gboolean gs_plugin_update (GsPlugin *plugin,
GList *apps,
GCancellable *cancellable,
GError **error);
+gboolean gs_plugin_needs_refresh (GsPlugin *plugin,
+ GsPluginRefreshFlags *out_flags);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]