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

Device shared / exclusive locking? #615

Open
ghost opened this issue Aug 23, 2023 · 1 comment
Open

Device shared / exclusive locking? #615

ghost opened this issue Aug 23, 2023 · 1 comment
Labels
bsd FreeBSD, NetBSD, OpenBSD, etc enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Aug 23, 2023

I noticed while implementing the NetBSD backend that each platform has different defaults. hidraw has no locking by default. uhid has mandatory locking in most implementations. I don't know what the situation is for the Mac and Win32 backends.

Would there be any value in adding an API for locking the device in the hidapi backend? For most unix platforms, flock can be used to achieve advisory locking for cooperating applications so it isn't without its merits but this would only be effective where the platform doesn't already enforce its own locks beyond the control of the application.

I could see there being value in the application having a way to get a lock on the device as well as knowing the type of lock that is in effect because sharing access between applications may be a problem depending on the device being used. I have seen devices that use vendor HID protocols that are stateful and therefore should not be interrupted by another application. One example is a HID device that implemented ymodem protocol by treating the HID transport as a packet system in order to upload firmware updates.

@Youw Youw added enhancement New feature or request bsd FreeBSD, NetBSD, OpenBSD, etc labels Aug 23, 2023
@Youw
Copy link
Member

Youw commented Aug 23, 2023

The thing is that there is no uniform to this approach. Depending on the platform - not everything is possible (e.g. libusb doesn't allow shared access to the device at all).
I've described this somewhere in comments to other tickets and can find my full answer at the moment.
Long story short: you may add something backend-specific if you think that makes sense.

Take a look at hid_darwin_set_open_exclusive for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bsd FreeBSD, NetBSD, OpenBSD, etc enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant