mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Format component bluetooth_traits
This commit is contained in:
parent
949e50d662
commit
0e3131a54c
3 changed files with 47 additions and 37 deletions
|
@ -10,24 +10,17 @@ use std::string::String;
|
||||||
|
|
||||||
const EXCLUDE_READS: &'static str = "exclude-reads";
|
const EXCLUDE_READS: &'static str = "exclude-reads";
|
||||||
const EXCLUDE_WRITES: &'static str = "exclude-writes";
|
const EXCLUDE_WRITES: &'static str = "exclude-writes";
|
||||||
const VALID_UUID_REGEX: &'static str = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
const VALID_UUID_REGEX: &'static str =
|
||||||
|
"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
||||||
|
|
||||||
thread_local!(pub static BLUETOOTH_BLOCKLIST: RefCell<BluetoothBlocklist> =
|
thread_local!(pub static BLUETOOTH_BLOCKLIST: RefCell<BluetoothBlocklist> =
|
||||||
RefCell::new(BluetoothBlocklist(parse_blocklist())));
|
RefCell::new(BluetoothBlocklist(parse_blocklist())));
|
||||||
|
|
||||||
pub fn uuid_is_blocklisted(uuid: &str, exclude_type: Blocklist) -> bool {
|
pub fn uuid_is_blocklisted(uuid: &str, exclude_type: Blocklist) -> bool {
|
||||||
BLUETOOTH_BLOCKLIST.with(|blist| {
|
BLUETOOTH_BLOCKLIST.with(|blist| match exclude_type {
|
||||||
match exclude_type {
|
Blocklist::All => blist.borrow().is_blocklisted(uuid),
|
||||||
Blocklist::All => {
|
Blocklist::Reads => blist.borrow().is_blocklisted_for_reads(uuid),
|
||||||
blist.borrow().is_blocklisted(uuid)
|
Blocklist::Writes => blist.borrow().is_blocklisted_for_writes(uuid),
|
||||||
},
|
|
||||||
Blocklist::Reads => {
|
|
||||||
blist.borrow().is_blocklisted_for_reads(uuid)
|
|
||||||
}
|
|
||||||
Blocklist::Writes => {
|
|
||||||
blist.borrow().is_blocklisted_for_writes(uuid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,8 +45,9 @@ impl BluetoothBlocklist {
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#blocklisted-for-reads
|
// https://webbluetoothcg.github.io/web-bluetooth/#blocklisted-for-reads
|
||||||
pub fn is_blocklisted_for_reads(&self, uuid: &str) -> bool {
|
pub fn is_blocklisted_for_reads(&self, uuid: &str) -> bool {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
Some(ref map) => map.get(uuid).map_or(false, |et| et.eq(&Blocklist::All) ||
|
Some(ref map) => map.get(uuid).map_or(false, |et| {
|
||||||
et.eq(&Blocklist::Reads)),
|
et.eq(&Blocklist::All) || et.eq(&Blocklist::Reads)
|
||||||
|
}),
|
||||||
None => false,
|
None => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,8 +55,9 @@ impl BluetoothBlocklist {
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#blocklisted-for-writes
|
// https://webbluetoothcg.github.io/web-bluetooth/#blocklisted-for-writes
|
||||||
pub fn is_blocklisted_for_writes(&self, uuid: &str) -> bool {
|
pub fn is_blocklisted_for_writes(&self, uuid: &str) -> bool {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
Some(ref map) => map.get(uuid).map_or(false, |et| et.eq(&Blocklist::All) ||
|
Some(ref map) => map.get(uuid).map_or(false, |et| {
|
||||||
et.eq(&Blocklist::Writes)),
|
et.eq(&Blocklist::All) || et.eq(&Blocklist::Writes)
|
||||||
|
}),
|
||||||
None => false,
|
None => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +93,7 @@ fn parse_blocklist() -> Option<HashMap<String, Blocklist>> {
|
||||||
exclude_type = Blocklist::Reads;
|
exclude_type = Blocklist::Reads;
|
||||||
},
|
},
|
||||||
Some(EXCLUDE_WRITES) => {
|
Some(EXCLUDE_WRITES) => {
|
||||||
exclude_type = Blocklist::Writes;
|
exclude_type = Blocklist::Writes;
|
||||||
},
|
},
|
||||||
// Step 4.4
|
// Step 4.4
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
extern crate embedder_traits;
|
extern crate embedder_traits;
|
||||||
extern crate ipc_channel;
|
extern crate ipc_channel;
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
#[macro_use] extern crate serde;
|
#[macro_use]
|
||||||
|
extern crate serde;
|
||||||
|
|
||||||
pub mod blocklist;
|
pub mod blocklist;
|
||||||
pub mod scanfilter;
|
pub mod scanfilter;
|
||||||
|
@ -83,7 +84,13 @@ pub enum BluetoothRequest {
|
||||||
RequestDevice(RequestDeviceoptions, IpcSender<BluetoothResponseResult>),
|
RequestDevice(RequestDeviceoptions, IpcSender<BluetoothResponseResult>),
|
||||||
GATTServerConnect(String, IpcSender<BluetoothResponseResult>),
|
GATTServerConnect(String, IpcSender<BluetoothResponseResult>),
|
||||||
GATTServerDisconnect(String, IpcSender<BluetoothResult<()>>),
|
GATTServerDisconnect(String, IpcSender<BluetoothResult<()>>),
|
||||||
GetGATTChildren(String, Option<String>, bool, GATTType, IpcSender<BluetoothResponseResult>),
|
GetGATTChildren(
|
||||||
|
String,
|
||||||
|
Option<String>,
|
||||||
|
bool,
|
||||||
|
GATTType,
|
||||||
|
IpcSender<BluetoothResponseResult>,
|
||||||
|
),
|
||||||
ReadValue(String, IpcSender<BluetoothResponseResult>),
|
ReadValue(String, IpcSender<BluetoothResponseResult>),
|
||||||
WriteValue(String, Vec<u8>, IpcSender<BluetoothResponseResult>),
|
WriteValue(String, Vec<u8>, IpcSender<BluetoothResponseResult>),
|
||||||
EnableNotification(String, bool, IpcSender<BluetoothResponseResult>),
|
EnableNotification(String, bool, IpcSender<BluetoothResponseResult>),
|
||||||
|
@ -91,7 +98,11 @@ pub enum BluetoothRequest {
|
||||||
SetRepresentedToNull(Vec<String>, Vec<String>, Vec<String>),
|
SetRepresentedToNull(Vec<String>, Vec<String>, Vec<String>),
|
||||||
IsRepresentedDeviceNull(String, IpcSender<bool>),
|
IsRepresentedDeviceNull(String, IpcSender<bool>),
|
||||||
GetAvailability(IpcSender<BluetoothResponseResult>),
|
GetAvailability(IpcSender<BluetoothResponseResult>),
|
||||||
MatchesFilter(String, BluetoothScanfilterSequence, IpcSender<BluetoothResult<bool>>),
|
MatchesFilter(
|
||||||
|
String,
|
||||||
|
BluetoothScanfilterSequence,
|
||||||
|
IpcSender<BluetoothResult<bool>>,
|
||||||
|
),
|
||||||
Test(String, IpcSender<BluetoothResult<()>>),
|
Test(String, IpcSender<BluetoothResult<()>>),
|
||||||
Exit,
|
Exit,
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,12 +36,13 @@ pub struct BluetoothScanfilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BluetoothScanfilter {
|
impl BluetoothScanfilter {
|
||||||
pub fn new(name: Option<String>,
|
pub fn new(
|
||||||
name_prefix: String,
|
name: Option<String>,
|
||||||
services: Vec<String>,
|
name_prefix: String,
|
||||||
manufacturer_data: Option<ManufacturerData>,
|
services: Vec<String>,
|
||||||
service_data: Option<ServiceData>)
|
manufacturer_data: Option<ManufacturerData>,
|
||||||
-> BluetoothScanfilter {
|
service_data: Option<ServiceData>,
|
||||||
|
) -> BluetoothScanfilter {
|
||||||
BluetoothScanfilter {
|
BluetoothScanfilter {
|
||||||
name: name,
|
name: name,
|
||||||
name_prefix: name_prefix,
|
name_prefix: name_prefix,
|
||||||
|
@ -73,12 +74,12 @@ impl BluetoothScanfilter {
|
||||||
|
|
||||||
pub fn is_empty_or_invalid(&self) -> bool {
|
pub fn is_empty_or_invalid(&self) -> bool {
|
||||||
(self.name.is_none() &&
|
(self.name.is_none() &&
|
||||||
self.name_prefix.is_empty() &&
|
self.name_prefix.is_empty() &&
|
||||||
self.get_services().is_empty() &&
|
self.get_services().is_empty() &&
|
||||||
self.manufacturer_data.is_none() &&
|
self.manufacturer_data.is_none() &&
|
||||||
self.service_data.is_none()) ||
|
self.service_data.is_none()) ||
|
||||||
self.get_name().unwrap_or("").len() > MAX_NAME_LENGTH ||
|
self.get_name().unwrap_or("").len() > MAX_NAME_LENGTH ||
|
||||||
self.name_prefix.len() > MAX_NAME_LENGTH
|
self.name_prefix.len() > MAX_NAME_LENGTH
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +100,9 @@ impl BluetoothScanfilterSequence {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_services_set(&self) -> HashSet<String> {
|
fn get_services_set(&self) -> HashSet<String> {
|
||||||
self.iter().flat_map(|filter| filter.services.get_services_set()).collect()
|
self.iter()
|
||||||
|
.flat_map(|filter| filter.services.get_services_set())
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_empty(&self) -> bool {
|
fn is_empty(&self) -> bool {
|
||||||
|
@ -114,9 +117,10 @@ pub struct RequestDeviceoptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequestDeviceoptions {
|
impl RequestDeviceoptions {
|
||||||
pub fn new(filters: BluetoothScanfilterSequence,
|
pub fn new(
|
||||||
services: ServiceUUIDSequence)
|
filters: BluetoothScanfilterSequence,
|
||||||
-> RequestDeviceoptions {
|
services: ServiceUUIDSequence,
|
||||||
|
) -> RequestDeviceoptions {
|
||||||
RequestDeviceoptions {
|
RequestDeviceoptions {
|
||||||
filters: filters,
|
filters: filters,
|
||||||
optional_services: services,
|
optional_services: services,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue