[gnome-software] Add gs_plugin_action_to_function_name()
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Add gs_plugin_action_to_function_name()
- Date: Fri, 19 May 2017 15:34:27 +0000 (UTC)
commit 5c720e2d1c08932891b64288137f91cb881e3124
Author: Richard Hughes <richard hughsie com>
Date: Fri May 19 10:20:00 2017 +0100
Add gs_plugin_action_to_function_name()
This allows us to move some code out of the plugin loader.
lib/gs-plugin-loader.c | 93 +++++------------------------------------------
lib/gs-plugin-private.h | 1 +
lib/gs-plugin.c | 90 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 101 insertions(+), 83 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 2c74d8a..9c0bb65 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1345,7 +1345,6 @@ gs_plugin_loader_get_updates_thread_cb (GTask *task,
/* do things that would block */
if (helper->action == GS_PLUGIN_ACTION_GET_UPDATES_HISTORICAL) {
- helper->function_name = "gs_plugin_add_updates_historical";
helper->list = gs_plugin_loader_run_results (helper, cancellable, &error);
if (helper->list == NULL) {
g_task_return_error (task, error);
@@ -1353,7 +1352,6 @@ gs_plugin_loader_get_updates_thread_cb (GTask *task,
}
} else {
/* get downloaded updates */
- helper->function_name = "gs_plugin_add_updates";
helper->list = gs_plugin_loader_run_results (helper, cancellable, &error);
if (helper->list == NULL) {
g_task_return_error (task, error);
@@ -1432,6 +1430,7 @@ gs_plugin_loader_get_updates_async (GsPluginLoader *plugin_loader,
helper->action = GS_PLUGIN_ACTION_GET_UPDATES_HISTORICAL;
else
helper->action = GS_PLUGIN_ACTION_GET_UPDATES;
+ helper->function_name = gs_plugin_action_to_function_name (helper->action);
gs_plugin_loader_helper_debug (helper);
/* run in a thread */
@@ -2634,7 +2633,7 @@ gs_plugin_loader_get_category_apps_async (GsPluginLoader *plugin_loader,
helper->list = gs_app_list_new ();
helper->category = g_object_ref (category);
helper->action = GS_PLUGIN_ACTION_GET_CATEGORY_APPS;
- helper->function_name = "gs_plugin_add_category_apps";
+ helper->function_name = gs_plugin_action_to_function_name (helper->action);
gs_plugin_loader_helper_debug (helper);
/* run in a thread */
@@ -2748,7 +2747,7 @@ gs_plugin_loader_get_recent_async (GsPluginLoader *plugin_loader,
helper->list = gs_app_list_new ();
helper->age = age;
helper->action = GS_PLUGIN_ACTION_GET_RECENT;
- helper->function_name = "gs_plugin_add_recent";
+ helper->function_name = gs_plugin_action_to_function_name (helper->action);
gs_plugin_loader_helper_debug (helper);
/* run in a thread */
@@ -3196,41 +3195,9 @@ gs_plugin_loader_app_action_async (GsPluginLoader *plugin_loader,
helper->app = g_object_ref (app);
helper->action = action;
helper->failure_flags = failure_flags;
+ helper->function_name = gs_plugin_action_to_function_name (helper->action);
gs_plugin_loader_helper_debug (helper);
- switch (action) {
- case GS_PLUGIN_ACTION_INSTALL:
- helper->function_name = "gs_plugin_app_install";
- break;
- case GS_PLUGIN_ACTION_REMOVE:
- helper->function_name = "gs_plugin_app_remove";
- break;
- case GS_PLUGIN_ACTION_SET_RATING:
- helper->function_name = "gs_plugin_app_set_rating";
- break;
- case GS_PLUGIN_ACTION_UPGRADE_DOWNLOAD:
- helper->function_name = "gs_plugin_app_upgrade_download";
- break;
- case GS_PLUGIN_ACTION_UPGRADE_TRIGGER:
- helper->function_name = "gs_plugin_app_upgrade_trigger";
- break;
- case GS_PLUGIN_ACTION_LAUNCH:
- helper->function_name = "gs_plugin_launch";
- break;
- case GS_PLUGIN_ACTION_UPDATE_CANCEL:
- helper->function_name = "gs_plugin_update_cancel";
- break;
- case GS_PLUGIN_ACTION_ADD_SHORTCUT:
- helper->function_name = "gs_plugin_add_shortcut";
- break;
- case GS_PLUGIN_ACTION_REMOVE_SHORTCUT:
- helper->function_name = "gs_plugin_remove_shortcut";
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
/* run in a thread */
task = g_task_new (plugin_loader, cancellable, callback, user_data);
g_task_set_task_data (task, helper, (GDestroyNotify) gs_plugin_loader_helper_free);
@@ -3260,32 +3227,9 @@ gs_plugin_loader_review_action_async (GsPluginLoader *plugin_loader,
helper->review = g_object_ref (review);
helper->action = action;
helper->failure_flags = failure_flags;
+ helper->function_name = gs_plugin_action_to_function_name (helper->action);
gs_plugin_loader_helper_debug (helper);
- switch (action) {
- case GS_PLUGIN_ACTION_REVIEW_SUBMIT:
- helper->function_name = "gs_plugin_review_submit";
- break;
- case GS_PLUGIN_ACTION_REVIEW_UPVOTE:
- helper->function_name = "gs_plugin_review_upvote";
- break;
- case GS_PLUGIN_ACTION_REVIEW_DOWNVOTE:
- helper->function_name = "gs_plugin_review_downvote";
- break;
- case GS_PLUGIN_ACTION_REVIEW_REPORT:
- helper->function_name = "gs_plugin_review_report";
- break;
- case GS_PLUGIN_ACTION_REVIEW_REMOVE:
- helper->function_name = "gs_plugin_review_remove";
- break;
- case GS_PLUGIN_ACTION_REVIEW_DISMISS:
- helper->function_name = "gs_plugin_review_dismiss";
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
/* run in a thread */
task = g_task_new (plugin_loader, cancellable, callback, user_data);
g_task_set_task_data (task, helper, (GDestroyNotify) gs_plugin_loader_helper_free);
@@ -3354,26 +3298,9 @@ gs_plugin_loader_auth_action_async (GsPluginLoader *plugin_loader,
helper->auth = g_object_ref (auth);
helper->action = action;
helper->failure_flags = failure_flags;
+ helper->function_name = gs_plugin_action_to_function_name (helper->action);
gs_plugin_loader_helper_debug (helper);
- switch (action) {
- case GS_PLUGIN_ACTION_AUTH_LOGIN:
- helper->function_name = "gs_plugin_auth_login";
- break;
- case GS_PLUGIN_ACTION_AUTH_LOGOUT:
- helper->function_name = "gs_plugin_auth_logout";
- break;
- case GS_PLUGIN_ACTION_AUTH_REGISTER:
- helper->function_name = "gs_plugin_auth_register";
- break;
- case GS_PLUGIN_ACTION_AUTH_LOST_PASSWORD:
- helper->function_name = "gs_plugin_auth_lost_password";
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
/* run in a thread */
task = g_task_new (plugin_loader, cancellable, callback, user_data);
g_task_set_task_data (task, helper, (GDestroyNotify) gs_plugin_loader_helper_free);
@@ -4586,7 +4513,7 @@ gs_plugin_loader_refresh_async (GsPluginLoader *plugin_loader,
helper->failure_flags = failure_flags;
helper->cache_age = cache_age;
helper->action = GS_PLUGIN_ACTION_REFRESH;
- helper->function_name = "gs_plugin_refresh";
+ helper->function_name = gs_plugin_action_to_function_name (helper->action);
gs_plugin_loader_helper_debug (helper);
/* run in a thread */
@@ -4748,7 +4675,7 @@ gs_plugin_loader_file_to_app_async (GsPluginLoader *plugin_loader,
helper->list = gs_app_list_new ();
helper->file = g_object_ref (file);
helper->action = GS_PLUGIN_ACTION_FILE_TO_APP;
- helper->function_name = "gs_plugin_file_to_app";
+ helper->function_name = gs_plugin_action_to_function_name (helper->action);
gs_plugin_loader_helper_debug (helper);
/* run in a thread */
@@ -4868,7 +4795,7 @@ gs_plugin_loader_url_to_app_async (GsPluginLoader *plugin_loader,
helper->list = gs_app_list_new ();
helper->value = g_strdup (url);
helper->action = GS_PLUGIN_ACTION_URL_TO_APP;
- helper->function_name = "gs_plugin_url_to_app";
+ helper->function_name = gs_plugin_action_to_function_name (helper->action);
gs_plugin_loader_helper_debug (helper);
/* run in a thread */
@@ -4970,7 +4897,6 @@ gs_plugin_loader_update_thread_cb (GTask *task,
guint i;
/* run each plugin */
- helper->function_name = "gs_plugin_update";
for (i = 0; i < priv->plugins->len; i++) {
GsPlugin *plugin = g_ptr_array_index (priv->plugins, i);
if (g_task_return_error_if_cancelled (task))
@@ -5086,6 +5012,7 @@ gs_plugin_loader_update_async (GsPluginLoader *plugin_loader,
helper->list = gs_app_list_copy (apps);
helper->action = GS_PLUGIN_ACTION_UPDATE;
helper->failure_flags = failure_flags;
+ helper->function_name = gs_plugin_action_to_function_name (helper->action);
gs_plugin_loader_helper_debug (helper);
/* run in a thread */
diff --git a/lib/gs-plugin-private.h b/lib/gs-plugin-private.h
index f83d428..32e2312 100644
--- a/lib/gs-plugin-private.h
+++ b/lib/gs-plugin-private.h
@@ -36,6 +36,7 @@ GsPlugin *gs_plugin_create (const gchar *filename,
GError **error);
const gchar *gs_plugin_error_to_string (GsPluginError error);
const gchar *gs_plugin_action_to_string (GsPluginAction action);
+const gchar *gs_plugin_action_to_function_name (GsPluginAction action);
void gs_plugin_clear_data (GsPlugin *plugin);
void gs_plugin_action_start (GsPlugin *plugin,
diff --git a/lib/gs-plugin.c b/lib/gs-plugin.c
index afe11f4..978f845 100644
--- a/lib/gs-plugin.c
+++ b/lib/gs-plugin.c
@@ -1669,6 +1669,96 @@ gs_plugin_error_to_string (GsPluginError error)
}
/**
+ * gs_plugin_action_to_function_name: (skip)
+ * @action: a #GsPluginAction, e.g. %GS_PLUGIN_ERROR_NO_NETWORK
+ *
+ * Converts the enumerated action to the vfunc name.
+ *
+ * Returns: a string, or %NULL for invalid
+ **/
+const gchar *
+gs_plugin_action_to_function_name (GsPluginAction action)
+{
+ if (action == GS_PLUGIN_ACTION_REFRESH)
+ return "gs_plugin_refresh";
+ if (action == GS_PLUGIN_ACTION_REVIEW_SUBMIT)
+ return "gs_plugin_review_submit";
+ if (action == GS_PLUGIN_ACTION_REVIEW_UPVOTE)
+ return "gs_plugin_review_upvote";
+ if (action == GS_PLUGIN_ACTION_REVIEW_DOWNVOTE)
+ return "gs_plugin_review_downvote";
+ if (action == GS_PLUGIN_ACTION_REVIEW_REPORT)
+ return "gs_plugin_review_report";
+ if (action == GS_PLUGIN_ACTION_REVIEW_REMOVE)
+ return "gs_plugin_review_remove";
+ if (action == GS_PLUGIN_ACTION_REVIEW_DISMISS)
+ return "gs_plugin_review_dismiss";
+ if (action == GS_PLUGIN_ACTION_INSTALL)
+ return "gs_plugin_app_install";
+ if (action == GS_PLUGIN_ACTION_REMOVE)
+ return "gs_plugin_app_remove";
+ if (action == GS_PLUGIN_ACTION_SET_RATING)
+ return "gs_plugin_app_set_rating";
+ if (action == GS_PLUGIN_ACTION_UPGRADE_DOWNLOAD)
+ return "gs_plugin_app_upgrade_download";
+ if (action == GS_PLUGIN_ACTION_UPGRADE_TRIGGER)
+ return "gs_plugin_app_upgrade_trigger";
+ if (action == GS_PLUGIN_ACTION_LAUNCH)
+ return "gs_plugin_launch";
+ if (action == GS_PLUGIN_ACTION_UPDATE_CANCEL)
+ return "gs_plugin_update_cancel";
+ if (action == GS_PLUGIN_ACTION_ADD_SHORTCUT)
+ return "gs_plugin_add_shortcut";
+ if (action == GS_PLUGIN_ACTION_REMOVE_SHORTCUT)
+ return "gs_plugin_remove_shortcut";
+ if (action == GS_PLUGIN_ACTION_REFINE)
+ return "gs_plugin_refine";
+ if (action == GS_PLUGIN_ACTION_UPDATE)
+ return "gs_plugin_update";
+ if (action == GS_PLUGIN_ACTION_FILE_TO_APP)
+ return "gs_plugin_file_to_app";
+ if (action == GS_PLUGIN_ACTION_URL_TO_APP)
+ return "gs_plugin_url_to_app";
+ if (action == GS_PLUGIN_ACTION_GET_DISTRO_UPDATES)
+ return "gs_plugin_add_distro_upgrades";
+ if (action == GS_PLUGIN_ACTION_GET_SOURCES)
+ return "gs_plugin_add_sources";
+ if (action == GS_PLUGIN_ACTION_GET_INSTALLED)
+ return "gs_plugin_add_installed";
+ if (action == GS_PLUGIN_ACTION_GET_FEATURED)
+ return "gs_plugin_add_featured";
+ if (action == GS_PLUGIN_ACTION_GET_UPDATES_HISTORICAL)
+ return "gs_plugin_add_updates_historical";
+ if (action == GS_PLUGIN_ACTION_GET_UPDATES)
+ return "gs_plugin_add_updates";
+ if (action == GS_PLUGIN_ACTION_GET_POPULAR)
+ return "gs_plugin_add_popular";
+ if (action == GS_PLUGIN_ACTION_GET_RECENT)
+ return "gs_plugin_add_recent";
+ if (action == GS_PLUGIN_ACTION_SEARCH)
+ return "gs_plugin_add_search";
+ if (action == GS_PLUGIN_ACTION_SEARCH_FILES)
+ return "gs_plugin_add_search_files";
+ if (action == GS_PLUGIN_ACTION_SEARCH_PROVIDES)
+ return "gs_plugin_add_search_what_provides";
+ if (action == GS_PLUGIN_ACTION_AUTH_LOGIN)
+ return "gs_plugin_auth_login";
+ if (action == GS_PLUGIN_ACTION_AUTH_LOGOUT)
+ return "gs_plugin_auth_logout";
+ if (action == GS_PLUGIN_ACTION_AUTH_REGISTER)
+ return "gs_plugin_auth_register";
+ if (action == GS_PLUGIN_ACTION_AUTH_LOST_PASSWORD)
+ return "gs_plugin_auth_lost_password";
+ if (action == GS_PLUGIN_ACTION_GET_CATEGORY_APPS)
+ return "gs_plugin_add_category_apps";
+ if (action == GS_PLUGIN_ACTION_GET_CATEGORIES)
+ return "gs_plugin_add_categories";
+ if (action == GS_PLUGIN_ACTION_SETUP)
+ return "gs_plugin_setup";
+ return NULL;
+}
+
+/**
* gs_plugin_action_to_string:
* @action: a #GsPluginAction, e.g. %GS_PLUGIN_ERROR_NO_NETWORK
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]