-
Notifications
You must be signed in to change notification settings - Fork 75
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
Support AND based scan filtering #586
Comments
Maybe we can create a So
This solution should be backwards compatible. Users that want to use the AND based filters, only need to add Let me know if this could work for you, and the exact name you would prefer? Filter.All, Filter.MatchAll, Filter.AndBased (naming is the most difficult thing in Software you know :) ) I'm happy to create a PR for you, if you agree to this approach. |
I'm not sure if it is feasible, but I was thinking of using filters = Filter.Name("Example") and Filter.Service(uuidFrom(..)) They could even be combined, for example: filters = (Filter.Name("Example") or Filter.Name("Test")) and Filter.Service(uuidFrom(..) ...this unfortunately would not be backwards compatible, but could have a deprecation cycle where the old behavior is moved to another property as the Maybe we could introduce the new syntax as |
Yeah, I see what you mean. The native filtering options, make my suggestion a bit clumsy to implement. |
@Entreco this has been slated (internally) for our next sprint. |
What would it mean to specify a filter like this? filters = Filter.Name("Example") and Filter.Name("Other") We would probably have to reject this with an exception at runtime? I am wondering if it would be simpler and cleaner to provide a product type that expresses the range of possible filters instead of attempting to write combinators to make up for the lack of expression with the existing sum type. |
Oof, definitely not ideal.
Interesting, can you give an example of what you think that might look like? |
I was thinking about this type (simplified for brevity): sealed class Filter {
class Service(uuid: Uuid) : Filter()
class Name(name: String) : Filter()
} when considered in isolation implies ONE OF a If we have some collection of these, we need to figure out a way to define whether to "OR" or "AND" that collection together, because the underlying type provides no guidance for how to combine them. Instead, if we change the shape of the type to something like this: class Filter(
val services: List<Uuid>,
val name: String?,
) when considered in isolation implies This type is providing an inherent "AND". (Aside: I suppose that we are, in fact, deliberately choosing to "AND" the properties together, but it feels like the expected behavior.) If we then have a collection of these, it necessarily implies that they be "OR"ed together, because an "AND" operation would be non-sensical. I haven't thought through all the options, but it seems like a type of this shape provides an API that more naturally models the problem space. And of course I didn't conclude this in isolation, but came to realize it after messing around with the W3C API! I do like the flexibility of the proposed It would be a fun exercise to implement it anyway, just to see how it shakes out. For the API consumer, the difference would be: listOf(Filter(services = listOf(uuid1)), Filter(services = listOf(uuid2), name = "bob")) vs Service(uuid1) or (Service(uuid2) and Name("bob")) The latter is much prettier, but then also allows for "incorrect" expressions. I'm leaning towards ugly-but-functional-and-less-work myself. |
After typing out the above I woke up in the middle of the night with the realization that I had accidentally worked out a solution, which is to combine both types. Will throw up a draft PR today of the concept. |
My personal need for this feature has vanished, but i'm happy to review/test/brainstorm any drafts. I'll keep an eye out for updates |
Welp, that didn't pan out and here we are some six weeks later 😬 Good news is we found a practical resolution to the issues: #695 |
Currently, filters are specified in a list and scan results are filtered by if they match any of the specified filters (OR based), for example:
Will match any advertisements with the name "Example" OR service UUID "96f630b5-7ee4-4e47-a550-ec0d0da5c487".
Kable should support AND based filtering, for example:
Will only match advertisements that have both the name "Example" AND the service UUID "2001b5ee-9bf6-48da-a6e8-2901865c0435".
The Web Bluetooth spec provides some nice examples of AND vs. OR matching.
The text was updated successfully, but these errors were encountered: