Skip to content

Commit 4342771

Browse files
committed
feat: add Adapter retrieve_peripherals method
1 parent d91a54c commit 4342771

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

src/api/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ pub struct ScanFilter {
209209
pub services: Vec<Uuid>,
210210
}
211211

212+
/// Parameters of retrieve_peripherals method.
213+
#[derive(Clone, Debug, Eq, PartialEq)]
214+
pub struct RetrievePeripheralsOptions {
215+
/// retrieve connected peripherals by services
216+
services: Option<Vec<Uuid>>,
217+
/// retrieve known peripherals by identifiers
218+
identifiers: Option<Vec<PeripheralId>>,
219+
}
220+
212221
/// The type of write operation to use.
213222
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
214223
pub enum WriteType {
@@ -363,6 +372,12 @@ pub trait Central: Send + Sync + Clone {
363372
/// may contain peripherals that are no longer available.
364373
async fn peripherals(&self) -> Result<Vec<Self::Peripheral>>;
365374

375+
/// Returns the list of known or connected [`Peripheral`]s
376+
async fn retrieve_peripherals(
377+
&self,
378+
options: RetrievePeripheralsOptions,
379+
) -> Result<Vec<Self::Peripheral>>;
380+
366381
/// Returns a particular [`Peripheral`] by its address if it has been discovered.
367382
async fn peripheral(&self, id: &PeripheralId) -> Result<Self::Peripheral>;
368383

src/bluez/adapter.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::peripheral::{Peripheral, PeripheralId};
2-
use crate::api::{Central, CentralEvent, CentralState, ScanFilter};
2+
use crate::api::{Central, CentralEvent, CentralState, RetrievePeripheralsOptions, ScanFilter};
33
use crate::{Error, Result};
44
use async_trait::async_trait;
55
use bluez_async::{
@@ -91,6 +91,13 @@ impl Central for Adapter {
9191
.collect())
9292
}
9393

94+
async fn retrieve_peripherals(
95+
&self,
96+
options: RetrievePeripheralsOptions,
97+
) -> Result<Vec<Peripheral>> {
98+
Err(Error::NotSupported("Not implemented".to_string()))
99+
}
100+
94101
async fn peripheral(&self, id: &PeripheralId) -> Result<Peripheral> {
95102
let device = self.session.get_device_info(&id.0).await.map_err(|e| {
96103
if let BluetoothError::DbusError(_) = e {

src/corebluetooth/adapter.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::internal::{
33
CoreBluetoothReplyFuture,
44
};
55
use super::peripheral::{Peripheral, PeripheralId};
6-
use crate::api::{Central, CentralEvent, CentralState, ScanFilter};
6+
use crate::api::{Central, CentralEvent, CentralState, RetrievePeripheralsOptions, ScanFilter};
77
use crate::common::adapter_manager::AdapterManager;
88
use crate::{Error, Result};
99
use async_trait::async_trait;
@@ -122,6 +122,13 @@ impl Central for Adapter {
122122
Ok(self.manager.peripherals())
123123
}
124124

125+
async fn retrieve_peripherals(
126+
&self,
127+
options: RetrievePeripheralsOptions,
128+
) -> Result<Vec<Peripheral>> {
129+
Err(Error::NotSupported("Not implemented".to_string()))
130+
}
131+
125132
async fn peripheral(&self, id: &PeripheralId) -> Result<Peripheral> {
126133
self.manager.peripheral(id).ok_or(Error::DeviceNotFound)
127134
}

src/droidplug/adapter.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use super::{
66
peripheral::{Peripheral, PeripheralId},
77
};
88
use crate::{
9-
api::{BDAddr, Central, CentralEvent, CentralState, PeripheralProperties, ScanFilter},
9+
api::{
10+
BDAddr, Central, CentralEvent, CentralState, PeripheralProperties,
11+
RetrievePeripheralsOptions, ScanFilter,
12+
},
1013
common::adapter_manager::AdapterManager,
1114
Error, Result,
1215
};
@@ -158,6 +161,13 @@ impl Central for Adapter {
158161
Ok(self.manager.peripherals())
159162
}
160163

164+
async fn retrieve_peripherals(
165+
&self,
166+
options: RetrievePeripheralsOptions,
167+
) -> Result<Vec<Peripheral>> {
168+
Err(Error::NotSupported("Not implemented".to_string()))
169+
}
170+
161171
async fn peripheral(&self, address: &PeripheralId) -> Result<Peripheral> {
162172
self.manager
163173
.peripheral(address)

src/winrtble/adapter.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use super::{ble::watcher::BLEWatcher, peripheral::Peripheral, peripheral::PeripheralId};
1515
use crate::{
16-
api::{BDAddr, Central, CentralEvent, CentralState, ScanFilter},
16+
api::{BDAddr, Central, CentralEvent, CentralState, RetrievePeripheralsOptions, ScanFilter},
1717
common::adapter_manager::AdapterManager,
1818
Error, Result,
1919
};
@@ -118,6 +118,13 @@ impl Central for Adapter {
118118
Ok(self.manager.peripherals())
119119
}
120120

121+
async fn retrieve_peripherals(
122+
&self,
123+
options: RetrievePeripheralsOptions,
124+
) -> Result<Vec<Peripheral>> {
125+
Err(Error::NotSupported("Not implemented".to_string()))
126+
}
127+
121128
async fn peripheral(&self, id: &PeripheralId) -> Result<Peripheral> {
122129
self.manager.peripheral(id).ok_or(Error::DeviceNotFound)
123130
}

0 commit comments

Comments
 (0)