[libgudev/wip/muktupavels/current-tags: 9/9] device: add g_udev_device_get_current_tags




commit df5ef9b7f560708ca97200b8e8ef5373fea18d8e
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
    
    https://lists.freedesktop.org/archives/systemd-devel/2020-November/045646.html

 gudev/gudevdevice.c | 35 +++++++++++++++++++++++++++++++++++
 gudev/gudevdevice.h |  1 +
 libgudev-1.0.sym    |  1 +
 3 files changed, 37 insertions(+)
---
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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]