mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Missing steps of Characteristic's readValue, writeValue functions
This commit is contained in:
parent
0ae07e07e6
commit
52e1d8325f
2 changed files with 19 additions and 1 deletions
|
@ -57,6 +57,8 @@ pub enum Error {
|
|||
QuotaExceeded,
|
||||
/// TypeMismatchError DOMException
|
||||
TypeMismatch,
|
||||
/// InvalidModificationError DOMException
|
||||
InvalidModification,
|
||||
|
||||
/// TypeError JavaScript Error
|
||||
Type(String),
|
||||
|
@ -97,6 +99,7 @@ pub unsafe fn throw_dom_exception(cx: *mut JSContext, global: GlobalRef, result:
|
|||
Error::NoModificationAllowed => DOMErrorName::NoModificationAllowedError,
|
||||
Error::QuotaExceeded => DOMErrorName::QuotaExceededError,
|
||||
Error::TypeMismatch => DOMErrorName::TypeMismatchError,
|
||||
Error::InvalidModification => DOMErrorName::InvalidModificationError,
|
||||
Error::Type(message) => {
|
||||
assert!(!JS_IsExceptionPending(cx));
|
||||
throw_type_error(cx, &message);
|
||||
|
|
|
@ -4,13 +4,15 @@
|
|||
|
||||
use bluetooth_blacklist::{Blacklist, uuid_is_blacklisted};
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::BluetoothCharacteristicPropertiesBinding::
|
||||
BluetoothCharacteristicPropertiesMethods;
|
||||
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, Security, Type};
|
||||
use dom::bindings::error::Error::{InvalidModification, Network, NotSupported, Security, Type};
|
||||
use dom::bindings::error::{Fallible, ErrorResult};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, MutHeap, Root};
|
||||
|
@ -23,6 +25,10 @@ use dom::bluetoothuuid::{BluetoothDescriptorUUID, BluetoothUUID};
|
|||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use net_traits::bluetooth_thread::BluetoothMethodMsg;
|
||||
|
||||
// Maximum length of an attribute value.
|
||||
// https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=286439 (Vol. 3, page 2169)
|
||||
const MAXIMUM_ATTRIBUTE_LENGTH: usize = 512;
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic
|
||||
#[dom_struct]
|
||||
pub struct BluetoothRemoteGATTCharacteristic {
|
||||
|
@ -160,6 +166,9 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
|||
if !self.Service().Device().Gatt().Connected() {
|
||||
return Err(Network)
|
||||
}
|
||||
if !self.Properties().Read() {
|
||||
return Err(NotSupported)
|
||||
}
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::ReadValue(self.get_instance_id(), sender)).unwrap();
|
||||
let result = receiver.recv().unwrap();
|
||||
|
@ -180,6 +189,12 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
|||
if uuid_is_blacklisted(self.uuid.as_ref(), Blacklist::Writes) {
|
||||
return Err(Security)
|
||||
}
|
||||
if value.len() > MAXIMUM_ATTRIBUTE_LENGTH {
|
||||
return Err(InvalidModification)
|
||||
}
|
||||
if !self.Service().Device().Gatt().Connected() {
|
||||
return Err(Network)
|
||||
}
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothMethodMsg::WriteValue(self.get_instance_id(), value, sender)).unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue