Top |
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_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()
,
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.
const gchar *
g_udev_device_get_subsystem (GUdevDevice *device
);
Gets the subsystem for device
.
const gchar *
g_udev_device_get_devtype (GUdevDevice *device
);
Gets the device type for device
.
const gchar *
g_udev_device_get_name (GUdevDevice *device
);
Gets the name of device
, e.g. "sda3".
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".
const gchar *
g_udev_device_get_sysfs_path (GUdevDevice *device
);
Gets the sysfs path for device
.
const gchar *
g_udev_device_get_driver (GUdevDevice *device
);
Gets the name of the driver used for device
.
const gchar *
g_udev_device_get_action (GUdevDevice *device
);
Gets the most recent action (e.g. "add", "remove", "change", etc.) for device
.
guint64
g_udev_device_get_seqnum (GUdevDevice *device
);
Gets the most recent sequence number for device
.
GUdevDeviceType
g_udev_device_get_device_type (GUdevDevice *device
);
Gets the type of the device file, if any, for device
.
The device number for device
or G_UDEV_DEVICE_TYPE_NONE if the device does not have a device file.
GUdevDeviceNumber
g_udev_device_get_device_number (GUdevDevice *device
);
Gets the device number, if any, for device
.
const gchar *
g_udev_device_get_device_file (GUdevDevice *device
);
Gets the device file for device
.
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
.
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]
GUdevDevice *
g_udev_device_get_parent (GUdevDevice *device
);
Gets the immediate parent of device
, if any.
A GUdevDevice or NULL
if
device
has no parent. Free with g_object_unref()
.
[nullable][transfer full]
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 |
[allow-none] |
A GUdevDevice or NULL
if
device
has no parent with subsystem
and devtype
. Free with
g_object_unref()
.
[nullable][transfer full]
const gchar * const *
g_udev_device_get_tags (GUdevDevice *device
);
Gets all tags for device
.
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
gboolean
g_udev_device_get_is_initialized (GUdevDevice *device
);
Gets whether device
has been initialized.
Since: 165
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.
Since: 165
const gchar * const *
g_udev_device_get_property_keys (GUdevDevice *device
);
Gets all keys for properties on device
.
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]
gboolean g_udev_device_has_property (GUdevDevice *device
,const gchar *key
);
Check if a the property with the given key exists.
const gchar * g_udev_device_get_property (GUdevDevice *device
,const gchar *key
);
Look up the value for key
on device
.
The value for key
or NULL
if key
doesn't
exist on device
. Do not free this string, it is owned by device
.
[nullable]
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()
.
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()
.
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 g_ascii_strtod()
.
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".
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).
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.
[nullable][transfer none][array zero-terminated=1][element-type utf8]
const gchar * const *
g_udev_device_get_sysfs_attr_keys (GUdevDevice *device
);
Gets all keys for sysfs attributes on device
.
A NULL
terminated string array of sysfs attribute keys. This array is owned by device
and should not be freed by the caller.
[transfer none][array zero-terminated=1][element-type utf8]
gboolean g_udev_device_has_sysfs_attr (GUdevDevice *device
,const gchar *key
);
Check if a the sysfs attribute with the given key exists. The retrieved value is cached in the device. Repeated calls will return the same result and not check for the presence of the attribute again, unless updated through one of the "uncached" functions.
const gchar * g_udev_device_get_sysfs_attr (GUdevDevice *device
,const gchar *name
);
Look up the sysfs attribute with name
on device
. The retrieved value
is cached in the device. Repeated calls will return the same value and
not open the attribute again, unless updated through one of the
"uncached" functions.
The value of the sysfs attribute or NULL
if
there is no such attribute. Do not free this string, it is owned by
device
.
[nullable]
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()
. The retrieved value is cached in the device. Repeated calls
will return the same value and not open the attribute again, unless updated
through one of the "uncached" functions.
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()
. The retrieved value is cached in the
device. Repeated calls will return the same value and not open the attribute
again, unless updated through one of the "uncached" functions.
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 g_ascii_strtod()
. The retrieved value is cached
in the device. Repeated calls will return the same value and not open the
attribute again, unless updated through one of the "uncached" functions.
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", "true", "Y" and "y". The retrieved value is
cached in the device. Repeated calls will return the same value and
not open the attribute again, unless updated through one of the
"uncached" functions.
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).
The retrieved value is cached in the device. Repeated calls will return the same value and not open the attribute again, unless updated through one of the "uncached" functions.
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.
[nullable][transfer none][array zero-terminated=1][element-type utf8]
gboolean g_udev_device_has_sysfs_attr_uncached (GUdevDevice *device
,const gchar *key
);
Check if a the sysfs attribute with the given key exists. The retrieved value is cached in the device. Repeated calls will return the same result and not check for the presence of the attribute again, unless updated through one of the "uncached" functions.
Since: 234
const gchar * g_udev_device_get_sysfs_attr_uncached (GUdevDevice *device
,const gchar *name
);
Look up the sysfs attribute with name
on device
. This function does
blocking I/O, and updates the sysfs attributes cache.
Before version 238 the uncached getters would not strip trailing newlines.
The value of the sysfs attribute or NULL
if
there is no such attribute. Do not free this string, it is owned by
device
.
[nullable]
Since: 234
gint g_udev_device_get_sysfs_attr_as_int_uncached (GUdevDevice *device
,const gchar *name
);
Look up the sysfs attribute with name
on device
and convert it to an integer
using strtol()
. This function does blocking I/O, and updates the sysfs
attributes cache.
Before version 238 the uncached getters would not strip trailing newlines.
Since: 234
guint64 g_udev_device_get_sysfs_attr_as_uint64_uncached (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()
. This function does blocking I/O, and
updates the sysfs attributes cache.
Before version 238 the uncached getters would not strip trailing newlines.
Since: 234
gdouble g_udev_device_get_sysfs_attr_as_double_uncached (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 g_ascii_strtod()
. This function does blocking
I/O, and updates the sysfs attributes cache.
Before version 238 the uncached getters would not strip trailing newlines.
Since: 234
gboolean g_udev_device_get_sysfs_attr_as_boolean_uncached (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", "true", "Y" and "y". This function does
blocking I/O, and updates the sysfs attributes cache.
Before version 238 the uncached getters would not strip trailing newlines.
Since: 234
const gchar * const * g_udev_device_get_sysfs_attr_as_strv_uncached (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).
This function does blocking I/O, and updates the sysfs attributes cache.
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.
Before version 238 the uncached getters would not strip trailing newlines.
[nullable][transfer none][array zero-terminated=1][element-type utf8]
Since: 234
typedef struct _GUdevDevice GUdevDevice;
The GUdevDevice struct is opaque and should not be accessed directly.
struct GUdevDeviceClass { GObjectClass parent_class; };
Class structure for GUdevDevice.