From 4db6c4a4b0c947ee79ac24124ef1f53ec0c7fd8b Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Mon, 5 Jun 2017 17:34:13 +0100 Subject: [PATCH] libfwupd: Split up FwupdResult into FwupdDevice and FwupdRelease This retains the old API to avoid breaking ABI. --- libfwupd/fwupd-client.c | 7 +- libfwupd/fwupd-device-private.h | 43 ++ libfwupd/fwupd-device.c | 1119 ++++++++++++++++++++++++++++++ libfwupd/fwupd-device.h | 111 +++ libfwupd/fwupd-release-private.h | 43 ++ libfwupd/fwupd-release.c | 891 ++++++++++++++++++++++++ libfwupd/fwupd-release.h | 96 +++ libfwupd/fwupd-result.c | 685 ++++-------------- libfwupd/fwupd-result.h | 6 + libfwupd/fwupd-self-test.c | 57 +- libfwupd/fwupd.h | 2 + libfwupd/meson.build | 4 + 12 files changed, 2490 insertions(+), 574 deletions(-) create mode 100644 libfwupd/fwupd-device-private.h create mode 100644 libfwupd/fwupd-device.c create mode 100644 libfwupd/fwupd-device.h create mode 100644 libfwupd/fwupd-release-private.h create mode 100644 libfwupd/fwupd-release.c create mode 100644 libfwupd/fwupd-release.h diff --git a/libfwupd/fwupd-client.c b/libfwupd/fwupd-client.c index 84d72c129..ced9b63b2 100644 --- a/libfwupd/fwupd-client.c +++ b/libfwupd/fwupd-client.c @@ -33,6 +33,7 @@ #include "fwupd-client.h" #include "fwupd-enums.h" #include "fwupd-error.h" +#include "fwupd-release-private.h" #include "fwupd-remote-private.h" #include "fwupd-result.h" @@ -146,7 +147,7 @@ fwupd_client_signal_cb (GDBusProxy *proxy, if (g_strcmp0 (signal_name, "DeviceAdded") == 0) { res = fwupd_result_new_from_data (parameters); g_debug ("Emitting ::device-added(%s)", - fwupd_result_get_device_id (res)); + fwupd_device_get_id (fwupd_result_get_device (res))); g_signal_emit (client, signals[SIGNAL_DEVICE_ADDED], 0, res); return; } @@ -154,14 +155,14 @@ fwupd_client_signal_cb (GDBusProxy *proxy, res = fwupd_result_new_from_data (parameters); g_signal_emit (client, signals[SIGNAL_DEVICE_REMOVED], 0, res); g_debug ("Emitting ::device-removed(%s)", - fwupd_result_get_device_id (res)); + fwupd_device_get_id (fwupd_result_get_device (res))); return; } if (g_strcmp0 (signal_name, "DeviceChanged") == 0) { res = fwupd_result_new_from_data (parameters); g_signal_emit (client, signals[SIGNAL_DEVICE_CHANGED], 0, res); g_debug ("Emitting ::device-changed(%s)", - fwupd_result_get_device_id (res)); + fwupd_device_get_id (fwupd_result_get_device (res))); return; } g_warning ("Unknown signal name '%s' from %s", diff --git a/libfwupd/fwupd-device-private.h b/libfwupd/fwupd-device-private.h new file mode 100644 index 000000000..43199ba33 --- /dev/null +++ b/libfwupd/fwupd-device-private.h @@ -0,0 +1,43 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2017 Richard Hughes + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __FWUPD_DEVICE_PRIVATE_H +#define __FWUPD_DEVICE_PRIVATE_H + +#include + +#include "fwupd-device.h" + +G_BEGIN_DECLS + +FwupdDevice *fwupd_device_new_from_data (GVariant *data); +GVariant *fwupd_device_to_data (FwupdDevice *device, + const gchar *type_string); +void fwupd_device_to_variant_builder (FwupdDevice *device, + GVariantBuilder *builder); +void fwupd_device_from_key_value (FwupdDevice *device, + const gchar *key, + GVariant *value); + +G_END_DECLS + +#endif /* __FWUPD_DEVICE_PRIVATE_H */ + diff --git a/libfwupd/fwupd-device.c b/libfwupd/fwupd-device.c new file mode 100644 index 000000000..fead7b361 --- /dev/null +++ b/libfwupd/fwupd-device.c @@ -0,0 +1,1119 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2015-2017 Richard Hughes + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include +#include +#include + +#include "fwupd-enums-private.h" +#include "fwupd-error.h" +#include "fwupd-device-private.h" + +static void fwupd_device_finalize (GObject *object); + +typedef struct { + gchar *id; + guint64 created; + guint64 modified; + guint64 flags; + gchar *appstream_id; + GPtrArray *guids; + gchar *name; + gchar *summary; + gchar *description; + gchar *vendor; + gchar *homepage; + gchar *provider; + gchar *version; + gchar *version_lowest; + gchar *version_bootloader; + gchar *checksum; + GChecksumType checksum_kind; + guint32 flashes_left; +} FwupdDevicePrivate; + +G_DEFINE_TYPE_WITH_PRIVATE (FwupdDevice, fwupd_device, G_TYPE_OBJECT) +#define GET_PRIVATE(o) (fwupd_device_get_instance_private (o)) + +/** + * fwupd_device_get_checksum: + * @device: A #FwupdDevice + * + * Gets the device checksum. + * + * Returns: the device checksum, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_device_get_checksum (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL); + return priv->checksum; +} + +/** + * fwupd_device_set_checksum: + * @device: A #FwupdDevice + * @checksum: the device checksum + * + * Sets the device checksum. + * + * Since: 0.9.3 + **/ +void +fwupd_device_set_checksum (FwupdDevice *device, const gchar *checksum) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + g_free (priv->checksum); + priv->checksum = g_strdup (checksum); +} + +/** + * fwupd_device_get_checksum_kind: + * @device: A #FwupdDevice + * + * Gets the device checkum kind. + * + * Returns: the #GChecksumType + * + * Since: 0.9.3 + **/ +GChecksumType +fwupd_device_get_checksum_kind (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), 0); + return priv->checksum_kind; +} + +/** + * fwupd_device_set_checksum_kind: + * @device: A #FwupdDevice + * @checkum_kind: the checksum kind, e.g. %G_CHECKSUM_SHA1 + * + * Sets the device checkum kind. + * + * Since: 0.9.3 + **/ +void +fwupd_device_set_checksum_kind (FwupdDevice *device, GChecksumType checkum_kind) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + priv->checksum_kind = checkum_kind; +} + +/** + * fwupd_device_get_summary: + * @device: A #FwupdDevice + * + * Gets the device summary. + * + * Returns: the device summary, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_device_get_summary (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL); + return priv->summary; +} + +/** + * fwupd_device_set_summary: + * @device: A #FwupdDevice + * @summary: the device one line summary + * + * Sets the device summary. + * + * Since: 0.9.3 + **/ +void +fwupd_device_set_summary (FwupdDevice *device, const gchar *summary) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + g_free (priv->summary); + priv->summary = g_strdup (summary); +} + +/** + * fwupd_device_get_id: + * @device: A #FwupdDevice + * + * Gets the ID. + * + * Returns: the ID, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_device_get_id (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL); + return priv->id; +} + +/** + * fwupd_device_set_id: + * @device: A #FwupdDevice + * @device_id: the device ID, e.g. "USB:foo" + * + * Sets the ID. + * + * Since: 0.9.3 + **/ +void +fwupd_device_set_id (FwupdDevice *device, const gchar *id) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + g_free (priv->id); + priv->id = g_strdup (id); +} + +/** + * fwupd_device_get_guids: + * @device: A #FwupdDevice + * + * Gets the GUIDs. + * + * Returns: (element-type utf8) (transfer none): the GUIDs + * + * Since: 0.9.3 + **/ +GPtrArray * +fwupd_device_get_guids (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL); + return priv->guids; +} + +/** + * fwupd_device_has_guid: + * @device: A #FwupdDevice + * @guid: the GUID, e.g. "2082b5e0-7a64-478a-b1b2-e3404fab6dad" + * + * Finds out if the device has this specific GUID. + * + * Returns: %TRUE if the GUID is found + * + * Since: 0.9.3 + **/ +gboolean +fwupd_device_has_guid (FwupdDevice *device, const gchar *guid) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + guint i; + + g_return_val_if_fail (FWUPD_IS_DEVICE (device), FALSE); + + for (i = 0; i < priv->guids->len; i++) { + const gchar *guid_tmp = g_ptr_array_index (priv->guids, i); + if (g_strcmp0 (guid, guid_tmp) == 0) + return TRUE; + } + return FALSE; +} + +/** + * fwupd_device_add_guid: + * @device: A #FwupdDevice + * @guid: the GUID, e.g. "2082b5e0-7a64-478a-b1b2-e3404fab6dad" + * + * Adds the GUID if it does not already exist. + * + * Since: 0.9.3 + **/ +void +fwupd_device_add_guid (FwupdDevice *device, const gchar *guid) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + if (fwupd_device_has_guid (device, guid)) + return; + g_ptr_array_add (priv->guids, g_strdup (guid)); +} + +/** + * fwupd_device_get_guid_default: + * @device: A #FwupdDevice + * + * Gets the default GUID. + * + * Returns: the GUID, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_device_get_guid_default (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL); + if (priv->guids->len == 0) + return NULL; + return g_ptr_array_index (priv->guids, 0); +} + +/** + * fwupd_device_get_name: + * @device: A #FwupdDevice + * + * Gets the device name. + * + * Returns: the device name, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_device_get_name (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL); + return priv->name; +} + +/** + * fwupd_device_set_name: + * @device: A #FwupdDevice + * @device_name: the device name, e.g. "ColorHug2" + * + * Sets the device name. + * + * Since: 0.9.3 + **/ +void +fwupd_device_set_name (FwupdDevice *device, const gchar *name) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + g_free (priv->name); + priv->name = g_strdup (name); +} + +/** + * fwupd_device_get_vendor: + * @device: A #FwupdDevice + * + * Gets the device vendor. + * + * Returns: the device vendor, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_device_get_vendor (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL); + return priv->vendor; +} + +/** + * fwupd_device_set_vendor: + * @device: A #FwupdDevice + * @device_vendor: the description + * + * Sets the device vendor. + * + * Since: 0.9.3 + **/ +void +fwupd_device_set_vendor (FwupdDevice *device, const gchar *vendor) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + g_free (priv->vendor); + priv->vendor = g_strdup (vendor); +} + +/** + * fwupd_device_get_description: + * @device: A #FwupdDevice + * + * Gets the device description in AppStream markup format. + * + * Returns: the device description, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_device_get_description (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL); + return priv->description; +} + +/** + * fwupd_device_set_description: + * @device: A #FwupdDevice + * @device_description: the description in AppStream markup format + * + * Sets the device description. + * + * Since: 0.9.3 + **/ +void +fwupd_device_set_description (FwupdDevice *device, const gchar *description) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + g_free (priv->description); + priv->description = g_strdup (description); +} + +/** + * fwupd_device_get_version: + * @device: A #FwupdDevice + * + * Gets the device version. + * + * Returns: the device version, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_device_get_version (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL); + return priv->version; +} + +/** + * fwupd_device_set_version: + * @device: A #FwupdDevice + * @device_version: the device version, e.g. "1.2.3" + * + * Sets the device version. + * + * Since: 0.9.3 + **/ +void +fwupd_device_set_version (FwupdDevice *device, const gchar *version) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + g_free (priv->version); + priv->version = g_strdup (version); +} + +/** + * fwupd_device_get_version_lowest: + * @device: A #FwupdDevice + * + * Gets the lowest version of firmware the device will accept. + * + * Returns: the device version_lowest, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_device_get_version_lowest (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL); + return priv->version_lowest; +} + +/** + * fwupd_device_set_version_lowest: + * @device: A #FwupdDevice + * @device_version_lowest: the description + * + * Sets the lowest version of firmware the device will accept. + * + * Since: 0.9.3 + **/ +void +fwupd_device_set_version_lowest (FwupdDevice *device, const gchar *version_lowest) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + g_free (priv->version_lowest); + priv->version_lowest = g_strdup (version_lowest); +} + +/** + * fwupd_device_get_version_bootloader: + * @device: A #FwupdDevice + * + * Gets the version of the bootloader. + * + * Returns: the device version_bootloader, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_device_get_version_bootloader (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL); + return priv->version_bootloader; +} + +/** + * fwupd_device_set_version_bootloader: + * @device: A #FwupdDevice + * @device_version_bootloader: the description + * + * Sets the bootloader version. + * + * Since: 0.9.3 + **/ +void +fwupd_device_set_version_bootloader (FwupdDevice *device, const gchar *version_bootloader) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + g_free (priv->version_bootloader); + priv->version_bootloader = g_strdup (version_bootloader); +} + +/** + * fwupd_device_device_get_flashes_left: + * @device: A #FwupdDevice + * + * Gets the number of flash cycles left on the device + * + * Returns: the flash cycles left, or %NULL if unset + * + * Since: 0.9.3 + **/ +guint32 +fwupd_device_get_flashes_left (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), 0); + return priv->flashes_left; +} + +/** + * fwupd_device_device_set_flashes_left: + * @device: A #FwupdDevice + * @flashes_left: the description + * + * Sets the number of flash cycles left on the device + * + * Since: 0.9.3 + **/ +void +fwupd_device_set_flashes_left (FwupdDevice *device, guint32 flashes_left) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + priv->flashes_left = flashes_left; +} + +/** + * fwupd_device_get_provider: + * @device: A #FwupdDevice + * + * Gets the device provider. + * + * Returns: the device provider, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_device_get_provider (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL); + return priv->provider; +} + +/** + * fwupd_device_set_provider: + * @device: A #FwupdDevice + * @device_provider: the provider name, e.g. "colorhug" + * + * Sets the device provider. + * + * Since: 0.9.3 + **/ +void +fwupd_device_set_provider (FwupdDevice *device, const gchar *provider) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + g_free (priv->provider); + priv->provider = g_strdup (provider); +} + +/** + * fwupd_device_get_flags: + * @device: A #FwupdDevice + * + * Gets the device flags. + * + * Returns: the device flags, or 0 if unset + * + * Since: 0.9.3 + **/ +guint64 +fwupd_device_get_flags (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), 0); + return priv->flags; +} + +/** + * fwupd_device_set_flags: + * @device: A #FwupdDevice + * @device_flags: the device flags, e.g. %FWUPD_DEVICE_FLAG_REQUIRE_AC + * + * Sets the device flags. + * + * Since: 0.9.3 + **/ +void +fwupd_device_set_flags (FwupdDevice *device, guint64 flags) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + priv->flags = flags; +} + +/** + * fwupd_device_add_flag: + * @device: A #FwupdDevice + * @flag: the #FwupdDeviceFlags + * + * Adds a specific device flag to the device. + * + * Since: 0.9.3 + **/ +void +fwupd_device_add_flag (FwupdDevice *device, FwupdDeviceFlags flag) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + priv->flags |= flag; +} + +/** + * fwupd_device_remove_flag: + * @device: A #FwupdDevice + * @flag: the #FwupdDeviceFlags + * + * Removes a specific device flag from the device. + * + * Since: 0.9.3 + **/ +void +fwupd_device_remove_flag (FwupdDevice *device, FwupdDeviceFlags flag) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + priv->flags &= ~flag; +} + +/** + * fwupd_device_has_flag: + * @device: A #FwupdDevice + * @flag: the #FwupdDeviceFlags + * + * Finds if the device has a specific device flag. + * + * Returns: %TRUE if the flag is set + * + * Since: 0.9.3 + **/ +gboolean +fwupd_device_has_flag (FwupdDevice *device, FwupdDeviceFlags flag) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), FALSE); + return (priv->flags & flag) > 0; +} + +/** + * fwupd_device_get_created: + * @device: A #FwupdDevice + * + * Gets when the device was created. + * + * Returns: the UNIX time, or 0 if unset + * + * Since: 0.9.3 + **/ +guint64 +fwupd_device_get_created (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), 0); + return priv->created; +} + + +/** + * fwupd_device_set_created: + * @device: A #FwupdDevice + * @device_created: the UNIX time + * + * Sets when the device was created. + * + * Since: 0.9.3 + **/ +void +fwupd_device_set_created (FwupdDevice *device, guint64 created) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + priv->created = created; +} + +/** + * fwupd_device_get_modified: + * @device: A #FwupdDevice + * + * Gets when the device was modified. + * + * Returns: the UNIX time, or 0 if unset + * + * Since: 0.9.3 + **/ +guint64 +fwupd_device_get_modified (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_val_if_fail (FWUPD_IS_DEVICE (device), 0); + return priv->modified; +} + +/** + * fwupd_device_set_modified: + * @device: A #FwupdDevice + * @device_modified: the UNIX time + * + * Sets when the device was modified. + * + * Since: 0.9.3 + **/ +void +fwupd_device_set_modified (FwupdDevice *device, guint64 modified) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + g_return_if_fail (FWUPD_IS_DEVICE (device)); + priv->modified = modified; +} + +void +fwupd_device_to_variant_builder (FwupdDevice *device, GVariantBuilder *builder) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + if (priv->guids->len > 0) { + guint i; + g_autoptr(GString) str = g_string_new (""); + for (i = 0; i < priv->guids->len; i++) { + const gchar *guid = g_ptr_array_index (priv->guids, i); + g_string_append_printf (str, "%s,", guid); + } + if (str->len > 0) + g_string_truncate (str, str->len - 1); + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_GUID, + g_variant_new_string (str->str)); + } + if (priv->name != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_DEVICE_NAME, + g_variant_new_string (priv->name)); + } + if (priv->vendor != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_DEVICE_VENDOR, + g_variant_new_string (priv->vendor)); + } + if (priv->flags > 0) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_DEVICE_FLAGS, + g_variant_new_uint64 (priv->flags)); + } + if (priv->created > 0) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_DEVICE_CREATED, + g_variant_new_uint64 (priv->created)); + } + if (priv->modified > 0) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_DEVICE_MODIFIED, + g_variant_new_uint64 (priv->modified)); + } + + if (priv->description != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_DEVICE_DESCRIPTION, + g_variant_new_string (priv->description)); + } + if (priv->checksum != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_DEVICE_CHECKSUM, + g_variant_new_string (priv->checksum)); + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_DEVICE_CHECKSUM_KIND, + g_variant_new_uint32 (priv->checksum_kind)); + } + if (priv->provider != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_DEVICE_PLUGIN, + g_variant_new_string (priv->provider)); + } + if (priv->version != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_DEVICE_VERSION, + g_variant_new_string (priv->version)); + } + if (priv->version_lowest != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_DEVICE_VERSION_LOWEST, + g_variant_new_string (priv->version_lowest)); + } + if (priv->version_bootloader != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_DEVICE_VERSION_BOOTLOADER, + g_variant_new_string (priv->version_bootloader)); + } + if (priv->flashes_left > 0) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_DEVICE_FLASHES_LEFT, + g_variant_new_uint32 (priv->flashes_left)); + } +} + +/** + * fwupd_device_to_data: + * @device: A #FwupdDevice + * @type_string: The Gvariant type string, e.g. "a{sv}" or "(a{sv})" + * + * Creates a GVariant from the device data. + * + * Returns: the GVariant, or %NULL for error + * + * Since: 0.9.3 + **/ +GVariant * +fwupd_device_to_data (FwupdDevice *device, const gchar *type_string) +{ + GVariantBuilder builder; + + g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL); + g_return_val_if_fail (type_string != NULL, NULL); + + /* create an array with all the metadata in */ + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); + fwupd_device_to_variant_builder (device, &builder); + + /* supported types */ + if (g_strcmp0 (type_string, "a{sv}") == 0) + return g_variant_new ("a{sv}", &builder); + if (g_strcmp0 (type_string, "(a{sv})") == 0) + return g_variant_new ("(a{sv})", &builder); + return NULL; +} + +void +fwupd_device_from_key_value (FwupdDevice *device, const gchar *key, GVariant *value) +{ + if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_FLAGS) == 0) { + fwupd_device_set_flags (device, g_variant_get_uint64 (value)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_CREATED) == 0) { + fwupd_device_set_created (device, g_variant_get_uint64 (value)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_MODIFIED) == 0) { + fwupd_device_set_modified (device, g_variant_get_uint64 (value)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_GUID) == 0) { + guint i; + const gchar *guids = g_variant_get_string (value, NULL); + g_auto(GStrv) split = g_strsplit (guids, ",", -1); + for (i = 0; split[i] != NULL; i++) + fwupd_device_add_guid (device, split[i]); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_NAME) == 0) { + fwupd_device_set_name (device, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_VENDOR) == 0) { + fwupd_device_set_vendor (device, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_DESCRIPTION) == 0) { + fwupd_device_set_description (device, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_CHECKSUM) == 0) { + fwupd_device_set_checksum (device, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_CHECKSUM_KIND) == 0) { + fwupd_device_set_checksum_kind (device, g_variant_get_uint32 (value)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_PLUGIN) == 0) { + fwupd_device_set_provider (device, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_VERSION) == 0) { + fwupd_device_set_version (device, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_VERSION_LOWEST) == 0) { + fwupd_device_set_version_lowest (device, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_VERSION_BOOTLOADER) == 0) { + fwupd_device_set_version_bootloader (device, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_FLASHES_LEFT) == 0) { + fwupd_device_set_flashes_left (device, g_variant_get_uint32 (value)); + return; + } +} + +static void +fwupd_pad_kv_str (GString *str, const gchar *key, const gchar *value) +{ + /* ignore */ + if (key == NULL || value == NULL) + return; + g_string_append_printf (str, " %s: ", key); + for (gsize i = strlen (key); i < 20; i++) + g_string_append (str, " "); + g_string_append_printf (str, "%s\n", value); +} + +static void +fwupd_pad_kv_unx (GString *str, const gchar *key, guint64 value) +{ + g_autoptr(GDateTime) date = NULL; + g_autofree gchar *tmp = NULL; + + /* ignore */ + if (value == 0) + return; + + date = g_date_time_new_from_unix_utc ((gint64) value); + tmp = g_date_time_format (date, "%F"); + fwupd_pad_kv_str (str, key, tmp); +} + +static void +fwupd_pad_kv_csk (GString *str, const gchar *key, GChecksumType checksum_type) +{ + const gchar *tmp = "unknown"; + if (checksum_type == G_CHECKSUM_SHA1) + tmp = "sha1"; + else if (checksum_type == G_CHECKSUM_SHA256) + tmp = "sha256"; + else if (checksum_type == G_CHECKSUM_SHA512) + tmp = "sha512"; + fwupd_pad_kv_str (str, key, tmp); +} + +static void +fwupd_pad_kv_dfl (GString *str, const gchar *key, guint64 device_flags) +{ + guint i; + g_autoptr(GString) tmp = NULL; + + tmp = g_string_new (""); + for (i = 0; i < 64; i++) { + if ((device_flags & ((guint64) 1 << i)) == 0) + continue; + g_string_append_printf (tmp, "%s|", + fwupd_device_flag_to_string ((guint64) 1 << i)); + } + if (tmp->len == 0) { + g_string_append (tmp, fwupd_device_flag_to_string (0)); + } else { + g_string_truncate (tmp, tmp->len - 1); + } + fwupd_pad_kv_str (str, key, tmp->str); +} + +static void +fwupd_pad_kv_int (GString *str, const gchar *key, guint32 value) +{ + g_autofree gchar *tmp = NULL; + + /* ignore */ + if (value == 0) + return; + tmp = g_strdup_printf("%" G_GUINT32_FORMAT, value); + fwupd_pad_kv_str (str, key, tmp); +} + +/** + * fwupd_device_to_string: + * @device: A #FwupdDevice + * + * Builds a text representation of the object. + * + * Returns: text, or %NULL for invalid + * + * Since: 0.9.3 + **/ +gchar * +fwupd_device_to_string (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + GString *str; + + g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL); + + str = g_string_new (""); + for (guint i = 0; i < priv->guids->len; i++) { + const gchar *guid = g_ptr_array_index (priv->guids, i); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_GUID, guid); + } + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_ID, priv->id); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_DESCRIPTION, priv->description); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_PLUGIN, priv->provider); + fwupd_pad_kv_dfl (str, FWUPD_RESULT_KEY_DEVICE_FLAGS, priv->flags); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_CHECKSUM, priv->checksum); + if (priv->checksum != NULL) + fwupd_pad_kv_csk (str, FWUPD_RESULT_KEY_DEVICE_CHECKSUM_KIND, priv->checksum_kind); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_VENDOR, priv->vendor); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_VERSION, priv->version); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_VERSION_LOWEST, priv->version_lowest); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_VERSION_BOOTLOADER, priv->version_bootloader); + if (priv->flashes_left < 2) + fwupd_pad_kv_int (str, FWUPD_RESULT_KEY_DEVICE_FLASHES_LEFT, priv->flashes_left); + fwupd_pad_kv_unx (str, FWUPD_RESULT_KEY_DEVICE_CREATED, priv->created); + fwupd_pad_kv_unx (str, FWUPD_RESULT_KEY_DEVICE_MODIFIED, priv->modified); + + return g_string_free (str, FALSE); +} + +static void +fwupd_device_class_init (FwupdDeviceClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->finalize = fwupd_device_finalize; +} + +static void +fwupd_device_init (FwupdDevice *device) +{ + FwupdDevicePrivate *priv = GET_PRIVATE (device); + priv->guids = g_ptr_array_new_with_free_func (g_free); + priv->checksum_kind = G_CHECKSUM_SHA1; +} + +static void +fwupd_device_finalize (GObject *object) +{ + FwupdDevice *device = FWUPD_DEVICE (object); + FwupdDevicePrivate *priv = GET_PRIVATE (device); + + g_free (priv->description); + g_free (priv->checksum); + g_free (priv->id); + g_free (priv->name); + g_free (priv->vendor); + g_free (priv->provider); + g_free (priv->version); + g_free (priv->version_lowest); + g_free (priv->version_bootloader); + g_ptr_array_unref (priv->guids); + + G_OBJECT_CLASS (fwupd_device_parent_class)->finalize (object); +} + +static void +fwupd_device_from_variant_iter (FwupdDevice *device, GVariantIter *iter) +{ + GVariant *value; + const gchar *key; + while (g_variant_iter_next (iter, "{&sv}", &key, &value)) { + fwupd_device_from_key_value (device, key, value); + g_variant_unref (value); + } +} + +/** + * fwupd_device_new_from_data: + * @data: a #GVariant + * + * Creates a new device using packed data. + * + * Returns: a new #FwupdDevice, or %NULL if @data was invalid + * + * Since: 0.9.3 + **/ +FwupdDevice * +fwupd_device_new_from_data (GVariant *data) +{ + FwupdDevice *res = NULL; + const gchar *type_string; + g_autoptr(GVariantIter) iter = NULL; + + /* format from GetDetails */ + type_string = g_variant_get_type_string (data); + if (g_strcmp0 (type_string, "(a{sv})") == 0) { + res = fwupd_device_new (); + g_variant_get (data, "(a{sv})", &iter); + fwupd_device_from_variant_iter (res, iter); + } else if (g_strcmp0 (type_string, "a{sv}") == 0) { + res = fwupd_device_new (); + g_variant_get (data, "a{sv}", &iter); + fwupd_device_from_variant_iter (res, iter); + } else { + g_warning ("type %s not known", type_string); + } + return res; +} + +/** + * fwupd_device_new: + * + * Creates a new device. + * + * Returns: a new #FwupdDevice + * + * Since: 0.9.3 + **/ +FwupdDevice * +fwupd_device_new (void) +{ + FwupdDevice *device; + device = g_object_new (FWUPD_TYPE_DEVICE, NULL); + return FWUPD_DEVICE (device); +} diff --git a/libfwupd/fwupd-device.h b/libfwupd/fwupd-device.h new file mode 100644 index 000000000..9fc2f5ba0 --- /dev/null +++ b/libfwupd/fwupd-device.h @@ -0,0 +1,111 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2015-2017 Richard Hughes + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __FWUPD_DEVICE_H +#define __FWUPD_DEVICE_H + +#include + +#include "fwupd-enums.h" + +G_BEGIN_DECLS + +#define FWUPD_TYPE_DEVICE (fwupd_device_get_type ()) +G_DECLARE_DERIVABLE_TYPE (FwupdDevice, fwupd_device, FWUPD, DEVICE, GObject) + +struct _FwupdDeviceClass +{ + GObjectClass parent_class; + /*< private >*/ + void (*_fwupd_reserved1) (void); + void (*_fwupd_reserved2) (void); + void (*_fwupd_reserved3) (void); + void (*_fwupd_reserved4) (void); + void (*_fwupd_reserved5) (void); + void (*_fwupd_reserved6) (void); + void (*_fwupd_reserved7) (void); +}; + +FwupdDevice *fwupd_device_new (void); +gchar *fwupd_device_to_string (FwupdDevice *device); + +const gchar *fwupd_device_get_id (FwupdDevice *device); +void fwupd_device_set_id (FwupdDevice *device, + const gchar *id); +const gchar *fwupd_device_get_name (FwupdDevice *device); +void fwupd_device_set_name (FwupdDevice *device, + const gchar *name); +const gchar *fwupd_device_get_summary (FwupdDevice *device); +void fwupd_device_set_summary (FwupdDevice *device, + const gchar *summary); +const gchar *fwupd_device_get_description (FwupdDevice *device); +void fwupd_device_set_description (FwupdDevice *device, + const gchar *description); +const gchar *fwupd_device_get_version (FwupdDevice *device); +void fwupd_device_set_version (FwupdDevice *device, + const gchar *version); +const gchar *fwupd_device_get_version_lowest (FwupdDevice *device); +void fwupd_device_set_version_lowest (FwupdDevice *device, + const gchar *version_lowest); +const gchar *fwupd_device_get_version_bootloader (FwupdDevice *device); +void fwupd_device_set_version_bootloader (FwupdDevice *device, + const gchar *version_bootloader); +guint32 fwupd_device_get_flashes_left (FwupdDevice *device); +void fwupd_device_set_flashes_left (FwupdDevice *device, + guint32 flashes_left); +guint64 fwupd_device_get_flags (FwupdDevice *device); +void fwupd_device_set_flags (FwupdDevice *device, + guint64 flags); +void fwupd_device_add_flag (FwupdDevice *device, + FwupdDeviceFlags flag); +void fwupd_device_remove_flag (FwupdDevice *device, + FwupdDeviceFlags flag); +gboolean fwupd_device_has_flag (FwupdDevice *device, + FwupdDeviceFlags flag); +guint64 fwupd_device_get_created (FwupdDevice *device); +void fwupd_device_set_created (FwupdDevice *device, + guint64 created); +guint64 fwupd_device_get_modified (FwupdDevice *device); +void fwupd_device_set_modified (FwupdDevice *device, + guint64 modified); +const gchar *fwupd_device_get_checksum (FwupdDevice *device); +void fwupd_device_set_checksum (FwupdDevice *device, + const gchar *checksum); +GChecksumType fwupd_device_get_checksum_kind (FwupdDevice *device); +void fwupd_device_set_checksum_kind (FwupdDevice *device, + GChecksumType checkum_kind); +const gchar *fwupd_device_get_provider (FwupdDevice *device); +void fwupd_device_set_provider (FwupdDevice *device, + const gchar *provider); +const gchar *fwupd_device_get_vendor (FwupdDevice *device); +void fwupd_device_set_vendor (FwupdDevice *device, + const gchar *vendor); +void fwupd_device_add_guid (FwupdDevice *device, + const gchar *guid); +gboolean fwupd_device_has_guid (FwupdDevice *device, + const gchar *guid); +GPtrArray *fwupd_device_get_guids (FwupdDevice *device); +const gchar *fwupd_device_get_guid_default (FwupdDevice *device); + +G_END_DECLS + +#endif /* __FWUPD_DEVICE_H */ + diff --git a/libfwupd/fwupd-release-private.h b/libfwupd/fwupd-release-private.h new file mode 100644 index 000000000..cc1f1f112 --- /dev/null +++ b/libfwupd/fwupd-release-private.h @@ -0,0 +1,43 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2017 Richard Hughes + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __FWUPD_RELEASE_PRIVATE_H +#define __FWUPD_RELEASE_PRIVATE_H + +#include + +#include "fwupd-release.h" + +G_BEGIN_DECLS + +FwupdRelease *fwupd_release_new_from_data (GVariant *data); +GVariant *fwupd_release_to_data (FwupdRelease *release, + const gchar *type_string); +void fwupd_release_to_variant_builder (FwupdRelease *release, + GVariantBuilder *builder); +void fwupd_release_from_key_value (FwupdRelease *release, + const gchar *key, + GVariant *value); + +G_END_DECLS + +#endif /* __FWUPD_RELEASE_PRIVATE_H */ + diff --git a/libfwupd/fwupd-release.c b/libfwupd/fwupd-release.c new file mode 100644 index 000000000..251fe11e3 --- /dev/null +++ b/libfwupd/fwupd-release.c @@ -0,0 +1,891 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2015-2017 Richard Hughes + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#include +#include +#include + +#include "fwupd-enums-private.h" +#include "fwupd-error.h" +#include "fwupd-release-private.h" + +static void fwupd_release_finalize (GObject *object); + +typedef struct { + gchar *checksum; + GChecksumType checksum_kind; + gchar *description; + gchar *filename; + gchar *homepage; + gchar *appstream_id; + gchar *license; + gchar *name; + gchar *summary; + gchar *uri; + gchar *vendor; + gchar *version; + gchar *remote_id; + guint64 size; +} FwupdReleasePrivate; + +G_DEFINE_TYPE_WITH_PRIVATE (FwupdRelease, fwupd_release, G_TYPE_OBJECT) +#define GET_PRIVATE(o) (fwupd_release_get_instance_private (o)) + +/** + * fwupd_release_get_remote_id: + * @release: A #FwupdRelease + * + * Gets the remote ID that can be used for downloading. + * + * Returns: the ID, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_release_get_remote_id (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_val_if_fail (FWUPD_IS_RELEASE (release), NULL); + return priv->remote_id; +} + +/** + * fwupd_release_set_remote_id: + * @release: A #FwupdRelease + * @remote_id: the release ID, e.g. "USB:foo" + * + * Sets the remote ID that can be used for downloading. + * + * Since: 0.9.3 + **/ +void +fwupd_release_set_remote_id (FwupdRelease *release, const gchar *remote_id) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_if_fail (FWUPD_IS_RELEASE (release)); + g_free (priv->remote_id); + priv->remote_id = g_strdup (remote_id); +} + +/** + * fwupd_release_get_version: + * @release: A #FwupdRelease + * + * Gets the update version. + * + * Returns: the update version, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_release_get_version (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_val_if_fail (FWUPD_IS_RELEASE (release), NULL); + return priv->version; +} + +/** + * fwupd_release_set_version: + * @release: A #FwupdRelease + * @version: the update version, e.g. "1.2.4" + * + * Sets the update version. + * + * Since: 0.9.3 + **/ +void +fwupd_release_set_version (FwupdRelease *release, const gchar *version) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_if_fail (FWUPD_IS_RELEASE (release)); + g_free (priv->version); + priv->version = g_strdup (version); +} + +/** + * fwupd_release_get_filename: + * @release: A #FwupdRelease + * + * Gets the update filename. + * + * Returns: the update filename, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_release_get_filename (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_val_if_fail (FWUPD_IS_RELEASE (release), NULL); + return priv->filename; +} + +/** + * fwupd_release_set_filename: + * @release: A #FwupdRelease + * @filename: the update filename on disk + * + * Sets the update filename. + * + * Since: 0.9.3 + **/ +void +fwupd_release_set_filename (FwupdRelease *release, const gchar *filename) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_if_fail (FWUPD_IS_RELEASE (release)); + g_free (priv->filename); + priv->filename = g_strdup (filename); +} + +/** + * fwupd_release_get_checksum: + * @release: A #FwupdRelease + * + * Gets the update checksum. + * + * Returns: the update checksum, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_release_get_checksum (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_val_if_fail (FWUPD_IS_RELEASE (release), NULL); + return priv->checksum; +} + +/** + * fwupd_release_set_checksum: + * @release: A #FwupdRelease + * @checksum: the update checksum + * + * Sets the update checksum. + * + * Since: 0.9.3 + **/ +void +fwupd_release_set_checksum (FwupdRelease *release, const gchar *checksum) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_if_fail (FWUPD_IS_RELEASE (release)); + g_free (priv->checksum); + priv->checksum = g_strdup (checksum); +} + +/** + * fwupd_release_get_checksum_kind: + * @release: A #FwupdRelease + * + * Gets the update checkum kind. + * + * Returns: the #GChecksumType + * + * Since: 0.9.3 + **/ +GChecksumType +fwupd_release_get_checksum_kind (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_val_if_fail (FWUPD_IS_RELEASE (release), 0); + return priv->checksum_kind; +} + +/** + * fwupd_release_set_checksum_kind: + * @release: A #FwupdRelease + * @checkum_kind: the checksum kind, e.g. %G_CHECKSUM_SHA1 + * + * Sets the update checkum kind. + * + * Since: 0.9.3 + **/ +void +fwupd_release_set_checksum_kind (FwupdRelease *release, GChecksumType checkum_kind) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_if_fail (FWUPD_IS_RELEASE (release)); + priv->checksum_kind = checkum_kind; +} + +/** + * fwupd_release_get_uri: + * @release: A #FwupdRelease + * + * Gets the update uri. + * + * Returns: the update uri, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_release_get_uri (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_val_if_fail (FWUPD_IS_RELEASE (release), NULL); + return priv->uri; +} + +/** + * fwupd_release_set_uri: + * @release: A #FwupdRelease + * @uri: the update URI + * + * Sets the update uri, i.e. where you can download the firmware from. + * + * Since: 0.9.3 + **/ +void +fwupd_release_set_uri (FwupdRelease *release, const gchar *uri) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_if_fail (FWUPD_IS_RELEASE (release)); + g_free (priv->uri); + priv->uri = g_strdup (uri); +} + +/** + * fwupd_release_get_homepage: + * @release: A #FwupdRelease + * + * Gets the update homepage. + * + * Returns: the update homepage, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_release_get_homepage (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_val_if_fail (FWUPD_IS_RELEASE (release), NULL); + return priv->homepage; +} + +/** + * fwupd_release_set_homepage: + * @release: A #FwupdRelease + * @homepage: the description + * + * Sets the update homepage. + * + * Since: 0.9.3 + **/ +void +fwupd_release_set_homepage (FwupdRelease *release, const gchar *homepage) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_if_fail (FWUPD_IS_RELEASE (release)); + g_free (priv->homepage); + priv->homepage = g_strdup (homepage); +} + +/** + * fwupd_release_get_description: + * @release: A #FwupdRelease + * + * Gets the update description in AppStream markup format. + * + * Returns: the update description, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_release_get_description (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_val_if_fail (FWUPD_IS_RELEASE (release), NULL); + return priv->description; +} + +/** + * fwupd_release_set_description: + * @release: A #FwupdRelease + * @description: the update description in AppStream markup format + * + * Sets the update description. + * + * Since: 0.9.3 + **/ +void +fwupd_release_set_description (FwupdRelease *release, const gchar *description) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_if_fail (FWUPD_IS_RELEASE (release)); + g_free (priv->description); + priv->description = g_strdup (description); +} + +/** + * fwupd_release_get_appstream_id: + * @release: A #FwupdRelease + * + * Gets the AppStream ID. + * + * Returns: the AppStream ID, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_release_get_appstream_id (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_val_if_fail (FWUPD_IS_RELEASE (release), NULL); + return priv->appstream_id; +} + +/** + * fwupd_release_set_appstream_id: + * @release: A #FwupdRelease + * @appstream_id: the AppStream component ID, e.g. "org.hughski.ColorHug2.firmware" + * + * Sets the AppStream ID. + * + * Since: 0.9.3 + **/ +void +fwupd_release_set_appstream_id (FwupdRelease *release, const gchar *appstream_id) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_if_fail (FWUPD_IS_RELEASE (release)); + g_free (priv->appstream_id); + priv->appstream_id = g_strdup (appstream_id); +} + +/** + * fwupd_release_get_size: + * @release: A #FwupdRelease + * + * Gets the update size. + * + * Returns: the update size in bytes, or 0 if unset + * + * Since: 0.9.3 + **/ +guint64 +fwupd_release_get_size (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_val_if_fail (FWUPD_IS_RELEASE (release), 0); + return priv->size; +} + +/** + * fwupd_release_set_size: + * @release: A #FwupdRelease + * @size: the update size in bytes + * + * Sets the update size. + * + * Since: 0.9.3 + **/ +void +fwupd_release_set_size (FwupdRelease *release, guint64 size) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_if_fail (FWUPD_IS_RELEASE (release)); + priv->size = size; +} + +/** + * fwupd_release_get_summary: + * @release: A #FwupdRelease + * + * Gets the update summary. + * + * Returns: the update summary, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_release_get_summary (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_val_if_fail (FWUPD_IS_RELEASE (release), NULL); + return priv->summary; +} + +/** + * fwupd_release_set_summary: + * @release: A #FwupdRelease + * @summary: the update one line summary + * + * Sets the update summary. + * + * Since: 0.9.3 + **/ +void +fwupd_release_set_summary (FwupdRelease *release, const gchar *summary) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_if_fail (FWUPD_IS_RELEASE (release)); + g_free (priv->summary); + priv->summary = g_strdup (summary); +} + +/** + * fwupd_release_get_vendor: + * @release: A #FwupdRelease + * + * Gets the update vendor. + * + * Returns: the update vendor, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_release_get_vendor (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_val_if_fail (FWUPD_IS_RELEASE (release), NULL); + return priv->vendor; +} + +/** + * fwupd_release_set_vendor: + * @release: A #FwupdRelease + * @vendor: the vendor name, e.g. "Hughski Limited" + * + * Sets the update vendor. + * + * Since: 0.9.3 + **/ +void +fwupd_release_set_vendor (FwupdRelease *release, const gchar *vendor) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_if_fail (FWUPD_IS_RELEASE (release)); + g_free (priv->vendor); + priv->vendor = g_strdup (vendor); +} + +/** + * fwupd_release_get_license: + * @release: A #FwupdRelease + * + * Gets the update license. + * + * Returns: the update license, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_release_get_license (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_val_if_fail (FWUPD_IS_RELEASE (release), NULL); + return priv->license; +} + +/** + * fwupd_release_set_license: + * @release: A #FwupdRelease + * @license: the description + * + * Sets the update license. + * + * Since: 0.9.3 + **/ +void +fwupd_release_set_license (FwupdRelease *release, const gchar *license) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_if_fail (FWUPD_IS_RELEASE (release)); + g_free (priv->license); + priv->license = g_strdup (license); +} + +/** + * fwupd_release_get_name: + * @release: A #FwupdRelease + * + * Gets the update name. + * + * Returns: the update name, or %NULL if unset + * + * Since: 0.9.3 + **/ +const gchar * +fwupd_release_get_name (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_val_if_fail (FWUPD_IS_RELEASE (release), NULL); + return priv->name; +} + +/** + * fwupd_release_set_name: + * @release: A #FwupdRelease + * @name: the description + * + * Sets the update name. + * + * Since: 0.9.3 + **/ +void +fwupd_release_set_name (FwupdRelease *release, const gchar *name) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + g_return_if_fail (FWUPD_IS_RELEASE (release)); + g_free (priv->name); + priv->name = g_strdup (name); +} + +void +fwupd_release_to_variant_builder (FwupdRelease *release, GVariantBuilder *builder) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + if (priv->remote_id != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_UPDATE_REMOTE_ID, + g_variant_new_string (priv->remote_id)); + } + if (priv->appstream_id != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_UPDATE_ID, + g_variant_new_string (priv->appstream_id)); + } + if (priv->filename != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_UPDATE_FILENAME, + g_variant_new_string (priv->filename)); + } + if (priv->license != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_UPDATE_LICENSE, + g_variant_new_string (priv->license)); + } + if (priv->name != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_UPDATE_NAME, + g_variant_new_string (priv->name)); + } + if (priv->size != 0) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_UPDATE_SIZE, + g_variant_new_uint64 (priv->size)); + } + if (priv->summary != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_UPDATE_SUMMARY, + g_variant_new_string (priv->summary)); + } + if (priv->description != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_UPDATE_DESCRIPTION, + g_variant_new_string (priv->description)); + } + if (priv->checksum != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_UPDATE_CHECKSUM, + g_variant_new_string (priv->checksum)); + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_UPDATE_CHECKSUM_KIND, + g_variant_new_uint32 (priv->checksum_kind)); + } + if (priv->uri != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_UPDATE_URI, + g_variant_new_string (priv->uri)); + } + if (priv->homepage != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_UPDATE_HOMEPAGE, + g_variant_new_string (priv->homepage)); + } + if (priv->version != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_UPDATE_VERSION, + g_variant_new_string (priv->version)); + } + if (priv->vendor != NULL) { + g_variant_builder_add (builder, "{sv}", + FWUPD_RESULT_KEY_UPDATE_VENDOR, + g_variant_new_string (priv->vendor)); + } +} + +/** + * fwupd_release_to_data: + * @release: A #FwupdRelease + * @type_string: The Gvariant type string, e.g. "a{sv}" or "(a{sv})" + * + * Creates a GVariant from the release data. + * + * Returns: the GVariant, or %NULL for error + * + * Since: 0.9.3 + **/ +GVariant * +fwupd_release_to_data (FwupdRelease *release, const gchar *type_string) +{ + GVariantBuilder builder; + + g_return_val_if_fail (FWUPD_IS_RELEASE (release), NULL); + g_return_val_if_fail (type_string != NULL, NULL); + + /* create an array with all the metadata in */ + g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); + fwupd_release_to_variant_builder (release, &builder); + + /* supported types */ + if (g_strcmp0 (type_string, "a{sv}") == 0) + return g_variant_new ("a{sv}", &builder); + if (g_strcmp0 (type_string, "(a{sv})") == 0) + return g_variant_new ("(a{sv})", &builder); + return NULL; +} + +void +fwupd_release_from_key_value (FwupdRelease *release, const gchar *key, GVariant *value) +{ + if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_REMOTE_ID) == 0) { + fwupd_release_set_remote_id (release, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_ID) == 0) { + fwupd_release_set_appstream_id (release, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_FILENAME) == 0) { + fwupd_release_set_filename (release, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_LICENSE) == 0) { + fwupd_release_set_license (release, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_NAME) == 0) { + fwupd_release_set_name (release, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_SIZE) == 0) { + fwupd_release_set_size (release, g_variant_get_uint64 (value)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_SUMMARY) == 0) { + fwupd_release_set_summary (release, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_DESCRIPTION) == 0) { + fwupd_release_set_description (release, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_CHECKSUM) == 0) { + fwupd_release_set_checksum (release, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_CHECKSUM_KIND) == 0) { + fwupd_release_set_checksum_kind (release, g_variant_get_uint32 (value)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_URI) == 0) { + fwupd_release_set_uri (release, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_HOMEPAGE) == 0) { + fwupd_release_set_homepage (release, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_VERSION) == 0) { + fwupd_release_set_version (release, g_variant_get_string (value, NULL)); + return; + } + if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_VENDOR) == 0) { + fwupd_release_set_vendor (release, g_variant_get_string (value, NULL)); + return; + } +} + +static void +fwupd_pad_kv_str (GString *str, const gchar *key, const gchar *value) +{ + /* ignore */ + if (key == NULL || value == NULL) + return; + g_string_append_printf (str, " %s: ", key); + for (gsize i = strlen (key); i < 20; i++) + g_string_append (str, " "); + g_string_append_printf (str, "%s\n", value); +} + +static void +fwupd_pad_kv_csk (GString *str, const gchar *key, GChecksumType checksum_type) +{ + const gchar *tmp = "unknown"; + if (checksum_type == G_CHECKSUM_SHA1) + tmp = "sha1"; + else if (checksum_type == G_CHECKSUM_SHA256) + tmp = "sha256"; + else if (checksum_type == G_CHECKSUM_SHA512) + tmp = "sha512"; + fwupd_pad_kv_str (str, key, tmp); +} + +static void +fwupd_pad_kv_siz (GString *str, const gchar *key, guint64 value) +{ + g_autofree gchar *tmp = NULL; + + /* ignore */ + if (value == 0) + return; + tmp = g_format_size (value); + fwupd_pad_kv_str (str, key, tmp); +} + +/** + * fwupd_release_to_string: + * @release: A #FwupdRelease + * + * Builds a text representation of the object. + * + * Returns: text, or %NULL for invalid + * + * Since: 0.9.3 + **/ +gchar * +fwupd_release_to_string (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + GString *str; + + g_return_val_if_fail (FWUPD_IS_RELEASE (release), NULL); + + str = g_string_new (""); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_ID, priv->appstream_id); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_REMOTE_ID, priv->remote_id); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_SUMMARY, priv->summary); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_DESCRIPTION, priv->description); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_VERSION, priv->version); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_FILENAME, priv->filename); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_CHECKSUM, priv->checksum); + if (priv->checksum != NULL) + fwupd_pad_kv_csk (str, FWUPD_RESULT_KEY_UPDATE_CHECKSUM_KIND, priv->checksum_kind); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_LICENSE, priv->license); + fwupd_pad_kv_siz (str, FWUPD_RESULT_KEY_UPDATE_SIZE, priv->size); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_URI, priv->uri); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_HOMEPAGE, priv->homepage); + fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_VENDOR, priv->vendor); + + return g_string_free (str, FALSE); +} + +static void +fwupd_release_class_init (FwupdReleaseClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->finalize = fwupd_release_finalize; +} + +static void +fwupd_release_init (FwupdRelease *release) +{ + FwupdReleasePrivate *priv = GET_PRIVATE (release); + priv->checksum_kind = G_CHECKSUM_SHA1; +} + +static void +fwupd_release_finalize (GObject *object) +{ + FwupdRelease *release = FWUPD_RELEASE (object); + FwupdReleasePrivate *priv = GET_PRIVATE (release); + + g_free (priv->description); + g_free (priv->filename); + g_free (priv->checksum); + g_free (priv->appstream_id); + g_free (priv->license); + g_free (priv->name); + g_free (priv->summary); + g_free (priv->uri); + g_free (priv->homepage); + g_free (priv->vendor); + g_free (priv->version); + g_free (priv->remote_id); + + G_OBJECT_CLASS (fwupd_release_parent_class)->finalize (object); +} + +static void +fwupd_release_from_variant_iter (FwupdRelease *release, GVariantIter *iter) +{ + GVariant *value; + const gchar *key; + while (g_variant_iter_next (iter, "{&sv}", &key, &value)) { + fwupd_release_from_key_value (release, key, value); + g_variant_unref (value); + } +} + +/** + * fwupd_release_new_from_data: + * @data: a #GVariant + * + * Creates a new release using packed data. + * + * Returns: a new #FwupdRelease, or %NULL if @data was invalid + * + * Since: 0.9.3 + **/ +FwupdRelease * +fwupd_release_new_from_data (GVariant *data) +{ + FwupdRelease *res = NULL; + const gchar *type_string; + g_autoptr(GVariantIter) iter = NULL; + + /* format from GetDetails */ + type_string = g_variant_get_type_string (data); + if (g_strcmp0 (type_string, "(a{sv})") == 0) { + res = fwupd_release_new (); + g_variant_get (data, "(a{sv})", &iter); + fwupd_release_from_variant_iter (res, iter); + } else if (g_strcmp0 (type_string, "a{sv}") == 0) { + res = fwupd_release_new (); + g_variant_get (data, "a{sv}", &iter); + fwupd_release_from_variant_iter (res, iter); + } else { + g_warning ("type %s not known", type_string); + } + return res; +} + +/** + * fwupd_release_new: + * + * Creates a new release. + * + * Returns: a new #FwupdRelease + * + * Since: 0.9.3 + **/ +FwupdRelease * +fwupd_release_new (void) +{ + FwupdRelease *release; + release = g_object_new (FWUPD_TYPE_RELEASE, NULL); + return FWUPD_RELEASE (release); +} diff --git a/libfwupd/fwupd-release.h b/libfwupd/fwupd-release.h new file mode 100644 index 000000000..f84b2341b --- /dev/null +++ b/libfwupd/fwupd-release.h @@ -0,0 +1,96 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2015-2017 Richard Hughes + * + * Licensed under the GNU Lesser General Public License Version 2.1 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __FWUPD_RELEASE_H +#define __FWUPD_RELEASE_H + +#include + +#include "fwupd-enums.h" + +G_BEGIN_DECLS + +#define FWUPD_TYPE_RELEASE (fwupd_release_get_type ()) +G_DECLARE_DERIVABLE_TYPE (FwupdRelease, fwupd_release, FWUPD, RELEASE, GObject) + +struct _FwupdReleaseClass +{ + GObjectClass parent_class; + /*< private >*/ + void (*_fwupd_reserved1) (void); + void (*_fwupd_reserved2) (void); + void (*_fwupd_reserved3) (void); + void (*_fwupd_reserved4) (void); + void (*_fwupd_reserved5) (void); + void (*_fwupd_reserved6) (void); + void (*_fwupd_reserved7) (void); +}; + +FwupdRelease *fwupd_release_new (void); +gchar *fwupd_release_to_string (FwupdRelease *release); + +const gchar *fwupd_release_get_version (FwupdRelease *release); +void fwupd_release_set_version (FwupdRelease *release, + const gchar *version); +const gchar *fwupd_release_get_uri (FwupdRelease *release); +void fwupd_release_set_uri (FwupdRelease *release, + const gchar *uri); +const gchar *fwupd_release_get_checksum (FwupdRelease *release); +void fwupd_release_set_checksum (FwupdRelease *release, + const gchar *checksum); +GChecksumType fwupd_release_get_checksum_kind (FwupdRelease *release); +void fwupd_release_set_checksum_kind (FwupdRelease *release, + GChecksumType checkum_kind); +const gchar *fwupd_release_get_filename (FwupdRelease *release); +void fwupd_release_set_filename (FwupdRelease *release, + const gchar *filename); +const gchar *fwupd_release_get_appstream_id (FwupdRelease *release); +void fwupd_release_set_appstream_id (FwupdRelease *release, + const gchar *id); +const gchar *fwupd_release_get_remote_id (FwupdRelease *release); +void fwupd_release_set_remote_id (FwupdRelease *release, + const gchar *remote_id); +const gchar *fwupd_release_get_vendor (FwupdRelease *release); +void fwupd_release_set_vendor (FwupdRelease *release, + const gchar *vendor); +const gchar *fwupd_release_get_name (FwupdRelease *release); +void fwupd_release_set_name (FwupdRelease *release, + const gchar *name); +const gchar *fwupd_release_get_summary (FwupdRelease *release); +void fwupd_release_set_summary (FwupdRelease *release, + const gchar *summary); +const gchar *fwupd_release_get_description (FwupdRelease *release); +void fwupd_release_set_description (FwupdRelease *release, + const gchar *description); +const gchar *fwupd_release_get_homepage (FwupdRelease *release); +void fwupd_release_set_homepage (FwupdRelease *release, + const gchar *homepage); +guint64 fwupd_release_get_size (FwupdRelease *release); +void fwupd_release_set_size (FwupdRelease *release, + guint64 size); +const gchar *fwupd_release_get_license (FwupdRelease *release); +void fwupd_release_set_license (FwupdRelease *release, + const gchar *license); + +G_END_DECLS + +#endif /* __FWUPD_RELEASE_H */ + diff --git a/libfwupd/fwupd-result.c b/libfwupd/fwupd-result.c index 7268cf59a..db27dfc44 100644 --- a/libfwupd/fwupd-result.c +++ b/libfwupd/fwupd-result.c @@ -25,50 +25,21 @@ #include #include +#include "fwupd-device-private.h" #include "fwupd-enums-private.h" #include "fwupd-error.h" +#include "fwupd-release-private.h" #include "fwupd-result.h" static void fwupd_result_finalize (GObject *object); typedef struct { - GPtrArray *guids; gchar *unique_id; - - /* device-specific */ - gchar *device_checksum; - GChecksumType device_checksum_kind; - gchar *device_description; - gchar *device_id; - gchar *device_name; - gchar *device_provider; - gchar *device_vendor; - gchar *device_version; - gchar *device_version_lowest; - gchar *device_version_bootloader; - guint32 device_flashes_left; - guint64 device_created; - guint64 device_flags; - guint64 device_modified; - - /* update-specific */ FwupdTrustFlags update_trust_flags; FwupdUpdateState update_state; - gchar *update_checksum; - GChecksumType update_checksum_kind; - gchar *update_description; gchar *update_error; - gchar *update_filename; - gchar *update_homepage; - gchar *update_id; - gchar *update_license; - gchar *update_name; - gchar *update_summary; - gchar *update_uri; - gchar *update_vendor; - gchar *update_version; - gchar *update_remote_id; - guint64 update_size; + FwupdDevice *device; + FwupdRelease *release; } FwupdResultPrivate; enum { @@ -136,7 +107,7 @@ fwupd_result_get_update_remote_id (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->update_remote_id; + return fwupd_release_get_remote_id (priv->release); } /** @@ -153,8 +124,43 @@ fwupd_result_set_update_remote_id (FwupdResult *result, const gchar *update_remo { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->update_remote_id); - priv->update_remote_id = g_strdup (update_remote_id); + fwupd_release_set_remote_id (priv->release, update_remote_id); +} + +/** + * fwupd_result_get_release: + * @result: A #FwupdResult + * + * Gets the default release for this result. + * + * Returns: (transfer none): the #FwupdRelease + * + * Since: 0.9.3 + **/ +FwupdRelease * +fwupd_result_get_release (FwupdResult *result) +{ + FwupdResultPrivate *priv = GET_PRIVATE (result); + g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); + return priv->release; +} + +/** + * fwupd_result_get_device: + * @result: A #FwupdResult + * + * Gets the default device for this result. + * + * Returns: (transfer none): the #FwupdDevice + * + * Since: 0.9.3 + **/ +FwupdDevice * +fwupd_result_get_device (FwupdResult *result) +{ + FwupdResultPrivate *priv = GET_PRIVATE (result); + g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); + return priv->device; } /** @@ -172,7 +178,7 @@ fwupd_result_get_device_id (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->device_id; + return fwupd_device_get_id (priv->device); } /** @@ -189,8 +195,7 @@ fwupd_result_set_device_id (FwupdResult *result, const gchar *device_id) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->device_id); - priv->device_id = g_strdup (device_id); + fwupd_device_set_id (priv->device, device_id); } /** @@ -208,7 +213,7 @@ fwupd_result_get_guids (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->guids; + return fwupd_device_get_guids (priv->device); } /** @@ -226,16 +231,8 @@ gboolean fwupd_result_has_guid (FwupdResult *result, const gchar *guid) { FwupdResultPrivate *priv = GET_PRIVATE (result); - guint i; - g_return_val_if_fail (FWUPD_IS_RESULT (result), FALSE); - - for (i = 0; i < priv->guids->len; i++) { - const gchar *guid_tmp = g_ptr_array_index (priv->guids, i); - if (g_strcmp0 (guid, guid_tmp) == 0) - return TRUE; - } - return FALSE; + return fwupd_device_has_guid (priv->device, guid); } /** @@ -252,9 +249,7 @@ fwupd_result_add_guid (FwupdResult *result, const gchar *guid) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - if (fwupd_result_has_guid (result, guid)) - return; - g_ptr_array_add (priv->guids, g_strdup (guid)); + fwupd_device_add_guid (priv->device, guid); } /** @@ -272,9 +267,7 @@ fwupd_result_get_guid_default (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - if (priv->guids->len == 0) - return NULL; - return g_ptr_array_index (priv->guids, 0); + return fwupd_device_get_guid_default (priv->device); } /** @@ -292,7 +285,9 @@ fwupd_result_get_guid_default (FwupdResult *result) const gchar * fwupd_result_get_guid (FwupdResult *result) { - return fwupd_result_get_guid_default (result); + FwupdResultPrivate *priv = GET_PRIVATE (result); + g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); + return fwupd_device_get_guid_default (priv->device); } /** @@ -309,7 +304,8 @@ fwupd_result_get_guid (FwupdResult *result) void fwupd_result_set_guid (FwupdResult *result, const gchar *guid) { - fwupd_result_add_guid (result, guid); + FwupdResultPrivate *priv = GET_PRIVATE (result); + fwupd_device_add_guid (priv->device, guid); } /** @@ -327,7 +323,7 @@ fwupd_result_get_device_name (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->device_name; + return fwupd_device_get_name (priv->device); } /** @@ -344,8 +340,7 @@ fwupd_result_set_device_name (FwupdResult *result, const gchar *device_name) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->device_name); - priv->device_name = g_strdup (device_name); + fwupd_device_set_name (priv->device, device_name); } /** @@ -363,7 +358,7 @@ fwupd_result_get_device_vendor (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->device_vendor; + return fwupd_device_get_vendor (priv->device); } /** @@ -380,8 +375,7 @@ fwupd_result_set_device_vendor (FwupdResult *result, const gchar *device_vendor) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->device_vendor); - priv->device_vendor = g_strdup (device_vendor); + fwupd_device_set_vendor (priv->device, device_vendor); } /** @@ -399,7 +393,7 @@ fwupd_result_get_device_description (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->device_description; + return fwupd_device_get_description (priv->device); } /** @@ -416,8 +410,7 @@ fwupd_result_set_device_description (FwupdResult *result, const gchar *device_de { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->device_description); - priv->device_description = g_strdup (device_description); + fwupd_device_set_description (priv->device, device_description); } /** @@ -435,7 +428,7 @@ fwupd_result_get_device_version (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->device_version; + return fwupd_device_get_version (priv->device); } /** @@ -452,8 +445,7 @@ fwupd_result_set_device_version (FwupdResult *result, const gchar *device_versio { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->device_version); - priv->device_version = g_strdup (device_version); + fwupd_device_set_version (priv->device, device_version); } /** @@ -471,7 +463,7 @@ fwupd_result_get_update_version (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->update_version; + return fwupd_release_get_version (priv->release); } /** @@ -489,7 +481,7 @@ fwupd_result_get_device_version_lowest (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->device_version_lowest; + return fwupd_device_get_version_lowest (priv->device); } /** @@ -506,8 +498,7 @@ fwupd_result_set_device_version_lowest (FwupdResult *result, const gchar *device { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->device_version_lowest); - priv->device_version_lowest = g_strdup (device_version_lowest); + fwupd_device_set_version_lowest (priv->device, device_version_lowest); } /** @@ -525,7 +516,7 @@ fwupd_result_get_device_version_bootloader (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->device_version_bootloader; + return fwupd_device_get_version_bootloader (priv->device); } /** @@ -543,8 +534,7 @@ fwupd_result_set_device_version_bootloader (FwupdResult *result, { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->device_version_bootloader); - priv->device_version_bootloader = g_strdup (device_version_bootloader); + fwupd_device_set_version_bootloader (priv->device, device_version_bootloader); } /** @@ -562,7 +552,7 @@ fwupd_result_get_device_flashes_left (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), 0); - return priv->device_flashes_left; + return fwupd_device_get_flashes_left (priv->device); } /** @@ -579,7 +569,7 @@ fwupd_result_set_device_flashes_left (FwupdResult *result, guint32 flashes_left) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - priv->device_flashes_left = flashes_left; + fwupd_device_set_flashes_left (priv->device, flashes_left); } /** @@ -596,8 +586,7 @@ fwupd_result_set_update_version (FwupdResult *result, const gchar *update_versio { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->update_version); - priv->update_version = g_strdup (update_version); + fwupd_release_set_version (priv->release, update_version); } /** @@ -615,7 +604,7 @@ fwupd_result_get_update_filename (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->update_filename; + return fwupd_release_get_filename (priv->release); } /** @@ -632,8 +621,7 @@ fwupd_result_set_update_filename (FwupdResult *result, const gchar *update_filen { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->update_filename); - priv->update_filename = g_strdup (update_filename); + fwupd_release_set_filename (priv->release, update_filename); } /** @@ -686,7 +674,7 @@ fwupd_result_get_update_checksum (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->update_checksum; + return fwupd_release_get_checksum (priv->release); } /** @@ -703,8 +691,7 @@ fwupd_result_set_update_checksum (FwupdResult *result, const gchar *update_check { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->update_checksum); - priv->update_checksum = g_strdup (update_checksum); + fwupd_release_set_checksum (priv->release, update_checksum); } /** @@ -722,7 +709,7 @@ fwupd_result_get_update_checksum_kind (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), 0); - return priv->update_checksum_kind; + return fwupd_release_get_checksum_kind (priv->release); } /** @@ -739,7 +726,7 @@ fwupd_result_set_update_checksum_kind (FwupdResult *result, GChecksumType checku { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - priv->update_checksum_kind = checkum_kind; + fwupd_release_set_checksum_kind (priv->release, checkum_kind); } /** @@ -757,7 +744,7 @@ fwupd_result_get_update_uri (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->update_uri; + return fwupd_release_get_uri (priv->release); } /** @@ -774,8 +761,7 @@ fwupd_result_set_update_uri (FwupdResult *result, const gchar *update_uri) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->update_uri); - priv->update_uri = g_strdup (update_uri); + fwupd_release_set_uri (priv->release, update_uri); } /** @@ -793,7 +779,7 @@ fwupd_result_get_update_homepage (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->update_homepage; + return fwupd_release_get_homepage (priv->release); } /** @@ -810,8 +796,7 @@ fwupd_result_set_update_homepage (FwupdResult *result, const gchar *update_homep { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->update_homepage); - priv->update_homepage = g_strdup (update_homepage); + fwupd_release_set_homepage (priv->release, update_homepage); } /** @@ -829,7 +814,7 @@ fwupd_result_get_update_description (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->update_description; + return fwupd_release_get_description (priv->release); } /** @@ -846,8 +831,7 @@ fwupd_result_set_update_description (FwupdResult *result, const gchar *update_de { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->update_description); - priv->update_description = g_strdup (update_description); + fwupd_release_set_description (priv->release, update_description); } /** @@ -865,7 +849,7 @@ fwupd_result_get_update_id (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->update_id; + return fwupd_release_get_appstream_id (priv->release); } /** @@ -882,8 +866,7 @@ fwupd_result_set_update_id (FwupdResult *result, const gchar *update_id) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->update_id); - priv->update_id = g_strdup (update_id); + fwupd_release_set_appstream_id (priv->release, update_id); } /** @@ -901,7 +884,7 @@ fwupd_result_get_update_size (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), 0); - return priv->update_size; + return fwupd_release_get_size (priv->release); } /** @@ -918,7 +901,7 @@ fwupd_result_set_update_size (FwupdResult *result, guint64 update_size) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - priv->update_size = update_size; + fwupd_release_set_size (priv->release, update_size); } /** @@ -936,7 +919,7 @@ fwupd_result_get_device_checksum (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->device_checksum; + return fwupd_device_get_checksum (priv->device); } /** @@ -953,8 +936,7 @@ fwupd_result_set_device_checksum (FwupdResult *result, const gchar *device_check { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->device_checksum); - priv->device_checksum = g_strdup (device_checksum); + fwupd_device_set_checksum (priv->device, device_checksum); } /** @@ -972,7 +954,7 @@ fwupd_result_get_device_checksum_kind (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), 0); - return priv->device_checksum_kind; + return fwupd_device_get_checksum_kind (priv->device); } /** @@ -989,7 +971,7 @@ fwupd_result_set_device_checksum_kind (FwupdResult *result, GChecksumType checku { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - priv->device_checksum_kind = checkum_kind; + fwupd_device_set_checksum_kind (priv->device, checkum_kind); } /** @@ -1007,7 +989,7 @@ fwupd_result_get_update_summary (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->update_summary; + return fwupd_release_get_summary (priv->release); } /** @@ -1024,8 +1006,7 @@ fwupd_result_set_update_summary (FwupdResult *result, const gchar *update_summar { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->update_summary); - priv->update_summary = g_strdup (update_summary); + fwupd_release_set_summary (priv->release, update_summary); } /** @@ -1043,7 +1024,7 @@ fwupd_result_get_device_provider (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->device_provider; + return fwupd_device_get_provider (priv->device); } /** @@ -1060,8 +1041,7 @@ fwupd_result_set_device_provider (FwupdResult *result, const gchar *device_provi { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->device_provider); - priv->device_provider = g_strdup (device_provider); + fwupd_device_set_provider (priv->device, device_provider); } /** @@ -1150,7 +1130,7 @@ fwupd_result_get_update_vendor (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->update_vendor; + return fwupd_release_get_vendor (priv->release); } /** @@ -1167,8 +1147,7 @@ fwupd_result_set_update_vendor (FwupdResult *result, const gchar *update_vendor) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->update_vendor); - priv->update_vendor = g_strdup (update_vendor); + fwupd_release_set_vendor (priv->release, update_vendor); } /** @@ -1186,7 +1165,7 @@ fwupd_result_get_update_license (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->update_license; + return fwupd_release_get_license (priv->release); } /** @@ -1203,8 +1182,7 @@ fwupd_result_set_update_license (FwupdResult *result, const gchar *update_licens { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->update_license); - priv->update_license = g_strdup (update_license); + fwupd_release_set_license (priv->release, update_license); } /** @@ -1222,7 +1200,7 @@ fwupd_result_get_update_name (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); - return priv->update_name; + return fwupd_release_get_name (priv->release); } /** @@ -1239,8 +1217,7 @@ fwupd_result_set_update_name (FwupdResult *result, const gchar *update_name) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - g_free (priv->update_name); - priv->update_name = g_strdup (update_name); + fwupd_release_set_name (priv->release, update_name); } /** @@ -1258,7 +1235,7 @@ fwupd_result_get_device_flags (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), 0); - return priv->device_flags; + return fwupd_device_get_flags (priv->device); } /** @@ -1275,7 +1252,7 @@ fwupd_result_set_device_flags (FwupdResult *result, guint64 device_flags) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - priv->device_flags = device_flags; + fwupd_device_set_flags (priv->device, device_flags); } /** @@ -1292,7 +1269,7 @@ fwupd_result_add_device_flag (FwupdResult *result, FwupdDeviceFlags flag) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - priv->device_flags |= flag; + fwupd_device_add_flag (priv->device, flag); } /** @@ -1309,7 +1286,7 @@ fwupd_result_remove_device_flag (FwupdResult *result, FwupdDeviceFlags flag) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - priv->device_flags &= ~flag; + fwupd_device_remove_flag (priv->device, flag); } /** @@ -1328,7 +1305,7 @@ fwupd_result_has_device_flag (FwupdResult *result, FwupdDeviceFlags flag) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), FALSE); - return (priv->device_flags & flag) > 0; + return fwupd_device_has_flag (priv->device, flag); } /** @@ -1346,7 +1323,7 @@ fwupd_result_get_device_created (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), 0); - return priv->device_created; + return fwupd_device_get_created (priv->device); } @@ -1364,7 +1341,7 @@ fwupd_result_set_device_created (FwupdResult *result, guint64 device_created) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - priv->device_created = device_created; + fwupd_device_set_created (priv->device, device_created); } /** @@ -1382,7 +1359,7 @@ fwupd_result_get_device_modified (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_val_if_fail (FWUPD_IS_RESULT (result), 0); - return priv->device_modified; + return fwupd_device_get_modified (priv->device); } /** @@ -1399,7 +1376,7 @@ fwupd_result_set_device_modified (FwupdResult *result, guint64 device_modified) { FwupdResultPrivate *priv = GET_PRIVATE (result); g_return_if_fail (FWUPD_IS_RESULT (result)); - priv->device_modified = device_modified; + fwupd_device_set_modified (priv->device, device_modified); } /** @@ -1424,88 +1401,11 @@ fwupd_result_to_data (FwupdResult *result, const gchar *type_string) /* create an array with all the metadata in */ g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); - if (priv->guids->len > 0) { - guint i; - g_autoptr(GString) str = g_string_new (""); - for (i = 0; i < priv->guids->len; i++) { - const gchar *guid = g_ptr_array_index (priv->guids, i); - g_string_append_printf (str, "%s,", guid); - } - if (str->len > 0) - g_string_truncate (str, str->len - 1); - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_GUID, - g_variant_new_string (str->str)); - } if (priv->unique_id != NULL) { g_variant_builder_add (&builder, "{sv}", FWUPD_RESULT_KEY_UNIQUE_ID, g_variant_new_string (priv->unique_id)); } - if (priv->update_remote_id != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_UPDATE_REMOTE_ID, - g_variant_new_string (priv->update_remote_id)); - } - if (priv->device_name != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_DEVICE_NAME, - g_variant_new_string (priv->device_name)); - } - if (priv->device_vendor != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_DEVICE_VENDOR, - g_variant_new_string (priv->device_vendor)); - } - if (priv->device_flags > 0) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_DEVICE_FLAGS, - g_variant_new_uint64 (priv->device_flags)); - } - if (priv->device_created > 0) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_DEVICE_CREATED, - g_variant_new_uint64 (priv->device_created)); - } - if (priv->device_modified > 0) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_DEVICE_MODIFIED, - g_variant_new_uint64 (priv->device_modified)); - } - - if (priv->update_id != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_UPDATE_ID, - g_variant_new_string (priv->update_id)); - } - if (priv->device_description != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_DEVICE_DESCRIPTION, - g_variant_new_string (priv->device_description)); - } - if (priv->update_filename != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_UPDATE_FILENAME, - g_variant_new_string (priv->update_filename)); - } - if (priv->device_checksum != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_DEVICE_CHECKSUM, - g_variant_new_string (priv->device_checksum)); - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_DEVICE_CHECKSUM_KIND, - g_variant_new_uint32 (priv->device_checksum_kind)); - } - if (priv->update_license != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_UPDATE_LICENSE, - g_variant_new_string (priv->update_license)); - } - if (priv->update_name != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_UPDATE_NAME, - g_variant_new_string (priv->update_name)); - } if (priv->update_error != NULL) { g_variant_builder_add (&builder, "{sv}", FWUPD_RESULT_KEY_UPDATE_ERROR, @@ -1516,83 +1416,19 @@ fwupd_result_to_data (FwupdResult *result, const gchar *type_string) FWUPD_RESULT_KEY_UPDATE_STATE, g_variant_new_uint32 (priv->update_state)); } - if (priv->device_provider != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_DEVICE_PLUGIN, - g_variant_new_string (priv->device_provider)); - } - if (priv->update_size != 0) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_UPDATE_SIZE, - g_variant_new_uint64 (priv->update_size)); - } if (priv->update_trust_flags != 0) { g_variant_builder_add (&builder, "{sv}", FWUPD_RESULT_KEY_UPDATE_TRUST_FLAGS, g_variant_new_uint64 (priv->update_trust_flags)); } - if (priv->update_summary != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_UPDATE_SUMMARY, - g_variant_new_string (priv->update_summary)); - } - if (priv->update_description != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_UPDATE_DESCRIPTION, - g_variant_new_string (priv->update_description)); - } - if (priv->update_checksum != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_UPDATE_CHECKSUM, - g_variant_new_string (priv->update_checksum)); - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_UPDATE_CHECKSUM_KIND, - g_variant_new_uint32 (priv->update_checksum_kind)); - } - if (priv->update_uri != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_UPDATE_URI, - g_variant_new_string (priv->update_uri)); - } - if (priv->update_homepage != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_UPDATE_HOMEPAGE, - g_variant_new_string (priv->update_homepage)); - } - if (priv->update_version != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_UPDATE_VERSION, - g_variant_new_string (priv->update_version)); - } - if (priv->update_vendor != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_UPDATE_VENDOR, - g_variant_new_string (priv->update_vendor)); - } - if (priv->device_version != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_DEVICE_VERSION, - g_variant_new_string (priv->device_version)); - } - if (priv->device_version_lowest != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_DEVICE_VERSION_LOWEST, - g_variant_new_string (priv->device_version_lowest)); - } - if (priv->device_version_bootloader != NULL) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_DEVICE_VERSION_BOOTLOADER, - g_variant_new_string (priv->device_version_bootloader)); - } - if (priv->device_flashes_left > 0) { - g_variant_builder_add (&builder, "{sv}", - FWUPD_RESULT_KEY_DEVICE_FLASHES_LEFT, - g_variant_new_uint32 (priv->device_flashes_left)); - } + + /* device and release objects */ + fwupd_release_to_variant_builder (priv->release, &builder); + fwupd_device_to_variant_builder (priv->device, &builder); /* supported types */ if (g_strcmp0 (type_string, "{sa{sv}}") == 0) { - const gchar *device_id = priv->device_id; + const gchar *device_id = fwupd_device_get_id (priv->device); if (device_id == NULL) device_id = ""; return g_variant_new ("{sa{sv}}", device_id, &builder); @@ -1603,80 +1439,16 @@ fwupd_result_to_data (FwupdResult *result, const gchar *type_string) } static void -fwupd_result_from_kv (FwupdResult *result, const gchar *key, GVariant *value) +fwupd_result_from_key_value (FwupdResult *result, const gchar *key, GVariant *value) { - if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_FLAGS) == 0) { - fwupd_result_set_device_flags (result, g_variant_get_uint64 (value)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_CREATED) == 0) { - fwupd_result_set_device_created (result, g_variant_get_uint64 (value)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_MODIFIED) == 0) { - fwupd_result_set_device_modified (result, g_variant_get_uint64 (value)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_GUID) == 0) { - guint i; - const gchar *guids = g_variant_get_string (value, NULL); - g_auto(GStrv) split = g_strsplit (guids, ",", -1); - for (i = 0; split[i] != NULL; i++) - fwupd_result_add_guid (result, split[i]); - return; - } if (g_strcmp0 (key, FWUPD_RESULT_KEY_UNIQUE_ID) == 0) { fwupd_result_set_unique_id (result, g_variant_get_string (value, NULL)); return; } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_REMOTE_ID) == 0) { - fwupd_result_set_update_remote_id (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_NAME) == 0) { - fwupd_result_set_device_name (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_VENDOR) == 0) { - fwupd_result_set_device_vendor (result, g_variant_get_string (value, NULL)); - return; - } if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_TRUST_FLAGS) == 0) { fwupd_result_set_update_trust_flags (result, g_variant_get_uint64 (value)); return; } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_ID) == 0) { - fwupd_result_set_update_id (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_DESCRIPTION) == 0) { - fwupd_result_set_device_description (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_FILENAME) == 0) { - fwupd_result_set_update_filename (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_CHECKSUM) == 0) { - fwupd_result_set_device_checksum (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_CHECKSUM_KIND) == 0) { - fwupd_result_set_device_checksum_kind (result, g_variant_get_uint32 (value)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_LICENSE) == 0) { - fwupd_result_set_update_license (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_NAME) == 0) { - fwupd_result_set_update_name (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_ERROR) == 0) { - fwupd_result_set_update_error (result, g_variant_get_string (value, NULL)); - return; - } if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_STATE) == 0) { /* old daemon version and new client */ if (g_strcmp0 (g_variant_get_type_string (value), "s") == 0) { @@ -1688,62 +1460,6 @@ fwupd_result_from_kv (FwupdResult *result, const gchar *key, GVariant *value) } return; } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_PLUGIN) == 0) { - fwupd_result_set_device_provider (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_SIZE) == 0) { - fwupd_result_set_update_size (result, g_variant_get_uint64 (value)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_SUMMARY) == 0) { - fwupd_result_set_update_summary (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_DESCRIPTION) == 0) { - fwupd_result_set_update_description (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_CHECKSUM) == 0) { - fwupd_result_set_update_checksum (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_CHECKSUM_KIND) == 0) { - fwupd_result_set_update_checksum_kind (result, g_variant_get_uint32 (value)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_URI) == 0) { - fwupd_result_set_update_uri (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_HOMEPAGE) == 0) { - fwupd_result_set_update_homepage (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_VERSION) == 0) { - fwupd_result_set_update_version (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_UPDATE_VENDOR) == 0) { - fwupd_result_set_update_vendor (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_VERSION) == 0) { - fwupd_result_set_device_version (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_VERSION_LOWEST) == 0) { - fwupd_result_set_device_version_lowest (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_VERSION_BOOTLOADER) == 0) { - fwupd_result_set_device_version_bootloader (result, g_variant_get_string (value, NULL)); - return; - } - if (g_strcmp0 (key, FWUPD_RESULT_KEY_DEVICE_FLASHES_LEFT) == 0) { - fwupd_result_set_device_flashes_left (result, g_variant_get_uint32 (value)); - return; - } } static void @@ -1758,21 +1474,6 @@ fwupd_pad_kv_str (GString *str, const gchar *key, const gchar *value) g_string_append_printf (str, "%s\n", value); } -static void -fwupd_pad_kv_unx (GString *str, const gchar *key, guint64 value) -{ - g_autoptr(GDateTime) date = NULL; - g_autofree gchar *tmp = NULL; - - /* ignore */ - if (value == 0) - return; - - date = g_date_time_new_from_unix_utc ((gint64) value); - tmp = g_date_time_format (date, "%F"); - fwupd_pad_kv_str (str, key, tmp); -} - static void fwupd_pad_kv_ups (GString *str, const gchar *key, FwupdUpdateState value) { @@ -1781,51 +1482,6 @@ fwupd_pad_kv_ups (GString *str, const gchar *key, FwupdUpdateState value) fwupd_pad_kv_str (str, key, fwupd_update_state_to_string (value)); } -static void -fwupd_pad_kv_siz (GString *str, const gchar *key, guint64 value) -{ - g_autofree gchar *tmp = NULL; - - /* ignore */ - if (value == 0) - return; - tmp = g_format_size (value); - fwupd_pad_kv_str (str, key, tmp); -} - -static void -fwupd_pad_kv_int (GString *str, const gchar *key, guint32 value) -{ - g_autofree gchar *tmp = NULL; - - /* ignore */ - if (value == 0) - return; - tmp = g_strdup_printf("%" G_GUINT32_FORMAT, value); - fwupd_pad_kv_str (str, key, tmp); -} - -static void -fwupd_pad_kv_dfl (GString *str, const gchar *key, guint64 device_flags) -{ - guint i; - g_autoptr(GString) tmp = NULL; - - tmp = g_string_new (""); - for (i = 0; i < 64; i++) { - if ((device_flags & ((guint64) 1 << i)) == 0) - continue; - g_string_append_printf (tmp, "%s|", - fwupd_device_flag_to_string ((guint64) 1 << i)); - } - if (tmp->len == 0) { - g_string_append (tmp, fwupd_device_flag_to_string (0)); - } else { - g_string_truncate (tmp, tmp->len - 1); - } - fwupd_pad_kv_str (str, key, tmp->str); -} - static void fwupd_pad_kv_tfl (GString *str, const gchar *key, FwupdTrustFlags trust_flags) { @@ -1847,19 +1503,6 @@ fwupd_pad_kv_tfl (GString *str, const gchar *key, FwupdTrustFlags trust_flags) fwupd_pad_kv_str (str, key, tmp->str); } -static void -fwupd_pad_kv_csk (GString *str, const gchar *key, GChecksumType checksum_type) -{ - const gchar *tmp = "unknown"; - if (checksum_type == G_CHECKSUM_SHA1) - tmp = "sha1"; - else if (checksum_type == G_CHECKSUM_SHA256) - tmp = "sha256"; - else if (checksum_type == G_CHECKSUM_SHA512) - tmp = "sha512"; - fwupd_pad_kv_str (str, key, tmp); -} - /** * fwupd_result_to_string: * @result: A #FwupdResult @@ -1875,62 +1518,29 @@ fwupd_result_to_string (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); GString *str; - guint i; + g_autofree gchar *device_str = NULL; + g_autofree gchar *release_str = NULL; g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); str = g_string_new (""); /* not set when using GetDetails */ - if (priv->device_name != NULL) - g_string_append_printf (str, "%s\n", priv->device_name); - else { - if (priv->update_name != NULL) - g_string_append_printf( str, "%s\n", priv->update_name); - else - g_string_append_printf (str, "%s\n", "Unknown Device"); - } + if (fwupd_device_get_name (priv->device) != NULL) + g_string_append_printf (str, "%s\n", fwupd_device_get_name (priv->device)); + else + g_string_append_printf (str, "%s\n", "Unknown Device"); /* device */ - for (i = 0; i < priv->guids->len; i++) { - const gchar *guid = g_ptr_array_index (priv->guids, i); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_GUID, guid); - } fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UNIQUE_ID, priv->unique_id); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_ID, priv->device_id); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_DESCRIPTION, priv->device_description); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_PLUGIN, priv->device_provider); - fwupd_pad_kv_dfl (str, FWUPD_RESULT_KEY_DEVICE_FLAGS, priv->device_flags); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_CHECKSUM, priv->device_checksum); - if (priv->device_checksum != NULL) - fwupd_pad_kv_csk (str, FWUPD_RESULT_KEY_DEVICE_CHECKSUM_KIND, priv->device_checksum_kind); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_VENDOR, priv->device_vendor); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_VERSION, priv->device_version); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_VERSION_LOWEST, priv->device_version_lowest); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_DEVICE_VERSION_BOOTLOADER, priv->device_version_bootloader); - if (priv->device_flashes_left < 2) - fwupd_pad_kv_int (str, FWUPD_RESULT_KEY_DEVICE_FLASHES_LEFT, priv->device_flashes_left); - fwupd_pad_kv_unx (str, FWUPD_RESULT_KEY_DEVICE_CREATED, priv->device_created); - fwupd_pad_kv_unx (str, FWUPD_RESULT_KEY_DEVICE_MODIFIED, priv->device_modified); - - /* updates */ - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_ID, priv->update_id); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_REMOTE_ID, priv->update_remote_id); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_SUMMARY, priv->update_summary); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_DESCRIPTION, priv->update_description); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_VERSION, priv->update_version); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_FILENAME, priv->update_filename); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_CHECKSUM, priv->update_checksum); - if (priv->update_checksum != NULL) - fwupd_pad_kv_csk (str, FWUPD_RESULT_KEY_UPDATE_CHECKSUM_KIND, priv->update_checksum_kind); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_LICENSE, priv->update_license); - fwupd_pad_kv_siz (str, FWUPD_RESULT_KEY_UPDATE_SIZE, priv->update_size); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_URI, priv->update_uri); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_HOMEPAGE, priv->update_homepage); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_VENDOR, priv->update_vendor); fwupd_pad_kv_ups (str, FWUPD_RESULT_KEY_UPDATE_STATE, priv->update_state); - fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_ERROR, priv->update_error); - if (priv->update_version != NULL) + + /* device and release */ + device_str = fwupd_device_to_string (priv->device); + g_string_append (str, device_str); + release_str = fwupd_release_to_string (priv->release); + g_string_append (str, release_str); + if (fwupd_release_get_version (priv->release) != NULL) fwupd_pad_kv_tfl (str, FWUPD_RESULT_KEY_UPDATE_TRUST_FLAGS, priv->update_trust_flags); return g_string_free (str, FALSE); @@ -1945,7 +1555,7 @@ fwupd_result_get_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_DEVICE_ID: - g_value_set_string (value, priv->device_id); + g_value_set_string (value, fwupd_device_get_id (priv->device)); break; case PROP_UNIQUE_ID: g_value_set_string (value, priv->unique_id); @@ -1965,8 +1575,7 @@ fwupd_result_set_property (GObject *object, guint prop_id, switch (prop_id) { case PROP_DEVICE_ID: - g_free (priv->device_id); - priv->device_id = g_strdup (g_value_get_string (value)); + fwupd_device_set_id (priv->device, g_value_get_string (value)); break; case PROP_UNIQUE_ID: g_free (priv->unique_id); @@ -2004,9 +1613,8 @@ static void fwupd_result_init (FwupdResult *result) { FwupdResultPrivate *priv = GET_PRIVATE (result); - priv->device_checksum_kind = G_CHECKSUM_SHA1; - priv->update_checksum_kind = G_CHECKSUM_SHA1; - priv->guids = g_ptr_array_new_with_free_func (g_free); + priv->release = fwupd_release_new (); + priv->device = fwupd_device_new (); } static void @@ -2015,30 +1623,10 @@ fwupd_result_finalize (GObject *object) FwupdResult *result = FWUPD_RESULT (object); FwupdResultPrivate *priv = GET_PRIVATE (result); - g_ptr_array_unref (priv->guids); + g_object_unref (priv->device); + g_object_unref (priv->release); g_free (priv->unique_id); - g_free (priv->device_description); - g_free (priv->device_checksum); - g_free (priv->device_id); - g_free (priv->device_name); - g_free (priv->device_vendor); - g_free (priv->device_provider); - g_free (priv->device_version); - g_free (priv->device_version_lowest); - g_free (priv->device_version_bootloader); - g_free (priv->update_description); g_free (priv->update_error); - g_free (priv->update_filename); - g_free (priv->update_checksum); - g_free (priv->update_id); - g_free (priv->update_license); - g_free (priv->update_name); - g_free (priv->update_summary); - g_free (priv->update_uri); - g_free (priv->update_homepage); - g_free (priv->update_vendor); - g_free (priv->update_version); - g_free (priv->update_remote_id); G_OBJECT_CLASS (fwupd_result_parent_class)->finalize (object); } @@ -2046,10 +1634,13 @@ fwupd_result_finalize (GObject *object) static void fwupd_result_from_variant_iter (FwupdResult *result, GVariantIter *iter) { + FwupdResultPrivate *priv = GET_PRIVATE (result); GVariant *value; const gchar *key; while (g_variant_iter_next (iter, "{&sv}", &key, &value)) { - fwupd_result_from_kv (result, key, value); + fwupd_result_from_key_value (result, key, value); + fwupd_release_from_key_value (priv->release, key, value); + fwupd_device_from_key_value (priv->device, key, value); g_variant_unref (value); } } @@ -2081,7 +1672,7 @@ fwupd_result_new_from_data (GVariant *data) } else if (g_strcmp0 (type_string, "{sa{sv}}") == 0) { res = fwupd_result_new (); g_variant_get (data, "{&sa{sv}}", &id, &iter); - fwupd_result_set_device_id (res, id); + fwupd_device_set_id (fwupd_result_get_device (res), id); fwupd_result_from_variant_iter (res, iter); } else { g_warning ("type %s not known", type_string); diff --git a/libfwupd/fwupd-result.h b/libfwupd/fwupd-result.h index 9e798418f..37d2d9288 100644 --- a/libfwupd/fwupd-result.h +++ b/libfwupd/fwupd-result.h @@ -24,7 +24,9 @@ #include +#include "fwupd-device.h" #include "fwupd-enums.h" +#include "fwupd-release.h" G_BEGIN_DECLS @@ -59,6 +61,10 @@ const gchar *fwupd_result_get_unique_id (FwupdResult *result); void fwupd_result_set_unique_id (FwupdResult *result, const gchar *unique_id); +/* helper objects */ +FwupdRelease *fwupd_result_get_release (FwupdResult *result); +FwupdDevice *fwupd_result_get_device (FwupdResult *result); + /* device-specific */ const gchar *fwupd_result_get_device_id (FwupdResult *result); void fwupd_result_set_device_id (FwupdResult *result, diff --git a/libfwupd/fwupd-self-test.c b/libfwupd/fwupd-self-test.c index c2946c279..4359c6871 100644 --- a/libfwupd/fwupd-self-test.c +++ b/libfwupd/fwupd-self-test.c @@ -97,6 +97,8 @@ fwupd_enums_func (void) static void fwupd_result_func (void) { + FwupdDevice *dev; + FwupdRelease *rel; gboolean ret; g_autofree gchar *str = NULL; g_autoptr(FwupdResult) result = NULL; @@ -104,31 +106,34 @@ fwupd_result_func (void) /* create dummy object */ result = fwupd_result_new (); - fwupd_result_set_device_checksum (result, "beefdead"); - fwupd_result_set_device_checksum_kind (result, G_CHECKSUM_SHA256); - fwupd_result_set_device_created (result, 1); - fwupd_result_set_device_flags (result, FWUPD_DEVICE_FLAG_ALLOW_OFFLINE); - fwupd_result_set_device_id (result, "USB:foo"); - fwupd_result_set_device_modified (result, 60 * 60 * 24); - fwupd_result_set_device_name (result, "ColorHug2"); - fwupd_result_add_guid (result, "2082b5e0-7a64-478a-b1b2-e3404fab6dad"); - fwupd_result_add_guid (result, "00000000-0000-0000-0000-000000000000"); - fwupd_result_set_update_checksum (result, "deadbeef"); - fwupd_result_set_update_description (result, "

