mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Add Bluetooth IPC support
This commit is contained in:
parent
9d55748de2
commit
9825ea41b4
20 changed files with 1037 additions and 46 deletions
|
@ -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!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue