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