Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ pub struct ScanFilter {
pub services: Vec<Uuid>,
}

/// Parameters of retrieve_peripherals method.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct RetrievePeripheralsOptions {
/// retrieve connected peripherals by services
services: Option<Vec<Uuid>>,
/// retrieve known peripherals by identifiers
identifiers: Option<Vec<PeripheralId>>,
}

/// The type of write operation to use.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum WriteType {
Expand Down Expand Up @@ -363,6 +372,12 @@ pub trait Central: Send + Sync + Clone {
/// may contain peripherals that are no longer available.
async fn peripherals(&self) -> Result<Vec<Self::Peripheral>>;

/// Returns the list of known or connected [`Peripheral`]s
async fn retrieve_peripherals(
&self,
options: RetrievePeripheralsOptions,
) -> Result<Vec<Self::Peripheral>>;

/// Returns a particular [`Peripheral`] by its address if it has been discovered.
async fn peripheral(&self, id: &PeripheralId) -> Result<Self::Peripheral>;

Expand Down
9 changes: 8 additions & 1 deletion src/bluez/adapter.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -91,6 +91,13 @@ impl Central for Adapter {
.collect())
}

async fn retrieve_peripherals(
&self,
options: RetrievePeripheralsOptions,
) -> Result<Vec<Peripheral>> {
Err(Error::NotSupported("Not implemented".to_string()))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe instead of throwing i should return an empty vec ? and only log/warn about missing implementation?

}

async fn peripheral(&self, id: &PeripheralId) -> Result<Peripheral> {
let device = self.session.get_device_info(&id.0).await.map_err(|e| {
if let BluetoothError::DbusError(_) = e {
Expand Down
9 changes: 8 additions & 1 deletion src/corebluetooth/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,6 +122,13 @@ impl Central for Adapter {
Ok(self.manager.peripherals())
}

async fn retrieve_peripherals(
&self,
options: RetrievePeripheralsOptions,
) -> Result<Vec<Peripheral>> {
Err(Error::NotSupported("Not implemented".to_string()))
}

async fn peripheral(&self, id: &PeripheralId) -> Result<Peripheral> {
self.manager.peripheral(id).ok_or(Error::DeviceNotFound)
}
Expand Down
12 changes: 11 additions & 1 deletion src/droidplug/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -158,6 +161,13 @@ impl Central for Adapter {
Ok(self.manager.peripherals())
}

async fn retrieve_peripherals(
&self,
options: RetrievePeripheralsOptions,
) -> Result<Vec<Peripheral>> {
Err(Error::NotSupported("Not implemented".to_string()))
}

async fn peripheral(&self, address: &PeripheralId) -> Result<Peripheral> {
self.manager
.peripheral(address)
Expand Down
9 changes: 8 additions & 1 deletion src/winrtble/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -118,6 +118,13 @@ impl Central for Adapter {
Ok(self.manager.peripherals())
}

async fn retrieve_peripherals(
&self,
options: RetrievePeripheralsOptions,
) -> Result<Vec<Peripheral>> {
Err(Error::NotSupported("Not implemented".to_string()))
}

async fn peripheral(&self, id: &PeripheralId) -> Result<Peripheral> {
self.manager.peripheral(id).ok_or(Error::DeviceNotFound)
}
Expand Down
Loading