diff options
author | Attila Dusnoki <dati91@gmail.com> | 2016-12-15 08:06:42 +0100 |
---|---|---|
committer | Attila Dusnoki <dati91@gmail.com> | 2016-12-16 21:02:58 +0100 |
commit | b0103682fa2cd5147778e70b065ad4ee051684fd (patch) | |
tree | b358ef229aa76bdcf1b3097a1c2fb30229428c7b /components/script/dom/bluetooth.rs | |
parent | 0bc84154858d76f57831affee348d0f1c573f9f1 (diff) | |
download | servo-b0103682fa2cd5147778e70b065ad4ee051684fd.tar.gz servo-b0103682fa2cd5147778e70b065ad4ee051684fd.zip |
Implement GetGATTChildren
Diffstat (limited to 'components/script/dom/bluetooth.rs')
-rw-r--r-- | components/script/dom/bluetooth.rs | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/components/script/dom/bluetooth.rs b/components/script/dom/bluetooth.rs index 440ee882c66..d2b3ced25fe 100644 --- a/components/script/dom/bluetooth.rs +++ b/components/script/dom/bluetooth.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use bluetooth_traits::{BluetoothError, BluetoothRequest}; +use bluetooth_traits::{BluetoothError, BluetoothRequest, GATTType}; use bluetooth_traits::{BluetoothResponse, BluetoothResponseListener, BluetoothResponseResult}; use bluetooth_traits::blocklist::{Blocklist, uuid_is_blocklisted}; use bluetooth_traits::scanfilter::{BluetoothScanfilter, BluetoothScanfilterSequence}; @@ -13,14 +13,14 @@ use dom::bindings::codegen::Bindings::BluetoothBinding::{self, BluetoothDataFilt use dom::bindings::codegen::Bindings::BluetoothBinding::{BluetoothMethods, RequestDeviceOptions}; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::UnionTypes::StringOrUnsignedLong; -use dom::bindings::error::Error::{self, NotFound, Security, Type}; +use dom::bindings::error::Error::{self, Network, NotFound, Security, Type}; use dom::bindings::error::Fallible; use dom::bindings::js::{MutJS, Root}; use dom::bindings::refcounted::{Trusted, TrustedPromise}; use dom::bindings::reflector::{DomObject, reflect_dom_object}; use dom::bindings::str::DOMString; use dom::bluetoothdevice::BluetoothDevice; -use dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID}; +use dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID, UUID}; use dom::eventtarget::EventTarget; use dom::globalscope::GlobalScope; use dom::promise::Promise; @@ -193,6 +193,57 @@ pub fn response_async<T: AsyncBluetoothListener + DomObject + 'static>( action_sender } +#[allow(unrooted_must_root)] +// https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren +pub fn get_gatt_children<T, F> ( + attribute: &T, + single: bool, + uuid_canonicalizer: F, + uuid: Option<StringOrUnsignedLong>, + instance_id: String, + connected: bool, + child_type: GATTType) + -> Rc<Promise> + where T: AsyncBluetoothListener + DomObject + 'static, + F: FnOnce(StringOrUnsignedLong) -> Fallible<UUID> { + let p = Promise::new(&attribute.global()); + let p_cx = p.global().get_cx(); + + let result_uuid = if let Some(u) = uuid { + // Step 1. + let canonicalized = match uuid_canonicalizer(u) { + Ok(canonicalized_uuid) => canonicalized_uuid.to_string(), + Err(e) => { + p.reject_error(p_cx, e); + return p; + } + }; + // Step 2. + if uuid_is_blocklisted(canonicalized.as_ref(), Blocklist::All) { + p.reject_error(p_cx, Security); + return p; + } + Some(canonicalized) + } else { + None + }; + + // Step 3 - 4. + if !connected { + p.reject_error(p_cx, Network); + return p; + } + + // TODO: Step 5: Implement representedDevice internal slot for BluetoothDevice. + + // Note: Steps 6 - 7 are implemented in components/bluetooth/lib.rs in get_descriptor function + // and in handle_response function. + let sender = response_async(&p, attribute); + attribute.global().as_window().bluetooth_thread().send( + BluetoothRequest::GetGATTChildren(instance_id, result_uuid, single, child_type, sender)).unwrap(); + return p; +} + // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothlescanfilterinit-canonicalizing fn canonicalize_filter(filter: &BluetoothLEScanFilterInit) -> Fallible<BluetoothScanfilter> { // Step 1. |