-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
win_event_device_watcher wait before notify
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.
- Loading branch information
Showing
1 changed file
with
35 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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