diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-11-07 09:50:13 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-07 09:50:13 -0600 |
commit | eb2484f86dd57c95957b417ac0dd249ea86df06b (patch) | |
tree | fca43c7d3874eeb6f03d18487f3db7615d7ef29a /components/script/dom/bluetoothremotegattcharacteristic.rs | |
parent | 94d0c485e10138e0d5b2bd8b41b6a922a22a059f (diff) | |
parent | 91a0c4d50da7df38e2902e29fbec699e34ee892b (diff) | |
download | servo-eb2484f86dd57c95957b417ac0dd249ea86df06b.tar.gz servo-eb2484f86dd57c95957b417ac0dd249ea86df06b.zip |
Auto merge of #13918 - szeged:wpt-error-fixes, r=jdm
WebBluetooth fixes for the wpt tests
<!-- Please describe your changes on the following line: -->
Note: depends on #13612
WebBluetooth fixes for the failing wpt tests, excluding the `disconnect-during` tests cases, due to the lack of the event handling in the current implementation.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] There are tests for these changes OR
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13918)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/bluetoothremotegattcharacteristic.rs')
-rw-r--r-- | components/script/dom/bluetoothremotegattcharacteristic.rs | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs index 0fae7548ede..1b2a16c1a4b 100644 --- a/components/script/dom/bluetoothremotegattcharacteristic.rs +++ b/components/script/dom/bluetoothremotegattcharacteristic.rs @@ -2,8 +2,8 @@ * 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_blacklist::{Blacklist, uuid_is_blacklisted}; use bluetooth_traits::BluetoothMethodMsg; +use bluetooth_traits::blacklist::{Blacklist, uuid_is_blacklisted}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::BluetoothCharacteristicPropertiesBinding:: BluetoothCharacteristicPropertiesMethods; @@ -87,16 +87,26 @@ impl BluetoothRemoteGATTCharacteristic { if uuid_is_blacklisted(uuid.as_ref(), Blacklist::All) { return Err(Security) } + if !self.Service().Device().Gatt().Connected() { + return Err(Network) + } let (sender, receiver) = ipc::channel().unwrap(); self.get_bluetooth_thread().send( BluetoothMethodMsg::GetDescriptor(self.get_instance_id(), uuid, sender)).unwrap(); let descriptor = receiver.recv().unwrap(); match descriptor { Ok(descriptor) => { - Ok(BluetoothRemoteGATTDescriptor::new(&self.global(), - self, - DOMString::from(descriptor.uuid), - descriptor.instance_id)) + let context = self.service.get().get_device().get_context(); + let mut descriptor_map = context.get_descriptor_map().borrow_mut(); + if let Some(existing_descriptor) = descriptor_map.get(&descriptor.instance_id) { + return Ok(existing_descriptor.get()); + } + let bt_descriptor = BluetoothRemoteGATTDescriptor::new(&self.global(), + self, + DOMString::from(descriptor.uuid), + descriptor.instance_id.clone()); + descriptor_map.insert(descriptor.instance_id, MutHeap::new(&bt_descriptor)); + Ok(bt_descriptor) }, Err(error) => { Err(Error::from(error)) @@ -117,18 +127,34 @@ impl BluetoothRemoteGATTCharacteristic { } } }; + if !self.Service().Device().Gatt().Connected() { + return Err(Network) + } + let mut descriptors = vec!(); let (sender, receiver) = ipc::channel().unwrap(); self.get_bluetooth_thread().send( BluetoothMethodMsg::GetDescriptors(self.get_instance_id(), uuid, sender)).unwrap(); let descriptors_vec = receiver.recv().unwrap(); match descriptors_vec { Ok(descriptor_vec) => { - Ok(descriptor_vec.into_iter() - .map(|desc| BluetoothRemoteGATTDescriptor::new(&self.global(), - self, - DOMString::from(desc.uuid), - desc.instance_id)) - .collect()) + let context = self.service.get().get_device().get_context(); + let mut descriptor_map = context.get_descriptor_map().borrow_mut(); + for descriptor in descriptor_vec { + let bt_descriptor = match descriptor_map.get(&descriptor.instance_id) { + Some(existing_descriptor) => existing_descriptor.get(), + None => { + BluetoothRemoteGATTDescriptor::new(&self.global(), + self, + DOMString::from(descriptor.uuid), + descriptor.instance_id.clone()) + }, + }; + if !descriptor_map.contains_key(&descriptor.instance_id) { + descriptor_map.insert(descriptor.instance_id, MutHeap::new(&bt_descriptor)); + } + descriptors.push(bt_descriptor); + } + Ok(descriptors) }, Err(error) => { Err(Error::from(error)) @@ -182,10 +208,10 @@ impl BluetoothRemoteGATTCharacteristic { } let (sender, receiver) = ipc::channel().unwrap(); self.get_bluetooth_thread().send( - BluetoothMethodMsg::WriteValue(self.get_instance_id(), value, sender)).unwrap(); + BluetoothMethodMsg::WriteValue(self.get_instance_id(), value.clone(), sender)).unwrap(); let result = receiver.recv().unwrap(); match result { - Ok(_) => Ok(()), + Ok(_) => Ok(*self.value.borrow_mut() = Some(ByteString::new(value))), Err(error) => { Err(Error::from(error)) }, |