Skip to content

Commit 41c8794

Browse files
Add clear_peripherals method to adapter
1 parent 1937ff5 commit 41c8794

File tree

6 files changed

+28
-0
lines changed

6 files changed

+28
-0
lines changed

src/api/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ pub trait Central: Send + Sync + Clone {
355355
/// Add a [`Peripheral`] from a MAC address without a scan result. Not supported on all Bluetooth systems.
356356
async fn add_peripheral(&self, address: &PeripheralId) -> Result<Self::Peripheral>;
357357

358+
/// Clear the list of [`Peripheral`]s that have been discovered so far.
359+
async fn clear_peripherals(&self) -> Result<()>;
360+
358361
/// Get information about the Bluetooth adapter being used, such as the model or type.
359362
///
360363
/// The details of this are platform-specific andyou should not attempt to parse it, but it may

src/bluez/adapter.rs

+6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ impl Central for Adapter {
101101
))
102102
}
103103

104+
async fn clear_peripherals(&self) -> Result<()> {
105+
Err(Error::NotSupported(
106+
"Can't clear peripheral list on this platform".to_string(),
107+
))
108+
}
109+
104110
async fn adapter_info(&self) -> Result<String> {
105111
let adapter_info = self.session.get_adapter_info(&self.adapter).await?;
106112
Ok(format!("{} ({})", adapter_info.id, adapter_info.modalias))

src/common/adapter_manager.rs

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ where
6666
self.peripherals.insert(peripheral.id(), peripheral);
6767
}
6868

69+
pub fn clear_peripherals(&self) {
70+
self.peripherals.clear();
71+
}
72+
6973
pub fn peripherals(&self) -> Vec<PeripheralType> {
7074
self.peripherals
7175
.iter()

src/corebluetooth/adapter.rs

+5
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ impl Central for Adapter {
117117
))
118118
}
119119

120+
async fn clear_peripherals(&self) -> Result<()> {
121+
self.manager.clear_peripherals();
122+
Ok(())
123+
}
124+
120125
async fn adapter_info(&self) -> Result<String> {
121126
// TODO: Get information about the adapter.
122127
Ok("CoreBluetooth".to_string())

src/droidplug/adapter.rs

+5
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ impl Central for Adapter {
167167
async fn add_peripheral(&self, address: &PeripheralId) -> Result<Peripheral> {
168168
self.add(address.0)
169169
}
170+
171+
async fn clear_peripherals(&self) -> Result<()> {
172+
self.manager.clear_peripherals();
173+
Ok(())
174+
}
170175
}
171176

172177
pub(crate) fn adapter_report_scan_result_internal(

src/winrtble/adapter.rs

+5
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ impl Central for Adapter {
9696
))
9797
}
9898

99+
async fn clear_peripherals(&self) -> Result<()> {
100+
self.manager.clear_peripherals();
101+
Ok(())
102+
}
103+
99104
async fn adapter_info(&self) -> Result<String> {
100105
// TODO: Get information about the adapter.
101106
Ok("WinRT".to_string())

0 commit comments

Comments
 (0)