Skip to content

Commit

Permalink
Add clear_peripherals method to adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstuart14 committed May 8, 2024
1 parent 1937ff5 commit 0c03933
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()>;

/// 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
Expand Down
5 changes: 5 additions & 0 deletions src/bluez/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
let adapter_info = self.session.get_adapter_info(&self.adapter).await?;
Ok(format!("{} ({})", adapter_info.id, adapter_info.modalias))
Expand Down
4 changes: 4 additions & 0 deletions src/common/adapter_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ where
self.peripherals.insert(peripheral.id(), peripheral);
}

pub fn clear_peripherals(&self) {
self.peripherals.clear();
}

pub fn peripherals(&self) -> Vec<PeripheralType> {
self.peripherals
.iter()
Expand Down
5 changes: 5 additions & 0 deletions src/corebluetooth/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
// TODO: Get information about the adapter.
Ok("CoreBluetooth".to_string())
Expand Down
5 changes: 5 additions & 0 deletions src/droidplug/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ impl Central for Adapter {
async fn add_peripheral(&self, address: &PeripheralId) -> Result<Peripheral> {
self.add(address.0)
}

async fn clear_peripherals(&self) -> Result<()> {
self.manager.clear_peripherals();
Ok(())
}
}

pub(crate) fn adapter_report_scan_result_internal(
Expand Down
5 changes: 5 additions & 0 deletions src/winrtble/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
// TODO: Get information about the adapter.
Ok("WinRT".to_string())
Expand Down

0 comments on commit 0c03933

Please sign in to comment.