Style fix

This commit is contained in:
fokinv 2016-04-15 15:32:13 +02:00 committed by Attila Dusnoki
parent 27ad1437a1
commit f47f8d1a5c
7 changed files with 220 additions and 200 deletions

View file

@ -23,13 +23,13 @@ use util::str::DOMString;
// A device name can never be longer than 29 bytes. An adv packet is at most
// 31 bytes long. The length and identifier of the length field take 2 bytes.
// That least 29 bytes for the name.
const MAX_FILTER_NAME_LENGTH: usize = 29;
// 248 is the maximum number of UTF-8 code units in a Bluetooth Device Name.
const MAX_DEVICE_NAME_LENGTH: usize = 248;
const FILTER_EMPTY_ERROR: &'static str = "'filters' member must be non - empty to find any devices.";
const FILTER_ERROR: &'static str = "A filter must restrict the devices in some way.";
const FILTER_NAME_TOO_LONG_ERROR: &'static str = "A 'name' or 'namePrefix' can't be longer then 29 bytes.";
// 248 is the maximum number of UTF-8 code units in a Bluetooth Device Name.
const MAX_DEVICE_NAME_LENGTH: usize = 248;
// That least 29 bytes for the name.
const MAX_FILTER_NAME_LENGTH: usize = 29;
const NAME_PREFIX_ERROR: &'static str = "'namePrefix', if present, must be non - empty.";
const NAME_TOO_LONG_ERROR: &'static str = "A device name can't be longer than 248 bytes.";
const SERVICE_ERROR: &'static str = "'services', if present, must contain at least one service.";
@ -79,11 +79,8 @@ impl Clone for RequestDeviceOptions {
}
}
fn canonicalize_filter(filter: &BluetoothScanFilter, global: GlobalRef)
-> Fallible<BluetoothScanfilter> {
if !(filter.services.is_some() ||
filter.name.is_some() ||
filter.namePrefix.is_some()) {
fn canonicalize_filter(filter: &BluetoothScanFilter, global: GlobalRef) -> Fallible<BluetoothScanfilter> {
if !(filter.services.is_some() || filter.name.is_some() || filter.namePrefix.is_some()) {
return Err(Type(FILTER_ERROR.to_owned()));
}
@ -129,8 +126,9 @@ fn canonicalize_filter(filter: &BluetoothScanFilter, global: GlobalRef)
Ok(BluetoothScanfilter::new(name, name_prefix, services_vec))
}
fn convert_request_device_options(options: &RequestDeviceOptions, global: GlobalRef)
-> Fallible<RequestDeviceoptions> {
fn convert_request_device_options(options: &RequestDeviceOptions,
global: GlobalRef)
-> Fallible<RequestDeviceoptions> {
if options.filters.is_empty() {
return Err(Type(FILTER_EMPTY_ERROR.to_owned()));
}
@ -160,15 +158,12 @@ fn convert_request_device_options(options: &RequestDeviceOptions, global: Global
impl BluetoothMethods for Bluetooth {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
fn RequestDevice(&self,
option: &RequestDeviceOptions)
-> Fallible<Root<BluetoothDevice>> {
fn RequestDevice(&self, option: &RequestDeviceOptions) -> Fallible<Root<BluetoothDevice>> {
let (sender, receiver) = ipc::channel().unwrap();
match convert_request_device_options(option, self.global().r()) {
Ok(option) => {
self.get_bluetooth_thread()
.send(BluetoothMethodMsg::RequestDevice(option, sender))
.unwrap();
self.get_bluetooth_thread().send(
BluetoothMethodMsg::RequestDevice(option, sender)).unwrap();
let device = receiver.recv().unwrap();
match device {
BluetoothObjectMsg::BluetoothDevice {
@ -211,7 +206,9 @@ impl BluetoothMethods for Bluetooth {
},
BluetoothObjectMsg::Error {
error
} => return Err(Type(error)),
} => {
Err(Type(error))
},
_ => unreachable!()
}
},

View file

@ -11,7 +11,7 @@ use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::Bluetoot
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
use dom::bindings::codegen::UnionTypes::StringOrUnsignedLong;
use dom::bindings::error::Error::{Network, Type};
use dom::bindings::error::Fallible;
use dom::bindings::error::{Fallible, ErrorResult};
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, MutHeap, Root};
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
@ -61,8 +61,8 @@ impl BluetoothRemoteGATTCharacteristic {
uuid,
properties,
instanceID),
global,
BluetoothRemoteGATTCharacteristicBinding::Wrap)
global,
BluetoothRemoteGATTCharacteristicBinding::Wrap)
}
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
@ -94,9 +94,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-getdescriptor
fn GetDescriptor(&self,
descriptor: StringOrUnsignedLong)
-> Fallible<Root<BluetoothRemoteGATTDescriptor>> {
fn GetDescriptor(&self, descriptor: StringOrUnsignedLong) -> Fallible<Root<BluetoothRemoteGATTDescriptor>> {
let uuid: String = match BluetoothUUID::GetDescriptor(self.global().r(), descriptor.clone()) {
Ok(domstring) => domstring.to_string(),
Err(error) => return Err(error),
@ -117,7 +115,9 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
},
BluetoothObjectMsg::Error {
error
} => Err(Type(error)),
} => {
Err(Type(error))
},
_ => unreachable!()
}
}
@ -126,12 +126,12 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
fn GetDescriptors(&self,
descriptor: Option<StringOrUnsignedLong>)
-> Fallible<Vec<Root<BluetoothRemoteGATTDescriptor>>> {
let uuid: Option<String> = match descriptor {
Some(d) => match BluetoothUUID::GetDescriptor(self.global().r(), d.clone()) {
Ok(domstring) => Some(domstring.to_string()),
let mut uuid: Option<String> = None;
if let Some(d)= descriptor {
match BluetoothUUID::GetCharacteristic(self.global().r(), d.clone()) {
Ok(domstring) => uuid = Some(domstring.to_string()),
Err(error) => return Err(error),
},
None => None,
}
};
let (sender, receiver) = ipc::channel().unwrap();
let mut descriptors: Vec<Root<BluetoothRemoteGATTDescriptor>> = vec!();
@ -151,7 +151,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
descriptors.push(BluetoothRemoteGATTDescriptor::new(self.global().r(),
&self,
DOMString::from(uuid),
instance_id))
instance_id));
},
_ => unreachable!(),
}
@ -160,7 +160,9 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
},
BluetoothObjectMsg::Error {
error
} => Err(Type(error)),
} => {
Err(Type(error))
},
_ => unreachable!(),
}
}
@ -175,8 +177,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
let (sender, receiver) = ipc::channel().unwrap();
if !self.Service().Device().Gatt().Connected() {
Err(Network)
}
else {
} else {
self.get_bluetooth_thread().send(
BluetoothMethodMsg::ReadValue(self.get_instance_id(), sender)).unwrap();
let result = receiver.recv().unwrap();
@ -188,7 +189,9 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
},
BluetoothObjectMsg::Error {
error
} => return Err(Type(error)),
} => {
return Err(Type(error))
},
_ => unreachable!()
};
*self.value.borrow_mut() = value;
@ -197,7 +200,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue
fn WriteValue(&self, value: Vec<u8>) -> Fallible<()> {
fn WriteValue(&self, value: Vec<u8>) -> ErrorResult {
let (sender, receiver) = ipc::channel().unwrap();
self.get_bluetooth_thread().send(
BluetoothMethodMsg::WriteValue(self.get_instance_id(), value, sender)).unwrap();
@ -206,7 +209,9 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
BluetoothObjectMsg::BluetoothWriteValue => Ok(()),
BluetoothObjectMsg::Error {
error
} => Err(Type(error)),
} => {
Err(Type(error))
},
_ => unreachable!()
}
}

View file

@ -11,7 +11,7 @@ use dom::bindings::codegen::Bindings::BluetoothRemoteGATTDescriptorBinding::Blue
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
use dom::bindings::error::Error::{Type, Network};
use dom::bindings::error::Fallible;
use dom::bindings::error::{Fallible, ErrorResult};
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, MutHeap, Root};
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
@ -90,8 +90,7 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
let (sender, receiver) = ipc::channel().unwrap();
if !self.Characteristic().Service().Device().Gatt().Connected() {
Err(Network)
}
else {
} else {
self.get_bluetooth_thread().send(
BluetoothMethodMsg::ReadValue(self.get_instance_id(), sender)).unwrap();
let result = receiver.recv().unwrap();
@ -103,7 +102,9 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
},
BluetoothObjectMsg::Error {
error
} => return Err(Type(error)),
} => {
return Err(Type(error))
},
_ => unreachable!()
};
*self.value.borrow_mut() = value;
@ -112,7 +113,7 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-writevalue
fn WriteValue(&self, value: Vec<u8>) -> Fallible<()> {
fn WriteValue(&self, value: Vec<u8>) -> ErrorResult {
let (sender, receiver) = ipc::channel().unwrap();
self.get_bluetooth_thread().send(
BluetoothMethodMsg::WriteValue(self.get_instance_id(), value, sender)).unwrap();
@ -121,7 +122,9 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
BluetoothObjectMsg::BluetoothWriteValue => Ok(()),
BluetoothObjectMsg::Error {
error
} => Err(Type(error)),
} => {
Err(Type(error))
},
_ => unreachable!()
}
}

View file

@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding;
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
use dom::bindings::codegen::UnionTypes::StringOrUnsignedLong;
use dom::bindings::error::Error::Type;
use dom::bindings::error::Fallible;
use dom::bindings::error::{Fallible, ErrorResult};
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, MutHeap, Root};
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
@ -64,9 +64,8 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect
fn Connect(&self) -> Fallible<Root<BluetoothRemoteGATTServer>> {
let (sender, receiver) = ipc::channel().unwrap();
self.get_bluetooth_thread()
.send(BluetoothMethodMsg::GATTServerConnect(String::from(self.Device().Id()), sender))
.unwrap();
self.get_bluetooth_thread().send(
BluetoothMethodMsg::GATTServerConnect(String::from(self.Device().Id()), sender)).unwrap();
let server = receiver.recv().unwrap();
match server {
BluetoothObjectMsg::BluetoothServer {
@ -77,13 +76,15 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
},
BluetoothObjectMsg::Error {
error
} => Err(Type(error)),
} => {
Err(Type(error))
},
_ => unreachable!()
}
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-disconnect
fn Disconnect(&self) -> Fallible<()>{
fn Disconnect(&self) -> ErrorResult {
let (sender, receiver) = ipc::channel().unwrap();
self.get_bluetooth_thread().send(
BluetoothMethodMsg::GATTServerDisconnect(String::from(self.Device().Id()), sender)).unwrap();
@ -97,7 +98,9 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
},
BluetoothObjectMsg::Error {
error
} => Err(Type(error)),
} => {
Err(Type(error))
},
_ => unreachable!()
}
}
@ -119,33 +122,35 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
instance_id,
} => {
Ok(BluetoothRemoteGATTService::new(self.global().r(),
&self.device.get(),
DOMString::from(uuid),
is_primary,
instance_id))
&self.device.get(),
DOMString::from(uuid),
is_primary,
instance_id))
},
BluetoothObjectMsg::Error {
error
} => Err(Type(error)),
} => {
Err(Type(error))
},
_ => unreachable!(),
}
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservices
fn GetPrimaryServices(&self, service: Option<StringOrUnsignedLong>)
fn GetPrimaryServices(&self,
service: Option<StringOrUnsignedLong>)
-> Fallible<Vec<Root<BluetoothRemoteGATTService>>> {
let uuid: Option<String> = match service {
Some(s) => match BluetoothUUID::GetService(self.global().r(), s.clone()) {
Ok(domstring) => Some(domstring.to_string()),
let mut uuid: Option<String> = None;
if let Some(s)= service {
match BluetoothUUID::GetService(self.global().r(), s.clone()) {
Ok(domstring) => uuid = Some(domstring.to_string()),
Err(error) => return Err(error),
},
None => None,
}
};
let mut services: Vec<Root<BluetoothRemoteGATTService>> = vec!();
let (sender, receiver) = ipc::channel().unwrap();
self.get_bluetooth_thread()
.send(BluetoothMethodMsg::GetPrimaryServices(String::from(self.Device().Id()), uuid, sender))
.unwrap();
self.get_bluetooth_thread().send(
BluetoothMethodMsg::GetPrimaryServices(String::from(self.Device().Id()), uuid, sender)).unwrap();
let services_vec = receiver.recv().unwrap();
match services_vec {
BluetoothObjectMsg::BluetoothServices {
@ -162,7 +167,7 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
&self.device.get(),
DOMString::from(uuid),
is_primary,
instance_id))
instance_id));
},
_ => unreachable!(),
}
@ -171,7 +176,9 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
},
BluetoothObjectMsg::Error {
error
} => Err(Type(error)),
} => {
Err(Type(error))
},
_ => unreachable!(),
}
}

