/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::Bindings::BluetoothDeviceBinding; use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::{BluetoothDeviceMethods, VendorIDSource}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root, MutHeap, MutNullableHeap}; use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; use dom::bluetoothadvertisingdata::BluetoothAdvertisingData; use dom::bluetoothremotegattserver::BluetoothRemoteGATTServer; use util::str::DOMString; // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothdevice #[dom_struct] pub struct BluetoothDevice { reflector_: Reflector, id: DOMString, name: Option, adData: MutHeap>, deviceClass: Option, vendorIDSource: Option, vendorID: Option, productID: Option, productVersion: Option, gatt: MutNullableHeap>, } impl BluetoothDevice { pub fn new_inherited(id: DOMString, name: Option, adData: &BluetoothAdvertisingData, deviceClass: Option, vendorIDSource: Option, vendorID: Option, productID: Option, productVersion: Option) -> BluetoothDevice { BluetoothDevice { reflector_: Reflector::new(), id: id, name: name, adData: MutHeap::new(adData), deviceClass: deviceClass, vendorIDSource: vendorIDSource, vendorID: vendorID, productID: productID, productVersion: productVersion, gatt: Default::default(), } } pub fn new(global: GlobalRef, id: DOMString, name: Option, adData: &BluetoothAdvertisingData, deviceClass: Option, vendorIDSource: Option, vendorID: Option, productID: Option, productVersion: Option) -> Root { reflect_dom_object(box BluetoothDevice::new_inherited(id, name, adData, deviceClass, vendorIDSource, vendorID, productID, productVersion), global, BluetoothDeviceBinding::Wrap) } } impl BluetoothDeviceMethods for BluetoothDevice { // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-id fn Id(&self) -> DOMString { self.id.clone() } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-name fn GetName(&self) -> Option { self.name.clone() } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-addata fn AdData(&self) -> Root { self.adData.get() } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-deviceclass fn GetDeviceClass(&self) -> Option { self.deviceClass } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-vendoridsource fn GetVendorIDSource(&self) -> Option { self.vendorIDSource } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-vendorid fn GetVendorID(&self) -> Option { self.vendorID } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-productid fn GetProductID(&self) -> Option { self.productID } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-productversion fn GetProductVersion(&self) -> Option { self.productVersion } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-gatt fn Gatt(&self) -> Root { self.gatt.or_init(|| BluetoothRemoteGATTServer::new(self.global().r(), self)) } }