GUdevDevice

GUdevDevice — Get information about a device

Synopsis

                    GUdevDevice;
struct              GUdevDeviceClass;
const gchar *       g_udev_device_get_subsystem         (GUdevDevice *device);
const gchar *       g_udev_device_get_devtype           (GUdevDevice *device);
const gchar *       g_udev_device_get_name              (GUdevDevice *device);
const gchar *       g_udev_device_get_number            (GUdevDevice *device);
const gchar *       g_udev_device_get_sysfs_path        (GUdevDevice *device);
const gchar *       g_udev_device_get_driver            (GUdevDevice *device);
const gchar *       g_udev_device_get_action            (GUdevDevice *device);
guint64             g_udev_device_get_seqnum            (GUdevDevice *device);
GUdevDeviceType     g_udev_device_get_device_type       (GUdevDevice *device);
GUdevDeviceNumber   g_udev_device_get_device_number     (GUdevDevice *device);
const gchar *       g_udev_device_get_device_file       (GUdevDevice *device);
const gchar * const * g_udev_device_get_device_file_symlinks
                                                        (GUdevDevice *device);
GUdevDevice *       g_udev_device_get_parent            (GUdevDevice *device);
GUdevDevice *       g_udev_device_get_parent_with_subsystem
                                                        (GUdevDevice *device,
                                                         const gchar *subsystem,
                                                         const gchar *devtype);
const gchar * const * g_udev_device_get_tags            (GUdevDevice *device);
gboolean            g_udev_device_get_is_initialized    (GUdevDevice *device);
guint64             g_udev_device_get_usec_since_initialized
                                                        (GUdevDevice *device);
const gchar * const * g_udev_device_get_property_keys   (GUdevDevice *device);
gboolean            g_udev_device_has_property          (GUdevDevice *device,
                                                         const gchar *key);
const gchar *       g_udev_device_get_property          (GUdevDevice *device,
                                                         const gchar *key);
gint                g_udev_device_get_property_as_int   (GUdevDevice *device,
                                                         const gchar *key);
guint64             g_udev_device_get_property_as_uint64
                                                        (GUdevDevice *device,
                                                         const gchar *key);
gdouble             g_udev_device_get_property_as_double
                                                        (GUdevDevice *device,
                                                         const gchar *key);
gboolean            g_udev_device_get_property_as_boolean
                                                        (GUdevDevice *device,
                                                         const gchar *key);
const gchar * const * g_udev_device_get_property_as_strv
                                                        (GUdevDevice *device,
                                                         const gchar *key);
const gchar *       g_udev_device_get_sysfs_attr        (GUdevDevice *device,
                                                         const gchar *name);
gint                g_udev_device_get_sysfs_attr_as_int (GUdevDevice *device,
                                                         const gchar *name);
guint64             g_udev_device_get_sysfs_attr_as_uint64
                                                        (GUdevDevice *device,
                                                         const gchar *name);
gdouble             g_udev_device_get_sysfs_attr_as_double
                                                        (GUdevDevice *device,
                                                         const gchar *name);
gboolean            g_udev_device_get_sysfs_attr_as_boolean
                                                        (GUdevDevice *device,
                                                         const gchar *name);
const gchar * const * g_udev_device_get_sysfs_attr_as_strv
                                                        (GUdevDevice *device,
                                                         const gchar *name);

Object Hierarchy

  GObject
   +----GUdevDevice

Description

The GUdevDevice class is used to get information about a specific device. Note that you cannot instantiate a GUdevDevice object yourself. Instead you must use GUdevClient to obtain GUdevDevice objects.

To get basic information about a device, use g_udev_device_get_subsystem(), g_udev_device_get_devtype(), g_udev_device_get_name(), g_udev_device_get_number(), g_udev_device_get_sysfs_path(), g_udev_device_get_driver(), g_udev_device_get_action(), g_udev_device_get_seqnum(), g_udev_device_get_device_type(), g_udev_device_get_device_number(), g_udev_device_get_device_file(), g_udev_device_get_device_file_symlinks().

To navigate the device tree, use g_udev_device_get_parent() and g_udev_device_get_parent_with_subsystem().

To access udev properties for the device, use g_udev_device_get_property_keys(), g_udev_device_has_property(), g_udev_device_get_property(), g_udev_device_get_property_as_int(), g_udev_device_get_property_as_uint64(), g_udev_device_get_property_as_double(), g_udev_device_get_property_as_boolean() and g_udev_device_get_property_as_strv().

To access sysfs attributes for the device, use g_udev_device_get_sysfs_attr(), g_udev_device_get_sysfs_attr_as_int(), g_udev_device_get_sysfs_attr_as_uint64(), g_udev_device_get_sysfs_attr_as_double(), g_udev_device_get_sysfs_attr_as_boolean() and g_udev_device_get_sysfs_attr_as_strv().

Note that all getters on GUdevDevice are non-reffing – returned values are owned by the object, should not be freed and are only valid as long as the object is alive.

By design, GUdevDevice will not react to changes for a device – it only contains a snapshot of information when the GUdevDevice object was created. To work with changes, you typically connect to the "uevent" signal on a GUdevClient and get a new GUdevDevice whenever an event happens.

Details

GUdevDevice

typedef struct _GUdevDevice GUdevDevice;

The GUdevDevice struct is opaque and should not be accessed directly.


struct GUdevDeviceClass

struct GUdevDeviceClass {
  GObjectClass parent_class;
};

Class structure for GUdevDevice.

GObjectClass parent_class;

Parent class.

g_udev_device_get_subsystem ()

const gchar *       g_udev_device_get_subsystem         (GUdevDevice *device);

Gets the subsystem for device.

device :

A GUdevDevice.

Returns :

The subsystem for device.

g_udev_device_get_devtype ()

const gchar *       g_udev_device_get_devtype           (GUdevDevice *device);

Gets the device type for device.

device :

A GUdevDevice.

Returns :

The devtype for device.

g_udev_device_get_name ()

const gchar *       g_udev_device_get_name              (GUdevDevice *device);

Gets the name of device, e.g. "sda3".

device :

A GUdevDevice.

Returns :

The name of device.

g_udev_device_get_number ()

const gchar *       g_udev_device_get_number            (GUdevDevice *device);

Gets the number of device, e.g. "3" if g_udev_device_get_name() returns "sda3".

device :

A GUdevDevice.

Returns :

The number of device.

g_udev_device_get_sysfs_path ()

const gchar *       g_udev_device_get_sysfs_path        (GUdevDevice *device);

Gets the sysfs path for device.

device :

A GUdevDevice.

Returns :

The sysfs path for device.

g_udev_device_get_driver ()

const gchar *       g_udev_device_get_driver            (GUdevDevice *device);

Gets the name of the driver used for device.

device :

A GUdevDevice.

Returns :

The name of the driver for device or NULL if unknown.

g_udev_device_get_action ()

const gchar *       g_udev_device_get_action            (GUdevDevice *device);

Gets the most recent action (e.g. "add", "remove", "change", etc.) for device.

device :

A GUdevDevice.

Returns :

An action string.

g_udev_device_get_seqnum ()

guint64             g_udev_device_get_seqnum            (GUdevDevice *device);

Gets the most recent sequence number for device.

device :

A GUdevDevice.

Returns :

A sequence number.

g_udev_device_get_device_type ()

GUdevDeviceType     g_udev_device_get_device_type       (GUdevDevice *device);

Gets the type of the device file, if any, for device.

device :

A GUdevDevice.

Returns :

The device number for device or G_UDEV_DEVICE_TYPE_NONE if the device does not have a device file.

g_udev_device_get_device_number ()

GUdevDeviceNumber   g_udev_device_get_device_number     (GUdevDevice *device);

Gets the device number, if any, for device.

device :

A GUdevDevice.

Returns :

The device number for device or 0 if unknown.

g_udev_device_get_device_file ()

const gchar *       g_udev_device_get_device_file       (GUdevDevice *device);

Gets the device file for device.

device :

A GUdevDevice.

Returns :

The device file for device or NULL if no device file exists.

g_udev_device_get_device_file_symlinks ()

const gchar * const * g_udev_device_get_device_file_symlinks
                                                        (GUdevDevice *device);

Gets a list of symlinks (in /dev) that points to the device file for device.

device :

A GUdevDevice.

Returns :

A NULL terminated string array of symlinks. This array is owned by device and should not be freed by the caller. [transfer none][array zero-terminated=1][element-type utf8]

g_udev_device_get_parent ()

GUdevDevice *       g_udev_device_get_parent            (GUdevDevice *device);

Gets the immediate parent of device, if any.

device :

A GUdevDevice.

Returns :

A GUdevDevice or NULL if device has no parent. Free with g_object_unref().

g_udev_device_get_parent_with_subsystem ()

GUdevDevice *       g_udev_device_get_parent_with_subsystem
                                                        (GUdevDevice *device,
                                                         const gchar *subsystem,
                                                         const gchar *devtype);

Walks up the chain of parents of device and returns the first device encountered where subsystem and devtype matches, if any.

device :

A GUdevDevice.

subsystem :

The subsystem of the parent to get.

devtype :

The devtype of the parent to get or NULL. [allow-none]

Returns :

A GUdevDevice or NULL if device has no parent with subsystem and devtype. Free with g_object_unref().

g_udev_device_get_tags ()

const gchar * const * g_udev_device_get_tags            (GUdevDevice *device);

Gets all tags for device.

device :

A GUdevDevice.

Returns :

A NULL terminated string array of tags. This array is owned by device and should not be freed by the caller. [transfer none][array zero-terminated=1][element-type utf8]

Since 165


g_udev_device_get_is_initialized ()

gboolean            g_udev_device_get_is_initialized    (GUdevDevice *device);

Gets whether device has been initalized.

device :

A GUdevDevice.

Returns :

Whether device has been initialized.

Since 165


g_udev_device_get_usec_since_initialized ()

guint64             g_udev_device_get_usec_since_initialized
                                                        (GUdevDevice *device);

Gets number of micro-seconds since device was initialized.

This only works for devices with properties in the udev database. All other devices return 0.

device :

A GUdevDevice.

Returns :

Number of micro-seconds since device was initialized or 0 if unknown.

Since 165


g_udev_device_get_property_keys ()

const gchar * const * g_udev_device_get_property_keys   (GUdevDevice *device);

Gets all keys for properties on device.

device :

A GUdevDevice.

Returns :

A NULL terminated string array of property keys. This array is owned by device and should not be freed by the caller. [transfer none][array zero-terminated=1][element-type utf8]

g_udev_device_has_property ()

gboolean            g_udev_device_has_property          (GUdevDevice *device,
                                                         const gchar *key);

Check if a the property with the given key exists.

device :

A GUdevDevice.

key :

Name of property.

Returns :

TRUE only if the value for key exist.

g_udev_device_get_property ()

const gchar *       g_udev_device_get_property          (GUdevDevice *device,
                                                         const gchar *key);

Look up the value for key on device.

device :

A GUdevDevice.

key :

Name of property.

Returns :

The value for key or NULL if key doesn't exist on device. Do not free this string, it is owned by device.

g_udev_device_get_property_as_int ()

gint                g_udev_device_get_property_as_int   (GUdevDevice *device,
                                                         const gchar *key);

Look up the value for key on device and convert it to an integer using strtol().

device :

A GUdevDevice.

key :

Name of property.

Returns :

The value for key or 0 if key doesn't exist or isn't an integer.

g_udev_device_get_property_as_uint64 ()

guint64             g_udev_device_get_property_as_uint64
                                                        (GUdevDevice *device,
                                                         const gchar *key);

Look up the value for key on device and convert it to an unsigned 64-bit integer using g_ascii_strtoull().

device :

A GUdevDevice.

key :

Name of property.

Returns :

