@@ -85,13 +85,10 @@ enum class AttributeQualityFlags : uint32_t
85
85
};
86
86
87
87
88
- // zero is not a valid privilege, just a default initial value for privileges
89
- constexpr std::underlying_type_t <Access::Privilege> kNoPrivilege (0 ) ;
90
88
91
89
92
90
struct AttributeEntry
93
91
{
94
-
95
92
AttributeId attributeId;
96
93
97
94
// Constructor
@@ -102,29 +99,37 @@ struct AttributeEntry
102
99
) : attributeId(id), mask{ attrQualityFlags, readPriv, writePriv } {}
103
100
104
101
102
+ enum class ReadWriteFlag : uint8_t
103
+ {
104
+ AssignReadPrivilege = 1 << 0 ,
105
+ AssignWritePrivilege = 1 << 1
106
+ };
107
+
108
+ ReadWriteFlag opFlag {ReadWriteFlag::AssignReadPrivilege};
105
109
106
- // Overload assignment operator for mask.readPrivilege
110
+
111
+ // Overload assignment operator for privileges
107
112
AttributeEntry& operator =(Access::Privilege value)
108
113
{
109
114
// Static ASSERT to check size of readPrivilege type vs entry parameter.
110
115
static_assert (sizeof (std::underlying_type_t <Access::Privilege>) >=
111
116
sizeof (chip::to_underlying (value)),
112
- " Size of readPrivilege is not able to accomodate parameter (value)." );
113
-
114
- this -> mask . readPrivilege = chip::to_underlying (value);
115
- return * this ;
116
- }
117
-
118
-
119
- // Overload assignment operator for mask.writePrivilege
120
- AttributeEntry& operator =(std:: underlying_type_t <Access::Privilege> value)
121
- {
122
- // Static ASSERT to check size of writePrivilege type vs entry parameter.
123
- static_assert ( sizeof (std:: underlying_type_t <Access::Privilege>) >=
124
- sizeof (value),
125
- " Size of writePrivilege is not able to accomodate parameter (value). " ) ;
126
-
127
- this -> mask . writePrivilege = value;
117
+ " Size of input privilege is not able to accomodate parameter (value)." );
118
+
119
+ switch (opFlag)
120
+ {
121
+ case ReadWriteFlag::AssignReadPrivilege :
122
+ this -> mask . readPrivilege = to_underlying (value);
123
+ break ;
124
+
125
+ case ReadWriteFlag::AssignWritePrivilege :
126
+ this -> mask . writePrivilege = to_underlying (value);
127
+ break ;
128
+
129
+ default :
130
+ break ;
131
+ }
132
+
128
133
return *this ;
129
134
}
130
135
@@ -157,14 +162,18 @@ struct AttributeEntry
157
162
}
158
163
159
164
160
- constexpr bool FlagsHas (AttributeQualityFlags f) const { return (mask.flags & chip::to_underlying (f)) != 0 ; }
165
+ constexpr bool HasFlags (AttributeQualityFlags f) const { return (mask.flags & chip::to_underlying (f)) != 0 ; }
161
166
162
167
bool ReadAllowed () {return mask.readPrivilege != kNoPrivilege ;}
163
168
bool WriteAllowed () {return mask.writePrivilege != kNoPrivilege ;}
164
169
165
170
166
171
private:
167
172
173
+ // zero is not a valid privilege, just a default initial value for privileges
174
+ static constexpr std::underlying_type_t <Access::Privilege> kNoPrivilege {0 } ;
175
+
176
+
168
177
struct attribute_entry_mask_t {
169
178
170
179
// attribute quality flags
@@ -200,7 +209,6 @@ enum class CommandQualityFlags : uint32_t
200
209
201
210
struct AcceptedCommandEntry
202
211
{
203
-
204
212
CommandId commandId;
205
213
206
214
// Constructor
@@ -222,7 +230,7 @@ struct AcceptedCommandEntry
222
230
this ->mask .invokePrivilege = chip::to_underlying (value);
223
231
return *this ;
224
232
}
225
-
233
+
226
234
227
235
// Getter for mask.invokePrivilege
228
236
Access::Privilege GetInvokePrivilege () const
@@ -245,11 +253,15 @@ struct AcceptedCommandEntry
245
253
}
246
254
247
255
248
- constexpr bool FlagsHas (CommandQualityFlags f) const { return (mask.flags & chip::to_underlying (f)) != 0 ; }
256
+ constexpr bool HasFlags (CommandQualityFlags f) const { return (mask.flags & chip::to_underlying (f)) != 0 ; }
249
257
250
258
251
259
private:
252
260
261
+ // zero is not a valid privilege, just a default initial value for privileges
262
+ static constexpr std::underlying_type_t <Access::Privilege> kNoPrivilege {0 } ;
263
+
264
+
253
265
struct accepted_command_entry_mask_t {
254
266
255
267
// command quality flags
0 commit comments