[libgudev/wip/muktupavels/current-tags] 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] device: add g_udev_device_get_current_tags
- Date: Tue, 21 Jun 2022 14:54:25 +0000 (UTC)
commit d03011e6a73b64740b02da1fef88be121b9f611e
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 | 35 +++++++++++++++++++++++++++++++++++
gudev/gudevdevice.h | 1 +
libgudev-1.0.sym | 1 +
meson.build | 2 +-
tests/test-gudevdevice.c | 4 ++++
5 files changed, 42 insertions(+), 1 deletion(-)
---
diff --git a/gudev/gudevdevice.c b/gudev/gudevdevice.c
index 248d272..d5736fd 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);
@@ -1206,6 +1208,39 @@ 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.
+ *
+ * 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)
+{
+ struct udev_list_entry *l;
+ GPtrArray *p;
+
+ g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
+
+ if (device->priv->current_tags != NULL)
+ goto out;
+
+ 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);
+
+ out:
+ 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 eae2c80..22a1d74 100644
--- a/meson.build
+++ b/meson.build
@@ -41,7 +41,7 @@ vapidir = join_paths(datadir, 'vala', 'vapi')
cc = meson.get_compiler('c')
glib_req = '>= 2.38.0'
-libudev_req = '>= 199'
+libudev_req = '>= 247'
introspection_req = '>= 1.31.1'
vapigen_req = '>= 0.38.0'
gtk_doc_req = '>= 1.18'
diff --git a/tests/test-gudevdevice.c b/tests/test-gudevdevice.c
index a197c22..5a6c72d 100644
--- a/tests/test-gudevdevice.c
+++ b/tests/test-gudevdevice.c
@@ -38,8 +38,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_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]