From 0c039337d71149ac1ac7b0dc1d23f6c99c07206d Mon Sep 17 00:00:00 2001 From: Daniel Stuart Date: Tue, 7 May 2024 23:12:19 -0300 Subject: [PATCH] Add clear_peripherals method to adapter --- src/api/mod.rs | 3 +++ src/bluez/adapter.rs | 5 +++++ src/common/adapter_manager.rs | 4 ++++ src/corebluetooth/adapter.rs | 5 +++++ src/droidplug/adapter.rs | 5 +++++ src/winrtble/adapter.rs | 5 +++++ 6 files changed, 27 insertions(+) diff --git a/src/api/mod.rs b/src/api/mod.rs index f24bba61..dab3982c 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -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; + /// Clear the list of [`Peripheral`]s that have been discovered so far. + async fn clear_peripherals(&self) -> Result<()>; + /// Get information about the Bluetooth adapter being used, such as the model or type. /// /// The details of this are platform-specific andyou should not attempt to parse it, but it may diff --git a/src/bluez/adapter.rs b/src/bluez/adapter.rs index dcf393b2..c8ce6b8f 100644 --- a/src/bluez/adapter.rs +++ b/src/bluez/adapter.rs @@ -101,6 +101,11 @@ impl Central for Adapter { )) } + async fn clear_peripherals(&self) -> Result<()> { + self.manager.clear_peripherals(); + Ok(()) + } + async fn adapter_info(&self) -> Result { let adapter_info = self.session.get_adapter_info(&self.adapter).await?; Ok(format!("{} ({})", adapter_info.id, adapter_info.modalias)) diff --git a/src/common/adapter_manager.rs b/src/common/adapter_manager.rs index beac7f01..01b58481 100644 --- a/src/common/adapter_manager.rs +++ b/src/common/adapter_manager.rs @@ -66,6 +66,10 @@ where self.peripherals.insert(peripheral.id(), peripheral); } + pub fn clear_peripherals(&self) { + self.peripherals.clear(); + } + pub fn peripherals(&self) -> Vec { self.peripherals .iter() diff --git a/src/corebluetooth/adapter.rs b/src/corebluetooth/adapter.rs index c139c43d..31c730a5 100644 --- a/src/corebluetooth/adapter.rs +++ b/src/corebluetooth/adapter.rs @@ -117,6 +117,11 @@ impl Central for Adapter { )) } + async fn clear_peripherals(&self) -> Result<()> { + self.manager.clear_peripherals(); + Ok(()) + } + async fn adapter_info(&self) -> Result { // TODO: Get information about the adapter. Ok("CoreBluetooth".to_string()) diff --git a/src/droidplug/adapter.rs b/src/droidplug/adapter.rs index a1f829c9..bf471205 100644 --- a/src/droidplug/adapter.rs +++ b/src/droidplug/adapter.rs @@ -167,6 +167,11 @@ impl Central for Adapter { async fn add_peripheral(&self, address: &PeripheralId) -> Result { self.add(address.0) } + + async fn clear_peripherals(&self) -> Result<()> { + self.manager.clear_peripherals(); + Ok(()) + } } pub(crate) fn adapter_report_scan_result_internal( diff --git a/src/winrtble/adapter.rs b/src/winrtble/adapter.rs index 6d41d24f..a620f888 100644 --- a/src/winrtble/adapter.rs +++ b/src/winrtble/adapter.rs @@ -96,6 +96,11 @@ impl Central for Adapter { )) } + async fn clear_peripherals(&self) -> Result<()> { + self.manager.clear_peripherals(); + Ok(()) + } + async fn adapter_info(&self) -> Result { // TODO: Get information about the adapter. Ok("WinRT".to_string())