diff options
author | Attila Dusnoki <dati91@gmail.com> | 2016-11-18 19:08:25 +0100 |
---|---|---|
committer | Attila Dusnoki <dati91@users.noreply.github.com> | 2016-11-28 10:49:49 +0100 |
commit | d9c7ffb5b3c86e16d412d8489c038573cf59f965 (patch) | |
tree | de5c94cbe85e5f50c65a53c4f00fff62ad54441e /components/script/dom/bluetoothremotegattcharacteristic.rs | |
parent | b18ec28fa7dab1728bb9e01d675534a28c43bb6a (diff) | |
download | servo-d9c7ffb5b3c86e16d412d8489c038573cf59f965.tar.gz servo-d9c7ffb5b3c86e16d412d8489c038573cf59f965.zip |
Add event target for bluetooth
Diffstat (limited to 'components/script/dom/bluetoothremotegattcharacteristic.rs')
-rw-r--r-- | components/script/dom/bluetoothremotegattcharacteristic.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs index 390878342db..9640ba95d52 100644 --- a/components/script/dom/bluetoothremotegattcharacteristic.rs +++ b/components/script/dom/bluetoothremotegattcharacteristic.rs @@ -13,15 +13,18 @@ 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::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::error::Error::{self, InvalidModification, Network, NotSupported, Security}; +use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutHeap, Root}; -use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; +use dom::bindings::reflector::{Reflectable, reflect_dom_object}; use dom::bindings::str::{ByteString, DOMString}; use dom::bluetooth::{AsyncBluetoothListener, response_async}; use dom::bluetoothcharacteristicproperties::BluetoothCharacteristicProperties; use dom::bluetoothremotegattdescriptor::BluetoothRemoteGATTDescriptor; use dom::bluetoothremotegattservice::BluetoothRemoteGATTService; use dom::bluetoothuuid::{BluetoothDescriptorUUID, BluetoothUUID}; +use dom::eventtarget::EventTarget; use dom::globalscope::GlobalScope; use dom::promise::Promise; use ipc_channel::ipc::IpcSender; @@ -35,7 +38,7 @@ pub const MAXIMUM_ATTRIBUTE_LENGTH: usize = 512; // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattcharacteristic #[dom_struct] pub struct BluetoothRemoteGATTCharacteristic { - reflector_: Reflector, + eventtarget: EventTarget, service: MutHeap<JS<BluetoothRemoteGATTService>>, uuid: DOMString, properties: MutHeap<JS<BluetoothCharacteristicProperties>>, @@ -50,7 +53,7 @@ impl BluetoothRemoteGATTCharacteristic { instance_id: String) -> BluetoothRemoteGATTCharacteristic { BluetoothRemoteGATTCharacteristic { - reflector_: Reflector::new(), + eventtarget: EventTarget::new_inherited(), service: MutHeap::new(service), uuid: uuid, properties: MutHeap::new(properties), @@ -255,6 +258,9 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris sender)).unwrap(); return p; } + + // https://webbluetoothcg.github.io/web-bluetooth/#dom-characteristiceventhandlers-oncharacteristicvaluechanged + event_handler!(characteristicvaluechanged, GetOncharacteristicvaluechanged, SetOncharacteristicvaluechanged); } impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic { @@ -297,6 +303,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic { BluetoothResponse::ReadValue(result) => { let value = ByteString::new(result); *self.value.borrow_mut() = Some(value.clone()); + self.upcast::<EventTarget>().fire_bubbling_event(atom!("characteristicvaluechanged")); promise.resolve_native(promise_cx, &value); }, BluetoothResponse::WriteValue(result) => { |