diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-12-14 15:29:43 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-14 15:29:43 -0800 |
commit | 6ee175bf705108ab25e80521d7be84b5e58ef698 (patch) | |
tree | b16a4ac9e07dad37cfff27facb7745b60025a87f /components/bluetooth | |
parent | eb1bd596822c7e24589fdc08c4f41c69c4207351 (diff) | |
parent | c3e771274a66745f4715e3ef5160dc310c0e29b7 (diff) | |
download | servo-6ee175bf705108ab25e80521d7be84b5e58ef698.tar.gz servo-6ee175bf705108ab25e80521d7be84b5e58ef698.zip |
Auto merge of #14567 - szeged:represented-attributes, r=jdm
Check if represented attributes are cached
<!-- Please describe your changes on the following line: -->
Improve existing cache checks in `/bluetooth/lib.rs`, and update Step comments in `script/dom` corresponding to this.
---
<!-- 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/14567)
<!-- Reviewable:end -->
Diffstat (limited to 'components/bluetooth')
-rw-r--r-- | components/bluetooth/lib.rs | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/components/bluetooth/lib.rs b/components/bluetooth/lib.rs index 47f3d89b011..e3045be4248 100644 --- a/components/bluetooth/lib.rs +++ b/components/bluetooth/lib.rs @@ -421,6 +421,10 @@ impl BluetoothManager { } } + fn device_is_cached(&self, device_id: &str) -> bool { + self.cached_devices.contains_key(device_id) && self.address_to_id.values().any(|v| v == device_id) + } + // Service fn get_and_cache_gatt_services(&mut self, @@ -463,6 +467,10 @@ impl BluetoothManager { services.into_iter().filter(|s| s.get_uuid().ok() == Some(service_uuid.to_string())).collect() } + fn service_is_cached(&self, service_id: &str) -> bool { + self.cached_services.contains_key(service_id) && self.service_to_device.contains_key(service_id) + } + // Characteristic fn get_and_cache_gatt_characteristics(&mut self, @@ -527,6 +535,11 @@ impl BluetoothManager { props } + fn characteristic_is_cached(&self, characteristic_id: &str) -> bool { + self.cached_characteristics.contains_key(characteristic_id) && + self.characteristic_to_service.contains_key(characteristic_id) + } + // Descriptor fn get_and_cache_gatt_descriptors(&mut self, @@ -627,6 +640,10 @@ impl BluetoothManager { // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect fn gatt_server_connect(&mut self, device_id: String, sender: IpcSender<BluetoothResponseResult>) { + // Step 2. + if !self.device_is_cached(&device_id) { + return drop(sender.send(Err(BluetoothError::Network))); + } let mut adapter = get_adapter_or_return_error!(self, sender); // Step 5.1.1. @@ -685,7 +702,7 @@ impl BluetoothManager { uuid: String, sender: IpcSender<BluetoothResponseResult>) { // Step 5. - if !self.cached_devices.contains_key(&device_id) { + if !self.device_is_cached(&device_id) { return drop(sender.send(Err(BluetoothError::InvalidState))); } let mut adapter = get_adapter_or_return_error!(self, sender); @@ -721,7 +738,7 @@ impl BluetoothManager { uuid: Option<String>, sender: IpcSender<BluetoothResponseResult>) { // Step 5. - if !self.cached_devices.contains_key(&device_id) { + if !self.device_is_cached(&device_id) { return drop(sender.send(Err(BluetoothError::InvalidState))); } let mut adapter = get_adapter_or_return_error!(self, sender); @@ -766,7 +783,7 @@ impl BluetoothManager { uuid: String, sender: IpcSender<BluetoothResponseResult>) { // Step 5. - if !self.cached_services.contains_key(&service_id) { + if !self.service_is_cached(&service_id) { return drop(sender.send(Err(BluetoothError::InvalidState))); } let mut adapter = get_adapter_or_return_error!(self, sender); @@ -807,7 +824,7 @@ impl BluetoothManager { uuid: Option<String>, sender: IpcSender<BluetoothResponseResult>) { // Step 5. - if !self.cached_services.contains_key(&service_id) { + if !self.service_is_cached(&service_id) { return drop(sender.send(Err(BluetoothError::InvalidState))); } let mut adapter = get_adapter_or_return_error!(self, sender); @@ -854,7 +871,7 @@ impl BluetoothManager { uuid: String, sender: IpcSender<BluetoothResponseResult>) { // Step 5. - if !self.cached_services.contains_key(&service_id) { + if !self.service_is_cached(&service_id) { return drop(sender.send(Err(BluetoothError::InvalidState))); } let mut adapter = get_adapter_or_return_error!(self, sender); @@ -891,7 +908,7 @@ impl BluetoothManager { uuid: Option<String>, sender: IpcSender<BluetoothResponseResult>) { // Step 5. - if !self.cached_services.contains_key(&service_id) { + if !self.service_is_cached(&service_id) { return drop(sender.send(Err(BluetoothError::InvalidState))); } let mut adapter = get_adapter_or_return_error!(self, sender); @@ -938,7 +955,7 @@ impl BluetoothManager { uuid: String, sender: IpcSender<BluetoothResponseResult>) { // Step 5. - if !self.cached_characteristics.contains_key(&characteristic_id) { + if !self.characteristic_is_cached(&characteristic_id) { return drop(sender.send(Err(BluetoothError::InvalidState))); } let mut adapter = get_adapter_or_return_error!(self, sender); @@ -968,7 +985,7 @@ impl BluetoothManager { uuid: Option<String>, sender: IpcSender<BluetoothResponseResult>) { // Step 5. - if !self.cached_characteristics.contains_key(&characteristic_id) { + if !self.characteristic_is_cached(&characteristic_id) { return drop(sender.send(Err(BluetoothError::InvalidState))); } let mut adapter = get_adapter_or_return_error!(self, sender); @@ -1069,6 +1086,11 @@ impl BluetoothManager { // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-startnotifications // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-stopnotifications fn enable_notification(&mut self, id: String, enable: bool, sender: IpcSender<BluetoothResponseResult>) { + // (StartNotifications) Step 2 - 3. + // (StopNotifications) Step 1 - 2. + if !self.characteristic_is_cached(&id) { + return drop(sender.send(Err(BluetoothError::InvalidState))); + } // (StartNotification) TODO: Step 7: Missing because it is optional. let mut adapter = get_adapter_or_return_error!(self, sender); match self.get_gatt_characteristic(&mut adapter, &id) { |