22
22
#include < access/Privilege.h>
23
23
#include < lib/core/DataModelTypes.h>
24
24
#include < lib/support/BitFlags.h>
25
- #include < assert.h>
26
25
27
26
namespace chip {
28
27
namespace app {
@@ -86,29 +85,13 @@ enum class AttributeQualityFlags : uint32_t
86
85
};
87
86
88
87
89
- struct attribute_entry_mask_t {
90
-
91
- // attribute quality flags
92
- //
93
- std::underlying_type_t <AttributeQualityFlags> flags : 7 ; // generally defaults to View if readable
94
-
95
- // read/write access privilege variables
96
- //
97
- std::underlying_type_t <Access::Privilege> readPrivilege : 5 ; // generally defaults to View if readable
98
- std::underlying_type_t <Access::Privilege> writePrivilege : 5 ; // generally defaults to Operate if writable
99
-
100
- };
101
-
102
-
103
- // Static ASSERT to check size of mask type.
104
- static_assert (sizeof (attribute_entry_mask_t ) <= 4 , " Size of attribute_entry_mask_t is not as expected." );
105
-
106
88
// zero is not a valid privilege, just a default initial value for privileges
107
89
constexpr std::underlying_type_t <Access::Privilege> kNoPrivilege (0 ) ;
108
90
109
91
110
92
struct AttributeEntry
111
93
{
94
+
112
95
AttributeId attributeId;
113
96
114
97
// Constructor
@@ -122,10 +105,6 @@ struct AttributeEntry
122
105
sizeof (chip::to_underlying (r)),
123
106
" Size of readPrivilege is not able to accomodate parameter (r)." );
124
107
125
- // ASSERT to validate entry parameter value.
126
- assert (kNoPrivilege != chip::to_underlying (r));
127
-
128
-
129
108
mask.readPrivilege = chip::to_underlying (r);
130
109
}
131
110
@@ -141,9 +120,6 @@ struct AttributeEntry
141
120
sizeof (chip::to_underlying (w)),
142
121
" Size of writePrivilege is not able to accomodate parameter (w)." );
143
122
144
- // ASSERT to validate entry parameter value.
145
- assert (kNoPrivilege != chip::to_underlying (w));
146
-
147
123
mask.writePrivilege = chip::to_underlying (w);
148
124
}
149
125
@@ -169,13 +145,30 @@ struct AttributeEntry
169
145
170
146
constexpr bool FlagsHas (AttributeQualityFlags f) const { return (mask.flags & chip::to_underlying (f)) != 0 ; }
171
147
172
- bool readPrivilegeHasValue () {return mask.readPrivilege ;}
173
- bool writePrivilegeHasValue () {return mask.writePrivilege ;}
148
+ bool ReadAllowed () {return mask.readPrivilege != kNoPrivilege ;}
149
+ bool WriteAllowed () {return mask.writePrivilege != kNoPrivilege ;}
174
150
175
151
176
152
private:
177
153
178
- attribute_entry_mask_t mask;
154
+ struct attribute_entry_mask_t {
155
+
156
+ // attribute quality flags
157
+ //
158
+ std::underlying_type_t <AttributeQualityFlags> flags : 7 ;
159
+
160
+ // read/write access privilege variables
161
+ //
162
+ std::underlying_type_t <Access::Privilege> readPrivilege : 5 ;
163
+ std::underlying_type_t <Access::Privilege> writePrivilege : 5 ;
164
+
165
+ };
166
+
167
+
168
+ // Static ASSERT to check size of mask type "attribute_entry_mask_t".
169
+ static_assert (sizeof (attribute_entry_mask_t ) <= 4 , " Size of attribute_entry_mask_t is not as expected." );
170
+
171
+ attribute_entry_mask_t mask;
179
172
180
173
};
181
174
@@ -191,24 +184,6 @@ enum class CommandQualityFlags : uint32_t
191
184
192
185
193
186
194
- struct accepted_command_entry_mask_t {
195
-
196
- // command quality flags
197
- //
198
- std::underlying_type_t <CommandQualityFlags> flags : 3 ; // generally defaults to View if readable
199
-
200
- // invoke privilege variable
201
- //
202
- std::underlying_type_t <Access::Privilege> invokePrivilege : 5 ;
203
-
204
- };
205
-
206
-
207
- // Static ASSERT to check size of mask type.
208
- static_assert (sizeof (accepted_command_entry_mask_t ) <= 4 , " Size of accepted_command_entry_mask_t is not as expected." );
209
-
210
-
211
-
212
187
struct AcceptedCommandEntry
213
188
{
214
189
CommandId commandId;
@@ -226,9 +201,6 @@ struct AcceptedCommandEntry
226
201
sizeof (chip::to_underlying (i)),
227
202
" Size of invokePrivilege is not able to accomodate parameter (i)." );
228
203
229
- // ASSERT to validate entry parameter value.
230
- assert (kNoPrivilege != chip::to_underlying (i));
231
-
232
204
mask.invokePrivilege = chip::to_underlying (i);
233
205
}
234
206
@@ -258,7 +230,23 @@ struct AcceptedCommandEntry
258
230
259
231
private:
260
232
261
- accepted_command_entry_mask_t mask;
233
+ struct accepted_command_entry_mask_t {
234
+
235
+ // command quality flags
236
+ //
237
+ std::underlying_type_t <CommandQualityFlags> flags : 3 ; // generally defaults to View if readable
238
+
239
+ // invoke privilege variable
240
+ //
241
+ std::underlying_type_t <Access::Privilege> invokePrivilege : 5 ;
242
+
243
+ };
244
+
245
+
246
+ // Static ASSERT to check size of mask type "accepted_command_entry_mask_t".
247
+ static_assert (sizeof (accepted_command_entry_mask_t ) <= 4 , " Size of accepted_command_entry_mask_t is not as expected." );
248
+
249
+ accepted_command_entry_mask_t mask;
262
250
263
251
};
264
252
0 commit comments