The value for key or 0 if key doesn't exist or isn't a guint64.

g_udev_device_get_property_as_double ()

gdouble             g_udev_device_get_property_as_double
                                                        (GUdevDevice *device,
                                                         const gchar *key);

Look up the value for key on device and convert it to a double precision floating point number using strtod().

device :

A GUdevDevice.

key :

Name of property.

Returns :

The value for key or 0.0 if key doesn't exist or isn't a gdouble.

g_udev_device_get_property_as_boolean ()

gboolean            g_udev_device_get_property_as_boolean
                                                        (GUdevDevice *device,
                                                         const gchar *key);

Look up the value for key on device and convert it to an boolean. This is done by doing a case-insensitive string comparison on the string value against "1" and "true".

device :

A GUdevDevice.

key :

Name of property.

Returns :

The value for key or FALSE if key doesn't exist or isn't a gboolean.

g_udev_device_get_property_as_strv ()

const gchar * const * g_udev_device_get_property_as_strv
                                                        (GUdevDevice *device,
                                                         const gchar *key);

Look up the value for key on device and return the result of splitting it into non-empty tokens split at white space (only space (' '), form-feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v') are considered; the locale is not taken into account).

device :

A GUdevDevice.

key :

Name of property.

Returns :

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. [transfer none][array zero-terminated=1][element-type utf8]

g_udev_device_get_sysfs_attr ()

const gchar *       g_udev_device_get_sysfs_attr        (GUdevDevice *device,
                                                         const gchar *name);

Look up the sysfs attribute with name on device.

device :

A GUdevDevice.

name :

Name of the sysfs attribute.

Returns :

The value of the sysfs attribute or NULL if there is no such attribute. Do not free this string, it is owned by device.

g_udev_device_get_sysfs_attr_as_int ()

gint                g_udev_device_get_sysfs_attr_as_int (GUdevDevice *device,
                                                         const gchar *name);

Look up the sysfs attribute with name on device and convert it to an integer using strtol().

device :

A GUdevDevice.

name :

Name of the sysfs attribute.

Returns :

The value of the sysfs attribute or 0 if there is no such attribute.

g_udev_device_get_sysfs_attr_as_uint64 ()

guint64             g_udev_device_get_sysfs_attr_as_uint64
                                                        (GUdevDevice *device,
                                                         const gchar *name);

Look up the sysfs attribute with name on device and convert it to an unsigned 64-bit integer using g_ascii_strtoull().

device :

A GUdevDevice.

name :

Name of the sysfs attribute.

Returns :

The value of the sysfs attribute or 0 if there is no such attribute.

g_udev_device_get_sysfs_attr_as_double ()

gdouble             g_udev_device_get_sysfs_attr_as_double
                                                        (GUdevDevice *device,
                                                         const gchar *name);

Look up the sysfs attribute with name on device and convert it to a double precision floating point number using strtod().

device :

A GUdevDevice.

name :

Name of the sysfs attribute.

Returns :

The value of the sysfs attribute or 0.0 if there is no such attribute.

g_udev_device_get_sysfs_attr_as_boolean ()

gboolean            g_udev_device_get_sysfs_attr_as_boolean
                                                        (GUdevDevice *device,
                                                         const gchar *name);

Look up the sysfs attribute with name on device and convert it to an boolean. This is done by doing a case-insensitive string comparison on the string value against "1" and "true".

device :

A GUdevDevice.

name :

Name of the sysfs attribute.

Returns :

The value of the sysfs attribute or FALSE if there is no such attribute.

g_udev_device_get_sysfs_attr_as_strv ()

const gchar * const * g_udev_device_get_sysfs_attr_as_strv
                                                        (GUdevDevice *device,
                                                         const gchar *name);

Look up the sysfs attribute with name on device and return the result of splitting it into non-empty tokens split at white space (only space (' '), form-feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v') are considered; the locale is not taken into account).

device :

A GUdevDevice.

name :

Name of the sysfs attribute.

Returns :

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. [transfer none][array zero-terminated=1][element-type utf8]