View file

@ -85,17 +85,16 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getcharacteristic
fn GetCharacteristic(&self, characteristic: StringOrUnsignedLong)
fn GetCharacteristic(&self,
characteristic: StringOrUnsignedLong)
-> Fallible<Root<BluetoothRemoteGATTCharacteristic>> {
let uuid: String = match BluetoothUUID::GetCharacteristic(self.global().r(),
characteristic.clone()) {
let uuid: String = match BluetoothUUID::GetCharacteristic(self.global().r(), characteristic.clone()) {
Ok(domstring) => domstring.to_string(),
Err(error) => return Err(error),
};
let (sender, receiver) = ipc::channel().unwrap();
self.get_bluetooth_thread()
.send(BluetoothMethodMsg::GetCharacteristic(self.get_instance_id(), uuid, sender))
.unwrap();
self.get_bluetooth_thread().send(
BluetoothMethodMsg::GetCharacteristic(self.get_instance_id(), uuid, sender)).unwrap();
let characteristic = receiver.recv().unwrap();
match characteristic {
BluetoothObjectMsg::BluetoothCharacteristic {
@ -122,33 +121,35 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
reliable_write,
writable_auxiliaries);
Ok(BluetoothRemoteGATTCharacteristic::new(self.global().r(),
&self,
DOMString::from(uuid),
properties,
instance_id))
&self,
DOMString::from(uuid),
properties,
instance_id))
},
BluetoothObjectMsg::Error {
error
} => return Err(Type(error)),
} => {
Err(Type(error))
},
_ => unreachable!(),
}
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattservice-getcharacteristics
fn GetCharacteristics(&self, characteristic: Option<StringOrUnsignedLong>)
fn GetCharacteristics(&self,
characteristic: Option<StringOrUnsignedLong>)
-> Fallible<Vec<Root<BluetoothRemoteGATTCharacteristic>>> {
let uuid: Option<String> = match characteristic {
Some(c) => match BluetoothUUID::GetCharacteristic(self.global().r(), c.clone()) {
Ok(domstring) => Some(domstring.to_string()),
let mut uuid: Option<String> = None;
if let Some(c)= characteristic {
match BluetoothUUID::GetCharacteristic(self.global().r(), c.clone()) {
Ok(domstring) => uuid = Some(domstring.to_string()),
Err(error) => return Err(error),
},
None => None,
}
};
let mut characteristics: Vec<Root<BluetoothRemoteGATTCharacteristic>> = vec!();
let (sender, receiver) = ipc::channel().unwrap();
self.get_bluetooth_thread()
.send(BluetoothMethodMsg::GetCharacteristics(self.get_instance_id(), uuid, sender))
.unwrap();
self.get_bluetooth_thread().send(
BluetoothMethodMsg::GetCharacteristics(self.get_instance_id(), uuid, sender)).unwrap();
let characteristics_vec = receiver.recv().unwrap();
match characteristics_vec {
BluetoothObjectMsg::BluetoothCharacteristics {
@ -169,23 +170,21 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
reliable_write,
writable_auxiliaries,
} => {
let properties = &BluetoothCharacteristicProperties::new(
self.global().r(),
broadcast,
read,
write_without_response,
write,
notify,
indicate,
authenticated_signed_writes,
reliable_write,
writable_auxiliaries);
characteristics.push(BluetoothRemoteGATTCharacteristic::new(
self.global().r(),
&self,
DOMString::from(uuid),
properties,
instance_id))
let properties = &BluetoothCharacteristicProperties::new(self.global().r(),
broadcast,
read,
write_without_response,
write,
notify,
indicate,
authenticated_signed_writes,
reliable_write,
writable_auxiliaries);
characteristics.push(BluetoothRemoteGATTCharacteristic::new(self.global().r(),
&self,
DOMString::from(uuid),
properties,
instance_id));
},
_ => unreachable!(),
}
@ -194,7 +193,9 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
},
BluetoothObjectMsg::Error {
error
} => return Err(Type(error)),
} => {
Err(Type(error))
},
_ => unreachable!(),
}
}