Hi there!

"); - fwupd_result_set_update_filename (result, "firmware.bin"); - fwupd_result_set_update_id (result, "org.dave.ColorHug.firmware"); - fwupd_result_set_update_size (result, 1024); - fwupd_result_set_update_uri (result, "http://foo.com"); - fwupd_result_set_update_version (result, "1.2.3"); - fwupd_result_add_device_flag (result, FWUPD_DEVICE_FLAG_REQUIRE_AC); + dev = fwupd_result_get_device (result); + fwupd_device_set_checksum (dev, "beefdead"); + fwupd_device_set_checksum_kind (dev, G_CHECKSUM_SHA256); + fwupd_device_set_created (dev, 1); + fwupd_device_set_flags (dev, FWUPD_DEVICE_FLAG_ALLOW_OFFLINE); + fwupd_device_set_id (dev, "USB:foo"); + fwupd_device_set_modified (dev, 60 * 60 * 24); + fwupd_device_set_name (dev, "ColorHug2"); + fwupd_device_add_guid (dev, "2082b5e0-7a64-478a-b1b2-e3404fab6dad"); + fwupd_device_add_guid (dev, "00000000-0000-0000-0000-000000000000"); + fwupd_device_add_flag (dev, FWUPD_DEVICE_FLAG_REQUIRE_AC); fwupd_result_set_update_trust_flags (result, FWUPD_TRUST_FLAG_PAYLOAD); + + rel = fwupd_result_get_release (result); + fwupd_release_set_checksum (rel, "deadbeef"); + fwupd_release_set_description (rel, "

