gudevdevice.c revision 23757887f768b0b7339239cc98aee879d9f4d87f
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering/* -*- Mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * Copyright (C) 2008 David Zeuthen <davidz@redhat.com>
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * This library is free software; you can redistribute it and/or
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * modify it under the terms of the GNU Library General Public
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * License as published by the Free Software Foundation; either
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * version 2 of the License, or (at your option) any later version.
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * This library is distributed in the hope that it will be useful,
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * but WITHOUT ANY WARRANTY; without even the implied warranty of
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * Library General Public License for more details.
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * You should have received a copy of the GNU Library General Public
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * License along with this library; if not, write to the Free Software
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * SECTION:gudevdevice
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * @short_description: Get information about a device
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * The #GUdevDevice class is used to get information about a specific
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * device. Note that you cannot instantiate a #GUdevDevice object
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * yourself. Instead you must use #GUdevClient to obtain #GUdevDevice
2e3c585472540d69a1f4f2023bc5ed67bad8bdb2Susant Sahani * To get basic information about a device, use
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering * g_udev_device_get_subsystem(), g_udev_device_get_devtype(),
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_get_name(), g_udev_device_get_number(),
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_get_sysfs_path(), g_udev_device_get_driver(),
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_get_action(), g_udev_device_get_seqnum(),
2e3c585472540d69a1f4f2023bc5ed67bad8bdb2Susant Sahani * g_udev_device_get_device_type(), g_udev_device_get_device_number(),
2e3c585472540d69a1f4f2023bc5ed67bad8bdb2Susant Sahani * g_udev_device_get_device_file(),
2e3c585472540d69a1f4f2023bc5ed67bad8bdb2Susant Sahani * g_udev_device_get_device_file_symlinks().
2e3c585472540d69a1f4f2023bc5ed67bad8bdb2Susant Sahani * To navigate the device tree, use g_udev_device_get_parent() and
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering * g_udev_device_get_parent_with_subsystem().
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * To access udev properties for the device, use
2e3c585472540d69a1f4f2023bc5ed67bad8bdb2Susant Sahani * g_udev_device_get_property_keys(),
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_has_property(),
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_get_property(),
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_get_property_as_int(),
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_get_property_as_uint64(),
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_get_property_as_double(),
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_get_property_as_boolean() and
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_get_property_as_strv().
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * To access sysfs attributes for the device, use
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_get_sysfs_attr(),
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_get_sysfs_attr_as_int(),
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_get_sysfs_attr_as_uint64(),
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_get_sysfs_attr_as_double(),
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_get_sysfs_attr_as_boolean() and
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering * g_udev_device_get_sysfs_attr_as_strv().
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * Note that all getters on #GUdevDevice are non-reffing – returned
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * values are owned by the object, should not be freed and are only
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * valid as long as the object is alive.
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * By design, #GUdevDevice will not react to changes for a device – it
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * only contains a snapshot of information when the #GUdevDevice
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * object was created. To work with changes, you typically connect to
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * the #GUdevClient::uevent signal on a #GUdevClient and get a new
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering * #GUdevDevice whenever an event happens.
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering /* computed ondemand and cached */
12ca818ffddb77eb6a0fabe369a5bcbf6994ff8bLennart PoetteringG_DEFINE_TYPE (GUdevDevice, g_udev_device, G_TYPE_OBJECT)
84e51726a38e133ca42d2f30f0668d3921b210cbLennart Poettering GUdevDevice *device = G_UDEV_DEVICE (object);
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering g_strfreev (device->priv->device_file_symlinks);
874ff7bf4d6fe693542209f127d23cd89adc499bLennart Poettering g_strfreev (device->priv->property_keys);
be795898c0d2fa21e3389b89793dcd45c47f8b9fJosh Triplett g_hash_table_unref (device->priv->prop_strvs);
return device;
const gchar *
const gchar *
const gchar *
const gchar *
const gchar *
const gchar *
const gchar *
* Returns: The device number for @device or #G_UDEV_DEVICE_TYPE_NONE if the device does not have a device file.
goto out;
goto out;
out:
return type;
const gchar *
* Returns: (transfer none) (array zero-terminated=1) (element-type utf8): A %NULL terminated string array of symlinks. This array is owned by @device and should not be freed by the caller.
const gchar * const *
struct udev_list_entry *l;
GPtrArray *p;
goto out;
p = g_ptr_array_new ();
for (l = udev_device_get_devlinks_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l))
out:
/* ---------------------------------------------------------------------------------------------------- */
* Returns: (transfer full): A #GUdevDevice or %NULL if @device has no parent. Free with g_object_unref().
goto out;
out:
return ret;
* Returns: (transfer full): A #GUdevDevice or %NULL if @device has no parent with @subsystem and @devtype. Free with g_object_unref().
devtype);
goto out;
out:
return ret;
/* ---------------------------------------------------------------------------------------------------- */
* Returns: (transfer none) (array zero-terminated=1) (element-type utf8): A %NULL terminated string array of property keys. This array is owned by @device and should not be freed by the caller.
const gchar* const *
struct udev_list_entry *l;
GPtrArray *p;
goto out;
p = g_ptr_array_new ();
for (l = udev_device_get_properties_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next (l))
out:
* Returns: The value for @key or %NULL if @key doesn't exist on @device. Do not free this string, it is owned by @device.
const gchar *
const gchar *s;
result = 0;
if (s == NULL)
goto out;
out:
return result;
const gchar *s;
result = 0;
if (s == NULL)
goto out;
out:
return result;
const gchar *s;
if (s == NULL)
goto out;
out:
return result;
const gchar *s;
if (s == NULL)
goto out;
out:
return result;
static gchar **
guint n;
guint m;
return result;
* Returns: (transfer none) (array zero-terminated=1) (element-type utf8): The value of @key on @device split into tokens or %NULL if @key doesn't exist. This array is owned by @device and should not be freed by the caller.
const gchar* const *
const gchar *s;
goto out;
if (s == NULL)
goto out;
goto out;
device->priv->prop_strvs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_strfreev);
out:
/* ---------------------------------------------------------------------------------------------------- */
const gchar *
const gchar *s;
result = 0;
if (s == NULL)
goto out;
out:
return result;
const gchar *s;
result = 0;
if (s == NULL)
goto out;
out:
return result;
const gchar *s;
if (s == NULL)
goto out;
out:
return result;
const gchar *s;
if (s == NULL)
goto out;
out:
return result;
* Returns: (transfer none) (array zero-terminated=1) (element-type utf8): The value of the sysfs attribute split into tokens or %NULL if there is no such attribute. This array is owned by @device and should not be freed by the caller.
const gchar * const *
const gchar *s;
goto out;
if (s == NULL)
goto out;
goto out;
device->priv->sysfs_attr_strvs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_strfreev);
out:
* 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.
const gchar* const *
struct udev_list_entry *l;
GPtrArray *p;
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))
out: