mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-07 10:27:36 +00:00
trivial: Add helpers that can be used for returning local files
This also allows us to drop the use of FwupdResult in the daemon.
This commit is contained in:
parent
cc3de2efa4
commit
93b1576bef
@ -29,6 +29,7 @@
|
|||||||
#include "fwupd-enums-private.h"
|
#include "fwupd-enums-private.h"
|
||||||
#include "fwupd-error.h"
|
#include "fwupd-error.h"
|
||||||
#include "fwupd-device-private.h"
|
#include "fwupd-device-private.h"
|
||||||
|
#include "fwupd-release-private.h"
|
||||||
|
|
||||||
static void fwupd_device_finalize (GObject *object);
|
static void fwupd_device_finalize (GObject *object);
|
||||||
|
|
||||||
@ -54,6 +55,7 @@ typedef struct {
|
|||||||
guint32 flashes_left;
|
guint32 flashes_left;
|
||||||
FwupdUpdateState update_state;
|
FwupdUpdateState update_state;
|
||||||
gchar *update_error;
|
gchar *update_error;
|
||||||
|
FwupdRelease *release_default;
|
||||||
} FwupdDevicePrivate;
|
} FwupdDevicePrivate;
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_PRIVATE (FwupdDevice, fwupd_device, G_TYPE_OBJECT)
|
G_DEFINE_TYPE_WITH_PRIVATE (FwupdDevice, fwupd_device, G_TYPE_OBJECT)
|
||||||
@ -917,6 +919,7 @@ fwupd_device_to_variant_builder (FwupdDevice *device, GVariantBuilder *builder)
|
|||||||
GVariant *
|
GVariant *
|
||||||
fwupd_device_to_data (FwupdDevice *device, const gchar *type_string)
|
fwupd_device_to_data (FwupdDevice *device, const gchar *type_string)
|
||||||
{
|
{
|
||||||
|
FwupdDevicePrivate *priv = GET_PRIVATE (device);
|
||||||
GVariantBuilder builder;
|
GVariantBuilder builder;
|
||||||
|
|
||||||
g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL);
|
g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL);
|
||||||
@ -925,6 +928,8 @@ fwupd_device_to_data (FwupdDevice *device, const gchar *type_string)
|
|||||||
/* create an array with all the metadata in */
|
/* create an array with all the metadata in */
|
||||||
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
|
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
|
||||||
fwupd_device_to_variant_builder (device, &builder);
|
fwupd_device_to_variant_builder (device, &builder);
|
||||||
|
if (priv->release_default != NULL)
|
||||||
|
fwupd_release_to_variant_builder (priv->release_default, &builder);
|
||||||
|
|
||||||
/* supported types */
|
/* supported types */
|
||||||
if (g_strcmp0 (type_string, "a{sv}") == 0)
|
if (g_strcmp0 (type_string, "a{sv}") == 0)
|
||||||
@ -1165,6 +1170,43 @@ fwupd_device_set_update_error (FwupdDevice *device, const gchar *update_error)
|
|||||||
priv->update_error = g_strdup (update_error);
|
priv->update_error = g_strdup (update_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fwupd_device_get_release_default:
|
||||||
|
* @device: A #FwupdDevice
|
||||||
|
*
|
||||||
|
* Gets the default release for this device.
|
||||||
|
*
|
||||||
|
* Returns: (transfer none): the #FwupdRelease, or %NULL if not set
|
||||||
|
*
|
||||||
|
* Since: 0.9.8
|
||||||
|
**/
|
||||||
|
FwupdRelease *
|
||||||
|
fwupd_device_get_release_default (FwupdDevice *device)
|
||||||
|
{
|
||||||
|
FwupdDevicePrivate *priv = GET_PRIVATE (device);
|
||||||
|
g_return_val_if_fail (FWUPD_IS_DEVICE (device), NULL);
|
||||||
|
return priv->release_default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fwupd_device_add_release:
|
||||||
|
* @device: A #FwupdDevice
|
||||||
|
* @release: a #FwupdRelease
|
||||||
|
*
|
||||||
|
* Adds a release for this device.
|
||||||
|
*
|
||||||
|
* NOTE: devices can only store one release at this point in time.
|
||||||
|
*
|
||||||
|
* Since: 0.9.8
|
||||||
|
**/
|
||||||
|
void
|
||||||
|
fwupd_device_add_release (FwupdDevice *device, FwupdRelease *release)
|
||||||
|
{
|
||||||
|
FwupdDevicePrivate *priv = GET_PRIVATE (device);
|
||||||
|
g_return_if_fail (FWUPD_IS_DEVICE (device));
|
||||||
|
g_set_object (&priv->release_default, release);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fwupd_pad_kv_ups (GString *str, const gchar *key, FwupdUpdateState value)
|
fwupd_pad_kv_ups (GString *str, const gchar *key, FwupdUpdateState value)
|
||||||
{
|
{
|
||||||
@ -1257,6 +1299,8 @@ fwupd_device_finalize (GObject *object)
|
|||||||
FwupdDevice *device = FWUPD_DEVICE (object);
|
FwupdDevice *device = FWUPD_DEVICE (object);
|
||||||
FwupdDevicePrivate *priv = GET_PRIVATE (device);
|
FwupdDevicePrivate *priv = GET_PRIVATE (device);
|
||||||
|
|
||||||
|
if (priv->release_default != NULL)
|
||||||
|
g_object_unref (priv->release_default);
|
||||||
g_free (priv->description);
|
g_free (priv->description);
|
||||||
g_free (priv->id);
|
g_free (priv->id);
|
||||||
g_free (priv->name);
|
g_free (priv->name);
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
|
|
||||||
#include "fwupd-enums.h"
|
#include "fwupd-enums.h"
|
||||||
|
#include "fwupd-release.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -114,6 +115,9 @@ void fwupd_device_set_update_state (FwupdDevice *device,
|
|||||||
const gchar *fwupd_device_get_update_error (FwupdDevice *device);
|
const gchar *fwupd_device_get_update_error (FwupdDevice *device);
|
||||||
void fwupd_device_set_update_error (FwupdDevice *device,
|
void fwupd_device_set_update_error (FwupdDevice *device,
|
||||||
const gchar *update_error);
|
const gchar *update_error);
|
||||||
|
void fwupd_device_add_release (FwupdDevice *device,
|
||||||
|
FwupdRelease *release);
|
||||||
|
FwupdRelease *fwupd_device_get_release_default (FwupdDevice *device);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
@ -1790,18 +1790,16 @@ fu_engine_get_store_from_blob (FuEngine *self, GBytes *blob_cab, GError **error)
|
|||||||
return g_steal_pointer (&store);
|
return g_steal_pointer (&store);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FwupdResult *
|
static FwupdDevice *
|
||||||
fu_engine_get_result_from_app (FuEngine *self, AsApp *app, GError **error)
|
fu_engine_get_result_from_app (FuEngine *self, AsApp *app, GError **error)
|
||||||
{
|
{
|
||||||
FwupdTrustFlags trust_flags = FWUPD_TRUST_FLAG_NONE;
|
FwupdTrustFlags trust_flags = FWUPD_TRUST_FLAG_NONE;
|
||||||
AsRelease *release;
|
AsRelease *release;
|
||||||
FwupdDevice *dev;
|
|
||||||
FwupdRelease *rel;
|
|
||||||
GPtrArray *provides;
|
GPtrArray *provides;
|
||||||
g_autoptr(FwupdResult) res = NULL;
|
g_autoptr(FwupdDevice) dev = NULL;
|
||||||
|
g_autoptr(FwupdRelease) rel = NULL;
|
||||||
|
|
||||||
res = fwupd_result_new ();
|
dev = fwupd_device_new ();
|
||||||
dev = fwupd_result_get_device (res);
|
|
||||||
provides = as_app_get_provides (app);
|
provides = as_app_get_provides (app);
|
||||||
for (guint i = 0; i < provides->len; i++) {
|
for (guint i = 0; i < provides->len; i++) {
|
||||||
AsProvide *prov = AS_PROVIDE (g_ptr_array_index (provides, i));
|
AsProvide *prov = AS_PROVIDE (g_ptr_array_index (provides, i));
|
||||||
@ -1851,7 +1849,7 @@ fu_engine_get_result_from_app (FuEngine *self, AsApp *app, GError **error)
|
|||||||
|
|
||||||
/* create a result with all the metadata in */
|
/* create a result with all the metadata in */
|
||||||
fwupd_device_set_description (dev, as_app_get_description (app, NULL));
|
fwupd_device_set_description (dev, as_app_get_description (app, NULL));
|
||||||
rel = fwupd_result_get_release (res);
|
rel = fwupd_release_new ();
|
||||||
fwupd_release_set_trust_flags (rel, trust_flags);
|
fwupd_release_set_trust_flags (rel, trust_flags);
|
||||||
fwupd_release_set_homepage (rel, as_app_get_url_item (app, AS_URL_KIND_HOMEPAGE));
|
fwupd_release_set_homepage (rel, as_app_get_url_item (app, AS_URL_KIND_HOMEPAGE));
|
||||||
fwupd_release_set_license (rel, as_app_get_project_license (app));
|
fwupd_release_set_license (rel, as_app_get_project_license (app));
|
||||||
@ -1860,7 +1858,8 @@ fu_engine_get_result_from_app (FuEngine *self, AsApp *app, GError **error)
|
|||||||
fwupd_release_set_vendor (rel, as_app_get_developer_name (app, NULL));
|
fwupd_release_set_vendor (rel, as_app_get_developer_name (app, NULL));
|
||||||
fwupd_release_set_appstream_id (rel, as_app_get_id (app));
|
fwupd_release_set_appstream_id (rel, as_app_get_id (app));
|
||||||
fu_engine_set_release_from_appstream (self, rel, release);
|
fu_engine_set_release_from_appstream (self, rel, release);
|
||||||
return g_steal_pointer (&res);
|
fwupd_device_add_release (dev, rel);
|
||||||
|
return g_steal_pointer (&dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1873,7 +1872,7 @@ fu_engine_get_result_from_app (FuEngine *self, AsApp *app, GError **error)
|
|||||||
*
|
*
|
||||||
* Note: this will close the fd when done
|
* Note: this will close the fd when done
|
||||||
*
|
*
|
||||||
* Returns: (transfer container) (element-type FwupdResult): results
|
* Returns: (transfer container) (element-type FwupdDevice): results
|
||||||
**/
|
**/
|
||||||
GPtrArray *
|
GPtrArray *
|
||||||
fu_engine_get_details_local (FuEngine *self, gint fd, GError **error)
|
fu_engine_get_details_local (FuEngine *self, gint fd, GError **error)
|
||||||
@ -1907,7 +1906,7 @@ fu_engine_get_details_local (FuEngine *self, gint fd, GError **error)
|
|||||||
details = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
|
details = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
|
||||||
for (guint i = 0; i < apps->len; i++) {
|
for (guint i = 0; i < apps->len; i++) {
|
||||||
AsApp *app = g_ptr_array_index (apps, i);
|
AsApp *app = g_ptr_array_index (apps, i);
|
||||||
FwupdResult *res = NULL;
|
FwupdDevice *res = NULL;
|
||||||
|
|
||||||
/* check we can install it */
|
/* check we can install it */
|
||||||
if (!fu_engine_check_requirements (app, NULL, error))
|
if (!fu_engine_check_requirements (app, NULL, error))
|
||||||
@ -1962,7 +1961,7 @@ fu_engine_get_devices (FuEngine *self, GError **error)
|
|||||||
*
|
*
|
||||||
* Gets the list of updates.
|
* Gets the list of updates.
|
||||||
*
|
*
|
||||||
* Returns: (transfer container) (element-type FwupdResult): results
|
* Returns: (transfer container) (element-type FwupdDevice): results
|
||||||
**/
|
**/
|
||||||
GPtrArray *
|
GPtrArray *
|
||||||
fu_engine_get_updates (FuEngine *self, GError **error)
|
fu_engine_get_updates (FuEngine *self, GError **error)
|
||||||
@ -1977,7 +1976,6 @@ fu_engine_get_updates (FuEngine *self, GError **error)
|
|||||||
FuDeviceItem *item = g_ptr_array_index (self->devices, i);
|
FuDeviceItem *item = g_ptr_array_index (self->devices, i);
|
||||||
g_autoptr(GError) error_local = NULL;
|
g_autoptr(GError) error_local = NULL;
|
||||||
g_autoptr(GPtrArray) rels = NULL;
|
g_autoptr(GPtrArray) rels = NULL;
|
||||||
g_autoptr(FwupdResult) result = fwupd_result_new ();
|
|
||||||
FwupdRelease *rel_default;
|
FwupdRelease *rel_default;
|
||||||
|
|
||||||
rels = fu_engine_get_upgrades (self, fu_device_get_id (item->device), &error_local);
|
rels = fu_engine_get_upgrades (self, fu_device_get_id (item->device), &error_local);
|
||||||
@ -1986,9 +1984,8 @@ fu_engine_get_updates (FuEngine *self, GError **error)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
rel_default = g_ptr_array_index (rels, 0);
|
rel_default = g_ptr_array_index (rels, 0);
|
||||||
fwupd_result_set_release (result, rel_default);
|
fwupd_device_add_release (FWUPD_DEVICE (item->device), rel_default);
|
||||||
fwupd_result_set_device (result, FWUPD_DEVICE (item->device));
|
g_ptr_array_add (updates, g_object_ref (item->device));
|
||||||
g_ptr_array_add (updates, g_steal_pointer (&result));
|
|
||||||
}
|
}
|
||||||
if (updates->len == 0) {
|
if (updates->len == 0) {
|
||||||
g_set_error_literal (error,
|
g_set_error_literal (error,
|
||||||
@ -2112,7 +2109,7 @@ fu_engine_get_releases_for_device (FuEngine *self, FuDevice *device, GError **er
|
|||||||
*
|
*
|
||||||
* Gets the releases available for a specific device.
|
* Gets the releases available for a specific device.
|
||||||
*
|
*
|
||||||
* Returns: (transfer container) (element-type FwupdResult): results
|
* Returns: (transfer container) (element-type FwupdDevice): results
|
||||||
**/
|
**/
|
||||||
GPtrArray *
|
GPtrArray *
|
||||||
fu_engine_get_releases (FuEngine *self, const gchar *device_id, GError **error)
|
fu_engine_get_releases (FuEngine *self, const gchar *device_id, GError **error)
|
||||||
@ -2152,7 +2149,7 @@ fu_engine_get_releases (FuEngine *self, const gchar *device_id, GError **error)
|
|||||||
*
|
*
|
||||||
* Gets the downgrades available for a specific device.
|
* Gets the downgrades available for a specific device.
|
||||||
*
|
*
|
||||||
* Returns: (transfer container) (element-type FwupdResult): results
|
* Returns: (transfer container) (element-type FwupdDevice): results
|
||||||
**/
|
**/
|
||||||
GPtrArray *
|
GPtrArray *
|
||||||
fu_engine_get_downgrades (FuEngine *self, const gchar *device_id, GError **error)
|
fu_engine_get_downgrades (FuEngine *self, const gchar *device_id, GError **error)
|
||||||
@ -2245,7 +2242,7 @@ fu_engine_get_downgrades (FuEngine *self, const gchar *device_id, GError **error
|
|||||||
*
|
*
|
||||||
* Gets the upgrades available for a specific device.
|
* Gets the upgrades available for a specific device.
|
||||||
*
|
*
|
||||||
* Returns: (transfer container) (element-type FwupdResult): results
|
* Returns: (transfer container) (element-type FwupdDevice): results
|
||||||
**/
|
**/
|
||||||
GPtrArray *
|
GPtrArray *
|
||||||
fu_engine_get_upgrades (FuEngine *self, const gchar *device_id, GError **error)
|
fu_engine_get_upgrades (FuEngine *self, const gchar *device_id, GError **error)
|
||||||
@ -2353,9 +2350,9 @@ fu_engine_clear_results (FuEngine *self, const gchar *device_id, GError **error)
|
|||||||
*
|
*
|
||||||
* Gets the historical state of a specific device operation.
|
* Gets the historical state of a specific device operation.
|
||||||
*
|
*
|
||||||
* Returns: (transfer container): a #FwupdResult, or %NULL
|
* Returns: (transfer container): a #FwupdDevice, or %NULL
|
||||||
**/
|
**/
|
||||||
FwupdResult *
|
FwupdDevice *
|
||||||
fu_engine_get_results (FuEngine *self, const gchar *device_id, GError **error)
|
fu_engine_get_results (FuEngine *self, const gchar *device_id, GError **error)
|
||||||
{
|
{
|
||||||
FuDeviceItem *item;
|
FuDeviceItem *item;
|
||||||
|
@ -66,7 +66,7 @@ GPtrArray *fu_engine_get_downgrades (FuEngine *self,
|
|||||||
GPtrArray *fu_engine_get_upgrades (FuEngine *self,
|
GPtrArray *fu_engine_get_upgrades (FuEngine *self,
|
||||||
const gchar *device_id,
|
const gchar *device_id,
|
||||||
GError **error);
|
GError **error);
|
||||||
FwupdResult *fu_engine_get_results (FuEngine *self,
|
FwupdDevice *fu_engine_get_results (FuEngine *self,
|
||||||
const gchar *device_id,
|
const gchar *device_id,
|
||||||
GError **error);
|
GError **error);
|
||||||
gboolean fu_engine_clear_results (FuEngine *self,
|
gboolean fu_engine_clear_results (FuEngine *self,
|
||||||
|
@ -230,8 +230,8 @@ fu_main_result_array_to_variant (GPtrArray *results)
|
|||||||
g_return_val_if_fail (results->len > 0, NULL);
|
g_return_val_if_fail (results->len > 0, NULL);
|
||||||
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
|
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
|
||||||
for (guint i = 0; i < results->len; i++) {
|
for (guint i = 0; i < results->len; i++) {
|
||||||
FwupdResult *result = g_ptr_array_index (results, i);
|
FwupdDevice *result = g_ptr_array_index (results, i);
|
||||||
GVariant *tmp = fwupd_result_to_data (result, "{sa{sv}}");
|
GVariant *tmp = fwupd_device_to_data (result, "{sa{sv}}");
|
||||||
g_variant_builder_add_value (&builder, tmp);
|
g_variant_builder_add_value (&builder, tmp);
|
||||||
}
|
}
|
||||||
return g_variant_new ("(a{sa{sv}})", &builder);
|
return g_variant_new ("(a{sa{sv}})", &builder);
|
||||||
@ -504,7 +504,7 @@ fu_main_daemon_method_call (GDBusConnection *connection, const gchar *sender,
|
|||||||
}
|
}
|
||||||
if (g_strcmp0 (method_name, "GetResults") == 0) {
|
if (g_strcmp0 (method_name, "GetResults") == 0) {
|
||||||
const gchar *device_id = NULL;
|
const gchar *device_id = NULL;
|
||||||
g_autoptr(FwupdResult) result = NULL;
|
g_autoptr(FwupdDevice) result = NULL;
|
||||||
g_variant_get (parameters, "(&s)", &device_id);
|
g_variant_get (parameters, "(&s)", &device_id);
|
||||||
g_debug ("Called %s(%s)", method_name, device_id);
|
g_debug ("Called %s(%s)", method_name, device_id);
|
||||||
result = fu_engine_get_results (priv->engine, device_id, &error);
|
result = fu_engine_get_results (priv->engine, device_id, &error);
|
||||||
@ -512,7 +512,7 @@ fu_main_daemon_method_call (GDBusConnection *connection, const gchar *sender,
|
|||||||
g_dbus_method_invocation_return_gerror (invocation, error);
|
g_dbus_method_invocation_return_gerror (invocation, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
val = fwupd_result_to_data (result, "(a{sv})");
|
val = fwupd_device_to_data (result, "(a{sv})");
|
||||||
g_dbus_method_invocation_return_value (invocation, val);
|
g_dbus_method_invocation_return_value (invocation, val);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user