win_event_device_watcher wait before notify - #12207
Merged
Merged
Conversation
Events on removal arrive rapidly and so calling the callback for each is
redundant but also wrong:
In testing, disconnection happened in two stages, triggering two events:
OLD group, before disconnection:
\\?\usb#vid_8086&pid_0b3a&mi_00#6&1e67ef5f&0&0000#{e5323777-f976-4f5b-9b55-b94699c46e44}\global
\\?\usb#vid_8086&pid_0b3a&mi_03#6&1e67ef5f&0&0003#{e5323777-f976-4f5b-9b55-b94699c46e44}\global
FIRST event after disconnection, NEW group:
\\?\usb#vid_8086&pid_0b3a&mi_03#6&1e67ef5f&0&0003#{e5323777-f976-4f5b-9b55-b94699c46e44}\global
OLD-NEW = removed
NEW-OLD = added
And operator-() is subtract_sets():
for each item on LEFT side:
add to result if none on RIGHT side is a superset of LEFT
In this case:
NEW is subset of OLD -> OLD is superset of NEW
OLD-NEW = 1 device removed
NEW-OLD = 0 device added
SECOND event after disconnection, OLD=previous NEW:
\\?\usb#vid_8086&pid_0b3a&mi_03#6&1e67ef5f&0&0003#{e5323777-f976-4f5b-9b55-b94699c46e44}\global
In this case:
NEW=empty
OLD-NEW = 1 device removed (again!?)
NEW-OLD = 0 device added
Solution is fairly simple, and was already done in udev device-watcher:
wait a short while and only notify of changes after a brief time elapses
post-event. Any new event refreshes the timer.
Nir-Az
reviewed
Sep 19, 2023
| break; | ||
| auto data = reinterpret_cast<extra_data*>(GetWindowLongPtr(hWnd, GWLP_USERDATA)); | ||
| auto next = data->_last; | ||
| std::wstring temp = reinterpret_cast<DEV_BROADCAST_DEVICEINTERFACE*>(lParam)->dbcc_name; |
Collaborator
There was a problem hiding this comment.
Any idea what was the reason for all of this code?
And why it is not needed anymore?
Contributor
Author
There was a problem hiding this comment.
I can't very well comment about the first.
But it's not needed any more because we just get everything again fresh (after a delay), just as if we did query_devices. This is how udev does it, too.
Contributor
Author
There was a problem hiding this comment.
Probably they were trying to save time...
Nir-Az
approved these changes
Sep 19, 2023
Nir-Az
left a comment
Collaborator
There was a problem hiding this comment.
Overall, it looks like a great enhancement.
Just wondering about the code removal, too bad they didn't wrote comments because I have no idea what they did there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Events on removal arrive rapidly and so calling the callback for each is redundant but also wrong:
In testing, disconnection happened in two stages, triggering two events:
OLD group, before disconnection:
\\?\usb#vid_8086&pid_0b3a&mi_00#6&1e67ef5f&0&0000#{e5323777-f976-4f5b-9b55-b94699c46e44}\global
\\?\usb#vid_8086&pid_0b3a&mi_03#6&1e67ef5f&0&0003#{e5323777-f976-4f5b-9b55-b94699c46e44}\global
FIRST event after disconnection, NEW group:
\\?\usb#vid_8086&pid_0b3a&mi_03#6&1e67ef5f&0&0003#{e5323777-f976-4f5b-9b55-b94699c46e44}\global
OLD-NEW = removed
NEW-OLD = added
And operator-() is subtract_sets():
for each item on LEFT side:
add to result if none on RIGHT side is a superset of LEFT
In this case:
NEW is subset of OLD -> OLD is superset of NEW
OLD-NEW = 1 device removed
NEW-OLD = 0 device added
SECOND event after disconnection, OLD=previous new:
\\?\usb#vid_8086&pid_0b3a&mi_03#6&1e67ef5f&0&0003#{e5323777-f976-4f5b-9b55-b94699c46e44}\global
In this case:
NEW=empty
OLD-NEW = 1 device removed (again!?)
NEW-OLD = 0 device added
Solution is fairly simple, and was already done in udev device-watcher: wait a short while and only notify of changes after a brief time elapses post-event. Any new event refreshes the timer.