- Notifications
You must be signed in to change notification settings - Fork 452
Linux Hotplug: connection-callback implementation for libusb backend#645
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
Linux Hotplug: connection-callback implementation for libusb backend #645
Conversation
12beacc to 74f61b3CompareYouw commented Nov 21, 2023
Before looking into this - lets finish with #646 - probably some comments are applicable here as well |
k1-801 commented Nov 21, 2023
Agreed. Going to squash all the commits into one so it's a little less messy, then will try to check for similar macro check related issues. |
e46ca78 to d6aa1ecComparek1-801 commented Nov 21, 2023
For now, my biggest concern is the |
25014be to b3937abComparek1-801 commented Nov 22, 2023
Attempted to adjust the code-style to the current style of the library, it only ended up messing some other locations where indentation is done with both tabs AND spaces :( |
b3937ab to bcefdc2Comparek1-801 commented Nov 23, 2023
Added some changes to list management during device removal. |
mcuee commented Dec 5, 2023
Ubuntu-cmake and Arch Linux github action build are still failing. |
1 similar comment
mcuee commented Dec 5, 2023
Ubuntu-cmake and Arch Linux github action build are still failing. |
k1-801 commented Dec 5, 2023 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Interesting. I will see to it right away. |
k1-801 commented Dec 5, 2023
Addressed the issue, should be fine now |
mcuee commented Mar 6, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Not so sure how to re-run the github actions as there were build error previously. |
mcuee commented Mar 6, 2024
I will test this under Linux later. |
mcuee commented Mar 8, 2024
This may be a bit tricky to test under Linux as we need to detach the kernel HID driver in order to use hidapi-libusb. BTW, libusb currently only supports hotplug under Linux and macOS. There is a PR for Windows. FreeBSD has its own libusb implementation and it supports hotplug. I will also test this PR under FreeBSD. |
16326c2 to 46f6784Comparek1-801 commented Mar 11, 2024
I just rebased this onto the updated |
mcuee commented Mar 12, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@k1-801
I have tried to detached kernel usbhid driver (same results if I do not detach the kernel driver). Details |
k1-801 commented Mar 12, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Okay, thank you for the info, I'll see what I can do. Keeping as a draft until I have tested it myself. |
mcuee commented Mar 12, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Thanks. FYI: libusb hotplug works fine. |
k1-801 commented Mar 12, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
It took me some time to track the issue, but I found it. In turn, calling |
k1-801 commented Mar 12, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
I managed to get the events going (there is some debug output in the printout below that will not be present in the real tests), BUT, the device info is always empty. So far, it's definitely an impovement. I don't know why the fields are empty or how to fix them, Maybe it is related to the fact that I used a second libusb context, but the documentation states they should not interfere with one another, and the processing code never mentions the context at all. UPD: every call to UPD2: libusb/libusb#408 - it is impossible to retrieve any strings while in the libusb's hotplug callback. Will think of a workaround, but this is really becoming complicated. I can imagine it running two threads, one for libusb running it's event processing, in which the events would be put on a queue. The other would be actually processing the queue and calling the callbacks registered in hidapi. DetailsHandle 1: New device is connected: 3-3:1.0. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 0 Usage (page): 0x0 (0x0)Handle 1: New device is connected: 3-3:1.1. Handle 1: New device is connected: 3-3:1.2. libusb callback fired! Event: out Handle 1: Device was disconnected: 3-3:1.1. Handle 1: Device was disconnected: 3-3:1.2. libusb callback fired! Event: in Handle 1: New device is connected: 3-3:1.1. Handle 1: New device is connected: 3-3:1.2. libusb callback fired! Event: out Handle 1: Device was disconnected: 3-3:1.1. Handle 1: Device was disconnected: 3-3:1.2. libusb callback fired! Event: in Handle 1: New device is connected: 3-2:1.1. Handle 1: New device is connected: 3-2:1.2. |
k1-801 commented Mar 12, 2024
Implemented a two-thread queue processing. Will push in a moment, needs some indentation cleanup. DetailsHandle 1: New device is connected: 3-2:1.0. type: 04d9 fc38 serial_number: (null) Manufacturer: (null) Product: USB Gaming Mouse Release: 110 Interface: 0 Usage (page): 0x0 (0x0)Handle 1: New device is connected: 3-2:1.1. Handle 1: New device is connected: 3-2:1.2. Handle 1: Device was disconnected: 3-2:1.0. Handle 1: Device was disconnected: 3-2:1.1. Handle 1: Device was disconnected: 3-2:1.2. Handle 1: New device is connected: 3-2:1.0. Handle 1: New device is connected: 3-2:1.1. Handle 1: New device is connected: 3-2:1.2. |
k1-801 commented Mar 12, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@mcuee this monstrocity is now more or less ready to be tested, reviewed |
k1-801 commented Mar 12, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Forgot a call to trigger the pthread_condition... |
mcuee commented Mar 12, 2024 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Now this works fine. Thanks. And yes it is not requird to detach kernel driver for event. Tested under Ubuntu Linux 20.04. Unplug and plug of Platronics USB headset Details |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Youw left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed some formatting concerns of mine, but still don't have enough time to go thru all of the code.
But I trust the community to review it properly and fix if anything needs to be fixed.
That said, I will not block the PR from getting into a feature branch.
No description provided.