Skip to content

Commit 42fa21f

Browse files
authored
drop support of macOS 10.5 and earlier (#121)
- IOHIDDeviceGetService is available since macOS 10.6
1 parent 7620bc7 commit 42fa21f

File tree

1 file changed

+1
-59
lines changed

1 file changed

+1
-59
lines changed

mac/hid.c

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -314,64 +314,6 @@ static wchar_t *dup_wcs(const wchar_t *s)
314314
return ret;
315315
}
316316

317-
/* hidapi_IOHIDDeviceGetService()
318-
*
319-
* Return the io_service_t corresponding to a given IOHIDDeviceRef, either by:
320-
* - on OS X 10.6 and above, calling IOHIDDeviceGetService()
321-
* - on OS X 10.5, extract it from the IOHIDDevice struct
322-
*/
323-
static io_service_t hidapi_IOHIDDeviceGetService(IOHIDDeviceRef device)
324-
{
325-
static void *iokit_framework = NULL;
326-
typedef io_service_t (*dynamic_IOHIDDeviceGetService_t)(IOHIDDeviceRef device);
327-
static dynamic_IOHIDDeviceGetService_t dynamic_IOHIDDeviceGetService = NULL;
328-
329-
/* Use dlopen()/dlsym() to get a pointer to IOHIDDeviceGetService() if it exists.
330-
* If any of these steps fail, dynamic_IOHIDDeviceGetService will be left NULL
331-
* and the fallback method will be used.
332-
*/
333-
if (iokit_framework == NULL) {
334-
iokit_framework = dlopen("/System/Library/Frameworks/IOKit.framework/IOKit", RTLD_LAZY);
335-
336-
if (iokit_framework != NULL)
337-
dynamic_IOHIDDeviceGetService = (dynamic_IOHIDDeviceGetService_t) dlsym(iokit_framework, "IOHIDDeviceGetService");
338-
}
339-
340-
if (dynamic_IOHIDDeviceGetService != NULL) {
341-
/* Running on OS X 10.6 and above: IOHIDDeviceGetService() exists */
342-
return dynamic_IOHIDDeviceGetService(device);
343-
}
344-
else
345-
{
346-
/* Running on OS X 10.5: IOHIDDeviceGetService() doesn't exist.
347-
*
348-
* Be naughty and pull the service out of the IOHIDDevice.
349-
* IOHIDDevice is an opaque struct not exposed to applications, but its
350-
* layout is stable through all available versions of OS X.
351-
* Tested and working on OS X 10.5.8 i386, x86_64, and ppc.
352-
*/
353-
struct IOHIDDevice_internal {
354-
/* The first field of the IOHIDDevice struct is a
355-
* CFRuntimeBase (which is a private CF struct).
356-
*
357-
* a, b, and c are the 3 fields that make up a CFRuntimeBase.
358-
* See http://opensource.apple.com/source/CF/CF-476.18/CFRuntime.h
359-
*
360-
* The second field of the IOHIDDevice is the io_service_t we're looking for.
361-
*/
362-
uintptr_t a;
363-
uint8_t b[4];
364-
#if __LP64__
365-
uint32_t c;
366-
#endif
367-
io_service_t service;
368-
};
369-
struct IOHIDDevice_internal *tmp = (struct IOHIDDevice_internal *) device;
370-
371-
return tmp->service;
372-
}
373-
}
374-
375317
/* Initialize the IOHIDManager. Return 0 for success and -1 for failure. */
376318
static int init_hid_manager(void)
377319
{
@@ -460,7 +402,7 @@ static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev,
460402
cur_dev->next = NULL;
461403

462404
/* Fill in the path (IOService plane) */
463-
iokit_dev = hidapi_IOHIDDeviceGetService(dev);
405+
iokit_dev = IOHIDDeviceGetService(dev);
464406
res = IORegistryEntryGetPath(iokit_dev, kIOServicePlane, path);
465407
if (res == KERN_SUCCESS)
466408
cur_dev->path = strdup(path);

0 commit comments

Comments
 (0)