summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2023-01-23 15:19:09 +0000
committerRichard Hughes <richard@hughsie.com>2023-01-23 16:39:36 +0000
commitd6ad4f72ad897fec83719b744a2265f22e996fe6 (patch)
tree1d2d3a2e7e0b11954702a1c430951ea811910a2f
parent52f1b23dae6b2700f62ec3bef425ffff9070087c (diff)
downloadgusb-d6ad4f72ad897fec83719b744a2265f22e996fe6.tar.gz
Add g_usb_device_remove_tag() for future use
-rw-r--r--gusb/gusb-device.c26
-rw-r--r--gusb/gusb-device.h2
-rw-r--r--gusb/gusb-self-test.c7
-rw-r--r--gusb/libgusb.ver6
4 files changed, 41 insertions, 0 deletions
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;