LdmDevice

LdmDevice — Abstract device encapsulation

Functions

Properties

LdmDeviceAttribute attributes Read
LdmDeviceType device-type Read
gchar * modalias Read
gchar * name Read
gpointer parent Read / Write / Construct Only
gchar * path Read
gint priority Read / Write
gint product-id Read
gchar * vendor Read
gint vendor-id Read

Types and Values

Object Hierarchy

    GEnum
    ╰── LdmPCIVendorID
    GFlags
    ├── LdmDeviceAttribute
    ╰── LdmDeviceType
    GObject
    ╰── GInitiallyUnowned
        ╰── LdmDevice
            ├── LdmBluetoothDevice
            ├── LdmDMIDevice
            ├── LdmHIDDevice
            ├── LdmPCIDevice
            ╰── LdmUSBDevice

Description

An LdmDevice is not directly created, it is owned and constructed by an LdmManager instance. Each LdmDevice may either be a PCI or USB device, and is in reality an abstraction of an underlying udev device.

This object provides easy access to system devices, allowing the end user to easily introspect basic properties such as the “name”, “vendor-id” or even the “modalias”.

Each device returned by the LdmManager is a composite toplevel device, that is to say, it is the sum of all of its properties. This is particularly helpful when dealing with LdmUSBDevice, whereby the root level properties of the device are the sum of all child parts. This allows users of the library to ignore USB interface internals and directly query an LdmDevice to determine what capabilities and classes it supports, such as a composite device with LDM_DEVICE_TYPE_VIDEO | LDM_DEVICE_TYPE_AUDIO capabilities.

Functions

ldm_device_get_modalias ()

const gchar *
ldm_device_get_modalias (LdmDevice *device);

The modalias is unique to the device and is used in identifying potential driver candidates.

The Linux kernel will assign each device (or interface) a modalias, which can be matched via LdmModalias and LdmModaliasPlugin to determine which package provides the drivers required to enable this device.

Returns

The modalias of the device.

[transfer none]


ldm_device_get_name ()

const gchar *
ldm_device_get_name (LdmDevice *device);

This function will return the name (model) of this device, suitable for presentation to a user.

Returns

The name of the device.

[transfer none]


ldm_device_get_path ()

const gchar *
ldm_device_get_path (LdmDevice *device);

This function will return the system-specific path for this device. This is the fully qualified /sys path.

Returns

The path of the device.

[transfer none]


ldm_device_get_product_id ()

gint
ldm_device_get_product_id (LdmDevice *device);

This function will return the product ID (model) of this device, suitable for comparison with known models.

Returns

The product ID of the device


ldm_device_get_vendor ()

const gchar *
ldm_device_get_vendor (LdmDevice *device);

This function will return the vendor (manufacturer) of this device, suitable for presentation to a user.

Returns

The vendor of the device.

[transfer none]


ldm_device_get_vendor_id ()

gint
ldm_device_get_vendor_id (LdmDevice *device);

This function will return the vendor ID (manufacturer) of this device, suitable for comparison with known vendors.

This is especially useful with the predefined LdmPCIVendorID IDs

C example:

1
2
3
if (ldm_device_get_vendor_id(device) == LDM_PCI_VENDOR_ID_NVIDIA) {
        g_message("Found an NVIDIA device!");
}

Returns

The vendor ID of the device


ldm_device_get_device_type ()

LdmDeviceType
ldm_device_get_device_type (LdmDevice *device);

Return the device type (bitwise field)


ldm_device_get_attributes ()

LdmDeviceAttribute
ldm_device_get_attributes (LdmDevice *device);

Return the device type (bitwise field)


ldm_device_has_type ()

gboolean
ldm_device_has_type (LdmDevice *device,
                     LdmDeviceType mask);

Test whether this device has the given type(s) by testing the mask against our known types.

C example:

1
2
3
if (ldm_device_has_type(device, LDM_DEVICE_TYPE_USB | LDM_DEVICE_TYPE_PRINTER) {
        g_message("Found a USB printer!");
}

Parameters

mask

Bitwise OR combination of LdmDeviceType

 

ldm_device_has_attribute ()

gboolean
ldm_device_has_attribute (LdmDevice *device,
                          LdmDeviceAttribute mask);

Test whether this device has the given attribute(s) by testing the mask against our known attributes

C example:

1
2
3
if (ldm_device_has_attribute(device, LDM_DEVICE_ATTRIBUTE_BOOT_VGA)) {
        g_message("User booted with this GPU: %s", ldm_device_get_name(device));
}

Parameters

mask

Bitwise OR combination of LdmDeviceAttribute

 

ldm_device_get_parent ()

LdmDevice *
ldm_device_get_parent (LdmDevice *device);

Get the parent device, if any

Returns

The parent device if it exists.

[transfer none][nullable]


ldm_device_get_children ()

GList *
ldm_device_get_children (LdmDevice *device);

Return any child devices, if any

Returns

a list of all child devices.

[element-type Ldm.Device][transfer container]


ldm_device_get_priority ()

gint
ldm_device_get_priority (LdmDevice *device);

Since: 1.0.2

Types and Values

enum LdmPCIVendorID

Well known vendor IDs that are statically defined here to make future lookup and comparisons simpler to users of libldm.

Members

LDM_PCI_VENDOR_ID_AMD

AMD PCI device ID

 

LDM_PCI_VENDOR_ID_INTEL

Intel PCI device ID

 

LDM_PCI_VENDOR_ID_NVIDIA

NVIDIA PCI device id

 

enum LdmDeviceType

Any device known to LDM may have one or more "types", defining the primary use-case for these devices. Simple devices will tend to have a single distinct type, such as "GPU". Composite devices, such as a USB camera, may have multiple types, such s HID|IMAGE.

As such - each LdmDevice stores a composite type which may be queried by the API.

Members

LDM_DEVICE_TYPE_ANY

Device type is either unknown or unhandled

 

LDM_DEVICE_TYPE_AUDIO

Audio device

 

LDM_DEVICE_TYPE_BLUETOOTH

Bluetooth communication device

 

LDM_DEVICE_TYPE_GPU

A graphics device (onboard, NVIDIA, etc.)

 

LDM_DEVICE_TYPE_HID

Human interface device (mouse, keyboard, etc.)

 

LDM_DEVICE_TYPE_IMAGE

Imaging device such as a camera

 

LDM_DEVICE_TYPE_PCI

The device is connected via PCI

 

LDM_DEVICE_TYPE_PLATFORM

   

LDM_DEVICE_TYPE_PRINTER

Printer

 

LDM_DEVICE_TYPE_STORAGE

Storage device

 

LDM_DEVICE_TYPE_VIDEO

Video device, perhaps a webcam

 

LDM_DEVICE_TYPE_WIRELESS

A wireless device, i.e. dongle or mouse

 

LDM_DEVICE_TYPE_USB

The device is connected via USB

 

LDM_DEVICE_TYPE_MAX

   

enum LdmDeviceAttribute

A device have one or more special attributes that need to be queried beyond the initial DeviceType search.

Members

LDM_DEVICE_ATTRIBUTE_ANY

No explicitly set attributes

 

LDM_DEVICE_ATTRIBUTE_BOOT_VGA

This device is the GPU used to boot the system

 

LDM_DEVICE_ATTRIBUTE_HOST

Enable differentiation between host and non host controllers

 

LDM_DEVICE_ATTRIBUTE_INTERFACE

Pseudo-device (USB interface, etc.)

 

LDM_DEVICE_ATTRIBUTE_MAX

   

Property Details

The “attributes” property

  “attributes”               LdmDeviceAttribute

The composite attributes of this device, which is a bitwise combination of multiple attribute (such as BOOT_VGA)

Owner: LdmDevice

Flags: Read


The “device-type” property

  “device-type”              LdmDeviceType

The composite type of this device, which is a bitwise combination of multiple device types (such as PCI|GPU)

Owner: LdmDevice

Flags: Read


The “modalias” property

  “modalias”                 gchar *

The modalias reported by the kernel for this device.

Owner: LdmDevice

Flags: Read

Default value: NULL


The “name” property

  “name”                     gchar *

The name used to display this device to users, i.e. the model.

Owner: LdmDevice

Flags: Read

Default value: NULL


The “parent” property

  “parent”                   gpointer

Parent device for this device instance

[transfer none]

Owner: LdmDevice

Flags: Read / Write / Construct Only


The “path” property

  “path”                     gchar *

The system path for this device. On Linux this is the sysfs path.

Owner: LdmDevice

Flags: Read

Default value: NULL


The “priority” property

  “priority”                 gint

Used to ensure stable device sorting.

Owner: LdmDevice

Flags: Read / Write

Allowed values: [0,1000]

Default value: 0

Since: 1.0.2


The “product-id” property

  “product-id”               gint

The product ID for this device.

Owner: LdmDevice

Flags: Read

Allowed values: [0,0]

Default value: 0


The “vendor” property

  “vendor”                   gchar *

The vendor string to display the users, i.e. the manufacturer.

Owner: LdmDevice

Flags: Read

Default value: NULL


The “vendor-id” property

  “vendor-id”                gint

The vendor ID for this device.

Owner: LdmDevice

Flags: Read

Allowed values: [0,0]

Default value: 0

See Also

LdmManager, LdmModalias