Hi there!

"); + fwupd_release_set_filename (rel, "firmware.bin"); + fwupd_release_set_appstream_id (rel, "org.dave.ColorHug.firmware"); + fwupd_release_set_size (rel, 1024); + fwupd_release_set_uri (rel, "http://foo.com"); + fwupd_release_set_version (rel, "1.2.3"); str = fwupd_result_to_string (result); g_print ("\n%s", str); /* check GUIDs */ - g_assert (fwupd_result_has_guid (result, "2082b5e0-7a64-478a-b1b2-e3404fab6dad")); - g_assert (fwupd_result_has_guid (result, "00000000-0000-0000-0000-000000000000")); - g_assert (!fwupd_result_has_guid (result, "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")); + g_assert (fwupd_device_has_guid (dev, "2082b5e0-7a64-478a-b1b2-e3404fab6dad")); + g_assert (fwupd_device_has_guid (dev, "00000000-0000-0000-0000-000000000000")); + g_assert (!fwupd_device_has_guid (dev, "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")); ret = as_test_compare_lines (str, "ColorHug2\n" @@ -156,6 +161,7 @@ fwupd_result_func (void) static void fwupd_client_devices_func (void) { + FwupdDevice *dev; FwupdResult *res; g_autoptr(FwupdClient) client = NULL; g_autoptr(GPtrArray) array = NULL; @@ -176,8 +182,9 @@ fwupd_client_devices_func (void) /* check device */ res = g_ptr_array_index (array, 0); g_assert (FWUPD_IS_RESULT (res)); - g_assert_cmpstr (fwupd_result_get_guid_default (res), !=, NULL); - g_assert_cmpstr (fwupd_result_get_device_id (res), !=, NULL); + dev = fwupd_result_get_device (res); + g_assert_cmpstr (fwupd_device_get_guid_default (dev), !=, NULL); + g_assert_cmpstr (fwupd_device_get_id (dev), !=, NULL); } static void @@ -230,6 +237,7 @@ fwupd_client_remotes_func (void) static void fwupd_client_updates_func (void) { + FwupdDevice *dev; FwupdResult *res; g_autoptr(FwupdClient) client = NULL; g_autoptr(GPtrArray) array = NULL; @@ -250,8 +258,9 @@ fwupd_client_updates_func (void) /* check device */ res = g_ptr_array_index (array, 0); g_assert (FWUPD_IS_RESULT (res)); - g_assert_cmpstr (fwupd_result_get_guid_default (res), !=, NULL); - g_assert_cmpstr (fwupd_result_get_device_id (res), !=, NULL); + dev = fwupd_result_get_device (res); + g_assert_cmpstr (fwupd_device_get_guid_default (dev), !=, NULL); + g_assert_cmpstr (fwupd_device_get_id (dev), !=, NULL); } static gboolean diff --git a/libfwupd/fwupd.h b/libfwupd/fwupd.h index 2dc26f627..7f6fd9ae4 100644 --- a/libfwupd/fwupd.h +++ b/libfwupd/fwupd.h @@ -30,8 +30,10 @@ #define __FWUPD_H_INSIDE__ #include +#include #include #include +#include #include #include #include diff --git a/libfwupd/meson.build b/libfwupd/meson.build index 8a46a06a6..74ee8fe2a 100644 --- a/libfwupd/meson.build +++ b/libfwupd/meson.build @@ -15,9 +15,11 @@ install_headers( install_headers([ 'fwupd-client.h', + 'fwupd-device.h', 'fwupd-enums.h', 'fwupd-error.h', 'fwupd-remote.h', + 'fwupd-release.h', 'fwupd-result.h', fwupd_version_h, ], @@ -30,8 +32,10 @@ fwupd = shared_library( 'fwupd', sources : [ 'fwupd-client.c', + 'fwupd-device.c', 'fwupd-enums.c', 'fwupd-error.c', + 'fwupd-release.c', 'fwupd-remote.c', 'fwupd-result.c', ],