Add fu_device_remove_backend_tag() for future use

This commit is contained in:
Richard Hughes 2023-01-24 13:15:28 +00:00 committed by Mario Limonciello
parent 8f4604a14a
commit 83c6b33778
5 changed files with 49 additions and 4 deletions

View File

@ -1293,6 +1293,33 @@ fu_device_add_backend_tag(FuDevice *self, const gchar *backend_tag)
g_object_notify(G_OBJECT(self), "backend-tags");
}
/**
* fu_device_remove_backend_tag:
* @self: a #FuDevice
* @backend_tag: a tag, for example `bootloader` or `runtime-reload`
*
* Removes a backend tag, which allows the backend to identify the specific device for a specific
* phase.
*
* Since: 1.8.11
**/
void
fu_device_remove_backend_tag(FuDevice *self, const gchar *backend_tag)
{
FuDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FU_IS_DEVICE(self));
g_return_if_fail(backend_tag != NULL);
for (guint i = 0; i < priv->backend_tags->len; i++) {
const gchar *backend_tag_tmp = g_ptr_array_index(priv->backend_tags, i);
if (g_strcmp0(backend_tag_tmp, backend_tag) == 0) {
g_ptr_array_remove_index(priv->backend_tags, i);
g_object_notify(G_OBJECT(self), "backend-tags");
break;
}
}
}
/**
* fu_device_has_backend_tag:
* @self: a #FuDevice

View File

@ -547,6 +547,8 @@ void
fu_device_set_version_from_uint64(FuDevice *self, guint64 version_raw);
void
fu_device_add_backend_tag(FuDevice *self, const gchar *backend_tag);
void
fu_device_remove_backend_tag(FuDevice *self, const gchar *backend_tag);
gboolean
fu_device_has_backend_tag(FuDevice *self, const gchar *backend_tag);
GPtrArray *

View File

@ -1217,6 +1217,8 @@ fu_device_func(void)
g_assert_cmpint(fu_device_get_backend_tags(device)->len, ==, 2);
g_assert_true(fu_device_has_backend_tag(device, "foo"));
g_assert_false(fu_device_has_backend_tag(device, "bazbazbazbazbaz"));
fu_device_remove_backend_tag(device, "foo");
g_assert_false(fu_device_has_backend_tag(device, "foo"));
}
static void

View File

@ -86,15 +86,23 @@ fu_usb_device_finalize(GObject *object)
G_OBJECT_CLASS(fu_usb_device_parent_class)->finalize(object);
}
#if G_USB_CHECK_VERSION(0, 4, 1)
#if G_USB_CHECK_VERSION(0, 4, 4)
static void
fu_usb_device_backend_tags_notify_cb(GObject *object, GParamSpec *pspec, FuUsbDevice *device)
{
FuUsbDevicePrivate *priv = GET_PRIVATE(device);
GPtrArray *backend_tags = fu_device_get_backend_tags(FU_DEVICE(device));
g_autoptr(GPtrArray) usb_device_tags = g_usb_device_get_tags(priv->usb_device);
for (guint i = 0; i < usb_device_tags->len; i++) {
const gchar *tag = g_ptr_array_index(usb_device_tags, i);
if (!fu_device_has_backend_tag(FU_DEVICE(device), tag))
g_usb_device_remove_tag(priv->usb_device, tag);
}
for (guint i = 0; i < backend_tags->len; i++) {
const gchar *backend_tag = g_ptr_array_index(backend_tags, i);
g_usb_device_add_tag(priv->usb_device, backend_tag);
const gchar *tag = g_ptr_array_index(backend_tags, i);
if (!g_usb_device_has_tag(priv->usb_device, tag))
g_usb_device_add_tag(priv->usb_device, tag);
}
}
#endif
@ -116,7 +124,7 @@ fu_usb_device_init(FuUsbDevice *device)
NULL);
#endif
#if G_USB_CHECK_VERSION(0, 4, 1)
#if G_USB_CHECK_VERSION(0, 4, 4)
/* copy this to the GUsbDevice */
g_signal_connect(FU_DEVICE(device),
"notify::backend-tags",

View File

@ -1162,3 +1162,9 @@ LIBFWUPDPLUGIN_1.8.10 {
fu_pefile_firmware_new;
local: *;
} LIBFWUPDPLUGIN_1.8.9;
LIBFWUPDPLUGIN_1.8.11 {
global:
fu_device_remove_backend_tag;
local: *;
} LIBFWUPDPLUGIN_1.8.10;