backends/scanner: add handle_early_stop hooks#1146
Conversation
f0f69f4 to
2e47a54
Compare
|
This has now been tested on Windows, Linux and Mac. It is working as expected (when used with #1147 and #1148). The test case is running the In the case of Linux with passive scanning, it is not working because "Release" of the advertisement watcher is not called. I think this could be considered a bug in BlueZ (the advertisement watcher is still experimental after all) since "Release" is called on other errors. It seems like Release should be called if the adapter is powered off or disappears. Release was called as expected when I gave bad args for |
All supported platforms provide some sort of hook that we can use to get a callback when scanning stops. On Mac and Linux, there is only a simple boolean value indicating if scanning is currently in progress. Windows and Android provide additional error information, but this is ignored for now since it isn't available cross-platform. What we actually do with this hook is not yet implemented.
2e47a54 to
047e18b
Compare
This is inspired by #1140 (comment). Quite a long time ago, I noticed that we weren't really handling scanner stop events when a scanner stops before we actually request it to. (This is somewhat similar to how we have a disconnect event for devices except in that case, the callback is called even if we requested the disconnect or not.) There haven't been any reported problems due to not having such a feature until now, so it has never been addressed until now.
So far, this PR just implements the platform-specific parts to call a common scanner backend method when an unrequested scanner stop event occurs. The idea is to use this as part of the context manager so that it will cancel the task if an early stop happens.
We probably also need some sort of API for anyone using
startandstopwithout a context manager (although maybe we don't want to support this and require a context manager if you want the callback to do something?).Code hasn't been tested yet on any platform, so expect bugs.
cc: @bojanpotocnik