darwin: add option to open device in non-exclusive mode #397

Merged
Youw merged 1 commit from macos-non-exclusive into master 2022-04-23 06:16:42 -05:00
Youw commented 2022-03-16 14:08:17 -05:00 (Migrated from github.com)

Resolves: #27
Resolves: #344

Resolves: #27 Resolves: #344
z3ntu (Migrated from github.com) reviewed 2022-03-16 14:08:17 -05:00
Youw commented 2022-03-16 14:12:12 -05:00 (Migrated from github.com)

@dnaq try if this works for you.

@dnaq try if this works for you.
dnaq commented 2022-03-16 14:26:24 -05:00 (Migrated from github.com)

That looks like it would work beautifully for my use case.

That looks like it would work beautifully for my use case.
DJm00n commented 2022-04-13 06:55:49 -05:00 (Migrated from github.com)

I thought that hidapi idea is to provide generic crossplatform API if possible.
We can add such option for Windows too (do not pass FILE_SHARE_READ and FILE_SHARE_WRITE to CreateFile). Maybe its better to do not-os-specific hid_open_path instead?

I thought that hidapi idea is to provide generic crossplatform API if possible. We can add such option for Windows too (do not pass `FILE_SHARE_READ` and `FILE_SHARE_WRITE` to [CreateFile](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew)). Maybe its better to do not-os-specific `hid_open_path` instead?
Youw commented 2022-04-13 07:44:57 -05:00 (Migrated from github.com)

I already had this conversation somewhere (but I can't find it, so here it goes again):

  1. HID Standard doesn't define such things like sharing the device on host side, so we can't reference to any existing specification or smth;
  2. Not all platforms supports such notion at all:
    • You can do Exclusive or Non-Exclusive Open on macOS;
    • (apparently) You can do Shared or Non-Shared Open on Windows (I never checked the actual behavior when you do Non-Shared Open on Windows);
    • Both LIBUSB and HIDRAW backends do not support Non-Exclusive Open due to OS/API specifics;

Having a "cross-platform" function that is known only to work for some platforms defeats the whole "cross-platform" idea.

Pretty much the same thing we can tell about similar option: ReadWrite or ReadOnly Open: supported by Windows and HIDRAW, but not supported by macOS and LIBUSB. More than that - on Window you can open a device without specifying ReadWrite or ReadOnly, and on HIDRAW you have to specify one of them.


There is also a question of consistency, e.g.: "shouldn't a cross-platform application behave consistently across platforms?".
I.e. since we open on Windows in shared mode, why don't we open in Non-Exclusive mode on macOS by default?
I already asked myself this question here.
In addition to that: on LIBUSB we open with exclusive access (and there is no option to do otherwise), so current behavior on macOS is consistent with LIBUSB.


Given all of the above, my strategy is:

  • try&keep the existing behavior whenever possible (unless it is a bug, which better be fixed, like #334);
  • (recently new strategy) Add platform-specific options for options/platforms where it makes sense.
I already had this conversation somewhere (but I can't find it, so here it goes again): 1) HID Standard doesn't define such things like sharing the device on host side, so we can't reference to any existing specification or smth; 2) Not all platforms supports such notion at all: - You can do Exclusive or Non-Exclusive Open on macOS; - (apparently) You can do Shared or Non-Shared Open on Windows (I never checked the actual behavior when you do Non-Shared Open on Windows); - Both LIBUSB and HIDRAW backends do not support Non-Exclusive Open due to OS/API specifics; Having a "cross-platform" function that is known only to work for _some_ platforms defeats the whole "cross-platform" idea. Pretty much the same thing we can tell about similar option: ReadWrite or ReadOnly Open: supported by Windows and HIDRAW, but not supported by macOS and LIBUSB. More than that - on Window you can open a device without specifying ReadWrite or ReadOnly, and on HIDRAW you have to specify one of them. --- There is also a question of consistency, e.g.: "shouldn't a cross-platform application behave consistently across platforms?". I.e. since we open on Windows in shared mode, why don't we open in Non-Exclusive mode on macOS by default? I already asked myself this question [here](https://github.com/libusb/hidapi/issues/27#issuecomment-590607926). In addition to that: on LIBUSB we open with exclusive access (and there is no option to do otherwise), so current behavior on macOS is consistent with LIBUSB. --- Given all of the above, my strategy is: - try&_keep the existing behavior whenever possible_ (unless it is a bug, which better be fixed, like #334); - (recently new strategy) Add platform-specific options for options/platforms where it makes sense.
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libusb/hidapi!397
No description provided.