blurmock/
lib.rs

1extern crate hex;
2extern crate core;
3
4macro_rules! make_getter(
5    ($function_name: ident, $attr: ident, $ret_type:ty) => {
6        pub fn $function_name(&self) -> Result<$ret_type, Box<Error>> {
7            let cloned = self.$attr.clone();
8            let attr_value = match cloned.lock() {
9                Ok(guard) => guard.deref().clone(),
10                Err(_) => return Err(Box::from("Could not get the value.")),
11            };
12            Ok(attr_value)
13        }
14    };
15
16    ($function_name: ident, $attr: ident) => {
17        pub fn $function_name(&self) -> String {
18            let cloned = self.$attr.clone();
19            let attr_value = match cloned.lock() {
20                Ok(guard) => guard.deref().clone(),
21                Err(_) => String::new(),
22            };
23            attr_value
24        }
25    };
26
27    ($attr_name: ident) => {
28        pub fn $attr_name(&self) -> Result<bool, Box<Error>> {
29            let cloned = self.$attr_name.clone();
30            let attr_value = match cloned.lock() {
31                Ok(guard) => guard.deref().clone(),
32                Err(_) => return Err(Box::from("Could not get the value.")),
33            };
34            Ok(attr_value)
35        }
36    };
37);
38
39macro_rules! make_option_getter(
40    ($function_name: ident, $attr: ident, $ret_type:ty) => {
41        pub fn $function_name(&self) -> Result<$ret_type, Box<Error>> {
42            let cloned = self.$attr.clone();
43            let attr_value = match cloned.lock() {
44                Ok(guard) => guard.deref().clone(),
45                Err(_) => return Err(Box::from("Could not get the value.")),
46            };
47            match attr_value {
48                Some(value) => return Ok(value),
49                None => return Err(Box::from("Could not get the value.")),
50            }
51        }
52    };
53);
54
55macro_rules! make_setter(
56    ($function_name: ident, $attr: ident, $attr_type:ty ) => {
57        pub fn $function_name(&self, value: $attr_type) -> Result<(), Box<Error>> {
58            let cloned = self.$attr.clone();
59            let mut value_to_change = match cloned.lock() {
60                Ok(guard) => guard,
61                Err(_) => return Err(Box::from("Could not get the value.")),
62            };
63            Ok(*value_to_change = value)
64        }
65    };
66
67    ($function_name: ident, $attr: ident) => {
68        pub fn $function_name(&self, value: String) {
69            let cloned = self.$attr.clone();
70            let mut value_to_change = match cloned.lock() {
71                Ok(guard) => guard,
72                Err(_) => return (),
73            };
74            *value_to_change = value
75        }
76    };
77);
78
79pub mod fake_adapter;
80pub mod fake_device;
81pub mod fake_service;
82pub mod fake_characteristic;
83pub mod fake_descriptor;
84pub mod fake_discovery_session;