[libgudev/wip/muktupavels/current-tags: 2/3] device: add g_udev_device_get_current_tags
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgudev/wip/muktupavels/current-tags: 2/3] device: add g_udev_device_get_current_tags
- Date: Tue, 9 Aug 2022 11:50:03 +0000 (UTC)
commit 1f76c2a79f43c1afd48854aec92bbbf2010f96e7
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Wed May 11 22:06:06 2022 +0300
device: add g_udev_device_get_current_tags
Starting with systemd-udevd 247 tags are "sticky" meaning that once
a tag is assigned to a device it will not be removed from the device
again until the device itself is removed.
New property CURRENT_TAGS has been added that works similar to the
existing TAGS property but only lists tags set by the most recent
uevent/database update.
https://lists.freedesktop.org/archives/systemd-devel/2020-November/045646.html
gudev/gudevdevice.c | 38 ++++++++++++++++++++++++++++++++++++++
gudev/gudevdevice.h | 1 +
libgudev-1.0.sym | 1 +
meson.build | 5 ++++-
tests/test-gudevdevice.c | 5 +++++
5 files changed, 49 insertions(+), 1 deletion(-)
---
diff --git a/gudev/gudevdevice.c b/gudev/gudevdevice.c
index 248d272..25af9d1 100644
--- a/gudev/gudevdevice.c
+++ b/gudev/gudevdevice.c
@@ -76,6 +76,7 @@ struct _GUdevDevicePrivate
gchar **property_keys;
gchar **sysfs_attr_keys;
gchar **tags;
+ gchar **current_tags;
GHashTable *prop_strvs;
GHashTable *sysfs_attr_strvs;
};
@@ -91,6 +92,7 @@ g_udev_device_finalize (GObject *object)
g_strfreev (device->priv->property_keys);
g_strfreev (device->priv->sysfs_attr_keys);
g_strfreev (device->priv->tags);
+ g_strfreev (device->priv->current_tags);
if (device->priv->udevice != NULL)
udev_device_unref (device->priv->udevice);
@@ -119,6 +121,20 @@ g_udev_device_init (GUdevDevice *device)
device->priv = g_udev_device_get_instance_private (device);
}
+static void
+fetch_current_tags (GUdevDevice *device)
+{
+ struct udev_list_entry *l;
+ GPtrArray *p;
+
+ p = g_ptr_array_new ();
+ for (l = udev_device_get_current_tags_list_entry (device->priv->udevice); l != NULL; l =
udev_list_entry_get_next (l))
+ {
+ g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l)));
+ }
+ g_ptr_array_add (p, NULL);
+ device->priv->current_tags = (gchar **) g_ptr_array_free (p, FALSE);
+}
GUdevDevice *
_g_udev_device_new (struct udev_device *udevice)
@@ -128,6 +144,8 @@ _g_udev_device_new (struct udev_device *udevice)
device = G_UDEV_DEVICE (g_object_new (G_UDEV_TYPE_DEVICE, NULL));
device->priv->udevice = udev_device_ref (udevice);
+ fetch_current_tags (device);
+
return device;
}
@@ -1206,6 +1224,26 @@ g_udev_device_get_tags (GUdevDevice *device)
return (const gchar * const *) device->priv->tags;
}
+/**
+ * g_udev_device_get_current_tags:
+ * @device: A #GUdevDevice.
+ *
+ * Gets all current tags for @device.
+ *
+ * https://www.freedesktop.org/software/systemd/man/udev_device_has_current_tag.html
+ *
+ * Returns: (transfer none) (array zero-terminated=1) (element-type utf8): A %NULL terminated string array
of current tags. This array is owned by @device and should not be freed by the caller.
+ *
+ * Since: 238
+ */
+const gchar* const *
+g_udev_device_get_current_tags (GUdevDevice *device)
+{
+ g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
+
+ return (const gchar * const *) device->priv->current_tags;
+}
+
/**
* g_udev_device_get_is_initialized:
* @device: A #GUdevDevice.
diff --git a/gudev/gudevdevice.h b/gudev/gudevdevice.h
index 69ecc0a..7d674f9 100644
--- a/gudev/gudevdevice.h
+++ b/gudev/gudevdevice.h
@@ -115,6 +115,7 @@ gboolean g_udev_device_get_sysfs_attr_as_boolean (GUdevDevice *devic
const gchar* const *g_udev_device_get_sysfs_attr_as_strv (GUdevDevice *device,
const gchar *name);
const gchar* const *g_udev_device_get_tags (GUdevDevice *device);
+const gchar* const *g_udev_device_get_current_tags (GUdevDevice *device);
gboolean g_udev_device_has_sysfs_attr_uncached (GUdevDevice *device,
const gchar *key);
diff --git a/libgudev-1.0.sym b/libgudev-1.0.sym
index ab9cccf..170f202 100644
--- a/libgudev-1.0.sym
+++ b/libgudev-1.0.sym
@@ -44,6 +44,7 @@ global:
g_udev_device_get_sysfs_attr_keys;
g_udev_device_get_sysfs_path;
g_udev_device_get_tags;
+ g_udev_device_get_current_tags;
g_udev_device_get_type;
g_udev_device_get_usec_since_initialized;
g_udev_device_has_property;
diff --git a/meson.build b/meson.build
index f547a6d..b19a05f 100644
--- a/meson.build
+++ b/meson.build
@@ -41,7 +41,10 @@ vapidir = join_paths(datadir, 'vala', 'vapi')
cc = meson.get_compiler('c')
glib_req = '>= 2.38.0'
-libudev_req = '>= 199'
+libudev_req = '>= 251.4'
+introspection_req = '>= 1.31.1'
+vapigen_req = '>= 0.38.0'
+gtk_doc_req = '>= 1.18'
glib_dep = dependency('glib-2.0', version: glib_req)
gobject_dep = dependency('gobject-2.0', version: glib_req)
diff --git a/tests/test-gudevdevice.c b/tests/test-gudevdevice.c
index a197c22..e176d36 100644
--- a/tests/test-gudevdevice.c
+++ b/tests/test-gudevdevice.c
@@ -19,6 +19,7 @@ static void
test_tags ()
{
const char *expected_tags[] = { "tag1", "tag2", "tag3", NULL };
+ const char *expected_current_tags[] = { "tag2", "tag3", NULL };
struct udev *udev = NULL;
struct udev_device *udev_device = NULL;
g_autoptr(GUdevDevice) dev = NULL;
@@ -38,8 +39,12 @@ test_tags ()
dev = _g_udev_device_new (udev_device);
+ g_assert_nonnull (g_udev_device_get_tags (dev));
g_assert_cmpstrv (expected_tags, g_udev_device_get_tags (dev));
+ g_assert_nonnull (g_udev_device_get_current_tags (dev));
+ g_assert_cmpstrv (expected_current_tags, g_udev_device_get_current_tags (dev));
+
g_clear_pointer (&udev, udev_unref);
g_clear_pointer (&udev_device, udev_device_unref);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]