View file

@ -274,9 +274,7 @@ impl BluetoothUUID {
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothuuid-getservice
pub fn GetService(globalref: GlobalRef,
name: StringOrUnsignedLong)
-> Fallible<UUID> {
pub fn GetService(globalref: GlobalRef, name: StringOrUnsignedLong) -> Fallible<UUID> {
BluetoothUUID::resolve_uuid_name(globalref,
name,
BLUETOOTH_ASSIGNED_SERVICES,
@ -284,9 +282,7 @@ impl BluetoothUUID {
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothuuid-getcharacteristic
pub fn GetCharacteristic(globalref: GlobalRef,
name: StringOrUnsignedLong)
-> Fallible<UUID> {
pub fn GetCharacteristic(globalref: GlobalRef, name: StringOrUnsignedLong) -> Fallible<UUID> {
BluetoothUUID::resolve_uuid_name(globalref,
name,
BLUETOOTH_ASSIGNED_CHARCTERISTICS,
@ -294,9 +290,7 @@ impl BluetoothUUID {
}
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothuuid-getdescriptor
pub fn GetDescriptor(globalref: GlobalRef,
name: StringOrUnsignedLong)
-> Fallible<UUID> {
pub fn GetDescriptor(globalref: GlobalRef, name: StringOrUnsignedLong) -> Fallible<UUID> {
BluetoothUUID::resolve_uuid_name(globalref,
name,
BLUETOOTH_ASSIGNED_DESCRIPTORS,
@ -311,7 +305,7 @@ impl BluetoothUUID {
-> Fallible<DOMString> {
match name {
// Step 1
StringOrUnsignedLong::UnsignedLong(unsigned32) =>{
StringOrUnsignedLong::UnsignedLong(unsigned32) => {
Ok(BluetoothUUID::CanonicalUUID(globalref, unsigned32))
},
StringOrUnsignedLong::String(dstring) => {
@ -322,8 +316,7 @@ impl BluetoothUUID {
} else {
// Step 3
let concatenated = format!("{}.{}", prefix, dstring);
let is_in_table = assigned_numbers_table.iter()
.find(|p| p.0 == concatenated);
let is_in_table = assigned_numbers_table.iter().find(|p| p.0 == concatenated);
match is_in_table {
Some(&(_, alias)) => Ok(BluetoothUUID::CanonicalUUID(globalref, alias)),
None => Err(Syntax),