GUDev Reference Manual | ||||
---|---|---|---|---|
Top | Description | Object Hierarchy |
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
);
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.
typedef struct _GUdevDevice GUdevDevice;
The GUdevDevice struct is opaque and should not be accessed directly.
struct GUdevDeviceClass { GObjectClass parent_class; };
Class structure for GUdevDevice.
GObjectClass |
Parent class. |
const gchar * g_udev_device_get_subsystem (GUdevDevice *device
);
Gets the subsystem for device
.
|
A GUdevDevice. |
Returns : |
The subsystem for device . |
const gchar * g_udev_device_get_devtype (GUdevDevice *device
);
Gets the device type for device
.
|
A GUdevDevice. |
Returns : |
The devtype for device . |
const gchar * g_udev_device_get_name (GUdevDevice *device
);
Gets the name of device
, e.g. "sda3".
|
A GUdevDevice. |
Returns : |
The name of device . |
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".
|
A GUdevDevice. |
Returns : |
The number of device . |
const gchar * g_udev_device_get_sysfs_path (GUdevDevice *device
);
Gets the sysfs path for device
.
|
A GUdevDevice. |
Returns : |
The sysfs path for device . |
const gchar * g_udev_device_get_driver (GUdevDevice *device
);
Gets the name of the driver used for device
.
|
A GUdevDevice. |
Returns : |
The name of the driver for device or NULL if unknown. |
const gchar * g_udev_device_get_action (GUdevDevice *device
);
Gets the most recent action (e.g. "add", "remove", "change", etc.) for device
.
|
A GUdevDevice. |
Returns : |
An action string. |
guint64 g_udev_device_get_seqnum (GUdevDevice *device
);
Gets the most recent sequence number for device
.
|
A GUdevDevice. |
Returns : |
A sequence number. |
GUdevDeviceType g_udev_device_get_device_type (GUdevDevice *device
);
Gets the type of the device file, if any, for device
.
|
A GUdevDevice. |
Returns : |
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
.
|
A GUdevDevice. |
Returns : |
The device number for device or 0 if unknown. |
const gchar * g_udev_device_get_device_file (GUdevDevice *device
);
Gets the device file for device
.
|
A GUdevDevice. |
Returns : |
The device file for device or NULL if no device file
exists. |
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 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]
|
GUdevDevice * g_udev_device_get_parent (GUdevDevice *device
);
Gets the immediate parent of device
, if any.
|
A GUdevDevice. |
Returns : |
A GUdevDevice or NULL if device has no parent. Free with g_object_unref() . |
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.
|
A GUdevDevice. |
|
The subsystem of the parent to get. |
|
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() . |
const gchar * const * g_udev_device_get_tags (GUdevDevice *device
);
Gets all tags for 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
gboolean g_udev_device_get_is_initialized (GUdevDevice *device
);
Gets whether device
has been initalized.
|
A GUdevDevice. |
Returns : |
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.
|
A GUdevDevice. |
Returns : |
Number of micro-seconds since device was initialized or 0 if unknown. |
Since 165
const gchar * const * g_udev_device_get_property_keys (GUdevDevice *device
);
Gets all keys for properties on 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]
|
gboolean g_udev_device_has_property (GUdevDevice *device
,const gchar *key
);
Check if a the property with the given key exists.
|
A GUdevDevice. |
|
Name of property. |
Returns : |
TRUE only if the value for key exist. |
const gchar * g_udev_device_get_property (GUdevDevice *device
,const gchar *key
);
Look up the value for key
on device
.
|
A GUdevDevice. |
|
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 . |
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()
.
|
A GUdevDevice. |
|
Name of property. |
Returns : |
The value for key or 0 if key doesn't exist or
isn't an integer. |
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()
.
|
A GUdevDevice. |
|
Name of property. |
Returns : |
The value for key or 0 if key doesn't exist or isn't a
guint64. |
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()
.
|
A GUdevDevice. |
|
Name of property. |
Returns : |
The value for key or 0.0 if key doesn't exist or isn't a
gdouble. |
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".
|
A GUdevDevice. |
|
Name of property. |
Returns : |
The value for key or FALSE if key doesn't exist or
isn't a gboolean. |
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).
|
A GUdevDevice. |
|
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]
|
const gchar * g_udev_device_get_sysfs_attr (GUdevDevice *device
,const gchar *name
);
Look up the sysfs attribute with name
on device
.
|
A GUdevDevice. |
|
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 . |
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()
.
|
A GUdevDevice. |
|
Name of the sysfs attribute. |
Returns : |
The value of the sysfs attribute or 0 if there is no such attribute. |
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()
.
|
A GUdevDevice. |
|
Name of the sysfs attribute. |
Returns : |
The value of the sysfs attribute or 0 if there is no such attribute. |
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()
.
|
A GUdevDevice. |
|
Name of the sysfs attribute. |
Returns : |
The value of the sysfs attribute or 0.0 if there is no such attribute. |
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".
|
A GUdevDevice. |
|
Name of the sysfs attribute. |
Returns : |
The value of the sysfs attribute or FALSE if there is no such
attribute. |
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).
|
A GUdevDevice. |
|
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]
|