Skip to content

Commit 816bc03

Browse files
Ihor DutchakIhor Dutchak
authored andcommitted
drop support of macOS 10.5 and earlier
IOHIDDeviceGetService is available since macOS 10.6 dropping an old workaround makes the implementation simpler
1 parent 083223e commit 816bc03

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
@@ -288,64 +288,6 @@ static wchar_t *dup_wcs(const wchar_t *s)
288288
return ret;
289289
}
290290

291-
/* hidapi_IOHIDDeviceGetService()
292-
*
293-
* Return the io_service_t corresponding to a given IOHIDDeviceRef, either by:
294-
* - on OS X 10.6 and above, calling IOHIDDeviceGetService()
295-
* - on OS X 10.5, extract it from the IOHIDDevice struct
296-
*/
297-
static io_service_t hidapi_IOHIDDeviceGetService(IOHIDDeviceRef device)
298-
{
299-
static void *iokit_framework = NULL;
300-
typedef io_service_t (*dynamic_IOHIDDeviceGetService_t)(IOHIDDeviceRef device);
301-
static dynamic_IOHIDDeviceGetService_t dynamic_IOHIDDeviceGetService = NULL;
302-
303-
/* Use dlopen()/dlsym() to get a pointer to IOHIDDeviceGetService() if it exists.
304-
* If any of these steps fail, dynamic_IOHIDDeviceGetService will be left NULL
305-
* and the fallback method will be used.
306-
*/
307-
if (iokit_framework == NULL) {
308-
iokit_framework = dlopen("/System/Library/IOKit.framework/IOKit", RTLD_LAZY);
309-
310-
if (iokit_framework != NULL)
311-
dynamic_IOHIDDeviceGetService = (dynamic_IOHIDDeviceGetService_t) dlsym(iokit_framework, "IOHIDDeviceGetService");
312-
}
313-
314-
if (dynamic_IOHIDDeviceGetService != NULL) {
315-
/* Running on OS X 10.6 and above: IOHIDDeviceGetService() exists */
316-
return dynamic_IOHIDDeviceGetService(device);
317-
}
318-
else
319-
{
320-
/* Running on OS X 10.5: IOHIDDeviceGetService() doesn't exist.
321-
*
322-
* Be naughty and pull the service out of the IOHIDDevice.
323-
* IOHIDDevice is an opaque struct not exposed to applications, but its
324-
* layout is stable through all available versions of OS X.
325-
* Tested and working on OS X 10.5.8 i386, x86_64, and ppc.
326-
*/
327-
struct IOHIDDevice_internal {
328-
/* The first field of the IOHIDDevice struct is a
329-
* CFRuntimeBase (which is a private CF struct).
330-
*
331-
* a, b, and c are the 3 fields that make up a CFRuntimeBase.
332-
* See http://opensource.apple.com/source/CF/CF-476.18/CFRuntime.h
333-
*
334-
* The second field of the IOHIDDevice is the io_service_t we're looking for.
335-
*/
336-
uintptr_t a;
337-
uint8_t b[4];
338-
#if __LP64__
339-
uint32_t c;
340-
#endif
341-
io_service_t service;
342-
};
343-
struct IOHIDDevice_internal *tmp = (struct IOHIDDevice_internal *) device;
344-
345-
return tmp->service;
346-
}
347-
}
348-
349291
/* Initialize the IOHIDManager. Return 0 for success and -1 for failure. */
350292
static int init_hid_manager(void)
351293
{
@@ -459,7 +401,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
459401
cur_dev->next = NULL;
460402

461403
/* Fill in the path (IOService plane) */
462-
iokit_dev = hidapi_IOHIDDeviceGetService(dev);
404+
iokit_dev = IOHIDDeviceGetService(dev);
463405
res = IORegistryEntryGetPath(iokit_dev, kIOServicePlane, path);
464406
if (res == KERN_SUCCESS)
465407
cur_dev->path = strdup(path);

0 commit comments

Comments
 (0)