Fix value types

This commit is contained in:
Attila Dusnoki 2016-03-22 14:24:45 +01:00
parent ddada69acb
commit 9e57364795
2 changed files with 48 additions and 44 deletions

View file

@ -12,13 +12,16 @@ use dom::bindings::reflector::{Reflector, reflect_dom_object};
#[dom_struct] #[dom_struct]
pub struct BluetoothAdvertisingData { pub struct BluetoothAdvertisingData {
reflector_: Reflector, reflector_: Reflector,
appearance: u16, appearance: Option<u16>,
txPower: i8, txPower: Option<i8>,
rssi: i8, rssi: Option<i8>,
} }
impl BluetoothAdvertisingData { impl BluetoothAdvertisingData {
pub fn new_inherited(appearance: u16, txPower: i8, rssi: i8) -> BluetoothAdvertisingData { pub fn new_inherited(appearance: Option<u16>,
txPower: Option<i8>,
rssi: Option<i8>)
-> BluetoothAdvertisingData {
BluetoothAdvertisingData { BluetoothAdvertisingData {
reflector_: Reflector::new(), reflector_: Reflector::new(),
appearance: appearance, appearance: appearance,
@ -27,7 +30,11 @@ impl BluetoothAdvertisingData {
} }
} }
pub fn new(global: GlobalRef, appearance: u16, txPower: i8, rssi: i8) -> Root<BluetoothAdvertisingData> { pub fn new(global: GlobalRef,
appearance: Option<u16>,
txPower: Option<i8>,
rssi: Option<i8>)
-> Root<BluetoothAdvertisingData> {
reflect_dom_object(box BluetoothAdvertisingData::new_inherited(appearance, reflect_dom_object(box BluetoothAdvertisingData::new_inherited(appearance,
txPower, txPower,
rssi), rssi),
@ -39,16 +46,16 @@ impl BluetoothAdvertisingData {
impl BluetoothAdvertisingDataMethods for BluetoothAdvertisingData { impl BluetoothAdvertisingDataMethods for BluetoothAdvertisingData {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingdata-appearance // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingdata-appearance
fn GetAppearance(&self) -> Option<u16> { fn GetAppearance(&self) -> Option<u16> {
Some(self.appearance) self.appearance
} }
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingdata-txpower // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingdata-txpower
fn GetTxPower(&self) -> Option<i8> { fn GetTxPower(&self) -> Option<i8> {
Some(self.txPower) self.txPower
} }
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingdata-rssi // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingdata-rssi
fn GetRssi(&self) -> Option<i8> { fn GetRssi(&self) -> Option<i8> {
Some(self.rssi) self.rssi
} }
} }

View file

@ -5,8 +5,8 @@
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding; use dom::bindings::codegen::Bindings::BluetoothDeviceBinding;
use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::{BluetoothDeviceMethods, VendorIDSource}; use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::{BluetoothDeviceMethods, VendorIDSource};
use dom::bindings::global::GlobalRef; use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, Root, MutHeap}; use dom::bindings::js::{JS, Root, MutHeap, MutNullableHeap};
use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
use dom::bluetoothadvertisingdata::BluetoothAdvertisingData; use dom::bluetoothadvertisingdata::BluetoothAdvertisingData;
use dom::bluetoothremotegattserver::BluetoothRemoteGATTServer; use dom::bluetoothremotegattserver::BluetoothRemoteGATTServer;
use util::str::DOMString; use util::str::DOMString;
@ -16,26 +16,25 @@ use util::str::DOMString;
pub struct BluetoothDevice { pub struct BluetoothDevice {
reflector_: Reflector, reflector_: Reflector,
id: DOMString, id: DOMString,
name: DOMString, name: Option<DOMString>,
adData: MutHeap<JS<BluetoothAdvertisingData>>, adData: MutHeap<JS<BluetoothAdvertisingData>>,
deviceClass: u32, deviceClass: Option<u32>,
vendorIDSource: VendorIDSource, vendorIDSource: Option<VendorIDSource>,
vendorID: u32, vendorID: Option<u32>,
productID: u32, productID: Option<u32>,
productVersion: u32, productVersion: Option<u32>,
gatt: MutHeap<JS<BluetoothRemoteGATTServer>>, gatt: MutNullableHeap<JS<BluetoothRemoteGATTServer>>,
} }
impl BluetoothDevice { impl BluetoothDevice {
pub fn new_inherited(id: DOMString, pub fn new_inherited(id: DOMString,
name: DOMString, name: Option<DOMString>,
adData: &BluetoothAdvertisingData, adData: &BluetoothAdvertisingData,
deviceClass: u32, deviceClass: Option<u32>,
vendorIDSource: VendorIDSource, vendorIDSource: Option<VendorIDSource>,
vendorID: u32, vendorID: Option<u32>,
productID: u32, productID: Option<u32>,
productVersion: u32, productVersion: Option<u32>)
gatt: &BluetoothRemoteGATTServer)
-> BluetoothDevice { -> BluetoothDevice {
BluetoothDevice { BluetoothDevice {
reflector_: Reflector::new(), reflector_: Reflector::new(),
@ -47,21 +46,20 @@ impl BluetoothDevice {
vendorID: vendorID, vendorID: vendorID,
productID: productID, productID: productID,
productVersion: productVersion, productVersion: productVersion,
gatt: MutHeap::new(gatt), gatt: Default::default(),
} }
} }
pub fn new(global: GlobalRef, pub fn new(global: GlobalRef,
id: DOMString, id: DOMString,
name: DOMString, name: Option<DOMString>,
adData: &BluetoothAdvertisingData, adData: &BluetoothAdvertisingData,
deviceClass: u32, deviceClass: Option<u32>,
vendorIDSource: VendorIDSource, vendorIDSource: Option<VendorIDSource>,
vendorID: u32, vendorID: Option<u32>,
productID: u32, productID: Option<u32>,
productVersion: u32, productVersion: Option<u32>)
gatt: &BluetoothRemoteGATTServer) -> Root<BluetoothDevice> {
-> Root<BluetoothDevice> {
reflect_dom_object(box BluetoothDevice::new_inherited(id, reflect_dom_object(box BluetoothDevice::new_inherited(id,
name, name,
adData, adData,
@ -69,8 +67,7 @@ impl BluetoothDevice {
vendorIDSource, vendorIDSource,
vendorID, vendorID,
productID, productID,
productVersion, productVersion),
gatt),
global, global,
BluetoothDeviceBinding::Wrap) BluetoothDeviceBinding::Wrap)
} }
@ -85,7 +82,7 @@ impl BluetoothDeviceMethods for BluetoothDevice {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-name // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-name
fn GetName(&self) -> Option<DOMString> { fn GetName(&self) -> Option<DOMString> {
Some(self.name.clone()) self.name.clone()
} }
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-addata // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-addata
@ -95,31 +92,31 @@ impl BluetoothDeviceMethods for BluetoothDevice {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-deviceclass // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-deviceclass
fn GetDeviceClass(&self) -> Option<u32> { fn GetDeviceClass(&self) -> Option<u32> {
Some(self.deviceClass) self.deviceClass
} }
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-vendoridsource // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-vendoridsource
fn GetVendorIDSource(&self) -> Option<VendorIDSource> { fn GetVendorIDSource(&self) -> Option<VendorIDSource> {
Some(self.vendorIDSource) self.vendorIDSource
} }
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-vendorid // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-vendorid
fn GetVendorID(&self) -> Option<u32> { fn GetVendorID(&self) -> Option<u32> {
Some(self.vendorID) self.vendorID
} }
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-productid // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-productid
fn GetProductID(&self) -> Option<u32> { fn GetProductID(&self) -> Option<u32> {
Some(self.productID) self.productID
} }
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-productversion // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-productversion
fn GetProductVersion(&self) -> Option<u32> { fn GetProductVersion(&self) -> Option<u32> {
Some(self.productVersion) self.productVersion
} }
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-gatt // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-gatt
fn Gatt(&self) -> Root<BluetoothRemoteGATTServer> { fn Gatt(&self) -> Root<BluetoothRemoteGATTServer> {
self.gatt.get() self.gatt.or_init(|| BluetoothRemoteGATTServer::new(self.global().r(), self))
} }
} }