bacnet_objects/access_control/
rights.rs1use super::*;
2
3pub struct AccessRightsObject {
11 oid: ObjectIdentifier,
12 name: String,
13 description: String,
14 global_identifier: u64,
15 positive_access_rules_count: u32,
16 negative_access_rules_count: u32,
17 status_flags: StatusFlags,
18 out_of_service: bool,
19 reliability: u32,
20}
21
22impl AccessRightsObject {
23 pub fn new(instance: u32, name: impl Into<String>) -> Result<Self, Error> {
25 let oid = ObjectIdentifier::new(ObjectType::ACCESS_RIGHTS, instance)?;
26 Ok(Self {
27 oid,
28 name: name.into(),
29 description: String::new(),
30 global_identifier: 0,
31 positive_access_rules_count: 0,
32 negative_access_rules_count: 0,
33 status_flags: StatusFlags::empty(),
34 out_of_service: false,
35 reliability: 0,
36 })
37 }
38}
39
40impl BACnetObject for AccessRightsObject {
41 fn object_identifier(&self) -> ObjectIdentifier {
42 self.oid
43 }
44
45 fn object_name(&self) -> &str {
46 &self.name
47 }
48
49 fn read_property(
50 &self,
51 property: PropertyIdentifier,
52 array_index: Option<u32>,
53 ) -> Result<PropertyValue, Error> {
54 if let Some(result) = read_common_properties!(self, property, array_index) {
55 return result;
56 }
57 match property {
58 p if p == PropertyIdentifier::OBJECT_TYPE => Ok(PropertyValue::Enumerated(
59 ObjectType::ACCESS_RIGHTS.to_raw(),
60 )),
61 p if p == PropertyIdentifier::GLOBAL_IDENTIFIER => {
62 Ok(PropertyValue::Unsigned(self.global_identifier))
63 }
64 p if p == PropertyIdentifier::POSITIVE_ACCESS_RULES => Ok(PropertyValue::Unsigned(
65 self.positive_access_rules_count as u64,
66 )),
67 p if p == PropertyIdentifier::NEGATIVE_ACCESS_RULES => Ok(PropertyValue::Unsigned(
68 self.negative_access_rules_count as u64,
69 )),
70 _ => Err(common::unknown_property_error()),
71 }
72 }
73
74 fn write_property(
75 &mut self,
76 property: PropertyIdentifier,
77 _array_index: Option<u32>,
78 value: PropertyValue,
79 _priority: Option<u8>,
80 ) -> Result<(), Error> {
81 if let Some(result) =
82 common::write_out_of_service(&mut self.out_of_service, property, &value)
83 {
84 return result;
85 }
86 if let Some(result) = common::write_description(&mut self.description, property, &value) {
87 return result;
88 }
89 match property {
90 p if p == PropertyIdentifier::GLOBAL_IDENTIFIER => {
91 if let PropertyValue::Unsigned(v) = value {
92 self.global_identifier = v;
93 Ok(())
94 } else {
95 Err(common::invalid_data_type_error())
96 }
97 }
98 _ => Err(common::write_access_denied_error()),
99 }
100 }
101
102 fn property_list(&self) -> Cow<'static, [PropertyIdentifier]> {
103 static PROPS: &[PropertyIdentifier] = &[
104 PropertyIdentifier::OBJECT_IDENTIFIER,
105 PropertyIdentifier::OBJECT_NAME,
106 PropertyIdentifier::DESCRIPTION,
107 PropertyIdentifier::OBJECT_TYPE,
108 PropertyIdentifier::GLOBAL_IDENTIFIER,
109 PropertyIdentifier::POSITIVE_ACCESS_RULES,
110 PropertyIdentifier::NEGATIVE_ACCESS_RULES,
111 PropertyIdentifier::STATUS_FLAGS,
112 PropertyIdentifier::OUT_OF_SERVICE,
113 PropertyIdentifier::RELIABILITY,
114 ];
115 Cow::Borrowed(PROPS)
116 }
117}
118
119