[gnome-software] trivial: Add different actions for INITIALIZE and DESTROY
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Add different actions for INITIALIZE and DESTROY
- Date: Fri, 19 May 2017 15:34:32 +0000 (UTC)
commit 6abb6a9a402766921a8fdaab91dac933062f27de
Author: Richard Hughes <richard hughsie com>
Date: Fri May 19 10:21:14 2017 +0100
trivial: Add different actions for INITIALIZE and DESTROY
lib/gs-plugin-loader.c | 44 ++++++++++++++++++++++----------------------
lib/gs-plugin-types.h | 4 ++++
lib/gs-plugin.c | 8 ++++++++
3 files changed, 34 insertions(+), 22 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 9c0bb65..0238f4d 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -592,18 +592,17 @@ gs_plugin_loader_call_vfunc (GsPluginLoaderHelper *helper,
/* run the correct vfunc */
gs_plugin_loader_action_start (helper->plugin_loader, plugin, FALSE);
switch (helper->action) {
- case GS_PLUGIN_ACTION_SETUP:
- if (g_strcmp0 (helper->function_name, "gs_plugin_initialize") == 0 ||
- g_strcmp0 (helper->function_name, "gs_plugin_destroy") == 0) {
+ case GS_PLUGIN_ACTION_INITIALIZE:
+ case GS_PLUGIN_ACTION_DESTROY:
+ {
GsPluginFunc plugin_func = func;
plugin_func (plugin);
- } else if (g_strcmp0 (helper->function_name, "gs_plugin_setup") == 0) {
+ }
+ break;
+ case GS_PLUGIN_ACTION_SETUP:
+ {
GsPluginSetupFunc plugin_func = func;
ret = plugin_func (plugin, cancellable, &error_local);
- } else {
- g_critical ("function_name %s invalid for %s",
- helper->function_name,
- gs_plugin_action_to_string (helper->action));
}
break;
case GS_PLUGIN_ACTION_REFINE:
@@ -3748,11 +3747,11 @@ void
gs_plugin_loader_setup_again (GsPluginLoader *plugin_loader)
{
GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
- const gchar *func_names[] = {
- "gs_plugin_destroy",
- "gs_plugin_initialize",
- "gs_plugin_setup",
- NULL };
+ GsPluginAction actions[] = {
+ GS_PLUGIN_ACTION_DESTROY,
+ GS_PLUGIN_ACTION_INITIALIZE,
+ GS_PLUGIN_ACTION_SETUP,
+ GS_PLUGIN_ACTION_UNKNOWN };
/* clear global cache */
gs_plugin_loader_clear_caches (plugin_loader);
@@ -3761,16 +3760,16 @@ gs_plugin_loader_setup_again (GsPluginLoader *plugin_loader)
gs_plugin_loader_remove_events (plugin_loader);
/* call in order */
- for (guint j = 0; func_names[j] != NULL; j++) {
+ for (guint j = 0; actions[j] != GS_PLUGIN_ACTION_UNKNOWN; j++) {
for (guint i = 0; i < priv->plugins->len; i++) {
g_autoptr(GError) error_local = NULL;
g_autoptr(GsPluginLoaderHelper) helper = gs_plugin_loader_helper_new (plugin_loader);
GsPlugin *plugin = g_ptr_array_index (priv->plugins, i);
if (!gs_plugin_get_enabled (plugin))
continue;
- helper->action = GS_PLUGIN_ACTION_SETUP;
+ helper->action = actions[j];
helper->failure_flags = GS_PLUGIN_FAILURE_FLAGS_NO_CONSOLE;
- helper->function_name = func_names[j];
+ helper->function_name = gs_plugin_action_to_function_name (helper->action);
if (!gs_plugin_loader_call_vfunc (helper, plugin, NULL, NULL,
NULL, &error_local)) {
g_warning ("resetup of %s failed: %s",
@@ -3778,7 +3777,7 @@ gs_plugin_loader_setup_again (GsPluginLoader *plugin_loader)
error_local->message);
break;
}
- if (g_strcmp0 (func_names[j], "gs_plugin_destroy") == 0)
+ if (actions[j] == GS_PLUGIN_ACTION_DESTROY)
gs_plugin_clear_data (plugin);
}
}
@@ -3900,9 +3899,9 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader,
/* run the plugins */
helper = gs_plugin_loader_helper_new (plugin_loader);
- helper->action = GS_PLUGIN_ACTION_SETUP;
+ helper->action = GS_PLUGIN_ACTION_INITIALIZE;
helper->failure_flags = failure_flags | GS_PLUGIN_FAILURE_FLAGS_NO_CONSOLE;
- helper->function_name = "gs_plugin_initialize";
+ helper->function_name = gs_plugin_action_to_function_name (helper->action);
for (i = 0; i < priv->plugins->len; i++) {
plugin = g_ptr_array_index (priv->plugins, i);
gs_plugin_loader_call_vfunc (helper, plugin, NULL, NULL,
@@ -4050,7 +4049,8 @@ gs_plugin_loader_setup (GsPluginLoader *plugin_loader,
} while (changes);
/* run setup */
- helper->function_name = "gs_plugin_setup";
+ helper->action = GS_PLUGIN_ACTION_SETUP;
+ helper->function_name = gs_plugin_action_to_function_name (helper->action);
for (i = 0; i < priv->plugins->len; i++) {
g_autoptr(GError) error_local = NULL;
plugin = g_ptr_array_index (priv->plugins, i);
@@ -4137,8 +4137,8 @@ gs_plugin_loader_dispose (GObject *object)
if (priv->plugins != NULL) {
g_autoptr(GsPluginLoaderHelper) helper = NULL;
helper = gs_plugin_loader_helper_new (plugin_loader);
- helper->action = GS_PLUGIN_ACTION_SETUP;
- helper->function_name = "gs_plugin_destroy";
+ helper->action = GS_PLUGIN_ACTION_DESTROY;
+ helper->function_name = gs_plugin_action_to_function_name (helper->action);
for (guint i = 0; i < priv->plugins->len; i++) {
GsPlugin *plugin = g_ptr_array_index (priv->plugins, i);
gs_plugin_loader_call_vfunc (helper, plugin, NULL, NULL, NULL, NULL);
diff --git a/lib/gs-plugin-types.h b/lib/gs-plugin-types.h
index a6e2533..7e9a650 100644
--- a/lib/gs-plugin-types.h
+++ b/lib/gs-plugin-types.h
@@ -264,6 +264,8 @@ typedef enum {
* @GS_PLUGIN_ACTION_URL_TO_APP: Convert the file to an application
* @GS_PLUGIN_ACTION_GET_RECENT: Get the apps recently released
* @GS_PLUGIN_ACTION_GET_UPDATES_HISTORICAL: Get the list of historical updates
+ * @GS_PLUGIN_ACTION_INITIALIZE: Initialize the plugin
+ * @GS_PLUGIN_ACTION_DESTROY: Destroy the plugin
*
* The plugin action.
**/
@@ -308,6 +310,8 @@ typedef enum {
GS_PLUGIN_ACTION_URL_TO_APP,
GS_PLUGIN_ACTION_GET_RECENT,
GS_PLUGIN_ACTION_GET_UPDATES_HISTORICAL,
+ GS_PLUGIN_ACTION_INITIALIZE,
+ GS_PLUGIN_ACTION_DESTROY,
/*< private >*/
GS_PLUGIN_ACTION_LAST
} GsPluginAction;
diff --git a/lib/gs-plugin.c b/lib/gs-plugin.c
index 978f845..4a0b479 100644
--- a/lib/gs-plugin.c
+++ b/lib/gs-plugin.c
@@ -1755,6 +1755,10 @@ gs_plugin_action_to_function_name (GsPluginAction action)
return "gs_plugin_add_categories";
if (action == GS_PLUGIN_ACTION_SETUP)
return "gs_plugin_setup";
+ if (action == GS_PLUGIN_ACTION_INITIALIZE)
+ return "gs_plugin_initialize";
+ if (action == GS_PLUGIN_ACTION_DESTROY)
+ return "gs_plugin_destroy";
return NULL;
}
@@ -1849,6 +1853,10 @@ gs_plugin_action_to_string (GsPluginAction action)
return "get-recent";
if (action == GS_PLUGIN_ACTION_GET_UPDATES_HISTORICAL)
return "get-updates-historical";
+ if (action == GS_PLUGIN_ACTION_INITIALIZE)
+ return "initialize";
+ if (action == GS_PLUGIN_ACTION_DESTROY)
+ return "destroy";
return NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]