mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Add discovery session
This commit is contained in:
parent
2572a7d2c5
commit
89f26f4653
1 changed files with 11 additions and 4 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
use device::bluetooth::BluetoothAdapter;
|
||||
use device::bluetooth::BluetoothDevice;
|
||||
use device::bluetooth::BluetoothDiscoverySession;
|
||||
use device::bluetooth::BluetoothGATTCharacteristic;
|
||||
use device::bluetooth::BluetoothGATTDescriptor;
|
||||
use device::bluetooth::BluetoothGATTService;
|
||||
|
@ -16,6 +17,8 @@ use net_traits::bluetooth_thread::{BluetoothResult, BluetoothServiceMsg, Bluetoo
|
|||
use std::borrow::ToOwned;
|
||||
use std::collections::HashMap;
|
||||
use std::string::String;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use util::thread::spawn_named;
|
||||
|
||||
const ADAPTER_ERROR: &'static str = "No adapter found";
|
||||
|
@ -25,6 +28,8 @@ const PRIMARY_SERVICE_ERROR: &'static str = "No primary service found";
|
|||
const CHARACTERISTIC_ERROR: &'static str = "No characteristic found";
|
||||
const DESCRIPTOR_ERROR: &'static str = "No descriptor found";
|
||||
const VALUE_ERROR: &'static str = "No characteristic or descriptor found with that id";
|
||||
// The discovery session needs some time to find any nearby devices
|
||||
const DISCOVERY_TIMEOUT_MS: u64 = 1500;
|
||||
|
||||
bitflags! {
|
||||
flags Flags: u32 {
|
||||
|
@ -355,11 +360,13 @@ impl BluetoothManager {
|
|||
Some(a) => a,
|
||||
None => return drop(sender.send(Err(String::from(ADAPTER_ERROR)))),
|
||||
};
|
||||
let devices = self.get_and_cache_devices(&mut adapter);
|
||||
if devices.is_empty() {
|
||||
return drop(sender.send(Err(String::from(DEVICE_ERROR))));
|
||||
if let Some(ref session) = BluetoothDiscoverySession::create_session(adapter.get_object_path()).ok() {
|
||||
if session.start_discovery().is_ok() {
|
||||
thread::sleep(Duration::from_millis(DISCOVERY_TIMEOUT_MS));
|
||||
}
|
||||
let _ = session.stop_discovery();
|
||||
}
|
||||
|
||||
let devices = self.get_and_cache_devices(&mut adapter);
|
||||
let matched_devices: Vec<BluetoothDevice> = devices.into_iter()
|
||||
.filter(|d| matches_filters(d, options.get_filters()))
|
||||
.collect();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue