1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::sync::RwLock;
use crate::mqtt::topic::geo_extension::GeoExtension;
use crate::reception::information::Information;
pub struct Configuration {
client_id: String,
information: RwLock<Information>,
region_of_responsibility: bool,
}
impl Configuration {
pub fn new(client_id: String, region_of_responsibility: bool) -> Self {
Configuration {
client_id,
information: RwLock::new(Information::new()),
region_of_responsibility,
}
}
pub fn gateway_component_name(&self) -> String {
let information_guard = self.information.read().unwrap();
information_guard.instance_id.clone()
}
pub fn component_name(&self, added_number: Option<u32>) -> String {
let information_guard = self.information.read().unwrap();
let number = match added_number {
Some(number) => information_guard.instance_id_number() + number,
None => information_guard.instance_id_number() + 10000,
};
format!("{}_{}", self.client_id, number)
}
pub fn station_id(&self, added_number: Option<u32>) -> u32 {
let information_guard = self.information.read().unwrap();
match added_number {
Some(number) => information_guard.instance_id_number() + number,
None => information_guard.instance_id_number() + 10000,
}
}
pub fn is_in_region_of_responsibility(&self, geo_extension: GeoExtension) -> bool {
let information_guard = self.information.read().unwrap();
!self.region_of_responsibility
|| information_guard.is_in_region_of_responsibility(geo_extension)
}
pub fn update(&self, new_information: Information) {
let mut information_guard = self.information.write().unwrap();
*information_guard = new_information;
}
}