[gnome-software] trivial: Add gs_plugin_loader_get_event_by_error()



commit d7c15f046c9e34bf8278ef88a26e87acdad0aacc
Author: Richard Hughes <richard hughsie com>
Date:   Tue May 9 14:22:54 2017 +0100

    trivial: Add gs_plugin_loader_get_event_by_error()
    
    This allows us to get an event by the error code.

 lib/gs-plugin-loader.c |   17 +++++++++++++++++
 lib/gs-plugin-loader.h |    2 ++
 2 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index f0ac05d..99cb8e8 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1271,6 +1271,23 @@ gs_plugin_loader_get_event_by_id (GsPluginLoader *plugin_loader, const gchar *un
        return g_hash_table_lookup (priv->events_by_id, unique_id);
 }
 
+GsPluginEvent *
+gs_plugin_loader_get_event_by_error (GsPluginLoader *plugin_loader, GsPluginError error_code)
+{
+       GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
+       g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->events_by_id_mutex);
+       g_autoptr(GList) values = g_hash_table_get_values (priv->events_by_id);
+
+       /* find the one that matches the error code */
+       for (GList *l = values; l != NULL; l = l->next) {
+               GsPluginEvent *event = GS_PLUGIN_EVENT (l->data);
+               const GError *error = gs_plugin_event_get_error (event);
+               if (g_error_matches (error, GS_PLUGIN_ERROR, error_code))
+                       return event;
+       }
+       return NULL;
+}
+
 static gboolean
 gs_plugin_loader_run_action (GsPluginLoaderJob *job,
                             GCancellable *cancellable,
diff --git a/lib/gs-plugin-loader.h b/lib/gs-plugin-loader.h
index e51b02e..53d9335 100644
--- a/lib/gs-plugin-loader.h
+++ b/lib/gs-plugin-loader.h
@@ -273,6 +273,8 @@ gboolean     gs_plugin_loader_get_plugin_supported  (GsPluginLoader *plugin_loader,
 GPtrArray      *gs_plugin_loader_get_events            (GsPluginLoader *plugin_loader);
 GsPluginEvent  *gs_plugin_loader_get_event_by_id       (GsPluginLoader *plugin_loader,
                                                         const gchar    *unique_id);
+GsPluginEvent  *gs_plugin_loader_get_event_by_error    (GsPluginLoader *plugin_loader,
+                                                        GsPluginError   error_code);
 GsPluginEvent  *gs_plugin_loader_get_event_default     (GsPluginLoader *plugin_loader);
 void            gs_plugin_loader_remove_events         (GsPluginLoader *plugin_loader);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]