Allowed services support

This commit is contained in:
zakorgy 2016-06-03 15:29:37 +02:00 committed by zakorgyula
parent 530b5a649e
commit 174516ac5b
2 changed files with 41 additions and 3 deletions

View file

@ -2,6 +2,7 @@
* 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 std::collections::HashSet;
use std::slice::Iter;
// A device name can never be longer than 29 bytes. An adv packet is at most
@ -16,6 +17,14 @@ impl ServiceUUIDSequence {
pub fn new(vec: Vec<String>) -> ServiceUUIDSequence {
ServiceUUIDSequence(vec)
}
fn get_services_set(&self) -> HashSet<String> {
let mut set = HashSet::new();
for s in self.0.iter() {
set.insert(s.clone());
}
set
}
}
#[derive(Deserialize, Serialize)]
@ -69,6 +78,14 @@ impl BluetoothScanfilterSequence {
pub fn iter(&self) -> Iter<BluetoothScanfilter> {
self.0.iter()
}
fn get_services_set(&self) -> HashSet<String> {
let mut set = HashSet::new();
for filter in self.iter() {
set = &set | &filter.services.get_services_set();
}
set
}
}
#[derive(Deserialize, Serialize)]
@ -90,4 +107,8 @@ impl RequestDeviceoptions {
pub fn get_filters(&self) -> &BluetoothScanfilterSequence {
&self.filters
}
pub fn get_services_set(&self) -> HashSet<String> {
&self.filters.get_services_set() | &self.optional_services.get_services_set()
}
}