Skip to content

Instantly share code, notes, and snippets.

@zakorgy
Created February 16, 2016 08:45
Show Gist options
  • Save zakorgy/bb50eae190d4941a7614 to your computer and use it in GitHub Desktop.
Save zakorgy/bb50eae190d4941a7614 to your computer and use it in GitHub Desktop.
encoding::codec::utf_8::UTF8Encoding;
encoding::types::EncoderTrap;
std::mem::size_of_val
Struct BluetoothScanfilter {
services: Vec<BluetoothServiceUUID>,
name: DOMString,
namePrefix: DOMString,
}
Struct RequestDeviceOptions {
filters: Vec<BluetoothScanfilter>,
optionalServices: Vec<BluetoothServiceUUID>,
}
Struct DeviceInstance {
device: BluetoothDevice,
promise: fn(BluetoothDevice) -> Result<BluetoothDevice>,
}
Struct attributeInstanceMap {
cache: BluetothCache,
promise:
}
fn nameMatch(DOMString,DOMString) -> bool {
}
fn namePrefixMatch(DOMString, DOMString) -> bool {
}
fn uuidMatch() -> Vec<BluetoothDevice> {
}
fn requestDevcie(&self,options: RequestDeviceOptions) -> MockDevice {
//TODO: Security checks(zakorgy)
if options.filters.len() == 0 {
MockDevice {
name: DOMString::from("TypeError"),
uuids: Vec::new(),
}
}
else {
let mut uuid_filters:Vec<BluetoothScanfilter> = Vec::new();
let mut required_service_uuids: HashSet<BluetoothServiceUUID> = Hashset::new();
for filter in &options.filters {
if filter.services.is_emtpy()
&& filter.name.is_emtpy()
&& filter.namePrefix.is_emtpy() {
MockDevice {
name: DOMString::from("TypeError"),
uuids: Vec::new(),
}
} else {
let mut canonicalized_filter = BluetoothScanfilter::new(); //FIXME(zakorgy) kitalálni a típusát
if !filter.services.is_emtpy() {
if filter.services.len() == 0 {
MockDevice {
name: DOMString::from("TypeError"),
uuids: Vec::new(),
}
} else {
let mut services:Vec<BluetoothUUID> = {
function_to_make_services(filter.services, BluetoothUUID.getService());
//FIXME(zakorgy) https://tc39.github.io/ecma262/#sec-array.prototype.map
}
//TODO(zakorgy) blacklistcheck
canonicalized_filter.services = services.clone();
required_service_uuids.insert(services);
//FIXME(zakorgy) for cilussal belerakni a Vec
//elemeket a required_service_uuids HashSet-be
}
if !filter.name()is_emtpy() {
let utf8_encoded_name = encode(filter.name.trim(), EncoderTrap::Ignore);
if size_of_val(utf8_encoded_name) > 248 {
MockDevice {
name: DOMString::from("TypeError"),
uuids: Vec::new(),
}
} else {
canonicalized_filter.name = filter.name;
}
} else {
();
}
if !filter.namePrefix()is_emtpy() {
let utf8_encoded_name = encode(filter.namePrefix.trim(), EncoderTrap::Ignore);
if size_of_val(utf8_encoded_name) > 248 || filter.namePrefix.len == 0 {
MockDevice {
name: DOMString::from("TypeError"),
uuids: Vec::new(),
}
} else {
canonicalized_filter.namePrefix = filter.namePrefix.clone();
}
} else {
();
}
uuid_filters.push(canonicalized_filter);//FIXME(zakorgy) nem biztos h push kell
}
}
}
let optiona_service_uuids:Vec<BluetoothUUID> = {
function_to_make_services(filter.optionalServices, BluetoothUUID.getService());
//FIXME(zakorgy) https://tc39.github.io/ecma262/#sec-array.prototype.map
//TODO blacklistcheck
}
let scanresult = {
scan_for_devices(required_service_uuids);
//TODO(zakorgy) scan_for_devices implentálása
}
let matchedDevices = {
//TODO(zakorgy) matching scanresult with uuid_filters
//use nameMatch namePrefixMatch and uuidMatch
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment