diff options
author | kingdido999 <kingdido999@gmail.com> | 2018-08-17 11:09:38 +0800 |
---|---|---|
committer | kingdido999 <kingdido999@gmail.com> | 2018-08-17 11:09:38 +0800 |
commit | 0e3131a54cab9c3025616a68803bee952c19a931 (patch) | |
tree | 798e2a1df0ae56d055da8d75e5e9df67937e5f63 /components/bluetooth_traits | |
parent | 949e50d662f8bdd6f3c77562e59bba1c8caac3c6 (diff) | |
download | servo-0e3131a54cab9c3025616a68803bee952c19a931.tar.gz servo-0e3131a54cab9c3025616a68803bee952c19a931.zip |
Format component bluetooth_traits
Diffstat (limited to 'components/bluetooth_traits')
-rw-r--r-- | components/bluetooth_traits/blocklist.rs | 31 | ||||
-rw-r--r-- | components/bluetooth_traits/lib.rs | 17 | ||||
-rw-r--r-- | components/bluetooth_traits/scanfilter.rs | 36 |
3 files changed, 47 insertions, 37 deletions
diff --git a/components/bluetooth_traits/blocklist.rs b/components/bluetooth_traits/blocklist.rs index f141baf81f4..e6cf937f8df 100644 --- a/components/bluetooth_traits/blocklist.rs +++ b/components/bluetooth_traits/blocklist.rs @@ -10,24 +10,17 @@ use std::string::String; const EXCLUDE_READS: &'static str = "exclude-reads"; 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> = RefCell::new(BluetoothBlocklist(parse_blocklist()))); pub fn uuid_is_blocklisted(uuid: &str, exclude_type: Blocklist) -> bool { - BLUETOOTH_BLOCKLIST.with(|blist| { - match exclude_type { - Blocklist::All => { - blist.borrow().is_blocklisted(uuid) - }, - Blocklist::Reads => { - blist.borrow().is_blocklisted_for_reads(uuid) - } - Blocklist::Writes => { - blist.borrow().is_blocklisted_for_writes(uuid) - } - } + BLUETOOTH_BLOCKLIST.with(|blist| match exclude_type { + Blocklist::All => blist.borrow().is_blocklisted(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 pub fn is_blocklisted_for_reads(&self, uuid: &str) -> bool { match self.0 { - Some(ref map) => map.get(uuid).map_or(false, |et| et.eq(&Blocklist::All) || - et.eq(&Blocklist::Reads)), + Some(ref map) => map.get(uuid).map_or(false, |et| { + et.eq(&Blocklist::All) || et.eq(&Blocklist::Reads) + }), None => false, } } @@ -61,8 +55,9 @@ impl BluetoothBlocklist { // https://webbluetoothcg.github.io/web-bluetooth/#blocklisted-for-writes pub fn is_blocklisted_for_writes(&self, uuid: &str) -> bool { match self.0 { - Some(ref map) => map.get(uuid).map_or(false, |et| et.eq(&Blocklist::All) || - et.eq(&Blocklist::Writes)), + Some(ref map) => map.get(uuid).map_or(false, |et| { + et.eq(&Blocklist::All) || et.eq(&Blocklist::Writes) + }), None => false, } } @@ -98,7 +93,7 @@ fn parse_blocklist() -> Option<HashMap<String, Blocklist>> { exclude_type = Blocklist::Reads; }, Some(EXCLUDE_WRITES) => { - exclude_type = Blocklist::Writes; + exclude_type = Blocklist::Writes; }, // Step 4.4 _ => { diff --git a/components/bluetooth_traits/lib.rs b/components/bluetooth_traits/lib.rs index b1cc68728a7..0925234666b 100644 --- a/components/bluetooth_traits/lib.rs +++ b/components/bluetooth_traits/lib.rs @@ -5,7 +5,8 @@ extern crate embedder_traits; extern crate ipc_channel; extern crate regex; -#[macro_use] extern crate serde; +#[macro_use] +extern crate serde; pub mod blocklist; pub mod scanfilter; @@ -83,7 +84,13 @@ pub enum BluetoothRequest { RequestDevice(RequestDeviceoptions, IpcSender<BluetoothResponseResult>), GATTServerConnect(String, IpcSender<BluetoothResponseResult>), GATTServerDisconnect(String, IpcSender<BluetoothResult<()>>), - GetGATTChildren(String, Option<String>, bool, GATTType, IpcSender<BluetoothResponseResult>), + GetGATTChildren( + String, + Option<String>, + bool, + GATTType, + IpcSender<BluetoothResponseResult>, + ), ReadValue(String, IpcSender<BluetoothResponseResult>), WriteValue(String, Vec<u8>, IpcSender<BluetoothResponseResult>), EnableNotification(String, bool, IpcSender<BluetoothResponseResult>), @@ -91,7 +98,11 @@ pub enum BluetoothRequest { SetRepresentedToNull(Vec<String>, Vec<String>, Vec<String>), IsRepresentedDeviceNull(String, IpcSender<bool>), GetAvailability(IpcSender<BluetoothResponseResult>), - MatchesFilter(String, BluetoothScanfilterSequence, IpcSender<BluetoothResult<bool>>), + MatchesFilter( + String, + BluetoothScanfilterSequence, + IpcSender<BluetoothResult<bool>>, + ), Test(String, IpcSender<BluetoothResult<()>>), Exit, } diff --git a/components/bluetooth_traits/scanfilter.rs b/components/bluetooth_traits/scanfilter.rs index a3b33f684c9..cde3d172a25 100644 --- a/components/bluetooth_traits/scanfilter.rs +++ b/components/bluetooth_traits/scanfilter.rs @@ -36,12 +36,13 @@ pub struct BluetoothScanfilter { } impl BluetoothScanfilter { - pub fn new(name: Option<String>, - name_prefix: String, - services: Vec<String>, - manufacturer_data: Option<ManufacturerData>, - service_data: Option<ServiceData>) - -> BluetoothScanfilter { + pub fn new( + name: Option<String>, + name_prefix: String, + services: Vec<String>, + manufacturer_data: Option<ManufacturerData>, + service_data: Option<ServiceData>, + ) -> BluetoothScanfilter { BluetoothScanfilter { name: name, name_prefix: name_prefix, @@ -73,12 +74,12 @@ impl BluetoothScanfilter { pub fn is_empty_or_invalid(&self) -> bool { (self.name.is_none() && - self.name_prefix.is_empty() && - self.get_services().is_empty() && - self.manufacturer_data.is_none() && - self.service_data.is_none()) || - self.get_name().unwrap_or("").len() > MAX_NAME_LENGTH || - self.name_prefix.len() > MAX_NAME_LENGTH + self.name_prefix.is_empty() && + self.get_services().is_empty() && + self.manufacturer_data.is_none() && + self.service_data.is_none()) || + self.get_name().unwrap_or("").len() > MAX_NAME_LENGTH || + self.name_prefix.len() > MAX_NAME_LENGTH } } @@ -99,7 +100,9 @@ impl BluetoothScanfilterSequence { } 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 { @@ -114,9 +117,10 @@ pub struct RequestDeviceoptions { } impl RequestDeviceoptions { - pub fn new(filters: BluetoothScanfilterSequence, - services: ServiceUUIDSequence) - -> RequestDeviceoptions { + pub fn new( + filters: BluetoothScanfilterSequence, + services: ServiceUUIDSequence, + ) -> RequestDeviceoptions { RequestDeviceoptions { filters: filters, optional_services: services, |