The Device class is used to get information about a specific device.
Note that you cannot instantiate a Device object yourself. Instead you must use
Client to obtain Device objects.
To get basic information about a device, use get_subsystem,
get_devtype, get_name,
get_number,
get_sysfs_path, get_driver,
get_action, get_seqnum
, get_device_type,
get_device_number,
get_device_file,
get_device_file_symlinks.
To navigate the device tree, use get_parent and
get_parent_with_subsystem.
To access udev properties for the device, use get_property_keys,
has_property,
get_property, get_property_as_int,
get_property_as_uint64,
get_property_as_double,
get_property_as_boolean and
get_property_as_strv.
To access sysfs attributes for the device, use get_sysfs_attr_keys,
has_sysfs_attr,
get_sysfs_attr, get_sysfs_attr_as_int,
get_sysfs_attr_as_uint64,
get_sysfs_attr_as_double,
get_sysfs_attr_as_boolean and
get_sysfs_attr_as_strv.
Note that all getters on Device 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, Device will not react to changes for a device – it only contains a snapshot of information when
the Device object was created. To work with changes, you typically connect to the
uevent signal on a Client and get a
new Device whenever an event happens.
- public unowned string get_action ()
Gets the most recent action (e.g. "add", "remove", "change", etc.
- public unowned string? get_device_file ()
Gets the device file for this.
- public unowned string[] get_device_file_symlinks ()
Gets a list of symlinks (in /dev) that points to the device
file for this.
- public DeviceNumber get_device_number ()
Gets the device number, if any, for this
.
- public DeviceType get_device_type ()
Gets the type of the device file, if any, for
this.
- public unowned string get_devtype ()
Gets the device type for this.
- public unowned string? get_driver ()
Gets the name of the driver used for this
.
- public bool get_is_initialized ()
Gets whether this has been
initialized.
- public unowned string get_name ()
Gets the name of this, e.g. "sda3".
- public unowned string get_number ()
Gets the number of this, e.g. "3" if
get_name returns "sda3".
- public Device? get_parent ()
Gets the immediate parent of this,
if any.
- public Device? get_parent_with_subsystem (string subsystem, string? devtype)
Walks up the chain of parents of this
and returns the first device encountered where subsystem
and devtype
matches, if any.
- public unowned string? get_property (string key)
Look up the value for key
on
this.
- public bool get_property_as_boolean (string key)
Look up the value for key
on
this and convert it to an boolean.
- public double get_property_as_double (string key)
Look up the value for key
on
this and convert it to a double precision floating point number using ascii_strtod.
- public int get_property_as_int (string key)
Look up the value for key
on
this and convert it to an integer using strtol.
- public unowned string[]? get_property_as_strv (string key)
Look up the value for key
on
this 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).
- public uint64 get_property_as_uint64 (string key)
Look up the value for key
on
this and convert it to an unsigned 64-bit integer using ascii_strtoull.
- public unowned string[] get_property_keys ()
Gets all keys for properties on this
.
- public uint64 get_seqnum ()
Gets the most recent sequence number for
this.
- public unowned string get_subsystem ()
Gets the subsystem for this.
- public unowned string? get_sysfs_attr (string name)
Look up the sysfs attribute with name
on
this.
- public bool get_sysfs_attr_as_boolean (string name)
Look up the sysfs attribute with name
on
this and convert it to an boolean.
- public bool get_sysfs_attr_as_boolean_uncached (string name)
Look up the sysfs attribute with name
on
this and convert it to an boolean.
- public double get_sysfs_attr_as_double (string name)
Look up the sysfs attribute with name
on
this and convert it to a double precision floating point number using
ascii_strtod.
- public double get_sysfs_attr_as_double_uncached (string name)
Look up the sysfs attribute with name
on
this and convert it to a double precision floating point number using
ascii_strtod.
- public int get_sysfs_attr_as_int (string name)
Look up the sysfs attribute with name
on
this and convert it to an integer using strtol.
- public int get_sysfs_attr_as_int_uncached (string name)
Look up the sysfs attribute with name
on
this and convert it to an integer using strtol.
- public unowned string[]? get_sysfs_attr_as_strv (string name)
Look up the sysfs attribute with name
on
this 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).
- public unowned string[]? get_sysfs_attr_as_strv_uncached (string name)
Look up the sysfs attribute with name
on
this 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).
- public uint64 get_sysfs_attr_as_uint64 (string name)
Look up the sysfs attribute with name
on
this and convert it to an unsigned 64-bit integer using ascii_strtoull
.
- public uint64 get_sysfs_attr_as_uint64_uncached (string name)
Look up the sysfs attribute with name
on
this and convert it to an unsigned 64-bit integer using ascii_strtoull
.
- public unowned string[] get_sysfs_attr_keys ()
Gets all keys for sysfs attributes on this
.
- public unowned string? get_sysfs_attr_uncached (string name)
Look up the sysfs attribute with name
on
this.
- public unowned string get_sysfs_path ()
Gets the sysfs path for this.
- public unowned string[] get_tags ()
Gets all tags for this.
- public uint64 get_usec_since_initialized ()
Gets number of micro-seconds since this
was initialized.
- public bool has_property (string key)
Check if a the property with the given key exists.
- public bool has_sysfs_attr (string key)
Check if a the sysfs attribute with the given key exists.
- public bool has_sysfs_attr_uncached (string key)
Check if a the sysfs attribute with the given key exists.