mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-16 11:55:39 +00:00
st/prober: Refactor hidraw enumeration code in udev file
This commit is contained in:
parent
dfdc794272
commit
cb44c822d2
|
@ -267,6 +267,7 @@ teardown_devices(struct prober* p)
|
|||
for (size_t i = 0; i < p->num_devices; i++) {
|
||||
struct prober_device* pdev = &p->devices[i];
|
||||
|
||||
#ifdef XRT_OS_LINUX
|
||||
for (size_t j = 0; j < pdev->num_hidraws; j++) {
|
||||
struct prober_hidraw* hidraw = &pdev->hidraws[j];
|
||||
free((char*)hidraw->path);
|
||||
|
@ -278,6 +279,7 @@ teardown_devices(struct prober* p)
|
|||
pdev->hidraws = NULL;
|
||||
pdev->num_hidraws = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (p->devices != NULL) {
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#define MAX_AUTO_PROBERS 8
|
||||
|
||||
|
||||
#ifdef XRT_OS_LINUX
|
||||
/*!
|
||||
* A hidraw interface that a @ref prober_device exposes.
|
||||
*/
|
||||
|
@ -63,6 +64,7 @@ struct prober_hidraw
|
|||
ssize_t interface;
|
||||
const char* path;
|
||||
};
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* A prober device.
|
||||
|
@ -101,10 +103,10 @@ struct prober_device
|
|||
{
|
||||
const char** paths;
|
||||
} v4l;
|
||||
#endif
|
||||
|
||||
size_t num_hidraws;
|
||||
struct prober_hidraw* hidraws;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct prober
|
||||
|
|
|
@ -34,7 +34,10 @@
|
|||
*/
|
||||
|
||||
static void
|
||||
p_udev_add_interface(struct prober_device* pdev,
|
||||
p_udev_enumerate_hidraw(struct prober* p, struct udev* udev);
|
||||
|
||||
static void
|
||||
p_udev_add_hidraw(struct prober_device* pdev,
|
||||
uint32_t interface,
|
||||
const char* path);
|
||||
|
||||
|
@ -50,7 +53,7 @@ p_udev_get_and_parse_uevent(struct udev_device* raw_dev,
|
|||
uint64_t* out_bluetooth_serial);
|
||||
|
||||
static int
|
||||
p_udev_get_usb_address(struct udev_device* raw_dev,
|
||||
p_udev_get_usb_hid_address(struct udev_device* raw_dev,
|
||||
uint32_t bus_type,
|
||||
uint16_t* usb_bus,
|
||||
uint16_t* usb_addr);
|
||||
|
@ -65,27 +68,32 @@ p_udev_get_usb_address(struct udev_device* raw_dev,
|
|||
int
|
||||
p_udev_probe(struct prober* p)
|
||||
{
|
||||
struct prober_device* pdev;
|
||||
struct udev* udev;
|
||||
struct udev_enumerate* enumerate;
|
||||
struct udev_list_entry *devices, *dev_list_entry;
|
||||
struct udev_device* raw_dev = NULL;
|
||||
uint16_t vendor_id, product_id, interface;
|
||||
uint16_t usb_bus = 0;
|
||||
uint16_t usb_addr = 0;
|
||||
uint32_t bus_type;
|
||||
uint64_t bluetooth_id;
|
||||
int ret;
|
||||
|
||||
const char* sysfs_path;
|
||||
const char* dev_path;
|
||||
|
||||
udev = udev_new();
|
||||
struct udev* udev = udev_new();
|
||||
if (!udev) {
|
||||
P_ERROR(p, "Can't create udev\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
p_udev_enumerate_hidraw(p, udev);
|
||||
|
||||
udev = udev_unref(udev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Internal functions.
|
||||
*
|
||||
*/
|
||||
|
||||
static void
|
||||
p_udev_enumerate_hidraw(struct prober* p, struct udev* udev)
|
||||
{
|
||||
struct udev_enumerate* enumerate;
|
||||
struct udev_list_entry *devices, *dev_list_entry;
|
||||
|
||||
enumerate = udev_enumerate_new(udev);
|
||||
udev_enumerate_add_match_subsystem(enumerate, "hidraw");
|
||||
udev_enumerate_scan_devices(enumerate);
|
||||
|
@ -94,6 +102,17 @@ p_udev_probe(struct prober* p)
|
|||
|
||||
udev_list_entry_foreach(dev_list_entry, devices)
|
||||
{
|
||||
struct prober_device* pdev = NULL;
|
||||
struct udev_device* raw_dev = NULL;
|
||||
uint16_t vendor_id, product_id, interface;
|
||||
uint16_t usb_bus = 0;
|
||||
uint16_t usb_addr = 0;
|
||||
uint32_t bus_type = 0;
|
||||
uint64_t bluetooth_id = 0;
|
||||
const char* sysfs_path;
|
||||
const char* dev_path;
|
||||
int ret;
|
||||
|
||||
// Where in the sysfs is.
|
||||
sysfs_path = udev_list_entry_get_name(dev_list_entry);
|
||||
// Raw sysfs node.
|
||||
|
@ -117,7 +136,7 @@ p_udev_probe(struct prober* p)
|
|||
}
|
||||
|
||||
// Get USB bus and address to de-dublicate devices.
|
||||
ret = p_udev_get_usb_address(raw_dev, bus_type, &usb_bus,
|
||||
ret = p_udev_get_usb_hid_address(raw_dev, bus_type, &usb_bus,
|
||||
&usb_addr);
|
||||
if (ret != 0) {
|
||||
P_ERROR(p, "Failed to get USB bus and addr.");
|
||||
|
@ -161,27 +180,17 @@ p_udev_probe(struct prober* p)
|
|||
}
|
||||
|
||||
// Add this interface to the usb device.
|
||||
p_udev_add_interface(pdev, interface, dev_path);
|
||||
p_udev_add_hidraw(pdev, interface, dev_path);
|
||||
|
||||
next:
|
||||
udev_device_unref(raw_dev);
|
||||
}
|
||||
|
||||
enumerate = udev_enumerate_unref(enumerate);
|
||||
udev = udev_unref(udev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Internal functions.
|
||||
*
|
||||
*/
|
||||
|
||||
static void
|
||||
p_udev_add_interface(struct prober_device* pdev,
|
||||
p_udev_add_hidraw(struct prober_device* pdev,
|
||||
uint32_t interface,
|
||||
const char* path)
|
||||
{
|
||||
|
@ -197,7 +206,7 @@ p_udev_add_interface(struct prober_device* pdev,
|
|||
}
|
||||
|
||||
static int
|
||||
p_udev_get_usb_address(struct udev_device* raw_dev,
|
||||
p_udev_get_usb_hid_address(struct udev_device* raw_dev,
|
||||
uint32_t bus_type,
|
||||
uint16_t* usb_bus,
|
||||
uint16_t* usb_addr)
|
||||
|
|
Loading…
Reference in a new issue