chiark / gitweb /
Add GUdevEnumerator type and Device.get_tags() method
authorDavid Zeuthen <davidz@redhat.com>
Tue, 14 Dec 2010 17:37:40 +0000 (12:37 -0500)
committerDavid Zeuthen <davidz@redhat.com>
Tue, 14 Dec 2010 17:37:40 +0000 (12:37 -0500)
Also add JS example to check the added API works.

Signed-off-by: David Zeuthen <davidz@redhat.com>
14 files changed:
Makefile.am
extras/gudev/docs/Makefile.am
extras/gudev/docs/gudev-docs.xml
extras/gudev/docs/gudev-sections.txt
extras/gudev/docs/gudev.types
extras/gudev/gudev.h
extras/gudev/gudevclient.c
extras/gudev/gudevdevice.c
extras/gudev/gudevdevice.h
extras/gudev/gudevenumerator.c [new file with mode: 0644]
extras/gudev/gudevenumerator.h [new file with mode: 0644]
extras/gudev/gudevprivate.h
extras/gudev/gudevtypes.h
extras/gudev/seed-example-enum.js [new file with mode: 0755]

index 2e0edd0..601246a 100644 (file)
@@ -334,7 +334,8 @@ libgudev_include_HEADERS = \
        extras/gudev/gudevenumtypes.h \
        extras/gudev/gudevtypes.h \
        extras/gudev/gudevclient.h \
-       extras/gudev/gudevdevice.h
+       extras/gudev/gudevdevice.h \
+       extras/gudev/gudevenumerator.h
 
 lib_LTLIBRARIES += extras/gudev/libgudev-1.0.la
 pkgconfig_DATA += extras/gudev/gudev-1.0.pc
@@ -348,6 +349,8 @@ extras_gudev_libgudev_1_0_la_SOURCES = \
        extras/gudev/gudevclient.c \
        extras/gudev/gudevdevice.h \
        extras/gudev/gudevdevice.c \
+       extras/gudev/gudevenumerator.h \
+       extras/gudev/gudevenumerator.c \
        extras/gudev/gudevprivate.h
 
 dist_extras_gudev_libgudev_1_0_la_SOURCES = \
@@ -418,8 +421,10 @@ extras/gudev/GUdev-1.0.gir: extras/gudev/libgudev-1.0.la $(G_IR_SCANNER) Makefil
                $(or $(wildcard $(top_builddir)/extras/gudev/gudevenumtypes.h),$(top_srcdir)/extras/gudev/gudevenumtypes.h) \
                $(top_srcdir)/extras/gudev/gudevclient.h \
                $(top_srcdir)/extras/gudev/gudevdevice.h \
+               $(top_srcdir)/extras/gudev/gudevenumerator.h \
                $(top_srcdir)/extras/gudev/gudevclient.c \
-               $(top_srcdir)/extras/gudev/gudevdevice.c
+               $(top_srcdir)/extras/gudev/gudevdevice.c \
+               $(top_srcdir)/extras/gudev/gudevenumerator.c
 
 extras/gudev/GUdev-1.0.typelib: extras/gudev/GUdev-1.0.gir $(G_IR_COMPILER)
        $(AM_V_GEN)g-ir-compiler $< -o $@
index 3da6fc7..5507434 100644 (file)
@@ -32,7 +32,7 @@ SCAN_OPTIONS=
 
 # Extra options to supply to gtkdoc-mkdb.
 # e.g. MKDB_OPTIONS=--sgml-mode --output-format=xml
-MKDB_OPTIONS=--sgml-mode --output-format=xml
+MKDB_OPTIONS=--sgml-mode --output-format=xml --name-space=g_udev
 
 # Extra options to supply to gtkdoc-mktmpl
 # e.g. MKTMPL_OPTIONS=--only-section-tmpl
index bb5f560..fefae40 100644 (file)
@@ -75,6 +75,7 @@
     </partintro>
     <xi:include href="xml/gudevclient.xml"/>
     <xi:include href="xml/gudevdevice.xml"/>
+    <xi:include href="xml/gudevenumerator.xml"/>
   </reference>
 
   <chapter id="gudev-hierarchy">
   <index>
     <title>Index</title>
   </index>
+  <index role="deprecated">
+    <title>Index of deprecated symbols</title>
+    <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
+  </index>
+  <index role="165">
+    <title>Index of new symbols in 165</title>
+    <xi:include href="xml/api-index-165.xml"><xi:fallback /></xi:include>
+  </index>
 
 </book>
index faa6a8d..15f1bb8 100644 (file)
@@ -40,6 +40,7 @@ g_udev_device_get_device_file
 g_udev_device_get_device_file_symlinks
 g_udev_device_get_parent
 g_udev_device_get_parent_with_subsystem
+g_udev_device_get_tags
 g_udev_device_get_property_keys
 g_udev_device_has_property
 g_udev_device_get_property
@@ -64,3 +65,28 @@ G_UDEV_IS_DEVICE_CLASS
 G_UDEV_DEVICE_GET_CLASS
 </SECTION>
 
+<SECTION>
+<FILE>gudevenumerator</FILE>
+<TITLE>GUdevEnumerator</TITLE>
+GUdevEnumerator
+GUdevEnumeratorClass
+g_udev_enumerator_new
+g_udev_enumerator_add_match_subsystem
+g_udev_enumerator_add_nomatch_subsystem
+g_udev_enumerator_add_match_sysfs_attr
+g_udev_enumerator_add_nomatch_sysfs_attr
+g_udev_enumerator_add_match_property
+g_udev_enumerator_add_match_name
+g_udev_enumerator_add_match_tag
+g_udev_enumerator_add_match_is_initialized
+g_udev_enumerator_add_sysfs_path
+g_udev_enumerator_execute
+<SUBSECTION Standard>
+G_UDEV_ENUMERATOR
+G_UDEV_IS_ENUMERATOR
+G_UDEV_TYPE_ENUMERATOR
+g_udev_enumerator_get_type
+G_UDEV_ENUMERATOR_CLASS
+G_UDEV_IS_ENUMERATOR_CLASS
+G_UDEV_ENUMERATOR_GET_CLASS
+</SECTION>
index be090b1..a89857a 100644 (file)
@@ -1,3 +1,4 @@
 g_udev_device_type_get_type
 g_udev_device_get_type
 g_udev_client_get_type
+g_udev_enumerator_get_type
index c3167f2..a313460 100644 (file)
@@ -27,6 +27,7 @@
 #include <gudev/gudevtypes.h>
 #include <gudev/gudevclient.h>
 #include <gudev/gudevdevice.h>
+#include <gudev/gudevenumerator.h>
 #undef _GUDEV_INSIDE_GUDEV_H
 
 #endif /* __G_UDEV_H__ */
index 9ebd8f8..853454b 100644 (file)
  * memory) and as such there are no asynchronous versions of the
  * provided methods.
  *
- * To get information about a device, use
+ * To get #GUdevDevice objects, use
  * g_udev_client_query_by_subsystem(),
  * g_udev_client_query_by_device_number(),
  * g_udev_client_query_by_device_file(),
- * g_udev_client_query_by_sysfs_path() or
- * g_udev_client_query_by_subsystem_and_name().
+ * g_udev_client_query_by_sysfs_path(),
+ * g_udev_client_query_by_subsystem_and_name()
+ * or the #GUdevEnumerator type.
  *
  * To listen to uevents, connect to the #GUdevClient::uevent signal.
  */
@@ -459,8 +460,6 @@ g_udev_client_query_by_device_file (GUdevClient  *client,
  * @sysfs_path: A sysfs path.
  *
  * Looks up a device for a sysfs path.
- *
- * Returns: (transfer full): A #GUdevDevice object or %NULL if the device was not found. Free with g_object_unref().
  */
 GUdevDevice *
 g_udev_client_query_by_sysfs_path (GUdevClient  *client,
@@ -518,3 +517,10 @@ g_udev_client_query_by_subsystem_and_name (GUdevClient  *client,
   return device;
 }
 
+struct udev *
+_g_udev_client_get_udev (GUdevClient *client)
+{
+  g_return_val_if_fail (G_UDEV_IS_CLIENT (client), NULL);
+  return client->priv->udev;
+}
+
index 76f2d7e..4c41849 100644 (file)
@@ -86,6 +86,7 @@ struct _GUdevDevicePrivate
   /* computed ondemand and cached */
   gchar **device_file_symlinks;
   gchar **property_keys;
+  gchar **tags;
   GHashTable *prop_strvs;
   GHashTable *sysfs_attr_strvs;
 };
@@ -99,6 +100,7 @@ g_udev_device_finalize (GObject *object)
 
   g_strfreev (device->priv->device_file_symlinks);
   g_strfreev (device->priv->property_keys);
+  g_strfreev (device->priv->tags);
 
   if (device->priv->udevice != NULL)
     udev_device_unref (device->priv->udevice);
@@ -889,3 +891,37 @@ g_udev_device_get_sysfs_attr_as_strv (GUdevDevice  *device,
 out:
   return (const gchar* const *) result;
 }
+
+/**
+ * g_udev_device_get_tags:
+ * @device: A #GUdevDevice.
+ *
+ * Gets all tags for @device.
+ *
+ * Returns: (transfer none) (array zero-terminated=1) (element-type utf8): A %NULL terminated string array of tags. This array is owned by @device and should not be freed by the caller.
+ *
+ * Since: 165
+ */
+const gchar* const *
+g_udev_device_get_tags (GUdevDevice  *device)
+{
+  struct udev_list_entry *l;
+  GPtrArray *p;
+
+  g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
+
+  if (device->priv->tags != NULL)
+    goto out;
+
+  p = g_ptr_array_new ();
+  for (l = udev_device_get_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->tags = (gchar **) g_ptr_array_free (p, FALSE);
+
+ out:
+  return (const gchar * const *) device->priv->tags;
+}
+
index 0ed3cf5..ffd064d 100644 (file)
@@ -120,6 +120,7 @@ gboolean            g_udev_device_get_sysfs_attr_as_boolean (GUdevDevice  *devic
                                                              const gchar  *name);
 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);
 
 G_END_DECLS
 
diff --git a/extras/gudev/gudevenumerator.c b/extras/gudev/gudevenumerator.c
new file mode 100644 (file)
index 0000000..db09074
--- /dev/null
@@ -0,0 +1,431 @@
+/* -*- Mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2008-2010 David Zeuthen <davidz@redhat.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "gudevclient.h"
+#include "gudevenumerator.h"
+#include "gudevdevice.h"
+#include "gudevmarshal.h"
+#include "gudevprivate.h"
+
+/**
+ * SECTION:gudevenumerator
+ * @short_description: Lookup and sort devices
+ *
+ * #GUdevEnumerator is used to lookup and sort devices.
+ *
+ * Since: 165
+ */
+
+struct _GUdevEnumeratorPrivate
+{
+  GUdevClient *client;
+  struct udev_enumerate *e;
+};
+
+enum
+{
+  PROP_0,
+  PROP_CLIENT,
+};
+
+G_DEFINE_TYPE (GUdevEnumerator, g_udev_enumerator, G_TYPE_OBJECT)
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+g_udev_enumerator_finalize (GObject *object)
+{
+  GUdevEnumerator *enumerator = G_UDEV_ENUMERATOR (object);
+
+  if (enumerator->priv->client != NULL)
+    {
+      g_object_unref (enumerator->priv->client);
+      enumerator->priv->client = NULL;
+    }
+
+  if (enumerator->priv->e != NULL)
+    {
+      udev_enumerate_unref (enumerator->priv->e);
+      enumerator->priv->e = NULL;
+    }
+
+  if (G_OBJECT_CLASS (g_udev_enumerator_parent_class)->finalize != NULL)
+    G_OBJECT_CLASS (g_udev_enumerator_parent_class)->finalize (object);
+}
+
+static void
+g_udev_enumerator_set_property (GObject      *object,
+                                guint         prop_id,
+                                const GValue *value,
+                                GParamSpec   *pspec)
+{
+  GUdevEnumerator *enumerator = G_UDEV_ENUMERATOR (object);
+
+  switch (prop_id)
+    {
+    case PROP_CLIENT:
+      if (enumerator->priv->client != NULL)
+        g_object_unref (enumerator->priv->client);
+      enumerator->priv->client = g_value_dup_object (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+g_udev_enumerator_get_property (GObject     *object,
+                                guint        prop_id,
+                                GValue      *value,
+                                GParamSpec  *pspec)
+{
+  GUdevEnumerator *enumerator = G_UDEV_ENUMERATOR (object);
+
+  switch (prop_id)
+    {
+    case PROP_CLIENT:
+      g_value_set_object (value, enumerator->priv->client);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+g_udev_enumerator_constructed (GObject *object)
+{
+  GUdevEnumerator *enumerator = G_UDEV_ENUMERATOR (object);
+
+  g_assert (G_UDEV_IS_CLIENT (enumerator->priv->client));
+
+  enumerator->priv->e = udev_enumerate_new (_g_udev_client_get_udev (enumerator->priv->client));
+
+  if (G_OBJECT_CLASS (g_udev_enumerator_parent_class)->constructed != NULL)
+    G_OBJECT_CLASS (g_udev_enumerator_parent_class)->constructed (object);
+}
+
+static void
+g_udev_enumerator_class_init (GUdevEnumeratorClass *klass)
+{
+  GObjectClass *gobject_class = (GObjectClass *) klass;
+
+  gobject_class->finalize     = g_udev_enumerator_finalize;
+  gobject_class->set_property = g_udev_enumerator_set_property;
+  gobject_class->get_property = g_udev_enumerator_get_property;
+  gobject_class->constructed  = g_udev_enumerator_constructed;
+
+  /**
+   * GUdevEnumerator:client:
+   *
+   * The #GUdevClient to enumerate devices from.
+   *
+   * Since: 165
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_CLIENT,
+                                   g_param_spec_object ("client",
+                                                        "The client to enumerate devices from",
+                                                        "The client to enumerate devices from",
+                                                        G_UDEV_TYPE_CLIENT,
+                                                        G_PARAM_CONSTRUCT_ONLY |
+                                                        G_PARAM_READWRITE));
+
+  g_type_class_add_private (klass, sizeof (GUdevEnumeratorPrivate));
+}
+
+static void
+g_udev_enumerator_init (GUdevEnumerator *enumerator)
+{
+  enumerator->priv = G_TYPE_INSTANCE_GET_PRIVATE (enumerator,
+                                                  G_UDEV_TYPE_ENUMERATOR,
+                                                  GUdevEnumeratorPrivate);
+}
+
+/**
+ * g_udev_enumerator_new:
+ * @client: A #GUdevClient to enumerate devices from.
+ *
+ * Constructs a #GUdevEnumerator object that can be used to enumerate
+ * and sort devices. Use the add_match_*() and add_nomatch_*() methods
+ * and execute the query to get a list of devices with
+ * g_udev_enumerator_execute().
+ *
+ * Returns: A new #GUdevEnumerator object. Free with g_object_unref().
+ *
+ * Since: 165
+ */
+GUdevEnumerator *
+g_udev_enumerator_new (GUdevClient *client)
+{
+  g_return_val_if_fail (G_UDEV_IS_CLIENT (client), NULL);
+  return G_UDEV_ENUMERATOR (g_object_new (G_UDEV_TYPE_ENUMERATOR, "client", client, NULL));
+}
+
+
+/**
+ * g_udev_enumerator_add_match_subsystem:
+ * @enumerator: A #GUdevEnumerator.
+ * @subsystem: Wildcard for subsystem name e.g. 'scsi' or 'a*'.
+ *
+ * All returned devices will match the given @subsystem.
+ *
+ * Returns: (transfer none): The passed in @enumerator.
+ *
+ * Since: 165
+ */
+GUdevEnumerator *
+g_udev_enumerator_add_match_subsystem (GUdevEnumerator  *enumerator,
+                                       const gchar      *subsystem)
+{
+  g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
+  g_return_val_if_fail (subsystem != NULL, NULL);
+  udev_enumerate_add_match_subsystem (enumerator->priv->e, subsystem);
+  return enumerator;
+}
+
+/**
+ * g_udev_enumerator_add_nomatch_subsystem:
+ * @enumerator: A #GUdevEnumerator.
+ * @subsystem: Wildcard for subsystem name e.g. 'scsi' or 'a*'.
+ *
+ * All returned devices will not match the given @subsystem.
+ *
+ * Returns: (transfer none): The passed in @enumerator.
+ *
+ * Since: 165
+ */
+GUdevEnumerator *
+g_udev_enumerator_add_nomatch_subsystem (GUdevEnumerator  *enumerator,
+                                         const gchar      *subsystem)
+{
+  g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
+  g_return_val_if_fail (subsystem != NULL, NULL);
+  udev_enumerate_add_nomatch_subsystem (enumerator->priv->e, subsystem);
+  return enumerator;
+}
+
+/**
+ * g_udev_enumerator_add_match_sysfs_attr:
+ * @enumerator: A #GUdevEnumerator.
+ * @name: Wildcard filter for sysfs attribute key.
+ * @value: Wildcard filter for sysfs attribute value.
+ *
+ * All returned devices will have a sysfs attribute matching the given @name and @value.
+ *
+ * Returns: (transfer none): The passed in @enumerator.
+ *
+ * Since: 165
+ */
+GUdevEnumerator *
+g_udev_enumerator_add_match_sysfs_attr (GUdevEnumerator  *enumerator,
+                                        const gchar      *name,
+                                        const gchar      *value)
+{
+  g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
+  g_return_val_if_fail (name != NULL, NULL);
+  g_return_val_if_fail (value != NULL, NULL);
+  udev_enumerate_add_match_sysattr (enumerator->priv->e, name, value);
+  return enumerator;
+}
+
+/**
+ * g_udev_enumerator_add_nomatch_sysfs_attr:
+ * @enumerator: A #GUdevEnumerator.
+ * @name: Wildcard filter for sysfs attribute key.
+ * @value: Wildcard filter for sysfs attribute value.
+ *
+ * All returned devices will not have a sysfs attribute matching the given @name and @value.
+ *
+ * Returns: (transfer none): The passed in @enumerator.
+ *
+ * Since: 165
+ */
+GUdevEnumerator *
+g_udev_enumerator_add_nomatch_sysfs_attr (GUdevEnumerator  *enumerator,
+                                          const gchar      *name,
+                                          const gchar      *value)
+{
+  g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
+  g_return_val_if_fail (name != NULL, NULL);
+  g_return_val_if_fail (value != NULL, NULL);
+  udev_enumerate_add_nomatch_sysattr (enumerator->priv->e, name, value);
+  return enumerator;
+}
+
+/**
+ * g_udev_enumerator_add_match_property:
+ * @enumerator: A #GUdevEnumerator.
+ * @name: Wildcard filter for property name.
+ * @value: Wildcard filter for property value.
+ *
+ * All returned devices will have a property matching the given @name and @value.
+ *
+ * Returns: (transfer none): The passed in @enumerator.
+ *
+ * Since: 165
+ */
+GUdevEnumerator *
+g_udev_enumerator_add_match_property (GUdevEnumerator  *enumerator,
+                                      const gchar      *name,
+                                      const gchar      *value)
+{
+  g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
+  g_return_val_if_fail (name != NULL, NULL);
+  g_return_val_if_fail (value != NULL, NULL);
+  udev_enumerate_add_match_property (enumerator->priv->e, name, value);
+  return enumerator;
+}
+
+/**
+ * g_udev_enumerator_add_match_name:
+ * @enumerator: A #GUdevEnumerator.
+ * @name: Wildcard filter for kernel name e.g. "sda*".
+ *
+ * All returned devices will match the given @name.
+ *
+ * Returns: (transfer none): The passed in @enumerator.
+ *
+ * Since: 165
+ */
+GUdevEnumerator *
+g_udev_enumerator_add_match_name (GUdevEnumerator  *enumerator,
+                                  const gchar      *name)
+{
+  g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
+  g_return_val_if_fail (name != NULL, NULL);
+  udev_enumerate_add_match_sysname (enumerator->priv->e, name);
+  return enumerator;
+}
+
+/**
+ * g_udev_enumerator_add_sysfs_path:
+ * @enumerator: A #GUdevEnumerator.
+ * @sysfs_path: A sysfs path, e.g. "/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda"
+ *
+ * Add a device to the list of devices, to retrieve it back sorted in dependency order.
+ *
+ * Returns: (transfer none): The passed in @enumerator.
+ *
+ * Since: 165
+ */
+GUdevEnumerator *
+g_udev_enumerator_add_sysfs_path (GUdevEnumerator  *enumerator,
+                                  const gchar      *sysfs_path)
+{
+  g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
+  g_return_val_if_fail (sysfs_path != NULL, NULL);
+  udev_enumerate_add_syspath (enumerator->priv->e, sysfs_path);
+  return enumerator;
+}
+
+/**
+ * g_udev_enumerator_add_match_tag:
+ * @enumerator: A #GUdevEnumerator.
+ * @tag: A udev tag e.g. "udev-acl".
+ *
+ * All returned devices will match the given @tag.
+ *
+ * Returns: (transfer none): The passed in @enumerator.
+ *
+ * Since: 165
+ */
+GUdevEnumerator *
+g_udev_enumerator_add_match_tag (GUdevEnumerator  *enumerator,
+                                 const gchar      *tag)
+{
+  g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
+  g_return_val_if_fail (tag != NULL, NULL);
+  udev_enumerate_add_match_tag (enumerator->priv->e, tag);
+  return enumerator;
+}
+
+/**
+ * g_udev_enumerator_add_match_is_initialized:
+ * @enumerator: A #GUdevEnumerator.
+ *
+ * All returned devices will be initialized.
+ *
+ * Returns: (transfer none): The passed in @enumerator.
+ *
+ * Since: 165
+ */
+GUdevEnumerator *
+g_udev_enumerator_add_match_is_initialized (GUdevEnumerator  *enumerator)
+{
+  g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
+  udev_enumerate_add_match_is_initialized (enumerator->priv->e);
+  return enumerator;
+}
+
+/**
+ * g_udev_enumerator_execute:
+ * @enumerator: A #GUdevEnumerator.
+ *
+ * Executes the query in @enumerator.
+ *
+ * Returns: (element-type GUdevDevice) (transfer full): A list of #GUdevDevice objects. The caller should free the result by using g_object_unref() on each element in the list and then g_list_free() on the list.
+ *
+ * Since: 165
+ */
+GList *
+g_udev_enumerator_execute (GUdevEnumerator  *enumerator)
+{
+  GList *ret;
+  struct udev_list_entry *l, *devices;
+
+  g_return_val_if_fail (G_UDEV_IS_ENUMERATOR (enumerator), NULL);
+
+  ret = NULL;
+
+  /* retrieve the list */
+  udev_enumerate_scan_devices (enumerator->priv->e);
+
+  devices = udev_enumerate_get_list_entry (enumerator->priv->e);
+  for (l = devices; l != NULL; l = udev_list_entry_get_next (l))
+    {
+      struct udev_device *udevice;
+      GUdevDevice *device;
+
+      udevice = udev_device_new_from_syspath (udev_enumerate_get_udev (enumerator->priv->e),
+                                              udev_list_entry_get_name (l));
+      if (udevice == NULL)
+        continue;
+
+      device = _g_udev_device_new (udevice);
+      udev_device_unref (udevice);
+      ret = g_list_prepend (ret, device);
+    }
+
+  ret = g_list_reverse (ret);
+
+  return ret;
+}
diff --git a/extras/gudev/gudevenumerator.h b/extras/gudev/gudevenumerator.h
new file mode 100644 (file)
index 0000000..ed54dbf
--- /dev/null
@@ -0,0 +1,108 @@
+/* -*- Mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2008-2010 David Zeuthen <davidz@redhat.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#if !defined (_GUDEV_COMPILATION) && !defined(_GUDEV_INSIDE_GUDEV_H)
+#error "Only <gudev/gudev.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef __G_UDEV_ENUMERATOR_H__
+#define __G_UDEV_ENUMERATOR_H__
+
+#include <gudev/gudevtypes.h>
+
+G_BEGIN_DECLS
+
+#define G_UDEV_TYPE_ENUMERATOR         (g_udev_enumerator_get_type ())
+#define G_UDEV_ENUMERATOR(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), G_UDEV_TYPE_ENUMERATOR, GUdevEnumerator))
+#define G_UDEV_ENUMERATOR_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), G_UDEV_TYPE_ENUMERATOR, GUdevEnumeratorClass))
+#define G_UDEV_IS_ENUMERATOR(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_UDEV_TYPE_ENUMERATOR))
+#define G_UDEV_IS_ENUMERATOR_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), G_UDEV_TYPE_ENUMERATOR))
+#define G_UDEV_ENUMERATOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_UDEV_TYPE_ENUMERATOR, GUdevEnumeratorClass))
+
+typedef struct _GUdevEnumeratorClass   GUdevEnumeratorClass;
+typedef struct _GUdevEnumeratorPrivate GUdevEnumeratorPrivate;
+
+/**
+ * GUdevEnumerator:
+ * @parent: Parent instance.
+ *
+ * The #GUdevEnumerator struct is opaque and should not be accessed directly.
+ *
+ * Since: 165
+ */
+struct _GUdevEnumerator
+{
+  GObject              parent;
+
+  /*< private >*/
+  GUdevEnumeratorPrivate *priv;
+};
+
+/**
+ * GUdevEnumeratorClass:
+ * @parent_class: Parent class.
+ *
+ * Class structure for #GUdevEnumerator.
+ *
+ * Since: 165
+ */
+struct _GUdevEnumeratorClass
+{
+  GObjectClass   parent_class;
+
+  /*< private >*/
+  /* Padding for future expansion */
+  void (*reserved1) (void);
+  void (*reserved2) (void);
+  void (*reserved3) (void);
+  void (*reserved4) (void);
+  void (*reserved5) (void);
+  void (*reserved6) (void);
+  void (*reserved7) (void);
+  void (*reserved8) (void);
+};
+
+GType            g_udev_enumerator_get_type                     (void) G_GNUC_CONST;
+GUdevEnumerator *g_udev_enumerator_new                          (GUdevClient      *client);
+GUdevEnumerator *g_udev_enumerator_add_match_subsystem          (GUdevEnumerator  *enumerator,
+                                                                 const gchar      *subsystem);
+GUdevEnumerator *g_udev_enumerator_add_nomatch_subsystem        (GUdevEnumerator  *enumerator,
+                                                                 const gchar      *subsystem);
+GUdevEnumerator *g_udev_enumerator_add_match_sysfs_attr         (GUdevEnumerator  *enumerator,
+                                                                 const gchar      *name,
+                                                                 const gchar      *value);
+GUdevEnumerator *g_udev_enumerator_add_nomatch_sysfs_attr       (GUdevEnumerator  *enumerator,
+                                                                 const gchar      *name,
+                                                                 const gchar      *value);
+GUdevEnumerator *g_udev_enumerator_add_match_property           (GUdevEnumerator  *enumerator,
+                                                                 const gchar      *name,
+                                                                 const gchar      *value);
+GUdevEnumerator *g_udev_enumerator_add_match_name               (GUdevEnumerator  *enumerator,
+                                                                 const gchar      *name);
+GUdevEnumerator *g_udev_enumerator_add_match_tag                (GUdevEnumerator  *enumerator,
+                                                                 const gchar      *tag);
+GUdevEnumerator *g_udev_enumerator_add_match_is_initialized     (GUdevEnumerator  *enumerator);
+GUdevEnumerator *g_udev_enumerator_add_sysfs_path               (GUdevEnumerator  *enumerator,
+                                                                 const gchar      *sysfs_path);
+GList           *g_udev_enumerator_execute                      (GUdevEnumerator  *enumerator);
+
+G_END_DECLS
+
+#endif /* __G_UDEV_ENUMERATOR_H__ */
index 4fd4987..8866f52 100644 (file)
@@ -34,6 +34,8 @@ G_BEGIN_DECLS
 GUdevDevice *
 _g_udev_device_new (struct udev_device *udevice);
 
+struct udev *_g_udev_client_get_udev (GUdevClient *client);
+
 G_END_DECLS
 
 #endif /* __G_UDEV_PRIVATE_H__ */
index b95cf97..8884827 100644 (file)
@@ -32,6 +32,7 @@ G_BEGIN_DECLS
 
 typedef struct _GUdevClient GUdevClient;
 typedef struct _GUdevDevice GUdevDevice;
+typedef struct _GUdevEnumerator GUdevEnumerator;
 
 /**
  * GUdevDeviceNumber:
diff --git a/extras/gudev/seed-example-enum.js b/extras/gudev/seed-example-enum.js
new file mode 100755 (executable)
index 0000000..2aa8036
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/env seed
+
+const GLib = imports.gi.GLib;
+const GUdev = imports.gi.GUdev;
+
+function print_device(device) {
+  print("  subsystem:             " + device.get_subsystem());
+  print("  devtype:               " + device.get_devtype());
+  print("  name:                  " + device.get_name());
+  print("  number:                " + device.get_number());
+  print("  sysfs_path:            " + device.get_sysfs_path());
+  print("  driver:                " + device.get_driver());
+  print("  action:                " + device.get_action());
+  print("  seqnum:                " + device.get_seqnum());
+  print("  device type:           " + device.get_device_type());
+  print("  device number:         " + device.get_device_number());
+  print("  device file:           " + device.get_device_file());
+  print("  device file symlinks:  " + device.get_device_file_symlinks());
+  print("  tags:                  " + device.get_tags());
+  var keys = device.get_property_keys();
+  for (var n = 0; n < keys.length; n++) {
+    print("    " + keys[n] + "=" + device.get_property(keys[n]));
+  }
+}
+
+var client = new GUdev.Client({subsystems: []});
+var enumerator = new GUdev.Enumerator({client: client});
+enumerator.add_match_subsystem('b*')
+
+var devices = enumerator.execute();
+
+for (var n=0; n < devices.length; n++) {
+    var device = devices[n];
+    print_device(device);
+    print("");
+}