Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac: Use IOKit paths #40

Closed
wants to merge 3 commits into from
Closed

Mac: Use IOKit paths #40

wants to merge 3 commits into from

Conversation

mrpippy
Copy link
Contributor

@mrpippy mrpippy commented Jan 26, 2012

These commits change hid_enumerate() and hid_open_path() to use IOKit IOService:/ paths for devices.

On 10.6 and above, it's real clean and much simpler than the previous hid_open_path() implementation.

On 10.5, it's a little sticky since IOHIDDeviceGetService() isn't available. First, I'm weakly linking to IOHIDDeviceGetService(), so its availability gets checked at runtime and used if it exists (10.6 and up). For 10.5, the backup plan is to just get the io_service_t directly out of the IOHIDDevice struct. The IOHIDDevice struct never changed throughout 10.5, and I've tested (with hidtest) successfully on 10.5.8 ppc, i386, and x86_64. It's naughty, but it works :)

Also, the device_list removal patches are needed for disconnect detection to work right. I guess since the IOHIDDevice is being created without going through the manager, assigning the removal callback to the manager wouldn't work (the callback wasn't getting called).

mrpippy and others added 3 commits November 24, 2014 12:56
Change hid_enumerate() and hid_open_path() to use IOKit IOService:/
paths to uniquely identify devices, instead of creating a path
(done by the make_path() function).

The path passed to hid_open_path() now must be a valid path to an
IOHIDDevice in the IOService plane, like:
"IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/EHC1@1D,7/
AppleUSBEHCI/PLAYSTATION(R)3
Controller@fd120000/IOUSBInterface@0/IOUSBHIDDriver"
Remove get_string_property_utf8(), it's not used since make_path() was removed
Disable get_location_id(), it's not used in active code since make_path() was removed
@mrpippy
Copy link
Contributor Author

mrpippy commented Nov 24, 2014

I was making the changes you suggested and realized that using dlopen()/dlsym() to get the address of IOHIDDeviceGetService() is simpler and works in more cases than doing the weak linking.

In particular, with weak-linking if hidapi was compiled on 10.5, the fallback method (pulling it out of IOHIDDevice) would always be used (regardless of what OS the binary was running on).
Now the check is purely runtime, and doesn't require any added compile flags.

I'll push a new version with these changes

@amullins83
Copy link
Contributor

After you get that done can you verify my PR #199? I'm not aware of anyone else on here who can test hidapi on a Mac. I'd gladly accept any changes.

@prusnak
Copy link
Contributor

prusnak commented Sep 13, 2016

As per discussion in #288, can we please get this fix in?

At the moment HIDAPI is unusable under OS X for devices with more than one interface.

@prusnak
Copy link
Contributor

prusnak commented Sep 15, 2016

Let's get this in. There are 2+ ACKs in #288 thread.

@karelbilek
Copy link

hey, is this moving along?

@signal11
Copy link
Owner

pushed 59a0767 474145e ae15b65

Brenden, thank you so much for all your hard work on this. This kind of code doesn't write itself, and I appreciate how painful some of it must have been to get right. I'm sorry I waited so long before merging it. -- Alan.

@signal11 signal11 closed this Sep 20, 2016
@karelbilek
Copy link

Thanks a lot to both of you :)

@prusnak
Copy link
Contributor

prusnak commented Sep 20, 2016

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants