mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Error handling
This commit is contained in:
parent
b851045415
commit
27ad1437a1
8 changed files with 61 additions and 76 deletions
|
@ -188,10 +188,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
|||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
None
|
||||
},
|
||||
} => return Err(Type(error)),
|
||||
_ => unreachable!()
|
||||
};
|
||||
*self.value.borrow_mut() = value;
|
||||
|
@ -200,19 +197,17 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
|||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue
|
||||
fn WriteValue(&self, value: Vec<u8>) {
|
||||
fn WriteValue(&self, value: Vec<u8>) -> Fallible<()> {
|
||||
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::BluetoothWriteValue => Ok(()),
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
},
|
||||
} => Err(Type(error)),
|
||||
_ => unreachable!()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ 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::Error::{Type, Network};
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, MutHeap, Root};
|
||||
|
@ -103,10 +103,7 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
|||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
None
|
||||
},
|
||||
} => return Err(Type(error)),
|
||||
_ => unreachable!()
|
||||
};
|
||||
*self.value.borrow_mut() = value;
|
||||
|
@ -115,19 +112,17 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
|||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-writevalue
|
||||
fn WriteValue(&self, value: Vec<u8>) {
|
||||
fn WriteValue(&self, value: Vec<u8>) -> Fallible<()> {
|
||||
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::BluetoothWriteValue => Ok(()),
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
},
|
||||
} => Err(Type(error)),
|
||||
_ => unreachable!()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::BluetoothDeviceMet
|
|||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
|
||||
use dom::bindings::codegen::UnionTypes::StringOrUnsignedLong;
|
||||
use dom::bindings::error::Error::Type;
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, MutHeap, Root};
|
||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
||||
|
@ -60,29 +62,28 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
|
|||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect
|
||||
fn Connect(&self) -> Root<BluetoothRemoteGATTServer> {
|
||||
fn Connect(&self) -> Fallible<Root<BluetoothRemoteGATTServer>> {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::GATTServerConnect(String::from(self.Device().Id()), sender)).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);
|
||||
Ok(Root::from_ref(self))
|
||||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
},
|
||||
} => Err(Type(error)),
|
||||
_ => unreachable!()
|
||||
}
|
||||
Root::from_ref(self)
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-disconnect
|
||||
fn Disconnect(&self) {
|
||||
fn Disconnect(&self) -> Fallible<()>{
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::GATTServerDisconnect(String::from(self.Device().Id()), sender)).unwrap();
|
||||
|
@ -92,24 +93,20 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
|
|||
connected
|
||||
} => {
|
||||
self.connected.set(connected);
|
||||
Ok(())
|
||||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
},
|
||||
} => Err(Type(error)),
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservice
|
||||
fn GetPrimaryService(&self, service: StringOrUnsignedLong) -> Option<Root<BluetoothRemoteGATTService>> {
|
||||
fn GetPrimaryService(&self, service: StringOrUnsignedLong) -> Fallible<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;
|
||||
},
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
|
@ -121,7 +118,7 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
|
|||
is_primary,
|
||||
instance_id,
|
||||
} => {
|
||||
Some(BluetoothRemoteGATTService::new(self.global().r(),
|
||||
Ok(BluetoothRemoteGATTService::new(self.global().r(),
|
||||
&self.device.get(),
|
||||
DOMString::from(uuid),
|
||||
is_primary,
|
||||
|
@ -129,28 +126,26 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
|
|||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
None
|
||||
},
|
||||
} => Err(Type(error)),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservices
|
||||
fn GetPrimaryServices(&self, service: Option<StringOrUnsignedLong>)
|
||||
-> Option<Vec<Root<BluetoothRemoteGATTService>>> {
|
||||
-> Fallible<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,
|
||||
Err(error) => return Err(error),
|
||||
},
|
||||
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();
|
||||
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 {
|
||||
|
@ -172,14 +167,11 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
|
|||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
Some(services)
|
||||
Ok(services)
|
||||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
None
|
||||
},
|
||||
} => Err(Type(error)),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
|
||||
use dom::bindings::codegen::UnionTypes::StringOrUnsignedLong;
|
||||
use dom::bindings::error::Error::Type;
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, MutHeap, Root};
|
||||
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
|
||||
|
@ -84,18 +86,16 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
|
|||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getcharacteristic
|
||||
fn GetCharacteristic(&self, characteristic: StringOrUnsignedLong)
|
||||
-> Option<Root<BluetoothRemoteGATTCharacteristic>> {
|
||||
-> Fallible<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;
|
||||
},
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::GetCharacteristic(self.get_instance_id(), uuid, sender)).unwrap();
|
||||
self.get_bluetooth_thread()
|
||||
.send(BluetoothMethodMsg::GetCharacteristic(self.get_instance_id(), uuid, sender))
|
||||
.unwrap();
|
||||
let characteristic = receiver.recv().unwrap();
|
||||
match characteristic {
|
||||
BluetoothObjectMsg::BluetoothCharacteristic {
|
||||
|
@ -121,7 +121,7 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
|
|||
authenticated_signed_writes,
|
||||
reliable_write,
|
||||
writable_auxiliaries);
|
||||
Some(BluetoothRemoteGATTCharacteristic::new(self.global().r(),
|
||||
Ok(BluetoothRemoteGATTCharacteristic::new(self.global().r(),
|
||||
&self,
|
||||
DOMString::from(uuid),
|
||||
properties,
|
||||
|
@ -129,28 +129,26 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
|
|||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
None
|
||||
},
|
||||
} => return Err(Type(error)),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getcharacteristics
|
||||
fn GetCharacteristics(&self, characteristic: Option<StringOrUnsignedLong>)
|
||||
-> Option<Vec<Root<BluetoothRemoteGATTCharacteristic>>> {
|
||||
-> Fallible<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,
|
||||
Err(error) => return Err(error),
|
||||
},
|
||||
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();
|
||||
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 {
|
||||
|
@ -192,14 +190,11 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
|
|||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
Some(characteristics)
|
||||
Ok(characteristics)
|
||||
},
|
||||
BluetoothObjectMsg::Error {
|
||||
error
|
||||
} => {
|
||||
println!("{}", error);
|
||||
None
|
||||
},
|
||||
} => return Err(Type(error)),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ interface BluetoothRemoteGATTCharacteristic {
|
|||
[Throws]
|
||||
ByteString readValue();
|
||||
//Promise<DataView> readValue();
|
||||
[Throws]
|
||||
void writeValue(sequence<octet> value);
|
||||
//Promise<void> writeValue(BufferSource value);
|
||||
//Promise<void> startNotifications();
|
||||
|
|
|
@ -12,6 +12,7 @@ interface BluetoothRemoteGATTDescriptor {
|
|||
[Throws]
|
||||
ByteString readValue();
|
||||
//Promise<DataView> readValue();
|
||||
[Throws]
|
||||
void writeValue(sequence<octet> value);
|
||||
//Promise<void> writeValue(BufferSource value);
|
||||
};
|
||||
|
|
|
@ -8,10 +8,14 @@
|
|||
interface BluetoothRemoteGATTServer {
|
||||
readonly attribute BluetoothDevice device;
|
||||
readonly attribute boolean connected;
|
||||
[Throws]
|
||||
BluetoothRemoteGATTServer connect();
|
||||
[Throws]
|
||||
void disconnect();
|
||||
BluetoothRemoteGATTService? getPrimaryService((DOMString or unsigned long) service);
|
||||
sequence<BluetoothRemoteGATTService>? getPrimaryServices(optional (DOMString or unsigned long) service);
|
||||
[Throws]
|
||||
BluetoothRemoteGATTService getPrimaryService((DOMString or unsigned long) service);
|
||||
[Throws]
|
||||
sequence<BluetoothRemoteGATTService> getPrimaryServices(optional (DOMString or unsigned long) service);
|
||||
//Promise<BluetoothRemoteGATTService> getPrimaryService(BluetoothServiceUUID service);
|
||||
//Promise<sequence<BluetoothRemoteGATTService>>getPrimaryServices(optional BluetoothServiceUUID service);
|
||||
//Promise<BluetoothRemoteGATTServer> connect();
|
||||
|
|
|
@ -9,8 +9,10 @@ interface BluetoothRemoteGATTService {
|
|||
readonly attribute BluetoothDevice device;
|
||||
readonly attribute DOMString uuid;
|
||||
readonly attribute boolean isPrimary;
|
||||
BluetoothRemoteGATTCharacteristic? getCharacteristic((DOMString or unsigned long) characteristic);
|
||||
sequence<BluetoothRemoteGATTCharacteristic>? getCharacteristics
|
||||
[Throws]
|
||||
BluetoothRemoteGATTCharacteristic getCharacteristic((DOMString or unsigned long) characteristic);
|
||||
[Throws]
|
||||
sequence<BluetoothRemoteGATTCharacteristic> getCharacteristics
|
||||
(optional (DOMString or unsigned long) characteristic);
|
||||
//Promise<BluetoothRemoteGATTCharacteristic>getCharacteristic(BluetoothCharacteristicUUID characteristic);
|
||||
//Promise<sequence<BluetoothRemoteGATTCharacteristic>>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue