diff --git a/src/api/mod.rs b/src/api/mod.rs index bb3acf68..c48650b1 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -209,6 +209,15 @@ pub struct ScanFilter { pub services: Vec, } +/// Parameters of retrieve_peripherals method. +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct RetrievePeripheralsOptions { + /// retrieve connected peripherals by services + services: Option>, + /// retrieve known peripherals by identifiers + identifiers: Option>, +} + /// The type of write operation to use. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum WriteType { @@ -363,6 +372,12 @@ pub trait Central: Send + Sync + Clone { /// may contain peripherals that are no longer available. async fn peripherals(&self) -> Result>; + /// Returns the list of known or connected [`Peripheral`]s + async fn retrieve_peripherals( + &self, + options: RetrievePeripheralsOptions, + ) -> Result>; + /// Returns a particular [`Peripheral`] by its address if it has been discovered. async fn peripheral(&self, id: &PeripheralId) -> Result; diff --git a/src/bluez/adapter.rs b/src/bluez/adapter.rs index 72efb407..4e0964fc 100644 --- a/src/bluez/adapter.rs +++ b/src/bluez/adapter.rs @@ -1,5 +1,5 @@ use super::peripheral::{Peripheral, PeripheralId}; -use crate::api::{Central, CentralEvent, CentralState, ScanFilter}; +use crate::api::{Central, CentralEvent, CentralState, RetrievePeripheralsOptions, ScanFilter}; use crate::{Error, Result}; use async_trait::async_trait; use bluez_async::{ @@ -91,6 +91,13 @@ impl Central for Adapter { .collect()) } + async fn retrieve_peripherals( + &self, + options: RetrievePeripheralsOptions, + ) -> Result> { + Err(Error::NotSupported("Not implemented".to_string())) + } + async fn peripheral(&self, id: &PeripheralId) -> Result { let device = self.session.get_device_info(&id.0).await.map_err(|e| { if let BluetoothError::DbusError(_) = e { diff --git a/src/corebluetooth/adapter.rs b/src/corebluetooth/adapter.rs index b8626bd1..17995b43 100644 --- a/src/corebluetooth/adapter.rs +++ b/src/corebluetooth/adapter.rs @@ -3,7 +3,7 @@ use super::internal::{ CoreBluetoothReplyFuture, }; use super::peripheral::{Peripheral, PeripheralId}; -use crate::api::{Central, CentralEvent, CentralState, ScanFilter}; +use crate::api::{Central, CentralEvent, CentralState, RetrievePeripheralsOptions, ScanFilter}; use crate::common::adapter_manager::AdapterManager; use crate::{Error, Result}; use async_trait::async_trait; @@ -122,6 +122,13 @@ impl Central for Adapter { Ok(self.manager.peripherals()) } + async fn retrieve_peripherals( + &self, + options: RetrievePeripheralsOptions, + ) -> Result> { + Err(Error::NotSupported("Not implemented".to_string())) + } + async fn peripheral(&self, id: &PeripheralId) -> Result { self.manager.peripheral(id).ok_or(Error::DeviceNotFound) } diff --git a/src/droidplug/adapter.rs b/src/droidplug/adapter.rs index f3d10c90..5a6ed6f2 100644 --- a/src/droidplug/adapter.rs +++ b/src/droidplug/adapter.rs @@ -6,7 +6,10 @@ use super::{ peripheral::{Peripheral, PeripheralId}, }; use crate::{ - api::{BDAddr, Central, CentralEvent, CentralState, PeripheralProperties, ScanFilter}, + api::{ + BDAddr, Central, CentralEvent, CentralState, PeripheralProperties, + RetrievePeripheralsOptions, ScanFilter, + }, common::adapter_manager::AdapterManager, Error, Result, }; @@ -158,6 +161,13 @@ impl Central for Adapter { Ok(self.manager.peripherals()) } + async fn retrieve_peripherals( + &self, + options: RetrievePeripheralsOptions, + ) -> Result> { + Err(Error::NotSupported("Not implemented".to_string())) + } + async fn peripheral(&self, address: &PeripheralId) -> Result { self.manager .peripheral(address) diff --git a/src/winrtble/adapter.rs b/src/winrtble/adapter.rs index d840c403..5a3085f8 100644 --- a/src/winrtble/adapter.rs +++ b/src/winrtble/adapter.rs @@ -13,7 +13,7 @@ use super::{ble::watcher::BLEWatcher, peripheral::Peripheral, peripheral::PeripheralId}; use crate::{ - api::{BDAddr, Central, CentralEvent, CentralState, ScanFilter}, + api::{BDAddr, Central, CentralEvent, CentralState, RetrievePeripheralsOptions, ScanFilter}, common::adapter_manager::AdapterManager, Error, Result, }; @@ -118,6 +118,13 @@ impl Central for Adapter { Ok(self.manager.peripherals()) } + async fn retrieve_peripherals( + &self, + options: RetrievePeripheralsOptions, + ) -> Result> { + Err(Error::NotSupported("Not implemented".to_string())) + } + async fn peripheral(&self, id: &PeripheralId) -> Result { self.manager.peripheral(id).ok_or(Error::DeviceNotFound) }