X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fgudev%2Fgudevdevice.c;h=2c768b7db7455dc16712ce6b45aa525ac5a1356f;hb=127dc4ea9487397b1ab70447e2f44d091e44ab5f;hp=62a26f99b7e639010aca4f1e4e35cf5510a6ff4b;hpb=6997e3b2dc0095985071e2f7496342a850cdb5ad;p=elogind.git diff --git a/src/gudev/gudevdevice.c b/src/gudev/gudevdevice.c index 62a26f99b..2c768b7db 100644 --- a/src/gudev/gudevdevice.c +++ b/src/gudev/gudevdevice.c @@ -3,20 +3,18 @@ * Copyright (C) 2008 David Zeuthen * * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public + * modify it under the terms of the GNU Library 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. + * Library General Public License for more details. * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifdef HAVE_CONFIG_H @@ -61,6 +59,8 @@ * g_udev_device_get_property_as_strv(). * * To access sysfs attributes for the device, use + * g_udev_device_get_sysfs_attr_keys(), + * g_udev_device_has_sysfs_attr(), * g_udev_device_get_sysfs_attr(), * g_udev_device_get_sysfs_attr_as_int(), * g_udev_device_get_sysfs_attr_as_uint64(), @@ -86,6 +86,7 @@ struct _GUdevDevicePrivate /* computed ondemand and cached */ gchar **device_file_symlinks; gchar **property_keys; + gchar **sysfs_attr_keys; gchar **tags; GHashTable *prop_strvs; GHashTable *sysfs_attr_strvs; @@ -100,6 +101,7 @@ g_udev_device_finalize (GObject *object) g_strfreev (device->priv->device_file_symlinks); g_strfreev (device->priv->property_keys); + g_strfreev (device->priv->sysfs_attr_keys); g_strfreev (device->priv->tags); if (device->priv->udevice != NULL) @@ -700,6 +702,55 @@ out: /* ---------------------------------------------------------------------------------------------------- */ +/** + * g_udev_device_get_sysfs_attr_keys: + * @device: A #GUdevDevice. + * + * Gets all keys for sysfs attributes on @device. + * + * Returns: (transfer none) (array zero-terminated=1) (element-type utf8): A %NULL terminated string array of sysfs attribute keys. This array is owned by @device and should not be freed by the caller. + */ +const gchar * const * +g_udev_device_get_sysfs_attr_keys (GUdevDevice *device) +{ + struct udev_list_entry *l; + GPtrArray *p; + + g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL); + + if (device->priv->sysfs_attr_keys != NULL) + goto out; + + p = g_ptr_array_new (); + for (l = udev_device_get_sysattr_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->sysfs_attr_keys = (gchar **) g_ptr_array_free (p, FALSE); + + out: + return (const gchar * const *) device->priv->sysfs_attr_keys; +} + +/** + * g_udev_device_has_sysfs_attr: + * @device: A #GUdevDevice. + * @key: Name of sysfs attribute. + * + * Check if a the sysfs attribute with the given key exists. + * + * Returns: %TRUE only if the value for @key exist. + */ +gboolean +g_udev_device_has_sysfs_attr (GUdevDevice *device, + const gchar *key) +{ + g_return_val_if_fail (G_UDEV_IS_DEVICE (device), FALSE); + g_return_val_if_fail (key != NULL, FALSE); + return udev_device_get_sysattr_value (device->priv->udevice, key) != NULL; +} + /** * g_udev_device_get_sysfs_attr: * @device: A #GUdevDevice.