mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Add Bluetooth IPC support
This commit is contained in:
parent
9d55748de2
commit
9825ea41b4
20 changed files with 1037 additions and 46 deletions
|
@ -4,10 +4,15 @@
|
|||
|
||||
use dom::bindings::codegen::Bindings::BluetoothBinding;
|
||||
use dom::bindings::codegen::Bindings::BluetoothBinding::BluetoothMethods;
|
||||
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::VendorIDSource;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::Root;
|
||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::bluetoothadvertisingdata::BluetoothAdvertisingData;
|
||||
use dom::bluetoothdevice::BluetoothDevice;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use net_traits::bluetooth_thread::{BluetoothMethodMsg, BluetoothObjectMsg};
|
||||
use util::str::DOMString;
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetooth
|
||||
#[dom_struct]
|
||||
|
@ -27,13 +32,67 @@ impl Bluetooth {
|
|||
global,
|
||||
BluetoothBinding::Wrap)
|
||||
}
|
||||
|
||||
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
|
||||
let global_root = self.global();
|
||||
let global_ref = global_root.r();
|
||||
global_ref.as_window().bluetooth_thread()
|
||||
}
|
||||
}
|
||||
|
||||
impl BluetoothMethods for Bluetooth {
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
|
||||
fn RequestDevice(&self) -> Option<Root<BluetoothDevice>> {
|
||||
//UNIMPLEMENTED
|
||||
None
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(BluetoothMethodMsg::RequestDevice(sender)).unwrap();
|
||||
let device = receiver.recv().unwrap();
|
||||
match device {
|
||||
BluetoothObjectMsg::BluetoothDevice {
|
||||
id,
|
||||
name,
|
||||
device_class,
|
||||
vendor_id_source,
|
||||
vendor_id,
|
||||
product_id,
|
||||
product_version,
|
||||
appearance,
|
||||
tx_power,
|
||||
rssi,
|
||||
} => {
|
||||
let ad_data = &BluetoothAdvertisingData::new(self.global().r(),
|
||||
appearance,
|
||||
tx_power,
|
||||
rssi);
|
||||
let vendor_id_source = match vendor_id_source {
|
||||
Some(vid) => match vid.as_ref() {
|
||||
"bluetooth" => Some(VendorIDSource::Bluetooth),
|
||||
"usb" => Some(VendorIDSource::Usb),
|
||||
_ => Some(VendorIDSource::Unknown),
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
let name = match name {
|
||||
Some(n) => Some(DOMString::from(n)),
|
||||
None => None,
|
||||
};
|
||||
Some(BluetoothDevice::new(self.global().r(),
|
||||
DOMString::from(id),
|
||||
name,
|
||||
ad_data,
|
||||
device_class,
|
||||
vendor_id_source,
|
||||
vendor_id,
|
||||
product_id,
|
||||
product_version))
|
||||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
None
|
||||
},
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,16 +2,24 @@
|
|||
* 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::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTCharacteristicBinding;
|
||||
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::error::Fallible;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, MutHeap, Root};
|
||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::bindings::str::ByteString;
|
||||
use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties;
|
||||
use dom::bluetoothremotegattdescriptor::BluetoothRemoteGATTDescriptor;
|
||||
use dom::bluetoothremotegattservice::BluetoothRemoteGATTService;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use net_traits::bluetooth_thread::{BluetoothMethodMsg, BluetoothObjectMsg};
|
||||
use util::str::DOMString;
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic
|
||||
|
@ -21,34 +29,49 @@ pub struct BluetoothRemoteGATTCharacteristic {
|
|||
service: MutHeap<JS<BluetoothRemoteGATTService>>,
|
||||
uuid: DOMString,
|
||||
properties: MutHeap<JS<BluetoothCharacteristicProperties>>,
|
||||
value: Option<ByteString>,
|
||||
value: DOMRefCell<Option<ByteString>>,
|
||||
instanceID: String,
|
||||
}
|
||||
|
||||
impl BluetoothRemoteGATTCharacteristic {
|
||||
pub fn new_inherited(service: &BluetoothRemoteGATTService,
|
||||
uuid: DOMString,
|
||||
properties: &BluetoothCharacteristicProperties)
|
||||
properties: &BluetoothCharacteristicProperties,
|
||||
instanceID: String)
|
||||
-> BluetoothRemoteGATTCharacteristic {
|
||||
BluetoothRemoteGATTCharacteristic {
|
||||
reflector_: Reflector::new(),
|
||||
service: MutHeap::new(service),
|
||||
uuid: uuid,
|
||||
properties: MutHeap::new(properties),
|
||||
value: None,
|
||||
value: DOMRefCell::new(None),
|
||||
instanceID: instanceID,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(global: GlobalRef,
|
||||
service: &BluetoothRemoteGATTService,
|
||||
uuid: DOMString,
|
||||
properties: &BluetoothCharacteristicProperties)
|
||||
properties: &BluetoothCharacteristicProperties,
|
||||
instanceID: String)
|
||||
-> Root<BluetoothRemoteGATTCharacteristic> {
|
||||
reflect_dom_object(box BluetoothRemoteGATTCharacteristic::new_inherited(service,
|
||||
uuid,
|
||||
properties),
|
||||
properties,
|
||||
instanceID),
|
||||
global,
|
||||
BluetoothRemoteGATTCharacteristicBinding::Wrap)
|
||||
}
|
||||
|
||||
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
|
||||
let global_root = self.global();
|
||||
let global_ref = global_root.r();
|
||||
global_ref.as_window().bluetooth_thread()
|
||||
}
|
||||
|
||||
pub fn get_instance_id(&self) -> String {
|
||||
self.instanceID.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteristic {
|
||||
|
@ -70,18 +93,78 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
|||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-getdescriptor
|
||||
fn GetDescriptor(&self) -> Option<Root<BluetoothRemoteGATTDescriptor>> {
|
||||
//UNIMPLEMENTED
|
||||
None
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::GetDescriptor(self.get_instance_id(), 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))
|
||||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
None
|
||||
},
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-value
|
||||
fn GetValue(&self) -> Option<ByteString> {
|
||||
self.value.clone()
|
||||
self.value.borrow().clone()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-readvalue
|
||||
fn ReadValue(&self) -> ByteString {
|
||||
//UNIMPLEMENTED
|
||||
ByteString::new(vec!())
|
||||
fn ReadValue(&self) -> Fallible<ByteString> {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
if !self.Service().Device().Gatt().Connected() {
|
||||
Err(Network)
|
||||
}
|
||||
else {
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::ReadValue(self.get_instance_id(), sender)).unwrap();
|
||||
let result = receiver.recv().unwrap();
|
||||
let value = match result {
|
||||
BluetoothObjectMsg::BluetoothReadValue {
|
||||
value
|
||||
} => {
|
||||
Some(ByteString::new(value))
|
||||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
None
|
||||
},
|
||||
_ => unreachable!()
|
||||
};
|
||||
*self.value.borrow_mut() = value;
|
||||
Ok(self.GetValue().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue
|
||||
fn WriteValue(&self, value: Vec<u8>) {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::WriteValue(self.get_instance_id(), value, sender)).unwrap();
|
||||
let result = receiver.recv().unwrap();
|
||||
match result {
|
||||
BluetoothObjectMsg::BluetoothWriteValue => (),
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
},
|
||||
_ => unreachable!()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,23 @@
|
|||
* 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::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMethods;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTCharacteristicBinding::
|
||||
BluetoothRemoteGATTCharacteristicMethods;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTDescriptorBinding;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTDescriptorBinding::BluetoothRemoteGATTDescriptorMethods;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
|
||||
use dom::bindings::error::Error::Network;
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, MutHeap, Root};
|
||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::bindings::str::ByteString;
|
||||
use dom::bluetoothremotegattcharacteristic::BluetoothRemoteGATTCharacteristic;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use net_traits::bluetooth_thread::{BluetoothMethodMsg, BluetoothObjectMsg};
|
||||
use util::str::DOMString;
|
||||
|
||||
// http://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattdescriptor
|
||||
|
@ -17,30 +27,45 @@ pub struct BluetoothRemoteGATTDescriptor {
|
|||
reflector_: Reflector,
|
||||
characteristic: MutHeap<JS<BluetoothRemoteGATTCharacteristic>>,
|
||||
uuid: DOMString,
|
||||
value: Option<ByteString>,
|
||||
value: DOMRefCell<Option<ByteString>>,
|
||||
instanceID: String,
|
||||
}
|
||||
|
||||
impl BluetoothRemoteGATTDescriptor {
|
||||
pub fn new_inherited(characteristic: &BluetoothRemoteGATTCharacteristic,
|
||||
uuid: DOMString)
|
||||
uuid: DOMString,
|
||||
instanceID: String)
|
||||
-> BluetoothRemoteGATTDescriptor {
|
||||
BluetoothRemoteGATTDescriptor {
|
||||
reflector_: Reflector::new(),
|
||||
characteristic: MutHeap::new(characteristic),
|
||||
uuid: uuid,
|
||||
value: None,
|
||||
value: DOMRefCell::new(None),
|
||||
instanceID: instanceID,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(global: GlobalRef,
|
||||
characteristic: &BluetoothRemoteGATTCharacteristic,
|
||||
uuid: DOMString)
|
||||
uuid: DOMString,
|
||||
instanceID: String)
|
||||
-> Root<BluetoothRemoteGATTDescriptor>{
|
||||
reflect_dom_object(box BluetoothRemoteGATTDescriptor::new_inherited(characteristic,
|
||||
uuid),
|
||||
uuid,
|
||||
instanceID),
|
||||
global,
|
||||
BluetoothRemoteGATTDescriptorBinding::Wrap)
|
||||
}
|
||||
|
||||
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
|
||||
let global_root = self.global();
|
||||
let global_ref = global_root.r();
|
||||
global_ref.as_window().bluetooth_thread()
|
||||
}
|
||||
|
||||
pub fn get_instance_id(&self) -> String {
|
||||
self.instanceID.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
||||
|
@ -57,12 +82,52 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
|||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-value
|
||||
fn GetValue(&self) -> Option<ByteString> {
|
||||
self.value.clone()
|
||||
self.value.borrow().clone()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-readvalue
|
||||
fn ReadValue(&self) -> ByteString {
|
||||
//UNIMPLEMENTED
|
||||
ByteString::new(vec!())
|
||||
fn ReadValue(&self) -> Fallible<ByteString> {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
if !self.Characteristic().Service().Device().Gatt().Connected() {
|
||||
Err(Network)
|
||||
}
|
||||
else {
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::ReadValue(self.get_instance_id(), sender)).unwrap();
|
||||
let result = receiver.recv().unwrap();
|
||||
let value = match result {
|
||||
BluetoothObjectMsg::BluetoothReadValue {
|
||||
value
|
||||
} => {
|
||||
Some(ByteString::new(value))
|
||||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
None
|
||||
},
|
||||
_ => unreachable!()
|
||||
};
|
||||
*self.value.borrow_mut() = value;
|
||||
Ok(self.GetValue().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-writevalue
|
||||
fn WriteValue(&self, value: Vec<u8>) {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::WriteValue(self.get_instance_id(), value, sender)).unwrap();
|
||||
let result = receiver.recv().unwrap();
|
||||
match result {
|
||||
BluetoothObjectMsg::BluetoothWriteValue => (),
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
},
|
||||
_ => unreachable!()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,14 +2,18 @@
|
|||
* 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::BluetoothRemoteGATTServerBinding;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, MutHeap, Root};
|
||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::bluetoothdevice::BluetoothDevice;
|
||||
use dom::bluetoothremotegattservice::BluetoothRemoteGATTService;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use net_traits::bluetooth_thread::{BluetoothMethodMsg, BluetoothObjectMsg};
|
||||
use std::cell::Cell;
|
||||
use util::str::DOMString;
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattserver
|
||||
#[dom_struct]
|
||||
|
@ -20,21 +24,25 @@ pub struct BluetoothRemoteGATTServer {
|
|||
}
|
||||
|
||||
impl BluetoothRemoteGATTServer {
|
||||
pub fn new_inherited(device: &BluetoothDevice, is_connected: bool) -> BluetoothRemoteGATTServer {
|
||||
pub fn new_inherited(device: &BluetoothDevice) -> BluetoothRemoteGATTServer {
|
||||
BluetoothRemoteGATTServer {
|
||||
reflector_: Reflector::new(),
|
||||
device: MutHeap::new(device),
|
||||
connected: Cell::new(is_connected),
|
||||
connected: Cell::new(false),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(global: GlobalRef, device: &BluetoothDevice, connected: bool) -> Root<BluetoothRemoteGATTServer> {
|
||||
reflect_dom_object(box BluetoothRemoteGATTServer::new_inherited(
|
||||
device,
|
||||
connected),
|
||||
pub fn new(global: GlobalRef, device: &BluetoothDevice) -> Root<BluetoothRemoteGATTServer> {
|
||||
reflect_dom_object(box BluetoothRemoteGATTServer::new_inherited(device),
|
||||
global,
|
||||
BluetoothRemoteGATTServerBinding::Wrap)
|
||||
}
|
||||
|
||||
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
|
||||
let global_root = self.global();
|
||||
let global_ref = global_root.r();
|
||||
global_ref.as_window().bluetooth_thread()
|
||||
}
|
||||
}
|
||||
|
||||
impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
|
||||
|
@ -51,20 +59,72 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
|
|||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect
|
||||
fn Connect(&self) -> Root<BluetoothRemoteGATTServer> {
|
||||
if !self.connected.get() {
|
||||
self.connected.set(true);
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::GATTServerConnect(String::from(self.Device().Id()), sender)).unwrap();
|
||||
let server = receiver.recv().unwrap();
|
||||
match server {
|
||||
BluetoothObjectMsg::BluetoothServer {
|
||||
connected
|
||||
} => {
|
||||
self.connected.set(connected);
|
||||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
},
|
||||
_ => unreachable!()
|
||||
}
|
||||
Root::from_ref(self)
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-disconnect
|
||||
fn Disconnect(&self) {
|
||||
self.connected.set(false);
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::GATTServerDisconnect(String::from(self.Device().Id()), sender)).unwrap();
|
||||
let server = receiver.recv().unwrap();
|
||||
match server {
|
||||
BluetoothObjectMsg::BluetoothServer {
|
||||
connected
|
||||
} => {
|
||||
self.connected.set(connected);
|
||||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
},
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservice
|
||||
fn GetPrimaryService(&self) -> Option<Root<BluetoothRemoteGATTService>> {
|
||||
//UNIMPLEMENTED
|
||||
None
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::GetPrimaryService(String::from(self.Device().Id()), sender)).unwrap();
|
||||
let service = receiver.recv().unwrap();
|
||||
match service {
|
||||
BluetoothObjectMsg::BluetoothService {
|
||||
uuid,
|
||||
is_primary,
|
||||
instance_id
|
||||
} => {
|
||||
Some(BluetoothRemoteGATTService::new(self.global().r(),
|
||||
&self.device.get(),
|
||||
DOMString::from(uuid),
|
||||
is_primary,
|
||||
instance_id))
|
||||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
None
|
||||
},
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,12 @@ use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding;
|
|||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, MutHeap, Root};
|
||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties;
|
||||
use dom::bluetoothdevice::BluetoothDevice;
|
||||
use dom::bluetoothremotegattcharacteristic::BluetoothRemoteGATTCharacteristic;
|
||||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use net_traits::bluetooth_thread::{BluetoothMethodMsg, BluetoothObjectMsg};
|
||||
use util::str::DOMString;
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice
|
||||
|
@ -18,32 +21,47 @@ pub struct BluetoothRemoteGATTService {
|
|||
device: MutHeap<JS<BluetoothDevice>>,
|
||||
uuid: DOMString,
|
||||
isPrimary: bool,
|
||||
instanceID: String,
|
||||
}
|
||||
|
||||
impl BluetoothRemoteGATTService {
|
||||
pub fn new_inherited(device: &BluetoothDevice,
|
||||
uuid: DOMString,
|
||||
isPrimary: bool)
|
||||
isPrimary: bool,
|
||||
instanceID: String)
|
||||
-> BluetoothRemoteGATTService {
|
||||
BluetoothRemoteGATTService {
|
||||
reflector_: Reflector::new(),
|
||||
device: MutHeap::new(device),
|
||||
uuid: uuid,
|
||||
isPrimary: isPrimary,
|
||||
instanceID: instanceID,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(global: GlobalRef,
|
||||
device: &BluetoothDevice,
|
||||
uuid: DOMString,
|
||||
isPrimary: bool)
|
||||
isPrimary: bool,
|
||||
instanceID: String)
|
||||
-> Root<BluetoothRemoteGATTService> {
|
||||
reflect_dom_object(box BluetoothRemoteGATTService::new_inherited(device,
|
||||
uuid,
|
||||
isPrimary),
|
||||
isPrimary,
|
||||
instanceID),
|
||||
global,
|
||||
BluetoothRemoteGATTServiceBinding::Wrap)
|
||||
}
|
||||
|
||||
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
|
||||
let global_root = self.global();
|
||||
let global_ref = global_root.r();
|
||||
global_ref.as_window().bluetooth_thread()
|
||||
}
|
||||
|
||||
pub fn get_instance_id(&self) -> String {
|
||||
self.instanceID.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
|
||||
|
@ -64,7 +82,47 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
|
|||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getcharacteristic
|
||||
fn GetCharacteristic(&self) -> Option<Root<BluetoothRemoteGATTCharacteristic>> {
|
||||
// UNIMPLEMENTED
|
||||
None
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::GetCharacteristic(self.get_instance_id(), sender)).unwrap();
|
||||
let characteristic = receiver.recv().unwrap();
|
||||
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);
|
||||
Some(BluetoothRemoteGATTCharacteristic::new(self.global().r(),
|
||||
&self,
|
||||
DOMString::from(uuid),
|
||||
properties,
|
||||
instance_id))
|
||||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
None
|
||||
},
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
// Allocation authorities for Vendor IDs:
|
||||
enum VendorIDSource {
|
||||
"bluetooth",
|
||||
"usb"
|
||||
"usb",
|
||||
"unknown"
|
||||
};
|
||||
|
||||
[Pref="dom.bluetooth.enabled"]
|
||||
|
|
|
@ -14,8 +14,10 @@ interface BluetoothRemoteGATTCharacteristic {
|
|||
//Promise<BluetoothRemoteGATTDescriptor> getDescriptor(BluetoothDescriptorUUID descriptor);
|
||||
//Promise<sequence<BluetoothRemoteGATTDescriptor>>
|
||||
//getDescriptors(optional BluetoothDescriptorUUID descriptor);
|
||||
//Promise<DataView> readValue();
|
||||
[Throws]
|
||||
ByteString readValue();
|
||||
//Promise<DataView> readValue();
|
||||
void writeValue(sequence<octet> value);
|
||||
//Promise<void> writeValue(BufferSource value);
|
||||
//Promise<void> startNotifications();
|
||||
//Promise<void> stopNotifications();
|
||||
|
|
|
@ -9,8 +9,9 @@ interface BluetoothRemoteGATTDescriptor {
|
|||
readonly attribute BluetoothRemoteGATTCharacteristic characteristic;
|
||||
readonly attribute DOMString uuid;
|
||||
readonly attribute ByteString? value;
|
||||
|
||||
[Throws]
|
||||
ByteString readValue();
|
||||
//Promise<DataView> readValue();
|
||||
void writeValue(sequence<octet> value);
|
||||
//Promise<void> writeValue(BufferSource value);
|
||||
};
|
||||
|
|
|
@ -47,6 +47,7 @@ use msg::constellation_msg::{ConstellationChan, LoadData, PipelineId, SubpageId}
|
|||
use msg::constellation_msg::{WindowSizeData, WindowSizeType};
|
||||
use msg::webdriver_msg::{WebDriverJSError, WebDriverJSResult};
|
||||
use net_traits::ResourceThread;
|
||||
use net_traits::bluetooth_thread::BluetoothMethodMsg;
|
||||
use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheThread};
|
||||
use net_traits::storage_thread::{StorageThread, StorageType};
|
||||
use num_traits::ToPrimitive;
|
||||
|
@ -212,6 +213,10 @@ pub struct Window {
|
|||
#[ignore_heap_size_of = "channels are hard"]
|
||||
resource_thread: Arc<ResourceThread>,
|
||||
|
||||
/// A handle for communicating messages to the bluetooth thread.
|
||||
#[ignore_heap_size_of = "channels are hard"]
|
||||
bluetooth_thread: IpcSender<BluetoothMethodMsg>,
|
||||
|
||||
/// A handle for communicating messages to the storage thread.
|
||||
#[ignore_heap_size_of = "channels are hard"]
|
||||
storage_thread: StorageThread,
|
||||
|
@ -334,6 +339,10 @@ impl Window {
|
|||
&*self.page
|
||||
}
|
||||
|
||||
pub fn bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
|
||||
self.bluetooth_thread.clone()
|
||||
}
|
||||
|
||||
pub fn storage_thread(&self) -> StorageThread {
|
||||
self.storage_thread.clone()
|
||||
}
|
||||
|
@ -1401,6 +1410,7 @@ impl Window {
|
|||
compositor: IpcSender<ScriptToCompositorMsg>,
|
||||
image_cache_thread: ImageCacheThread,
|
||||
resource_thread: Arc<ResourceThread>,
|
||||
bluetooth_thread: IpcSender<BluetoothMethodMsg>,
|
||||
storage_thread: StorageThread,
|
||||
mem_profiler_chan: mem::ProfilerChan,
|
||||
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
|
||||
|
@ -1456,6 +1466,7 @@ impl Window {
|
|||
dom_static: GlobalStaticData::new(),
|
||||
js_runtime: DOMRefCell::new(Some(runtime.clone())),
|
||||
resource_thread: resource_thread,
|
||||
bluetooth_thread: bluetooth_thread,
|
||||
storage_thread: storage_thread,
|
||||
constellation_chan: constellation_chan,
|
||||
page_clip_rect: Cell::new(MAX_RECT),
|
||||
|
|
|
@ -64,6 +64,7 @@ use msg::constellation_msg::{PipelineId, PipelineNamespace};
|
|||
use msg::constellation_msg::{SubpageId, WindowSizeData, WindowSizeType};
|
||||
use msg::webdriver_msg::WebDriverScriptCommand;
|
||||
use net_traits::LoadData as NetLoadData;
|
||||
use net_traits::bluetooth_thread::BluetoothMethodMsg;
|
||||
use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheResult, ImageCacheThread};
|
||||
use net_traits::storage_thread::StorageThread;
|
||||
use net_traits::{AsyncResponseTarget, ControlMsg, LoadConsumer, LoadContext, Metadata, ResourceThread};
|
||||
|
@ -310,6 +311,8 @@ pub struct ScriptThread {
|
|||
/// A handle to the resource thread. This is an `Arc` to avoid running out of file descriptors if
|
||||
/// there are many iframes.
|
||||
resource_thread: Arc<ResourceThread>,
|
||||
/// A handle to the bluetooth thread.
|
||||
bluetooth_thread: IpcSender<BluetoothMethodMsg>,
|
||||
/// A handle to the storage thread.
|
||||
storage_thread: StorageThread,
|
||||
|
||||
|
@ -540,6 +543,7 @@ impl ScriptThread {
|
|||
image_cache_port: image_cache_port,
|
||||
|
||||
resource_thread: Arc::new(state.resource_thread),
|
||||
bluetooth_thread: state.bluetooth_thread,
|
||||
storage_thread: state.storage_thread,
|
||||
|
||||
port: port,
|
||||
|
@ -1482,6 +1486,7 @@ impl ScriptThread {
|
|||
self.compositor.borrow_mut().clone(),
|
||||
self.image_cache_thread.clone(),
|
||||
self.resource_thread.clone(),
|
||||
self.bluetooth_thread.clone(),
|
||||
self.storage_thread.clone(),
|
||||
self.mem_profiler_chan.clone(),
|
||||
self.devtools_chan.clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue