[libgudev/wip/hadess/sub-device-file] gudev: Add g_udev_client_query_by_subsystem_and_device_file()




commit ea4252aa226985e202040babbbf3fef1c2ce9960
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Nov 15 17:30:41 2021 +0100

    gudev: Add g_udev_client_query_by_subsystem_and_device_file()
    
    Looks up a device for a device file for a particular subsystem. In contrast to
    g_udev_client_query_device_file() this function does not make blocking I/O
    through stat()'ing a device file, and relies solely on the udev database making
    it a better fit for mocked sysfs hierarchies.

 gudev/gudevclient.c | 33 +++++++++++++++++++++++++++++++++
 gudev/gudevclient.h |  3 +++
 2 files changed, 36 insertions(+)
---
diff --git a/gudev/gudevclient.c b/gudev/gudevclient.c
index cfd8baa..8bbf2b8 100644
--- a/gudev/gudevclient.c
+++ b/gudev/gudevclient.c
@@ -515,6 +515,39 @@ g_udev_client_query_by_subsystem_and_name (GUdevClient  *client,
   return device;
 }
 
+/**
+ * g_udev_client_query_by_subsystem_and_device_file:
+ * @client: A #GUdevClient.
+ * @subsystem: A subsystem name.
+ * @device_file: A device file.
+ *
+ * Looks up a device for a device file for a particular subsystem. In contrast to
+ * g_udev_client_query_device_file() this function does not make blocking I/O
+ * through stat()'ing a device file, and relies solely on the udev database making
+ * it a better fit for mocked sysfs hierarchies.
+ *
+ * Returns: (nullable) (transfer full): A #GUdevDevice object or %NULL
+ * if the device was not found. Free with g_object_unref().
+ */
+GUdevDevice *
+g_udev_client_query_by_subsystem_and_device_file (GUdevClient  *client,
+                                                  const char   *subsystem,
+                                                  const gchar  *device_file)
+{
+  GList *l;
+  g_autolist(GUdevDevice) devices = NULL;
+
+  g_return_val_if_fail (G_UDEV_IS_CLIENT (client), NULL);
+  g_return_val_if_fail (device_file != NULL, NULL);
+
+  devices = g_udev_client_query_by_subsystem (client, subsystem);
+  for (l = devices; l != NULL; l = l->next) {
+    if (g_strcmp0 (g_udev_device_get_device_file (l->data), path) == 0)
+      return g_object_ref (l->data);
+  }
+  return NULL;
+}
+
 struct udev_enumerate *
 _g_udev_client_new_enumerate (GUdevClient *client)
 {
diff --git a/gudev/gudevclient.h b/gudev/gudevclient.h
index 329f22d..c3e4df2 100644
--- a/gudev/gudevclient.h
+++ b/gudev/gudevclient.h
@@ -84,6 +84,9 @@ GUdevDevice *g_udev_client_query_by_sysfs_path         (GUdevClient        *clie
 GUdevDevice *g_udev_client_query_by_subsystem_and_name (GUdevClient        *client,
                                                         const gchar        *subsystem,
                                                         const gchar        *name);
+GUdevDevice *g_udev_client_query_by_subsystem_and_device_file (GUdevClient  *client,
+                                                               const char   *subsystem,
+                                                               const gchar  *device_file);
 
 G_END_DECLS
 


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