Skip to content
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

Add clear_peripherals method to adapter #382

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

danielstuart14
Copy link
Contributor

@danielstuart14 danielstuart14 commented May 8, 2024

Add clear_peripherals method to adapter, so that the peripheral list can be cleared after being used.
Without this, the list would keep growing until the whole adapter object is dropped.

The method returns a result so that later if a platform/functionality needs to be fallible the API won't need to be changed.

AFAIK, Linux doesn't support this as the peripheral list comes from bluez directly.

Solves #206

@qwandor qwandor changed the base branch from master to dev May 8, 2024 09:18
@@ -355,6 +355,9 @@ pub trait Central: Send + Sync + Clone {
/// Add a [`Peripheral`] from a MAC address without a scan result. Not supported on all Bluetooth systems.
async fn add_peripheral(&self, address: &PeripheralId) -> Result<Self::Peripheral>;

/// Clear the list of [`Peripheral`]s that have been discovered so far.
async fn clear_peripherals(&self) -> Result<()>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see there's no need for this to be async.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is best to keep it async, so that if a new platform (or even a linux solution later) needs it to be async we don't have to break the API. What do you think?

@@ -101,6 +101,12 @@ impl Central for Adapter {
))
}

async fn clear_peripherals(&self) -> Result<()> {
Err(Error::NotSupported(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried that this will result in people writing programs that crash on Linux as they only tested it on other platforms. What do you think about this just being a silent no-op on Linux? Not being able to clear the peripheral list shouldn't be a big issue in most cases I can think of.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good, I'll change it. It may be possible to clear the bluez list, but the bluez-async lib doesn't seem to currently support it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants