[gnome-software/wip/hughsie/fwupd] Get the historical updates from fwupd



commit 1038820f73164773c292628f3520395c8580bbd1
Author: Richard Hughes <richard hughsie com>
Date:   Wed Mar 18 21:39:22 2015 +0000

    Get the historical updates from fwupd

 src/plugins/gs-plugin-fwupd.c |  167 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 162 insertions(+), 5 deletions(-)
---
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index 75ce356..02e83f4 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -36,6 +36,78 @@
 #define FWUPD_DBUS_SERVICE             "org.freedesktop.fwupd"
 #define FWUPD_DBUS_INTERFACE           "org.freedesktop.fwupd"
 
+typedef enum {
+       FU_ERROR_INTERNAL,
+       FU_ERROR_ALREADY_NEWER_VERSION,
+       FU_ERROR_ALREADY_SAME_VERSION,
+       FU_ERROR_ALREADY_SCHEDULED,
+       FU_ERROR_FAILED_TO_AUTHENTICATE,
+       FU_ERROR_FAILED_TO_READ,
+       FU_ERROR_FAILED_TO_WRITE,
+       FU_ERROR_INVALID_FILE,
+       FU_ERROR_NO_SUCH_DEVICE,
+       FU_ERROR_NO_SUCH_METHOD,
+       FU_ERROR_NO_SUCH_PROPERTY,
+       FU_ERROR_NOTHING_TO_DO,
+       FU_ERROR_NOT_POSSIBLE,
+       /* private */
+       FU_ERROR_LAST
+} FuError;
+
+/**
+ * fu_error_quark:
+ **/
+static GQuark
+fu_error_quark (void)
+{
+       static GQuark quark = 0;
+       if (!quark) {
+               quark = g_quark_from_static_string ("FuError");
+               g_dbus_error_register_error (quark,
+                                            FU_ERROR_INTERNAL,
+                                            "org.freedesktop.fwupd.InternalError");
+               g_dbus_error_register_error (quark,
+                                            FU_ERROR_ALREADY_NEWER_VERSION,
+                                            "org.freedesktop.fwupd.AlreadyNewerVersion");
+               g_dbus_error_register_error (quark,
+                                            FU_ERROR_ALREADY_SAME_VERSION,
+                                            "org.freedesktop.fwupd.AlreadySameVersion");
+               g_dbus_error_register_error (quark,
+                                            FU_ERROR_ALREADY_SCHEDULED,
+                                            "org.freedesktop.fwupd.AlreadyScheduled");
+               g_dbus_error_register_error (quark,
+                                            FU_ERROR_FAILED_TO_AUTHENTICATE,
+                                            "org.freedesktop.fwupd.FailedToAuthenticate");
+               g_dbus_error_register_error (quark,
+                                            FU_ERROR_FAILED_TO_READ,
+                                            "org.freedesktop.fwupd.FailedToRead");
+               g_dbus_error_register_error (quark,
+                                            FU_ERROR_FAILED_TO_WRITE,
+                                            "org.freedesktop.fwupd.FailedToWrite");
+               g_dbus_error_register_error (quark,
+                                            FU_ERROR_INVALID_FILE,
+                                            "org.freedesktop.fwupd.InvalidFile");
+               g_dbus_error_register_error (quark,
+                                            FU_ERROR_NO_SUCH_DEVICE,
+                                            "org.freedesktop.fwupd.NoSuchDevice");
+               g_dbus_error_register_error (quark,
+                                            FU_ERROR_NO_SUCH_METHOD,
+                                            "org.freedesktop.fwupd.NoSuchMethod");
+               g_dbus_error_register_error (quark,
+                                            FU_ERROR_NO_SUCH_PROPERTY,
+                                            "org.freedesktop.fwupd.NoSuchProperty");
+               g_dbus_error_register_error (quark,
+                                            FU_ERROR_NOTHING_TO_DO,
+                                            "org.freedesktop.fwupd.NothingToDo");
+               g_dbus_error_register_error (quark,
+                                            FU_ERROR_NOT_POSSIBLE,
+                                            "org.freedesktop.fwupd.NotPossible");
+       }
+       return quark;
+}
+
+#define FU_ERROR                       fu_error_quark()
+
 struct GsPluginPrivate {
        gsize                    done_init;
        GDBusProxy              *proxy;
@@ -133,6 +205,10 @@ gs_plugin_startup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
 {
        gint rc;
        _cleanup_object_unref_ GDBusConnection *conn = NULL;
+
+       /* register D-Bus errors */
+       fu_error_quark ();
+
        conn = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
        if (conn == NULL)
                return FALSE;
@@ -372,6 +448,77 @@ gs_plugin_fwupd_add_device (GsPlugin *plugin,
 }
 
 /**
+ * gs_plugin_add_updates_historical:
+ */
+gboolean
+gs_plugin_add_updates_historical (GsPlugin *plugin,
+                                 GList **list,
+                                 GCancellable *cancellable,
+                                 GError **error)
+{
+       GVariant *variant;
+       const gchar *key;
+       gboolean ret;
+       _cleanup_error_free_ GError *error_local = NULL;
+       _cleanup_object_unref_ GsApp *app = NULL;
+       _cleanup_variant_iter_free_ GVariantIter *iter = NULL;
+       _cleanup_variant_unref_ GVariant *val = NULL;
+
+       /* watch the file in case it comes or goes */
+       if (g_once_init_enter (&plugin->priv->done_init)) {
+               ret = gs_plugin_startup (plugin, cancellable, error);
+               g_once_init_leave (&plugin->priv->done_init, TRUE);
+               if (!ret)
+                       return FALSE;
+       }
+
+       val = g_dbus_proxy_call_sync (plugin->priv->proxy,
+                                     "GetResults",
+                                     g_variant_new ("(s)", "*"),
+                                     G_DBUS_CALL_FLAGS_NONE,
+                                     -1,
+                                     NULL,
+                                     &error_local);
+       if (val == NULL) {
+               if (g_error_matches (error_local,
+                                    FU_ERROR,
+                                    FU_ERROR_NOTHING_TO_DO))
+                       return TRUE;
+               g_set_error_literal (error,
+                                    GS_PLUGIN_ERROR,
+                                    GS_PLUGIN_ERROR_FAILED,
+                                    error_local->message);
+               return FALSE;
+       }
+
+       /* parse */
+       app = gs_app_new (NULL);
+       gs_app_set_management_plugin (app, "fwupd");
+       gs_app_set_state (app, AS_APP_STATE_UPDATABLE);
+       gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
+       g_variant_get (val, "(a{sv})", &iter);
+       while (g_variant_iter_next (iter, "{&sv}", &key, &variant)) {
+               g_debug ("key %s", key);
+               if (g_strcmp0 (key, "Guid") == 0) {
+                       gs_app_set_id (app, g_variant_get_string (variant, NULL));
+                       continue;
+               }
+               if (g_strcmp0 (key, "VersionNew") == 0) {
+                       gs_app_set_update_version (app, g_variant_get_string (variant, NULL));
+                       continue;
+               }
+               if (g_strcmp0 (key, "Name") == 0) {
+                       gs_app_add_source (app, g_variant_get_string (variant, NULL));
+                       continue;
+               }
+               g_variant_unref (variant);
+       }
+       gs_plugin_add_app (list, app);
+
+       return TRUE;
+}
+
+/**
  * gs_plugin_add_updates:
  */
 gboolean
@@ -383,6 +530,7 @@ gs_plugin_add_updates (GsPlugin *plugin,
        const gchar *id;
        gboolean ret;
        GVariantIter *iter_device;
+       _cleanup_error_free_ GError *error_local = NULL;
        _cleanup_variant_iter_free_ GVariantIter *iter = NULL;
        _cleanup_variant_unref_ GVariant *val = NULL;
 
@@ -400,9 +548,18 @@ gs_plugin_add_updates (GsPlugin *plugin,
                                      G_DBUS_CALL_FLAGS_NONE,
                                      -1,
                                      NULL,
-                                     error);
-       if (val == NULL)
+                                     &error_local);
+       if (val == NULL) {
+               if (g_error_matches (error_local,
+                                    FU_ERROR,
+                                    FU_ERROR_NOTHING_TO_DO))
+                       return TRUE;
+               g_set_error_literal (error,
+                                    GS_PLUGIN_ERROR,
+                                    GS_PLUGIN_ERROR_FAILED,
+                                    error_local->message);
                return FALSE;
+       }
 
        /* parse */
        g_variant_get (val, "(a{sa{sv}})", &iter);
@@ -424,15 +581,15 @@ gs_plugin_add_updates (GsPlugin *plugin,
 
                /* we got all we needed */
                if (guid != NULL && version != NULL) {
-                       _cleanup_error_free_ GError *error_local = NULL;
+                       _cleanup_error_free_ GError *error_local2 = NULL;
                        if (!gs_plugin_fwupd_add_device (plugin,
                                                         id,
                                                         guid,
                                                         version,
                                                         list,
-                                                        &error_local)) {
+                                                        &error_local2)) {
                                g_debug ("cannot add device %s: %s",
-                                        id, error_local->message);
+                                        id, error_local2->message);
                        }
                }
 


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