Backed out change to dynamically load udev - it's already happening in SDL_hidapi.c
authorSam Lantinga <slouken@libsdl.org>
Mon, 25 Nov 2019 15:02:45 -0800
changeset 13286fcb5afd26d62
parent 13285 4780fabbb0ea
child 13287 38b490ed9e32
Backed out change to dynamically load udev - it's already happening in SDL_hidapi.c
src/hidapi/linux/hid.c
     1.1 --- a/src/hidapi/linux/hid.c	Mon Nov 25 13:27:26 2019 -0800
     1.2 +++ b/src/hidapi/linux/hid.c	Mon Nov 25 15:02:45 2019 -0800
     1.3 @@ -48,8 +48,7 @@
     1.4  #include <linux/hidraw.h>
     1.5  #include <linux/version.h>
     1.6  #include <linux/input.h>
     1.7 -//#include <libudev.h>
     1.8 -#include "../../core/linux/SDL_udev.h"
     1.9 +#include <libudev.h>
    1.10  
    1.11  #include "hidapi.h"
    1.12  
    1.13 @@ -67,8 +66,6 @@
    1.14  #define HIDIOCGFEATURE(len)    _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x07, len)
    1.15  #endif
    1.16  
    1.17 -static const SDL_UDEV_Symbols *udev_syms;
    1.18 -
    1.19  /* USB HID device property names */
    1.20  const char *device_string_names[] = {
    1.21  	"manufacturer",
    1.22 @@ -150,7 +147,7 @@
    1.23     string. The returned string must be freed with free() when done.*/
    1.24  static wchar_t *copy_udev_string(struct udev_device *dev, const char *udev_name)
    1.25  {
    1.26 -	return utf8_to_wchar_t(udev_syms->udev_device_get_sysattr_value(dev, udev_name));
    1.27 +	return utf8_to_wchar_t(udev_device_get_sysattr_value(dev, udev_name));
    1.28  }
    1.29  
    1.30  /* uses_numbered_reports() returns 1 if report_descriptor describes a device
    1.31 @@ -280,7 +277,7 @@
    1.32  	int ret = -1;
    1.33  
    1.34  	/* Create the udev object */
    1.35 -	udev = udev_syms->udev_new();
    1.36 +	udev = udev_new();
    1.37  	if (!udev) {
    1.38  		printf("Can't create udev\n");
    1.39  		return -1;
    1.40 @@ -289,14 +286,14 @@
    1.41  	/* Get the dev_t (major/minor numbers) from the file handle. */
    1.42  	ret = fstat(dev->device_handle, &s);
    1.43  	if (-1 == ret) {
    1.44 -		udev_syms->udev_unref(udev);
    1.45 +		udev_unref(udev);
    1.46  		return ret;
    1.47  	}
    1.48  
    1.49  	/* Open a udev device from the dev_t. 'c' means character device. */
    1.50 -	udev_dev = udev_syms->udev_device_new_from_devnum(udev, 'c', s.st_rdev);
    1.51 +	udev_dev = udev_device_new_from_devnum(udev, 'c', s.st_rdev);
    1.52  	if (udev_dev) {
    1.53 -		hid_dev = udev_syms->udev_device_get_parent_with_subsystem_devtype(
    1.54 +		hid_dev = udev_device_get_parent_with_subsystem_devtype(
    1.55  			udev_dev,
    1.56  			"hid",
    1.57  			NULL);
    1.58 @@ -308,7 +305,7 @@
    1.59  			char *product_name_utf8 = NULL;
    1.60  
    1.61  			ret = parse_uevent_info(
    1.62 -			           udev_syms->udev_device_get_sysattr_value(hid_dev, "uevent"),
    1.63 +			           udev_device_get_sysattr_value(hid_dev, "uevent"),
    1.64  			           &bus_type,
    1.65  			           &dev_vid,
    1.66  			           &dev_pid,
    1.67 @@ -322,10 +319,10 @@
    1.68  			/* hid_dev doesn't need to be (and can't be) unref'd.
    1.69  			   I'm not sure why, but it'll throw double-free() errors. */
    1.70  		}
    1.71 -		udev_syms->udev_device_unref(udev_dev);
    1.72 +		udev_device_unref(udev_dev);
    1.73  	}
    1.74  
    1.75 -	udev_syms->udev_unref(udev);
    1.76 +	udev_unref(udev);
    1.77  
    1.78  	return ret;
    1.79  }
    1.80 @@ -342,7 +339,7 @@
    1.81  	char *tmp;
    1.82  
    1.83  	/* Create the udev object */
    1.84 -	udev = udev_syms->udev_new();
    1.85 +	udev = udev_new();
    1.86  	if (!udev) {
    1.87  		printf("Can't create udev\n");
    1.88  		return -1;
    1.89 @@ -351,13 +348,13 @@
    1.90  	/* Get the dev_t (major/minor numbers) from the file handle. */
    1.91  	ret = fstat(dev->device_handle, &s);
    1.92  	if (-1 == ret) {
    1.93 -		udev_syms->udev_unref(udev);
    1.94 +		udev_unref(udev);
    1.95  		return ret;
    1.96  	}
    1.97  	/* Open a udev device from the dev_t. 'c' means character device. */
    1.98 -	udev_dev = udev_syms->udev_device_new_from_devnum(udev, 'c', s.st_rdev);
    1.99 +	udev_dev = udev_device_new_from_devnum(udev, 'c', s.st_rdev);
   1.100  	if (udev_dev) {
   1.101 -		hid_dev = udev_syms->udev_device_get_parent_with_subsystem_devtype(
   1.102 +		hid_dev = udev_device_get_parent_with_subsystem_devtype(
   1.103  			udev_dev,
   1.104  			"hid",
   1.105  			NULL);
   1.106 @@ -368,7 +365,7 @@
   1.107  			size_t retm;
   1.108  
   1.109  			ret = parse_uevent_info(
   1.110 -			           udev_syms->udev_device_get_sysattr_value(hid_dev, "uevent"),
   1.111 +			           udev_device_get_sysattr_value(hid_dev, "uevent"),
   1.112  			           &bus_type,
   1.113  			           &dev_vid,
   1.114  			           &dev_pid,
   1.115 @@ -404,7 +401,7 @@
   1.116  			}
   1.117  			else {
   1.118  				/* This is a USB device. Find its parent USB Device node. */
   1.119 -				parent = udev_syms->udev_device_get_parent_with_subsystem_devtype(
   1.120 +				parent = udev_device_get_parent_with_subsystem_devtype(
   1.121  					   udev_dev,
   1.122  					   "usb",
   1.123  					   "usb_device");
   1.124 @@ -419,7 +416,7 @@
   1.125  						goto end;
   1.126  					}
   1.127  
   1.128 -					str = udev_syms->udev_device_get_sysattr_value(parent, key_str);
   1.129 +					str = udev_device_get_sysattr_value(parent, key_str);
   1.130  					if (str) {
   1.131  						/* Convert the string from UTF-8 to wchar_t */
   1.132  						retm = mbstowcs(string, str, maxlen);
   1.133 @@ -435,10 +432,10 @@
   1.134          free(serial_number_utf8);
   1.135          free(product_name_utf8);
   1.136  
   1.137 -	udev_syms->udev_device_unref(udev_dev);
   1.138 +	udev_device_unref(udev_dev);
   1.139  	/* parent and hid_dev don't need to be (and can't be) unref'd.
   1.140  	   I'm not sure why, but they'll throw double-free() errors. */
   1.141 -	udev_syms->udev_unref(udev);
   1.142 +	udev_unref(udev);
   1.143  
   1.144  	return ret;
   1.145  }
   1.146 @@ -454,17 +451,11 @@
   1.147  
   1.148  	kernel_version = detect_kernel_version();
   1.149  
   1.150 -	udev_syms = SDL_UDEV_GetUdevSyms();
   1.151 -	if (!udev_syms)
   1.152 -		return -1;
   1.153 -	
   1.154  	return 0;
   1.155  }
   1.156  
   1.157  int HID_API_EXPORT hid_exit(void)
   1.158  {
   1.159 -	SDL_UDEV_ReleaseUdevSyms();
   1.160 -
   1.161  	/* Nothing to do for this in the Linux/hidraw implementation. */
   1.162  	return 0;
   1.163  }
   1.164 @@ -483,23 +474,20 @@
   1.165  	hid_init();
   1.166  
   1.167  	/* Create the udev object */
   1.168 -	udev = udev_syms->udev_new();
   1.169 +	udev = udev_new();
   1.170  	if (!udev) {
   1.171  		printf("Can't create udev\n");
   1.172  		return NULL;
   1.173  	}
   1.174  
   1.175  	/* Create a list of the devices in the 'hidraw' subsystem. */
   1.176 -	enumerate = udev_syms->udev_enumerate_new(udev);
   1.177 -	udev_syms->udev_enumerate_add_match_subsystem(enumerate, "hidraw");
   1.178 -	udev_syms->udev_enumerate_scan_devices(enumerate);
   1.179 -	devices = udev_syms->udev_enumerate_get_list_entry(enumerate);
   1.180 +	enumerate = udev_enumerate_new(udev);
   1.181 +	udev_enumerate_add_match_subsystem(enumerate, "hidraw");
   1.182 +	udev_enumerate_scan_devices(enumerate);
   1.183 +	devices = udev_enumerate_get_list_entry(enumerate);
   1.184  	/* For each item, see if it matches the vid/pid, and if so
   1.185  	   create a udev_device record for it */
   1.186 -        for (dev_list_entry = devices;
   1.187 -             dev_list_entry;
   1.188 -             dev_list_entry = udev_syms->udev_list_entry_get_next(dev_list_entry)) {
   1.189 -
   1.190 +	udev_list_entry_foreach(dev_list_entry, devices) {
   1.191  		const char *sysfs_path;
   1.192  		const char *dev_path;
   1.193  		const char *str;
   1.194 @@ -516,11 +504,11 @@
   1.195  
   1.196  		/* Get the filename of the /sys entry for the device
   1.197  		   and create a udev_device object (dev) representing it */
   1.198 -		sysfs_path = udev_syms->udev_list_entry_get_name(dev_list_entry);
   1.199 -		raw_dev = udev_syms->udev_device_new_from_syspath(udev, sysfs_path);
   1.200 -		dev_path = udev_syms->udev_device_get_devnode(raw_dev);
   1.201 +		sysfs_path = udev_list_entry_get_name(dev_list_entry);
   1.202 +		raw_dev = udev_device_new_from_syspath(udev, sysfs_path);
   1.203 +		dev_path = udev_device_get_devnode(raw_dev);
   1.204  
   1.205 -		hid_dev = udev_syms->udev_device_get_parent_with_subsystem_devtype(
   1.206 +		hid_dev = udev_device_get_parent_with_subsystem_devtype(
   1.207  			raw_dev,
   1.208  			"hid",
   1.209  			NULL);
   1.210 @@ -531,7 +519,7 @@
   1.211  		}
   1.212  
   1.213  		result = parse_uevent_info(
   1.214 -			udev_syms->udev_device_get_sysattr_value(hid_dev, "uevent"),
   1.215 +			udev_device_get_sysattr_value(hid_dev, "uevent"),
   1.216  			&bus_type,
   1.217  			&dev_vid,
   1.218  			&dev_pid,
   1.219 @@ -594,7 +582,7 @@
   1.220  					   subsystem/devtype pair of "usb"/"usb_device". This will
   1.221  					   be several levels up the tree, but the function will find
   1.222  					   it. */
   1.223 -					usb_dev = udev_syms->udev_device_get_parent_with_subsystem_devtype(
   1.224 +					usb_dev = udev_device_get_parent_with_subsystem_devtype(
   1.225  							raw_dev,
   1.226  							"usb",
   1.227  							"usb_device");
   1.228 @@ -622,16 +610,16 @@
   1.229  					cur_dev->product_string = copy_udev_string(usb_dev, device_string_names[DEVICE_STRING_PRODUCT]);
   1.230  
   1.231  					/* Release Number */
   1.232 -					str = udev_syms->udev_device_get_sysattr_value(usb_dev, "bcdDevice");
   1.233 +					str = udev_device_get_sysattr_value(usb_dev, "bcdDevice");
   1.234  					cur_dev->release_number = (str)? strtol(str, NULL, 16): 0x0;
   1.235  
   1.236  					/* Get a handle to the interface's udev node. */
   1.237 -					intf_dev = udev_syms->udev_device_get_parent_with_subsystem_devtype(
   1.238 +					intf_dev = udev_device_get_parent_with_subsystem_devtype(
   1.239  							raw_dev,
   1.240  							"usb",
   1.241  							"usb_interface");
   1.242  					if (intf_dev) {
   1.243 -						str = udev_syms->udev_device_get_sysattr_value(intf_dev, "bInterfaceNumber");
   1.244 +						str = udev_device_get_sysattr_value(intf_dev, "bInterfaceNumber");
   1.245  						cur_dev->interface_number = (str)? strtol(str, NULL, 16): -1;
   1.246  					}
   1.247  
   1.248 @@ -654,14 +642,14 @@
   1.249  	next:
   1.250  		free(serial_number_utf8);
   1.251  		free(product_name_utf8);
   1.252 -		udev_syms->udev_device_unref(raw_dev);
   1.253 +		udev_device_unref(raw_dev);
   1.254  		/* hid_dev, usb_dev and intf_dev don't need to be (and can't be)
   1.255  		   unref()d.  It will cause a double-free() error.  I'm not
   1.256  		   sure why.  */
   1.257  	}
   1.258  	/* Free the enumerator and udev objects. */
   1.259 -	udev_syms->udev_enumerate_unref(enumerate);
   1.260 -	udev_syms->udev_unref(udev);
   1.261 +	udev_enumerate_unref(enumerate);
   1.262 +	udev_unref(udev);
   1.263  
   1.264  	return root;
   1.265  }