aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bluetoothremotegattcharacteristic.rs
diff options
context:
space:
mode:
authorzakorgyula <gyula.zakor@gmail.com>2016-10-07 16:17:11 +0200
committerzakorgyula <gyula.zakor@gmail.com>2016-11-04 15:36:57 +0100
commite8c1c98a77dd64a902a4941a8889b9bd5603ce2d (patch)
treee65e36e8d1a67182795d4f8a79fcf322b27b18ba /components/script/dom/bluetoothremotegattcharacteristic.rs
parentd30bcbd33948f41fc3389f8105885060fd7541a5 (diff)
downloadservo-e8c1c98a77dd64a902a4941a8889b9bd5603ce2d.tar.gz
servo-e8c1c98a77dd64a902a4941a8889b9bd5603ce2d.zip
Return the same JS object for the same Bluetooth item.
Diffstat (limited to 'components/script/dom/bluetoothremotegattcharacteristic.rs')
-rw-r--r--components/script/dom/bluetoothremotegattcharacteristic.rs40
1 files changed, 30 insertions, 10 deletions
diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs
index 299ef921ee6..1b2a16c1a4b 100644
--- a/components/script/dom/bluetoothremotegattcharacteristic.rs
+++ b/components/script/dom/bluetoothremotegattcharacteristic.rs
@@ -96,10 +96,17 @@ impl BluetoothRemoteGATTCharacteristic {
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))
@@ -123,18 +130,31 @@ 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))