From d6ad4f72ad897fec83719b744a2265f22e996fe6 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Mon, 23 Jan 2023 15:19:09 +0000 Subject: Add g_usb_device_remove_tag() for future use --- gusb/gusb-device.c | 26 ++++++++++++++++++++++++++ gusb/gusb-device.h | 2 ++ gusb/gusb-self-test.c | 7 +++++++ gusb/libgusb.ver | 6 ++++++ 4 files changed, 41 insertions(+) diff --git a/gusb/gusb-device.c b/gusb/gusb-device.c index 9217be8..3c0a125 100644 --- a/gusb/gusb-device.c +++ b/gusb/gusb-device.c @@ -501,6 +501,32 @@ g_usb_device_add_tag(GUsbDevice *self, const gchar *tag) g_ptr_array_add(priv->tags, g_strdup(tag)); } +/** + * g_usb_device_remove_tag: + * @self: a #GUsbDevice + * @tag: a tag, for example `bootloader` or `runtime-reload` + * + * Removes a tag, which is included in the JSON log to identify the specific device. + * + * Since: 0.4.4 + **/ +void +g_usb_device_remove_tag(GUsbDevice *self, const gchar *tag) +{ + GUsbDevicePrivate *priv = GET_PRIVATE(self); + + g_return_if_fail(G_USB_IS_DEVICE(self)); + g_return_if_fail(tag != NULL); + + for (guint i = 0; i < priv->tags->len; i++) { + const gchar *tag_tmp = g_ptr_array_index(priv->tags, i); + if (g_strcmp0(tag_tmp, tag) == 0) { + g_ptr_array_remove_index(priv->tags, i); + return; + } + } +} + /* not defined in FreeBSD */ #ifndef HAVE_LIBUSB_GET_PARENT static libusb_device * diff --git a/gusb/gusb-device.h b/gusb/gusb-device.h index 5c5a3d6..2708f43 100644 --- a/gusb/gusb-device.h +++ b/gusb/gusb-device.h @@ -172,6 +172,8 @@ g_usb_device_get_device_protocol(GUsbDevice *self); void g_usb_device_add_tag(GUsbDevice *self, const gchar *tag); +void +g_usb_device_remove_tag(GUsbDevice *self, const gchar *tag); gboolean g_usb_device_has_tag(GUsbDevice *self, const gchar *tag); diff --git a/gusb/gusb-self-test.c b/gusb/gusb-self-test.c index 072e3a0..970ae21 100644 --- a/gusb/gusb-self-test.c +++ b/gusb/gusb-self-test.c @@ -35,6 +35,13 @@ gusb_device_func(void) g_assert_cmpint(g_usb_device_get_vid(device), >, 0x0000); g_assert_cmpint(g_usb_device_get_pid(device), >, 0x0000); + + g_assert_false(g_usb_device_has_tag(device, "foobar")); + g_usb_device_add_tag(device, "foobar"); + g_usb_device_add_tag(device, "foobar"); + g_assert_true(g_usb_device_has_tag(device, "foobar")); + g_usb_device_remove_tag(device, "foobar"); + g_assert_false(g_usb_device_has_tag(device, "foobar")); } static void diff --git a/gusb/libgusb.ver b/gusb/libgusb.ver index 9862f86..d1f9455 100644 --- a/gusb/libgusb.ver +++ b/gusb/libgusb.ver @@ -199,3 +199,9 @@ LIBGUSB_0.4.3 { g_usb_device_has_tag; local: *; } LIBGUSB_0.4.1; + +LIBGUSB_0.4.4 { + global: + g_usb_device_remove_tag; + local: *; +} LIBGUSB_0.4.3; -- cgit v1.2.1