LdmUSBDevice

LdmUSBDevice — USB Device abstraction

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── LdmDevice
            ╰── LdmUSBDevice

Description

An LdmUSBDevice is a specialised implementation of the LdmDevice which is aware of UB interface capabilities. This class is never directly created by the user, but is instead returned by the LdmManager.

This class extends the base LdmDevice to add USB specific data.

Users can test if a device is a USB device without having to cast, by simply checking the “device-type”:

1
2
3
4
5
6
7
8
if (ldm_device_has_type(device, LDM_DEVICE_TYPE_USB)) {
        g_message("Found PCI device");
}

// Alternatively..
if (LDM_IS_USB_DEVICE(device)) {
        g_message("Found PCI device through casting");
}

Internally USB devices are complex, having a top-level device visible to the operating system and specialised interfaces (bInterfaceClass) exposed via ports. LdmUSBDevice abstracts that complexity away, and is instead composed of multiple devices.

Conceptually, a LdmUSBDevice has each interface as a separate child within the toplevel instance. Most end users will be able to safely ignore this difference, as LdmUSBDevice will modify the “device-type” to be the merged type of the toplevel device, and all interfaces.

As a result, any capabilities exposed by interfaces are available in the toplevel object returned by the LdmManager instance. This can be used to search for specific types of USB devices:

1
2
3
4
5
6
7
gint search_mask = LDM_DEVICE_TYPE_USB | LDM_DEVICE_TYPE_PRINTER;
g_autoptr(GPtrArray) usb_printers = ldm_manager_get_devices(search_mask);
g_message("Got %u printers", usb_printers->len);
LdmDevice *device = usb_printers->pdata[0];
if (ldm_device_has_type(device, LDM_DEVICE_TYPE_IMAGE)) {
        g_message("Printer supports PTP!");
}

Functions

Types and Values

See Also

LdmDevice