aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/net/bluetooth_thread.rs211
-rw-r--r--components/net_traits/bluetooth_thread.rs18
-rw-r--r--components/script/dom/bluetoothremotegattcharacteristic.rs68
-rw-r--r--components/script/dom/bluetoothremotegattserver.rs64
-rw-r--r--components/script/dom/bluetoothremotegattservice.rs84
-rw-r--r--components/script/dom/bluetoothuuid.rs9
-rw-r--r--components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl5
-rw-r--r--components/script/dom/webidls/BluetoothRemoteGATTServer.webidl3
-rw-r--r--components/script/dom/webidls/BluetoothRemoteGATTService.webidl4
9 files changed, 409 insertions, 57 deletions
diff --git a/components/net/bluetooth_thread.rs b/components/net/bluetooth_thread.rs
index e2bb015673e..ba7ab276ac0 100644
--- a/components/net/bluetooth_thread.rs
+++ b/components/net/bluetooth_thread.rs
@@ -85,14 +85,23 @@ impl BluetoothManager {
BluetoothMethodMsg::GATTServerDisconnect(device_id, sender) => {
self.gatt_server_disconnect(device_id, sender)
}
- BluetoothMethodMsg::GetPrimaryService(device_id, sender) => {
- self.get_primary_service(device_id, sender)
+ BluetoothMethodMsg::GetPrimaryService(device_id, uuid, sender) => {
+ self.get_primary_service(device_id, uuid, sender)
}
- BluetoothMethodMsg::GetCharacteristic(service_id, sender) => {
- self.get_characteristic(service_id, sender)
+ BluetoothMethodMsg::GetPrimaryServices(device_id, uuid, sender) => {
+ self.get_primary_services(device_id, uuid, sender)
}
- BluetoothMethodMsg::GetDescriptor(characteristic_id, sender) => {
- self.get_descriptor(characteristic_id, sender)
+ BluetoothMethodMsg::GetCharacteristic(service_id, uuid, sender) => {
+ self.get_characteristic(service_id, uuid, sender)
+ }
+ BluetoothMethodMsg::GetCharacteristics(service_id, uuid, sender) => {
+ self.get_characteristics(service_id, uuid, sender)
+ }
+ BluetoothMethodMsg::GetDescriptor(characteristic_id, uuid, sender) => {
+ self.get_descriptor(characteristic_id, uuid, sender)
+ }
+ BluetoothMethodMsg::GetDescriptors(characteristic_id, uuid, sender) => {
+ self.get_descriptors(characteristic_id, uuid, sender)
}
BluetoothMethodMsg::ReadValue(id, sender) => {
self.read_value(id, sender)
@@ -164,7 +173,6 @@ impl BluetoothManager {
None
}
- #[allow(dead_code)]
fn get_gatt_service_by_uuid(&mut self,
adapter: &mut BluetoothAdapter,
device_id: &str,
@@ -185,6 +193,21 @@ impl BluetoothManager {
None
}
+ fn get_gatt_services_by_uuid(&mut self,
+ adapter: &mut BluetoothAdapter,
+ device_id: &str,
+ service_uuid: &str)
+ -> Vec<BluetoothGATTService> {
+ let mut services_vec: Vec<BluetoothGATTService> = vec!();
+ let services = self.get_gatt_services(adapter, device_id);
+ for service in services {
+ if service.get_uuid().unwrap_or("".to_owned()) == service_uuid {
+ services_vec.push(service.clone());
+ }
+ }
+ services_vec
+ }
+
// Characteristic
fn get_gatt_characteristics(&mut self,
@@ -218,7 +241,6 @@ impl BluetoothManager {
None
}
- #[allow(dead_code)]
fn get_gatt_characteristic_by_uuid(&mut self,
adapter: &mut BluetoothAdapter,
service_id: &str,
@@ -239,6 +261,21 @@ impl BluetoothManager {
None
}
+ fn get_gatt_characteristics_by_uuid(&mut self,
+ adapter: &mut BluetoothAdapter,
+ service_id: &str,
+ characteristic_uuid: &str)
+ -> Vec<BluetoothGATTCharacteristic> {
+ let mut characteristics_vec: Vec<BluetoothGATTCharacteristic> = vec!();
+ let characteristics = self.get_gatt_characteristics(adapter, service_id);
+ for characteristic in characteristics {
+ if characteristic.get_uuid().unwrap_or("".to_owned()) == characteristic_uuid {
+ characteristics_vec.push(characteristic.clone());
+ }
+ }
+ characteristics_vec
+ }
+
fn get_characteristic_properties(&self, characteristic: &BluetoothGATTCharacteristic) -> [bool; 9] {
let mut props = [false; 9];
let flags = characteristic.get_flags().unwrap_or(vec!());
@@ -292,7 +329,6 @@ impl BluetoothManager {
None
}
- #[allow(dead_code)]
fn get_gatt_descriptor_by_uuid(&mut self,
adapter: &mut BluetoothAdapter,
characteristic_id: &str,
@@ -313,6 +349,21 @@ impl BluetoothManager {
None
}
+ fn get_gatt_descriptors_by_uuid(&mut self,
+ adapter: &mut BluetoothAdapter,
+ characteristic_id: &str,
+ descriptor_uuid: &str)
+ -> Vec<BluetoothGATTDescriptor> {
+ let mut descriptors_vec: Vec<BluetoothGATTDescriptor> = vec!();
+ let descriptors = self.get_gatt_descriptors(adapter, characteristic_id);
+ for descriptor in descriptors {
+ if descriptor.get_uuid().unwrap_or("".to_owned()) == descriptor_uuid {
+ descriptors_vec.push(descriptor.clone());
+ }
+ }
+ descriptors_vec
+ }
+
// Methods
fn request_device(&mut self, sender: IpcSender<BluetoothObjectMsg>) {
@@ -395,44 +446,67 @@ impl BluetoothManager {
sender.send(message).unwrap();
}
- pub fn get_primary_service(&mut self, device_id: String, sender: IpcSender<BluetoothObjectMsg>) {
+ pub fn get_primary_service(&mut self, device_id: String, uuid: String, sender: IpcSender<BluetoothObjectMsg>) {
let mut adapter = match self.get_adapter() {
Some(a) => a,
None => send_error!(sender, "No adapter found"),
};
+ let service = match self.get_gatt_service_by_uuid(&mut adapter, &device_id, &uuid) {
+ Some(s) => s,
+ None => send_error!(sender, "No primary service found")
+ };
+ if !service.is_primary().unwrap_or(false) {
+ send_error!(sender, "No primary service found");
+ }
+ let message = BluetoothObjectMsg::BluetoothService {
+ uuid: service.get_uuid().unwrap_or("".to_owned()),
+ is_primary: true,
+ instance_id: service.get_object_path(),
+ };
+ sender.send(message).unwrap();
+ }
- let services = self.get_gatt_services(&mut adapter, &device_id);
+ pub fn get_primary_services(&mut self,
+ device_id: String,
+ uuid: Option<String>,
+ sender: IpcSender<BluetoothObjectMsg>) {
+ let mut adapter = match self.get_adapter() {
+ Some(a) => a,
+ None => send_error!(sender, "No adapter found"),
+ };
+ let services: Vec<BluetoothGATTService> = match uuid {
+ Some(id) => self.get_gatt_services_by_uuid(&mut adapter, &device_id, &id),
+ None => self.get_gatt_services(&mut adapter, &device_id),
+ };
if services.is_empty() {
send_error!(sender, "No service found");
}
-
+ let mut services_vec: Vec<BluetoothObjectMsg> = vec!();
for service in services {
if service.is_primary().unwrap_or(false) {
- let message = BluetoothObjectMsg::BluetoothService {
+ services_vec.push(BluetoothObjectMsg::BluetoothService {
uuid: service.get_uuid().unwrap_or("".to_owned()),
is_primary: true,
- instance_id: service.get_object_path()
- };
- sender.send(message).unwrap();
- return;
+ instance_id: service.get_object_path(),
+ });
}
}
-
- send_error!(sender, "No primary service found");
+ if services_vec.is_empty() {
+ send_error!(sender, "No service found");
+ }
+ let message = BluetoothObjectMsg::BluetoothServices { services_vec: services_vec };
+ sender.send(message).unwrap();
}
- pub fn get_characteristic(&mut self, service_id: String, sender: IpcSender<BluetoothObjectMsg>) {
+ pub fn get_characteristic(&mut self, service_id: String, uuid: String, sender: IpcSender<BluetoothObjectMsg>) {
let mut adapter = match self.get_adapter() {
Some(a) => a,
None => send_error!(sender, "No adapter found"),
};
-
- let characteristics = self.get_gatt_characteristics(&mut adapter, &service_id);
- if characteristics.is_empty() {
- send_error!(sender, "No characteristic found");
- }
-
- let characteristic = &characteristics[0];
+ let characteristic = match self.get_gatt_characteristic_by_uuid(&mut adapter, &service_id, &uuid) {
+ Some(c) => c,
+ None => send_error!(sender, "No characteristic found"),
+ };
let properties = self.get_characteristic_properties(&characteristic);
let message = BluetoothObjectMsg::BluetoothCharacteristic {
uuid: characteristic.get_uuid().unwrap_or("".to_owned()),
@@ -445,23 +519,63 @@ impl BluetoothManager {
indicate: properties[5],
authenticated_signed_writes: properties[6],
reliable_write: properties[7],
- writable_auxiliaries: properties[8]
+ writable_auxiliaries: properties[8],
};
sender.send(message).unwrap();
}
- pub fn get_descriptor(&mut self, characteristic_id: String, sender: IpcSender<BluetoothObjectMsg>) {
+ pub fn get_characteristics(&mut self,
+ service_id: String,
+ uuid: Option<String>,
+ sender: IpcSender<BluetoothObjectMsg>) {
let mut adapter = match self.get_adapter() {
Some(a) => a,
None => send_error!(sender, "No adapter found"),
};
-
- let descriptors = self.get_gatt_descriptors(&mut adapter, &characteristic_id);
- if descriptors.is_empty() {
- send_error!(sender, "No descriptor found");
+ let characteristics = match uuid {
+ Some(id) => self.get_gatt_characteristics_by_uuid(&mut adapter, &service_id, &id),
+ None => self.get_gatt_characteristics(&mut adapter, &service_id),
+ };
+ if characteristics.is_empty() {
+ send_error!(sender, "No characteristic found");
+ }
+ let mut characteristics_vec: Vec<BluetoothObjectMsg> = vec!();
+ for characteristic in characteristics {
+ let properties = self.get_characteristic_properties(&characteristic);
+ characteristics_vec.push(BluetoothObjectMsg::BluetoothCharacteristic {
+ uuid: characteristic.get_uuid().unwrap_or("".to_owned()),
+ instance_id: characteristic.get_object_path(),
+ broadcast: properties[0],
+ read: properties[1],
+ write_without_response: properties[2],
+ write: properties[3],
+ notify: properties[4],
+ indicate: properties[5],
+ authenticated_signed_writes: properties[6],
+ reliable_write: properties[7],
+ writable_auxiliaries: properties[8],
+ });
}
+ if characteristics_vec.is_empty() {
+ send_error!(sender, "No characteristic found");
+ }
+ let message = BluetoothObjectMsg::BluetoothCharacteristics { characteristics_vec: characteristics_vec };
+ sender.send(message).unwrap();
+ }
+
+ pub fn get_descriptor(&mut self,
+ characteristic_id: String,
+ uuid: String,
+ sender: IpcSender<BluetoothObjectMsg>) {
+ let mut adapter = match self.get_adapter() {
+ Some(a) => a,
+ None => send_error!(sender, "No adapter found"),
+ };
- let descriptor = &descriptors[0];
+ let descriptor = match self.get_gatt_descriptor_by_uuid(&mut adapter, &characteristic_id, &uuid) {
+ Some(d) => d,
+ None => send_error!(sender, "No descriptor found"),
+ };
let message = BluetoothObjectMsg::BluetoothDescriptor {
uuid: descriptor.get_uuid().unwrap_or("".to_owned()),
instance_id: descriptor.get_object_path(),
@@ -469,6 +583,35 @@ impl BluetoothManager {
sender.send(message).unwrap();
}
+ pub fn get_descriptors(&mut self,
+ characteristic_id: String,
+ uuid: Option<String>,
+ sender: IpcSender<BluetoothObjectMsg>) {
+ let mut adapter = match self.get_adapter() {
+ Some(a) => a,
+ None => send_error!(sender, "No adapter found"),
+ };
+ let descriptors = match uuid {
+ Some(id) => self.get_gatt_descriptors_by_uuid(&mut adapter, &characteristic_id, &id),
+ None => self.get_gatt_descriptors(&mut adapter, &characteristic_id),
+ };
+ if descriptors.is_empty() {
+ send_error!(sender, "No descriptor found");
+ }
+ let mut descriptors_vec: Vec<BluetoothObjectMsg> = vec!();
+ for descriptor in descriptors {
+ descriptors_vec.push(BluetoothObjectMsg::BluetoothDescriptor {
+ uuid: descriptor.get_uuid().unwrap_or("".to_owned()),
+ instance_id: descriptor.get_object_path(),
+ });
+ }
+ if descriptors_vec.is_empty() {
+ send_error!(sender, "No descriptor found");
+ }
+ let message = BluetoothObjectMsg::BluetoothDescriptors { descriptors_vec: descriptors_vec };
+ sender.send(message).unwrap();
+ }
+
pub fn read_value(&mut self, id: String, sender: IpcSender<BluetoothObjectMsg>) {
let mut adapter = match self.get_adapter() {
Some(a) => a,
diff --git a/components/net_traits/bluetooth_thread.rs b/components/net_traits/bluetooth_thread.rs
index 86bdffc1fff..c035a1ea164 100644
--- a/components/net_traits/bluetooth_thread.rs
+++ b/components/net_traits/bluetooth_thread.rs
@@ -8,9 +8,12 @@ pub enum BluetoothMethodMsg {
RequestDevice(IpcSender<BluetoothObjectMsg>),
GATTServerConnect(String, IpcSender<BluetoothObjectMsg>),
GATTServerDisconnect(String, IpcSender<BluetoothObjectMsg>),
- GetPrimaryService(String, IpcSender<BluetoothObjectMsg>),
- GetCharacteristic(String, IpcSender<BluetoothObjectMsg>),
- GetDescriptor(String, IpcSender<BluetoothObjectMsg>),
+ GetPrimaryService(String, String, IpcSender<BluetoothObjectMsg>),
+ GetPrimaryServices(String, Option<String>, IpcSender<BluetoothObjectMsg>),
+ GetCharacteristic(String, String, IpcSender<BluetoothObjectMsg>),
+ GetCharacteristics(String, Option<String>, IpcSender<BluetoothObjectMsg>),
+ GetDescriptor(String, String, IpcSender<BluetoothObjectMsg>),
+ GetDescriptors(String, Option<String>, IpcSender<BluetoothObjectMsg>),
ReadValue(String, IpcSender<BluetoothObjectMsg>),
WriteValue(String, Vec<u8>, IpcSender<BluetoothObjectMsg>),
Exit,
@@ -40,6 +43,9 @@ pub enum BluetoothObjectMsg {
is_primary: bool,
instance_id: String
},
+ BluetoothServices {
+ services_vec: Vec<BluetoothObjectMsg>
+ },
BluetoothCharacteristic {
// Characteristic
uuid: String,
@@ -55,10 +61,16 @@ pub enum BluetoothObjectMsg {
reliable_write: bool,
writable_auxiliaries: bool
},
+ BluetoothCharacteristics {
+ characteristics_vec: Vec<BluetoothObjectMsg>
+ },
BluetoothDescriptor {
uuid: String,
instance_id: String
},
+ BluetoothDescriptors {
+ descriptors_vec: Vec<BluetoothObjectMsg>,
+ },
BluetoothReadValue {
value: Vec<u8>
},
diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs
index 3ce8749979a..db487bb70bc 100644
--- a/components/script/dom/bluetoothremotegattcharacteristic.rs
+++ b/components/script/dom/bluetoothremotegattcharacteristic.rs
@@ -9,7 +9,8 @@ use dom::bindings::codegen::Bindings::BluetoothRemoteGATTCharacteristicBinding::
BluetoothRemoteGATTCharacteristicMethods;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
-use dom::bindings::error::Error::Network;
+use dom::bindings::codegen::UnionTypes::StringOrUnsignedLong;
+use dom::bindings::error::Error::{Network, Type};
use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, MutHeap, Root};
@@ -18,6 +19,7 @@ use dom::bindings::str::ByteString;
use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties;
use dom::bluetoothremotegattdescriptor::BluetoothRemoteGATTDescriptor;
use dom::bluetoothremotegattservice::BluetoothRemoteGATTService;
+use dom::bluetoothuuid::BluetoothUUID;
use ipc_channel::ipc::{self, IpcSender};
use net_traits::bluetooth_thread::{BluetoothMethodMsg, BluetoothObjectMsg};
use util::str::DOMString;
@@ -92,28 +94,74 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-getdescriptor
- fn GetDescriptor(&self) -> Option<Root<BluetoothRemoteGATTDescriptor>> {
+ fn GetDescriptor(&self,
+ descriptor: StringOrUnsignedLong)
+ -> Fallible<Root<BluetoothRemoteGATTDescriptor>> {
+ let uuid: String = match BluetoothUUID::GetDescriptor(self.global().r(), descriptor.clone()) {
+ Ok(domstring) => domstring.to_string(),
+ Err(error) => return Err(error),
+ };
let (sender, receiver) = ipc::channel().unwrap();
self.get_bluetooth_thread().send(
- BluetoothMethodMsg::GetDescriptor(self.get_instance_id(), sender)).unwrap();
+ BluetoothMethodMsg::GetDescriptor(self.get_instance_id(), uuid, sender)).unwrap();
let descriptor = receiver.recv().unwrap();
match descriptor {
BluetoothObjectMsg::BluetoothDescriptor {
uuid,
instance_id
} => {
- Some(BluetoothRemoteGATTDescriptor::new(self.global().r(),
- &self,
- DOMString::from(uuid),
- instance_id))
+ Ok(BluetoothRemoteGATTDescriptor::new(self.global().r(),
+ &self,
+ DOMString::from(uuid),
+ instance_id))
},
BluetoothObjectMsg::Error {
error
+ } => Err(Type(error)),
+ _ => unreachable!()
+ }
+ }
+
+ // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-getdescriptors
+ fn GetDescriptors(&self,
+ descriptor: Option<StringOrUnsignedLong>)
+ -> Fallible<Vec<Root<BluetoothRemoteGATTDescriptor>>> {
+ let uuid: Option<String> = match descriptor {
+ Some(d) => match BluetoothUUID::GetDescriptor(self.global().r(), d.clone()) {
+ Ok(domstring) => Some(domstring.to_string()),
+ Err(error) => return Err(error),
+ },
+ None => None,
+ };
+ let (sender, receiver) = ipc::channel().unwrap();
+ let mut descriptors: Vec<Root<BluetoothRemoteGATTDescriptor>> = vec!();
+ self.get_bluetooth_thread().send(
+ BluetoothMethodMsg::GetDescriptors(self.get_instance_id(), uuid, sender)).unwrap();
+ let descriptors_vec = receiver.recv().unwrap();
+ match descriptors_vec {
+ BluetoothObjectMsg::BluetoothDescriptors {
+ descriptors_vec
} => {
- println!("{}", error);
- None
+ for d in descriptors_vec {
+ match d {
+ BluetoothObjectMsg::BluetoothDescriptor {
+ uuid,
+ instance_id,
+ } => {
+ descriptors.push(BluetoothRemoteGATTDescriptor::new(self.global().r(),
+ &self,
+ DOMString::from(uuid),
+ instance_id))
+ },
+ _ => unreachable!(),
+ }
+ }
+ Ok(descriptors)
},
- _ => unreachable!()
+ BluetoothObjectMsg::Error {
+ error
+ } => Err(Type(error)),
+ _ => unreachable!(),
}
}
diff --git a/components/script/dom/bluetoothremotegattserver.rs b/components/script/dom/bluetoothremotegattserver.rs
index 2eec908d4c5..e3b0e5bd8c9 100644
--- a/components/script/dom/bluetoothremotegattserver.rs
+++ b/components/script/dom/bluetoothremotegattserver.rs
@@ -5,11 +5,13 @@
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
+use dom::bindings::codegen::UnionTypes::StringOrUnsignedLong;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, MutHeap, Root};
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
use dom::bluetoothdevice::BluetoothDevice;
use dom::bluetoothremotegattservice::BluetoothRemoteGATTService;
+use dom::bluetoothuuid::BluetoothUUID;
use ipc_channel::ipc::{self, IpcSender};
use net_traits::bluetooth_thread::{BluetoothMethodMsg, BluetoothObjectMsg};
use std::cell::Cell;
@@ -101,16 +103,23 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservice
- fn GetPrimaryService(&self) -> Option<Root<BluetoothRemoteGATTService>> {
+ fn GetPrimaryService(&self, service: StringOrUnsignedLong) -> Option<Root<BluetoothRemoteGATTService>> {
+ let uuid: String = match BluetoothUUID::GetService(self.global().r(), service.clone()) {
+ Ok(domstring) => domstring.to_string(),
+ Err(_) => {
+ println!("No UUID provided!");
+ return None;
+ },
+ };
let (sender, receiver) = ipc::channel().unwrap();
self.get_bluetooth_thread().send(
- BluetoothMethodMsg::GetPrimaryService(String::from(self.Device().Id()), sender)).unwrap();
+ BluetoothMethodMsg::GetPrimaryService(String::from(self.Device().Id()), uuid, sender)).unwrap();
let service = receiver.recv().unwrap();
match service {
BluetoothObjectMsg::BluetoothService {
uuid,
is_primary,
- instance_id
+ instance_id,
} => {
Some(BluetoothRemoteGATTService::new(self.global().r(),
&self.device.get(),
@@ -124,7 +133,54 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
println!("{}", error);
None
},
- _ => unreachable!()
+ _ => unreachable!(),
+ }
+ }
+
+ // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservices
+ fn GetPrimaryServices(&self, service: Option<StringOrUnsignedLong>)
+ -> Option<Vec<Root<BluetoothRemoteGATTService>>> {
+ let uuid: Option<String> = match service {
+ Some(s) => match BluetoothUUID::GetService(self.global().r(), s.clone()) {
+ Ok(domstring) => Some(domstring.to_string()),
+ Err(_) => None,
+ },
+ None => None,
+ };
+ let mut services: Vec<Root<BluetoothRemoteGATTService>> = vec!();
+ let (sender, receiver) = ipc::channel().unwrap();
+ self.get_bluetooth_thread().send(
+ BluetoothMethodMsg::GetPrimaryServices(String::from(self.Device().Id()), uuid, sender)).unwrap();
+ let services_vec = receiver.recv().unwrap();
+ match services_vec {
+ BluetoothObjectMsg::BluetoothServices {
+ services_vec
+ } => {
+ for s in services_vec {
+ match s {
+ BluetoothObjectMsg::BluetoothService {
+ uuid,
+ is_primary,
+ instance_id,
+ } => {
+ services.push(BluetoothRemoteGATTService::new(self.global().r(),
+ &self.device.get(),
+ DOMString::from(uuid),
+ is_primary,
+ instance_id))
+ },
+ _ => unreachable!(),
+ }
+ }
+ Some(services)
+ },
+ BluetoothObjectMsg::Error {
+ error
+ } => {
+ println!("{}", error);
+ None
+ },
+ _ => unreachable!(),
}
}
}
diff --git a/components/script/dom/bluetoothremotegattservice.rs b/components/script/dom/bluetoothremotegattservice.rs
index 433bf8ef9d8..8d4afe48ed3 100644
--- a/components/script/dom/bluetoothremotegattservice.rs
+++ b/components/script/dom/bluetoothremotegattservice.rs
@@ -4,12 +4,14 @@
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
+use dom::bindings::codegen::UnionTypes::StringOrUnsignedLong;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, MutHeap, Root};
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties;
use dom::bluetoothdevice::BluetoothDevice;
use dom::bluetoothremotegattcharacteristic::BluetoothRemoteGATTCharacteristic;
+use dom::bluetoothuuid::BluetoothUUID;
use ipc_channel::ipc::{self, IpcSender};
use net_traits::bluetooth_thread::{BluetoothMethodMsg, BluetoothObjectMsg};
use util::str::DOMString;
@@ -81,10 +83,19 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getcharacteristic
- fn GetCharacteristic(&self) -> Option<Root<BluetoothRemoteGATTCharacteristic>> {
+ fn GetCharacteristic(&self, characteristic: StringOrUnsignedLong)
+ -> Option<Root<BluetoothRemoteGATTCharacteristic>> {
+ let uuid: String = match BluetoothUUID::GetCharacteristic(self.global().r(),
+ characteristic.clone()) {
+ Ok(domstring) => domstring.to_string(),
+ Err(_) => {
+ println!("No UUID provided!");
+ return None;
+ },
+ };
let (sender, receiver) = ipc::channel().unwrap();
self.get_bluetooth_thread().send(
- BluetoothMethodMsg::GetCharacteristic(self.get_instance_id(), sender)).unwrap();
+ BluetoothMethodMsg::GetCharacteristic(self.get_instance_id(), uuid, sender)).unwrap();
let characteristic = receiver.recv().unwrap();
match characteristic {
BluetoothObjectMsg::BluetoothCharacteristic {
@@ -122,7 +133,74 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
println!("{}", error);
None
},
- _ => unreachable!()
+ _ => unreachable!(),
+ }
+ }
+
+ // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getcharacteristics
+ fn GetCharacteristics(&self, characteristic: Option<StringOrUnsignedLong>)
+ -> Option<Vec<Root<BluetoothRemoteGATTCharacteristic>>> {
+ let uuid: Option<String> = match characteristic {
+ Some(c) => match BluetoothUUID::GetCharacteristic(self.global().r(), c.clone()) {
+ Ok(domstring) => Some(domstring.to_string()),
+ Err(_) => None,
+ },
+ None => None,
+ };
+ let mut characteristics: Vec<Root<BluetoothRemoteGATTCharacteristic>> = vec!();
+ let (sender, receiver) = ipc::channel().unwrap();
+ self.get_bluetooth_thread().send(
+ BluetoothMethodMsg::GetCharacteristics(self.get_instance_id(), uuid, sender)).unwrap();
+ let characteristics_vec = receiver.recv().unwrap();
+ match characteristics_vec {
+ BluetoothObjectMsg::BluetoothCharacteristics {
+ characteristics_vec
+ } => {
+ for characteristic in characteristics_vec {
+ match characteristic {
+ BluetoothObjectMsg::BluetoothCharacteristic {
+ uuid,
+ instance_id,
+ broadcast,
+ read,
+ write_without_response,
+ write,
+ notify,
+ indicate,
+ authenticated_signed_writes,
+ reliable_write,
+ writable_auxiliaries,
+ } => {
+ let properties = &BluetoothCharacteristicProperties::new(
+ self.global().r(),
+ broadcast,
+ read,
+ write_without_response,
+ write,
+ notify,
+ indicate,
+ authenticated_signed_writes,
+ reliable_write,
+ writable_auxiliaries);
+ characteristics.push(BluetoothRemoteGATTCharacteristic::new(
+ self.global().r(),
+ &self,
+ DOMString::from(uuid),
+ properties,
+ instance_id))
+ },
+ _ => unreachable!(),
+ }
+ }
+ Some(characteristics)
+ },
+ BluetoothObjectMsg::Error {
+ error
+ } => {
+ println!("{}", error);
+ None
+ },
+ _ => unreachable!(),
}
}
}
diff --git a/components/script/dom/bluetoothuuid.rs b/components/script/dom/bluetoothuuid.rs
index 1817601dc97..91c581d5d3b 100644
--- a/components/script/dom/bluetoothuuid.rs
+++ b/components/script/dom/bluetoothuuid.rs
@@ -333,3 +333,12 @@ impl BluetoothUUID {
}
}
}
+
+impl Clone for StringOrUnsignedLong {
+ fn clone(&self) -> StringOrUnsignedLong {
+ match self {
+ &StringOrUnsignedLong::String(ref s) => StringOrUnsignedLong::String(s.clone()),
+ &StringOrUnsignedLong::UnsignedLong(ul) => StringOrUnsignedLong::UnsignedLong(ul),
+ }
+ }
+}
diff --git a/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl b/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl
index b3a1e691351..3024b3bc7f2 100644
--- a/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl
+++ b/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl
@@ -10,7 +10,10 @@ interface BluetoothRemoteGATTCharacteristic {
readonly attribute DOMString uuid;
readonly attribute BluetoothCharacteristicProperties properties;
readonly attribute ByteString? value;
- BluetoothRemoteGATTDescriptor? getDescriptor(/*BluetoothDescriptorUUID descriptor*/);
+ [Throws]
+ BluetoothRemoteGATTDescriptor getDescriptor((DOMString or unsigned long) descriptor);
+ [Throws]
+ sequence<BluetoothRemoteGATTDescriptor> getDescriptors(optional (DOMString or unsigned long) descriptor);
//Promise<BluetoothRemoteGATTDescriptor> getDescriptor(BluetoothDescriptorUUID descriptor);
//Promise<sequence<BluetoothRemoteGATTDescriptor>>
//getDescriptors(optional BluetoothDescriptorUUID descriptor);
diff --git a/components/script/dom/webidls/BluetoothRemoteGATTServer.webidl b/components/script/dom/webidls/BluetoothRemoteGATTServer.webidl
index 327542b522f..ac6af9649b1 100644
--- a/components/script/dom/webidls/BluetoothRemoteGATTServer.webidl
+++ b/components/script/dom/webidls/BluetoothRemoteGATTServer.webidl
@@ -10,7 +10,8 @@ interface BluetoothRemoteGATTServer {
readonly attribute boolean connected;
BluetoothRemoteGATTServer connect();
void disconnect();
- BluetoothRemoteGATTService? getPrimaryService();
+ BluetoothRemoteGATTService? getPrimaryService((DOMString or unsigned long) service);
+ sequence<BluetoothRemoteGATTService>? getPrimaryServices(optional (DOMString or unsigned long) service);
//Promise<BluetoothRemoteGATTService> getPrimaryService(BluetoothServiceUUID service);
//Promise<sequence<BluetoothRemoteGATTService>>getPrimaryServices(optional BluetoothServiceUUID service);
//Promise<BluetoothRemoteGATTServer> connect();
diff --git a/components/script/dom/webidls/BluetoothRemoteGATTService.webidl b/components/script/dom/webidls/BluetoothRemoteGATTService.webidl
index e8d66f6ac63..1cc34ba41a3 100644
--- a/components/script/dom/webidls/BluetoothRemoteGATTService.webidl
+++ b/components/script/dom/webidls/BluetoothRemoteGATTService.webidl
@@ -9,7 +9,9 @@ interface BluetoothRemoteGATTService {
readonly attribute BluetoothDevice device;
readonly attribute DOMString uuid;
readonly attribute boolean isPrimary;
- BluetoothRemoteGATTCharacteristic? getCharacteristic(/*DOMString characteristic*/);
+ BluetoothRemoteGATTCharacteristic? getCharacteristic((DOMString or unsigned long) characteristic);
+ sequence<BluetoothRemoteGATTCharacteristic>? getCharacteristics
+ (optional (DOMString or unsigned long) characteristic);
//Promise<BluetoothRemoteGATTCharacteristic>getCharacteristic(BluetoothCharacteristicUUID characteristic);
//Promise<sequence<BluetoothRemoteGATTCharacteristic>>
//getCharacteristics(optional BluetoothCharacteristicUUID characteristic);