Backed out change to dynamically load udev - it's already happening in SDL_hidapi.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
diff --git a/src/hidapi/linux/hid.c b/src/hidapi/linux/hid.c
index bde15da..2cc2d8b 100644
--- a/src/hidapi/linux/hid.c
+++ b/src/hidapi/linux/hid.c
@@ -48,8 +48,7 @@
#include <linux/hidraw.h>
#include <linux/version.h>
#include <linux/input.h>
-//#include <libudev.h>
-#include "../../core/linux/SDL_udev.h"
+#include <libudev.h>
#include "hidapi.h"
@@ -67,8 +66,6 @@ namespace NAMESPACE
#define HIDIOCGFEATURE(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x07, len)
#endif
-static const SDL_UDEV_Symbols *udev_syms;
-
/* USB HID device property names */
const char *device_string_names[] = {
"manufacturer",
@@ -150,7 +147,7 @@ static wchar_t *utf8_to_wchar_t(const char *utf8)
string. The returned string must be freed with free() when done.*/
static wchar_t *copy_udev_string(struct udev_device *dev, const char *udev_name)
{
- return utf8_to_wchar_t(udev_syms->udev_device_get_sysattr_value(dev, udev_name));
+ return utf8_to_wchar_t(udev_device_get_sysattr_value(dev, udev_name));
}
/* uses_numbered_reports() returns 1 if report_descriptor describes a device
@@ -280,7 +277,7 @@ static int is_bluetooth(hid_device *dev)
int ret = -1;
/* Create the udev object */
- udev = udev_syms->udev_new();
+ udev = udev_new();
if (!udev) {
printf("Can't create udev\n");
return -1;
@@ -289,14 +286,14 @@ static int is_bluetooth(hid_device *dev)
/* Get the dev_t (major/minor numbers) from the file handle. */
ret = fstat(dev->device_handle, &s);
if (-1 == ret) {
- udev_syms->udev_unref(udev);
+ udev_unref(udev);
return ret;
}
/* Open a udev device from the dev_t. 'c' means character device. */
- udev_dev = udev_syms->udev_device_new_from_devnum(udev, 'c', s.st_rdev);
+ udev_dev = udev_device_new_from_devnum(udev, 'c', s.st_rdev);
if (udev_dev) {
- hid_dev = udev_syms->udev_device_get_parent_with_subsystem_devtype(
+ hid_dev = udev_device_get_parent_with_subsystem_devtype(
udev_dev,
"hid",
NULL);
@@ -308,7 +305,7 @@ static int is_bluetooth(hid_device *dev)
char *product_name_utf8 = NULL;
ret = parse_uevent_info(
- udev_syms->udev_device_get_sysattr_value(hid_dev, "uevent"),
+ udev_device_get_sysattr_value(hid_dev, "uevent"),
&bus_type,
&dev_vid,
&dev_pid,
@@ -322,10 +319,10 @@ static int is_bluetooth(hid_device *dev)
/* hid_dev doesn't need to be (and can't be) unref'd.
I'm not sure why, but it'll throw double-free() errors. */
}
- udev_syms->udev_device_unref(udev_dev);
+ udev_device_unref(udev_dev);
}
- udev_syms->udev_unref(udev);
+ udev_unref(udev);
return ret;
}
@@ -342,7 +339,7 @@ static int get_device_string(hid_device *dev, enum device_string_id key, wchar_t
char *tmp;
/* Create the udev object */
- udev = udev_syms->udev_new();
+ udev = udev_new();
if (!udev) {
printf("Can't create udev\n");
return -1;
@@ -351,13 +348,13 @@ static int get_device_string(hid_device *dev, enum device_string_id key, wchar_t
/* Get the dev_t (major/minor numbers) from the file handle. */
ret = fstat(dev->device_handle, &s);
if (-1 == ret) {
- udev_syms->udev_unref(udev);
+ udev_unref(udev);
return ret;
}
/* Open a udev device from the dev_t. 'c' means character device. */
- udev_dev = udev_syms->udev_device_new_from_devnum(udev, 'c', s.st_rdev);
+ udev_dev = udev_device_new_from_devnum(udev, 'c', s.st_rdev);
if (udev_dev) {
- hid_dev = udev_syms->udev_device_get_parent_with_subsystem_devtype(
+ hid_dev = udev_device_get_parent_with_subsystem_devtype(
udev_dev,
"hid",
NULL);
@@ -368,7 +365,7 @@ static int get_device_string(hid_device *dev, enum device_string_id key, wchar_t
size_t retm;
ret = parse_uevent_info(
- udev_syms->udev_device_get_sysattr_value(hid_dev, "uevent"),
+ udev_device_get_sysattr_value(hid_dev, "uevent"),
&bus_type,
&dev_vid,
&dev_pid,
@@ -404,7 +401,7 @@ static int get_device_string(hid_device *dev, enum device_string_id key, wchar_t
}
else {
/* This is a USB device. Find its parent USB Device node. */
- parent = udev_syms->udev_device_get_parent_with_subsystem_devtype(
+ parent = udev_device_get_parent_with_subsystem_devtype(
udev_dev,
"usb",
"usb_device");
@@ -419,7 +416,7 @@ static int get_device_string(hid_device *dev, enum device_string_id key, wchar_t
goto end;
}
- str = udev_syms->udev_device_get_sysattr_value(parent, key_str);
+ str = udev_device_get_sysattr_value(parent, key_str);
if (str) {
/* Convert the string from UTF-8 to wchar_t */
retm = mbstowcs(string, str, maxlen);
@@ -435,10 +432,10 @@ end:
free(serial_number_utf8);
free(product_name_utf8);
- udev_syms->udev_device_unref(udev_dev);
+ udev_device_unref(udev_dev);
/* parent and hid_dev don't need to be (and can't be) unref'd.
I'm not sure why, but they'll throw double-free() errors. */
- udev_syms->udev_unref(udev);
+ udev_unref(udev);
return ret;
}
@@ -454,17 +451,11 @@ int HID_API_EXPORT hid_init(void)
kernel_version = detect_kernel_version();
- udev_syms = SDL_UDEV_GetUdevSyms();
- if (!udev_syms)
- return -1;
-
return 0;
}
int HID_API_EXPORT hid_exit(void)
{
- SDL_UDEV_ReleaseUdevSyms();
-
/* Nothing to do for this in the Linux/hidraw implementation. */
return 0;
}
@@ -483,23 +474,20 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
hid_init();
/* Create the udev object */
- udev = udev_syms->udev_new();
+ udev = udev_new();
if (!udev) {
printf("Can't create udev\n");
return NULL;
}
/* Create a list of the devices in the 'hidraw' subsystem. */
- enumerate = udev_syms->udev_enumerate_new(udev);
- udev_syms->udev_enumerate_add_match_subsystem(enumerate, "hidraw");
- udev_syms->udev_enumerate_scan_devices(enumerate);
- devices = udev_syms->udev_enumerate_get_list_entry(enumerate);
+ enumerate = udev_enumerate_new(udev);
+ udev_enumerate_add_match_subsystem(enumerate, "hidraw");
+ udev_enumerate_scan_devices(enumerate);
+ devices = udev_enumerate_get_list_entry(enumerate);
/* For each item, see if it matches the vid/pid, and if so
create a udev_device record for it */
- for (dev_list_entry = devices;
- dev_list_entry;
- dev_list_entry = udev_syms->udev_list_entry_get_next(dev_list_entry)) {
-
+ udev_list_entry_foreach(dev_list_entry, devices) {
const char *sysfs_path;
const char *dev_path;
const char *str;
@@ -516,11 +504,11 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
/* Get the filename of the /sys entry for the device
and create a udev_device object (dev) representing it */
- sysfs_path = udev_syms->udev_list_entry_get_name(dev_list_entry);
- raw_dev = udev_syms->udev_device_new_from_syspath(udev, sysfs_path);
- dev_path = udev_syms->udev_device_get_devnode(raw_dev);
+ sysfs_path = udev_list_entry_get_name(dev_list_entry);
+ raw_dev = udev_device_new_from_syspath(udev, sysfs_path);
+ dev_path = udev_device_get_devnode(raw_dev);
- hid_dev = udev_syms->udev_device_get_parent_with_subsystem_devtype(
+ hid_dev = udev_device_get_parent_with_subsystem_devtype(
raw_dev,
"hid",
NULL);
@@ -531,7 +519,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
}
result = parse_uevent_info(
- udev_syms->udev_device_get_sysattr_value(hid_dev, "uevent"),
+ udev_device_get_sysattr_value(hid_dev, "uevent"),
&bus_type,
&dev_vid,
&dev_pid,
@@ -594,7 +582,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
subsystem/devtype pair of "usb"/"usb_device". This will
be several levels up the tree, but the function will find
it. */
- usb_dev = udev_syms->udev_device_get_parent_with_subsystem_devtype(
+ usb_dev = udev_device_get_parent_with_subsystem_devtype(
raw_dev,
"usb",
"usb_device");
@@ -622,16 +610,16 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
cur_dev->product_string = copy_udev_string(usb_dev, device_string_names[DEVICE_STRING_PRODUCT]);
/* Release Number */
- str = udev_syms->udev_device_get_sysattr_value(usb_dev, "bcdDevice");
+ str = udev_device_get_sysattr_value(usb_dev, "bcdDevice");
cur_dev->release_number = (str)? strtol(str, NULL, 16): 0x0;
/* Get a handle to the interface's udev node. */
- intf_dev = udev_syms->udev_device_get_parent_with_subsystem_devtype(
+ intf_dev = udev_device_get_parent_with_subsystem_devtype(
raw_dev,
"usb",
"usb_interface");
if (intf_dev) {
- str = udev_syms->udev_device_get_sysattr_value(intf_dev, "bInterfaceNumber");
+ str = udev_device_get_sysattr_value(intf_dev, "bInterfaceNumber");
cur_dev->interface_number = (str)? strtol(str, NULL, 16): -1;
}
@@ -654,14 +642,14 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
next:
free(serial_number_utf8);
free(product_name_utf8);
- udev_syms->udev_device_unref(raw_dev);
+ udev_device_unref(raw_dev);
/* hid_dev, usb_dev and intf_dev don't need to be (and can't be)
unref()d. It will cause a double-free() error. I'm not
sure why. */
}
/* Free the enumerator and udev objects. */
- udev_syms->udev_enumerate_unref(enumerate);
- udev_syms->udev_unref(udev);
+ udev_enumerate_unref(enumerate);
+ udev_unref(udev);
return root;
}