aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAttila Dusnoki <dati91@users.noreply.github.com>2016-05-24 15:50:33 +0200
committerAttila Dusnoki <dati91@users.noreply.github.com>2016-05-24 15:50:33 +0200
commit39c99af4c87ef7eb6965842436b23d9364c341ca (patch)
tree748e7bbdc7b3e3693993edea9eb38736384f162b
parent03465ad8c77f03ae2f538d046ae1e1dc86f04723 (diff)
downloadservo-39c99af4c87ef7eb6965842436b23d9364c341ca.tar.gz
servo-39c99af4c87ef7eb6965842436b23d9364c341ca.zip
Add included services
-rw-r--r--components/net/bluetooth_thread.rs67
-rw-r--r--components/net_traits/bluetooth_thread.rs2
-rw-r--r--components/script/dom/bluetoothremotegattservice.rs58
-rw-r--r--components/script/dom/webidls/BluetoothRemoteGATTService.webidl4
-rw-r--r--components/servo/Cargo.lock6
-rw-r--r--ports/cef/Cargo.lock6
-rw-r--r--ports/gonk/Cargo.lock6
-rw-r--r--tests/html/bluetooth_included_service_info.html62
8 files changed, 201 insertions, 10 deletions
diff --git a/components/net/bluetooth_thread.rs b/components/net/bluetooth_thread.rs
index c8a6e4af31e..ecd59a5bda0 100644
--- a/components/net/bluetooth_thread.rs
+++ b/components/net/bluetooth_thread.rs
@@ -22,6 +22,7 @@ const ADAPTER_ERROR: &'static str = "No adapter found";
const DEVICE_ERROR: &'static str = "No device found";
const DEVICE_MATCH_ERROR: &'static str = "No device found, that matches the given options";
const PRIMARY_SERVICE_ERROR: &'static str = "No primary service found";
+const INCLUDED_SERVICE_ERROR: &'static str = "No included service found";
const CHARACTERISTIC_ERROR: &'static str = "No characteristic found";
const DESCRIPTOR_ERROR: &'static str = "No descriptor found";
const VALUE_ERROR: &'static str = "No characteristic or descriptor found with that id";
@@ -149,6 +150,12 @@ impl BluetoothManager {
BluetoothMethodMsg::GetPrimaryServices(device_id, uuid, sender) => {
self.get_primary_services(device_id, uuid, sender)
},
+ BluetoothMethodMsg::GetIncludedService(service_id, uuid, sender) => {
+ self.get_included_service(service_id, uuid, sender)
+ },
+ BluetoothMethodMsg::GetIncludedServices(service_id, uuid, sender) => {
+ self.get_included_services(service_id, uuid, sender)
+ },
BluetoothMethodMsg::GetCharacteristic(service_id, uuid, sender) => {
self.get_characteristic(service_id, uuid, sender)
},
@@ -478,6 +485,66 @@ impl BluetoothManager {
let _ = sender.send(Ok(services_vec));
}
+ fn get_included_service(&mut self,
+ service_id: String,
+ uuid: String,
+ sender: IpcSender<BluetoothResult<BluetoothServiceMsg>>) {
+ let mut adapter = match self.get_or_create_adapter() {
+ Some(a) => a,
+ None => return drop(sender.send(Err(String::from(ADAPTER_ERROR)))),
+ };
+ let primary_service = match self.get_gatt_service(&mut adapter, &service_id) {
+ Some(s) => s,
+ None => return drop(sender.send(Err(String::from(PRIMARY_SERVICE_ERROR)))),
+ };
+ let services = primary_service.get_includes().unwrap_or(vec!());
+ for service in services {
+ if let Ok(service_uuid) = service.get_uuid() {
+ if uuid == service_uuid {
+ return drop(sender.send(Ok(BluetoothServiceMsg {
+ uuid: uuid,
+ is_primary: service.is_primary().unwrap_or(false),
+ instance_id: service.get_object_path(),
+ })));
+ }
+ }
+ }
+ return drop(sender.send(Err(String::from(INCLUDED_SERVICE_ERROR))));
+ }
+
+ fn get_included_services(&mut self,
+ service_id: String,
+ uuid: Option<String>,
+ sender: IpcSender<BluetoothResult<BluetoothServicesMsg>>) {
+ let mut adapter = match self.get_or_create_adapter() {
+ Some(a) => a,
+ None => return drop(sender.send(Err(String::from(ADAPTER_ERROR)))),
+ };
+ let primary_service = match self.get_gatt_service(&mut adapter, &service_id) {
+ Some(s) => s,
+ None => return drop(sender.send(Err(String::from(PRIMARY_SERVICE_ERROR)))),
+ };
+ let services = primary_service.get_includes().unwrap_or(vec!());
+ let mut services_vec = vec!();
+ for service in services {
+ if let Ok(service_uuid) = service.get_uuid() {
+ services_vec.push(BluetoothServiceMsg {
+ uuid: service_uuid,
+ is_primary: service.is_primary().unwrap_or(false),
+ instance_id: service.get_object_path(),
+ });
+ }
+ }
+ if let Some(uuid) = uuid {
+ services_vec.retain(|ref s| s.uuid == uuid);
+ }
+ if services_vec.is_empty() {
+ return drop(sender.send(Err(String::from(INCLUDED_SERVICE_ERROR))));
+ }
+
+ let _ = sender.send(Ok(services_vec));
+ }
+
fn get_characteristic(&mut self,
service_id: String,
uuid: String,
diff --git a/components/net_traits/bluetooth_thread.rs b/components/net_traits/bluetooth_thread.rs
index 9a2e6f07e93..caeadabd6d4 100644
--- a/components/net_traits/bluetooth_thread.rs
+++ b/components/net_traits/bluetooth_thread.rs
@@ -60,6 +60,8 @@ pub enum BluetoothMethodMsg {
GATTServerDisconnect(String, IpcSender<BluetoothResult<bool>>),
GetPrimaryService(String, String, IpcSender<BluetoothResult<BluetoothServiceMsg>>),
GetPrimaryServices(String, Option<String>, IpcSender<BluetoothResult<BluetoothServicesMsg>>),
+ GetIncludedService(String, String, IpcSender<BluetoothResult<BluetoothServiceMsg>>),
+ GetIncludedServices(String, Option<String>, IpcSender<BluetoothResult<BluetoothServicesMsg>>),
GetCharacteristic(String, String, IpcSender<BluetoothResult<BluetoothCharacteristicMsg>>),
GetCharacteristics(String, Option<String>, IpcSender<BluetoothResult<BluetoothCharacteristicsMsg>>),
GetDescriptor(String, String, IpcSender<BluetoothResult<BluetoothDescriptorMsg>>),
diff --git a/components/script/dom/bluetoothremotegattservice.rs b/components/script/dom/bluetoothremotegattservice.rs
index 92a5edc2f28..bff15493428 100644
--- a/components/script/dom/bluetoothremotegattservice.rs
+++ b/components/script/dom/bluetoothremotegattservice.rs
@@ -2,6 +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 dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
use dom::bindings::error::Error::Type;
@@ -12,7 +13,7 @@ use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties;
use dom::bluetoothdevice::BluetoothDevice;
use dom::bluetoothremotegattcharacteristic::BluetoothRemoteGATTCharacteristic;
-use dom::bluetoothuuid::{BluetoothCharacteristicUUID, BluetoothUUID};
+use dom::bluetoothuuid::{BluetoothCharacteristicUUID, BluetoothServiceUUID, BluetoothUUID};
use ipc_channel::ipc::{self, IpcSender};
use net_traits::bluetooth_thread::BluetoothMethodMsg;
use util::str::DOMString;
@@ -155,4 +156,59 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
},
}
}
+
+ // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getincludedservice
+ fn GetIncludedService(&self,
+ service: BluetoothServiceUUID)
+ -> Fallible<Root<BluetoothRemoteGATTService>> {
+ let uuid = try!(BluetoothUUID::GetService(self.global().r(), service)).to_string();
+ let (sender, receiver) = ipc::channel().unwrap();
+ self.get_bluetooth_thread().send(
+ BluetoothMethodMsg::GetIncludedService(self.get_instance_id(),
+ uuid,
+ sender)).unwrap();
+ let service = receiver.recv().unwrap();
+ match service {
+ Ok(service) => {
+ Ok(BluetoothRemoteGATTService::new(self.global().r(),
+ &self.device.get(),
+ DOMString::from(service.uuid),
+ service.is_primary,
+ service.instance_id))
+ },
+ Err(error) => {
+ Err(Type(error))
+ },
+ }
+ }
+
+ // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getincludedservices
+ fn GetIncludedServices(&self,
+ service: Option<BluetoothServiceUUID>)
+ -> Fallible<Vec<Root<BluetoothRemoteGATTService>>> {
+ let mut uuid: Option<String> = None;
+ if let Some(s) = service {
+ uuid = Some(try!(BluetoothUUID::GetService(self.global().r(), s)).to_string())
+ };
+ let (sender, receiver) = ipc::channel().unwrap();
+ self.get_bluetooth_thread().send(
+ BluetoothMethodMsg::GetIncludedServices(self.get_instance_id(),
+ uuid,
+ sender)).unwrap();
+ let services_vec = receiver.recv().unwrap();
+ match services_vec {
+ Ok(service_vec) => {
+ Ok(service_vec.into_iter()
+ .map(|service| BluetoothRemoteGATTService::new(self.global().r(),
+ &self.device.get(),
+ DOMString::from(service.uuid),
+ service.is_primary,
+ service.instance_id))
+ .collect())
+ },
+ Err(error) => {
+ Err(Type(error))
+ },
+ }
+ }
}
diff --git a/components/script/dom/webidls/BluetoothRemoteGATTService.webidl b/components/script/dom/webidls/BluetoothRemoteGATTService.webidl
index 3a41865de1e..e137ec727cd 100644
--- a/components/script/dom/webidls/BluetoothRemoteGATTService.webidl
+++ b/components/script/dom/webidls/BluetoothRemoteGATTService.webidl
@@ -17,6 +17,10 @@ interface BluetoothRemoteGATTService {
//Promise<BluetoothRemoteGATTCharacteristic>getCharacteristic(BluetoothCharacteristicUUID characteristic);
//Promise<sequence<BluetoothRemoteGATTCharacteristic>>
//getCharacteristics(optional BluetoothCharacteristicUUID characteristic);
+ [Throws]
+ BluetoothRemoteGATTService getIncludedService(BluetoothServiceUUID service);
+ [Throws]
+ sequence<BluetoothRemoteGATTService> getIncludedServices(optional BluetoothServiceUUID service);
//Promise<BluetoothRemoteGATTService>getIncludedService(BluetoothServiceUUID service);
//Promise<sequence<BluetoothRemoteGATTService>>getIncludedServices(optional BluetoothServiceUUID service);
};
diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock
index f7d8bf44037..7cb15a30a34 100644
--- a/components/servo/Cargo.lock
+++ b/components/servo/Cargo.lock
@@ -164,7 +164,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "blurz"
-version = "0.1.6"
+version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dbus 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -446,9 +446,9 @@ dependencies = [
[[package]]
name = "device"
version = "0.0.1"
-source = "git+https://github.com/servo/devices#cac0952154f65b416acef273a6d1099421ce113e"
+source = "git+https://github.com/servo/devices#3c39846a019eeed939eb7090096631254e6b5efc"
dependencies = [
- "blurz 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "blurz 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock
index a9721a5c3b9..6ede5720a94 100644
--- a/ports/cef/Cargo.lock
+++ b/ports/cef/Cargo.lock
@@ -142,7 +142,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "blurz"
-version = "0.1.6"
+version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dbus 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -409,9 +409,9 @@ dependencies = [
[[package]]
name = "device"
version = "0.0.1"
-source = "git+https://github.com/servo/devices#cac0952154f65b416acef273a6d1099421ce113e"
+source = "git+https://github.com/servo/devices#3c39846a019eeed939eb7090096631254e6b5efc"
dependencies = [
- "blurz 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "blurz 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock
index d6bad36d3c0..a138e02853e 100644
--- a/ports/gonk/Cargo.lock
+++ b/ports/gonk/Cargo.lock
@@ -144,7 +144,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "blurz"
-version = "0.1.6"
+version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dbus 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -411,9 +411,9 @@ dependencies = [
[[package]]
name = "device"
version = "0.0.1"
-source = "git+https://github.com/servo/devices#cac0952154f65b416acef273a6d1099421ce113e"
+source = "git+https://github.com/servo/devices#3c39846a019eeed939eb7090096631254e6b5efc"
dependencies = [
- "blurz 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "blurz 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
diff --git a/tests/html/bluetooth_included_service_info.html b/tests/html/bluetooth_included_service_info.html
new file mode 100644
index 00000000000..76a351606b7
--- /dev/null
+++ b/tests/html/bluetooth_included_service_info.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<title>Included Service info</title>
+<body>
+ <input id="service" type="text" autofocus placeholder="Bluetooth Service">
+ <input id="name" type="text" placeholder="Device Name">
+ <input id="namePrefix" type="text" placeholder="Device Name Prefix">
+ <button type="button" onclick="onButtonClick()">Get Primary Service Info</button>
+ <pre id="log"></pre>
+ <script>
+ function onButtonClick() {
+ clear();
+ var options = {filters: [], optinalServices: []};
+
+ var filterService = document.getElementById('service').value;
+ if (filterService.startsWith('0x'))
+ filterService = parseInt(filterService, 16);
+
+ if (filterService)
+ options.filters.push({services: [filterService]});
+
+ var filterName = document.getElementById('name').value;
+ if (filterName)
+ options.filters.push({name: filterName});
+
+ var filterNamePrefix = document.getElementById('namePrefix').value;
+ if (filterNamePrefix)
+ options.filters.push({namePrefix: filterNamePrefix});
+
+ try {
+ log('Requesting Bluetooth Device...');
+ var device = window.navigator.bluetooth.requestDevice(options);
+
+ log('Connecting to GATTserver on device...');
+ var server = device.gatt.connect();
+
+ log('Getting Primary Service...');
+ var primaryService = server.getPrimaryService(filterService);
+
+ log('Primary Service found on device: ' + primaryService.device.name);
+ log('> UUID: ' + primaryService.uuid);
+
+ log('Getting Included Services...');
+ var includedServices = primaryService.getIncludedServices();
+
+ log('> Included Services: ' +
+ includedServices.map(s => s.uuid).join('\n' + ' '.repeat(21)));
+ } catch(err) {
+ log(err);
+ }
+ }
+
+ function clear() {
+ document.getElementById("log").textContent = "";
+ }
+
+ function log(line) {
+ document.getElementById("log").textContent += line + '\n';
+ }
+ </script>
+</body>
+</html>