aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bluetoothremotegattserver.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-12-16 12:30:41 -0800
committerGitHub <noreply@github.com>2016-12-16 12:30:41 -0800
commit6efea399ed0e44fe6bd151f346ca2c3371e2f66c (patch)
tree0ef00cb38846e01b45b1c0a72f236e6c56d903ef /components/script/dom/bluetoothremotegattserver.rs
parenta4ecdf2d5fda281f25e2689852bc2134429e07c6 (diff)
parentb0103682fa2cd5147778e70b065ad4ee051684fd (diff)
downloadservo-6efea399ed0e44fe6bd151f346ca2c3371e2f66c.tar.gz
servo-6efea399ed0e44fe6bd151f346ca2c3371e2f66c.zip
Auto merge of #14593 - szeged:getgattchildren, r=jdm
Implement GetGATTChildren <!-- Please describe your changes on the following line: --> Implement the [GetGATTChildren](https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren) function for webbluetooth. --- <!-- 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 <!-- Either: --> - [X] There are tests for these changes <!-- 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/14593) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/bluetoothremotegattserver.rs')
-rw-r--r--components/script/dom/bluetoothremotegattserver.rs92
1 files changed, 14 insertions, 78 deletions
diff --git a/components/script/dom/bluetoothremotegattserver.rs b/components/script/dom/bluetoothremotegattserver.rs
index 307c3b87f66..ad7833af908 100644
--- a/components/script/dom/bluetoothremotegattserver.rs
+++ b/components/script/dom/bluetoothremotegattserver.rs
@@ -2,16 +2,15 @@
* 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::{BluetoothRequest, BluetoothResponse};
-use bluetooth_traits::blocklist::{Blocklist, uuid_is_blocklisted};
+use bluetooth_traits::{BluetoothRequest, BluetoothResponse, GATTType};
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
-use dom::bindings::error::Error::{self, Network, Security};
+use dom::bindings::error::Error;
use dom::bindings::error::ErrorResult;
use dom::bindings::js::{MutJS, Root};
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
-use dom::bluetooth::{AsyncBluetoothListener, response_async};
+use dom::bluetooth::{AsyncBluetoothListener, get_gatt_children, response_async};
use dom::bluetoothdevice::BluetoothDevice;
use dom::bluetoothuuid::{BluetoothServiceUUID, BluetoothUUID};
use dom::globalscope::GlobalScope;
@@ -114,84 +113,24 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservice
fn GetPrimaryService(&self, service: BluetoothServiceUUID) -> Rc<Promise> {
// TODO: Step 1: Implement the Permission API and the allowedServices BluetoothDevice internal slot.
- // Subsequent steps are relative to https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren
- let p = Promise::new(&self.global());
- let p_cx = p.global().get_cx();
-
- // Step 1.
- let uuid = match BluetoothUUID::service(service) {
- Ok(uuid) => uuid.to_string(),
- Err(e) => {
- p.reject_error(p_cx, e);
- return p;
- }
- };
-
// Step 2.
- if uuid_is_blocklisted(uuid.as_ref(), Blocklist::All) {
- p.reject_error(p_cx, Security);
- return p;
- }
-
- // Step 3 - 4.
- if !self.Device().Gatt().Connected() {
- p.reject_error(p_cx, Network);
- return p;
- }
-
- // Note: Steps 5 - 7 are implemented in components/bluetooth/lib.rs in get_primary_service function
- // and in handle_response function.
- let sender = response_async(&p, self);
- self.get_bluetooth_thread().send(
- BluetoothRequest::GetPrimaryService(String::from(self.Device().Id()), uuid, sender)).unwrap();
- return p;
+ get_gatt_children(self, true, BluetoothUUID::service, Some(service), String::from(self.Device().Id()),
+ self.Device().Gatt().Connected(), GATTType::PrimaryService)
}
#[allow(unrooted_must_root)]
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservices
fn GetPrimaryServices(&self, service: Option<BluetoothServiceUUID>) -> Rc<Promise> {
// TODO: Step 1: Implement the Permission API and the allowedServices BluetoothDevice internal slot.
- // Subsequent steps are relative to https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren
- let p = Promise::new(&self.global());
- let p_cx = p.global().get_cx();
-
- let mut uuid: Option<String> = None;
- if let Some(s) = service {
- // Step 1.
- uuid = match BluetoothUUID::service(s) {
- Ok(uuid) => Some(uuid.to_string()),
- Err(e) => {
- p.reject_error(p_cx, e);
- return p;
- }
- };
- if let Some(ref uuid) = uuid {
- // Step 2.
- if uuid_is_blocklisted(uuid.as_ref(), Blocklist::All) {
- p.reject_error(p_cx, Security);
- return p;
- }
- }
- };
-
- // Step 3 - 4.
- if !self.Device().Gatt().Connected() {
- p.reject_error(p_cx, Network);
- return p;
- }
+ // Step 2.
+ get_gatt_children(self, false, BluetoothUUID::service, service, String::from(self.Device().Id()),
+ self.Connected(), GATTType::PrimaryService)
- // Note: Steps 5 - 7 are implemented in components/bluetooth/lib.rs in get_primary_services function
- // and in handle_response function.
- let sender = response_async(&p, self);
- self.get_bluetooth_thread().send(
- BluetoothRequest::GetPrimaryServices(String::from(self.Device().Id()), uuid, sender)).unwrap();
- return p;
}
}
impl AsyncBluetoothListener for BluetoothRemoteGATTServer {
fn handle_response(&self, response: BluetoothResponse, promise_cx: *mut JSContext, promise: &Rc<Promise>) {
- let device = self.Device();
match response {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect
BluetoothResponse::GATTServerConnect(connected) => {
@@ -201,17 +140,14 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTServer {
// Step 5.2.5.
promise.resolve_native(promise_cx, self);
},
- // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservice
- // https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren
- // Step 7.
- BluetoothResponse::GetPrimaryService(service) => {
- let bt_service = device.get_or_create_service(&service, &self);
- promise.resolve_native(promise_cx, &bt_service);
- },
- // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservices
// https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren
// Step 7.
- BluetoothResponse::GetPrimaryServices(services_vec) => {
+ BluetoothResponse::GetPrimaryServices(services_vec, single) => {
+ let device = self.Device();
+ if single {
+ promise.resolve_native(promise_cx, &device.get_or_create_service(&services_vec[0], &self));
+ return;
+ }
let mut services = vec!();
for service in services_vec {
let bt_service = device.get_or_create_service(&service, &self);