mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Switches characteristic to use BufferSource
This commit is contained in:
parent
40235da2d3
commit
5bf2e71407
6 changed files with 17 additions and 12 deletions
|
@ -12,6 +12,7 @@ use dom::bindings::codegen::Bindings::BluetoothRemoteGATTCharacteristicBinding::
|
|||
BluetoothRemoteGATTCharacteristicMethods;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
|
||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
|
||||
use dom::bindings::codegen::UnionTypes::ArrayBufferViewOrArrayBuffer;
|
||||
use dom::bindings::error::Error::{self, InvalidModification, Network, NotSupported, Security};
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::reflector::{DomObject, reflect_dom_object};
|
||||
|
@ -155,7 +156,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
|||
|
||||
#[allow(unrooted_must_root)]
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue
|
||||
fn WriteValue(&self, value: Vec<u8>) -> Rc<Promise> {
|
||||
fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer) -> Rc<Promise> {
|
||||
let p = Promise::new(&self.global());
|
||||
|
||||
// Step 1.
|
||||
|
@ -165,7 +166,12 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
|||
}
|
||||
|
||||
// Step 2 - 3.
|
||||
if value.len() > MAXIMUM_ATTRIBUTE_LENGTH {
|
||||
let vec = match value {
|
||||
ArrayBufferViewOrArrayBuffer::ArrayBufferView(mut avb) => avb.to_vec(),
|
||||
ArrayBufferViewOrArrayBuffer::ArrayBuffer(mut ab) => ab.to_vec(),
|
||||
};
|
||||
|
||||
if vec.len() > MAXIMUM_ATTRIBUTE_LENGTH {
|
||||
p.reject_error(InvalidModification);
|
||||
return p;
|
||||
}
|
||||
|
@ -190,7 +196,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
|
|||
// in writeValue function and in handle_response function.
|
||||
let sender = response_async(&p, self);
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothRequest::WriteValue(self.get_instance_id(), value, sender)).unwrap();
|
||||
BluetoothRequest::WriteValue(self.get_instance_id(), vec, sender)).unwrap();
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
|
@ -125,11 +125,11 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
|||
}
|
||||
|
||||
// Step 2 - 3.
|
||||
let v = match value {
|
||||
let vec = match value {
|
||||
ArrayBufferViewOrArrayBuffer::ArrayBufferView(mut avb) => avb.to_vec(),
|
||||
ArrayBufferViewOrArrayBuffer::ArrayBuffer(mut ab) => ab.to_vec(),
|
||||
};
|
||||
if v.len() > MAXIMUM_ATTRIBUTE_LENGTH {
|
||||
if vec.len() > MAXIMUM_ATTRIBUTE_LENGTH {
|
||||
p.reject_error(InvalidModification);
|
||||
return p;
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
|||
// in writeValue function and in handle_response function.
|
||||
let sender = response_async(&p, self);
|
||||
self.get_bluetooth_thread().send(
|
||||
BluetoothRequest::WriteValue(self.get_instance_id(), v, sender)).unwrap();
|
||||
BluetoothRequest::WriteValue(self.get_instance_id(), vec, sender)).unwrap();
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,7 @@ interface BluetoothRemoteGATTCharacteristic : EventTarget {
|
|||
getDescriptors(optional BluetoothDescriptorUUID descriptor);
|
||||
Promise<ByteString> readValue();
|
||||
//Promise<DataView> readValue();
|
||||
Promise<void> writeValue(sequence<octet> value);
|
||||
//Promise<void> writeValue(BufferSource value);
|
||||
Promise<void> writeValue(BufferSource value);
|
||||
Promise<BluetoothRemoteGATTCharacteristic> startNotifications();
|
||||
Promise<BluetoothRemoteGATTCharacteristic> stopNotifications();
|
||||
};
|
||||
|
|
|
@ -11,6 +11,6 @@ interface BluetoothRemoteGATTDescriptor {
|
|||
readonly attribute DOMString uuid;
|
||||
readonly attribute ByteString? value;
|
||||
Promise<ByteString> readValue();
|
||||
// Promise<DataView> readValue();
|
||||
//Promise<DataView> readValue();
|
||||
Promise<void> writeValue(BufferSource value);
|
||||
};
|
||||
|
|
|
@ -15,8 +15,8 @@ promise_test(() => {
|
|||
.then(service => service.getCharacteristic(device_name.name))
|
||||
.then(characteristic => {
|
||||
assert_equals(characteristic.value, null);
|
||||
return characteristic.writeValue(asciiToDecimal('foo'))
|
||||
.then(() => assert_equals(characteristic.value, 'foo'));
|
||||
return characteristic.writeValue(Uint8Array.of(1, 2))
|
||||
.then(() => assert_equals(characteristic.value, '\x01\x02'));
|
||||
});
|
||||
}, 'A regular write request to a writable characteristic should update value.');
|
||||
</script>
|
||||
|
|
|
@ -17,7 +17,7 @@ promise_test(() => {
|
|||
.then(descriptor => {
|
||||
assert_equals(descriptor.value, null);
|
||||
return descriptor.writeValue(Uint8Array.of(1, 2))
|
||||
.then(() => assert_equals(descriptor.value, "\x01\x02"));
|
||||
.then(() => assert_equals(descriptor.value, '\x01\x02'));
|
||||
});
|
||||
}, 'A regular write request to a writable descriptor should update value.');
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue