Skip to content

Commit 326ca35

Browse files
committed
Issue 37140 - new getters and setters
1 parent a07a8e4 commit 326ca35

File tree

4 files changed

+42
-54
lines changed

4 files changed

+42
-54
lines changed

src/app/WriteHandler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ DataModel::ActionReturnStatus WriteHandler::CheckWriteAllowed(const Access::Subj
788788
}
789789

790790
// Allow writes on writable attributes only
791-
VerifyOrReturnValue(attributeEntry->writePrivilegeHasValue(), Status::UnsupportedWrite);
791+
VerifyOrReturnValue(attributeEntry->WriteAllowed(), Status::UnsupportedWrite);
792792

793793
bool checkAcl = true;
794794
if (mLastSuccessfullyWrittenPath.has_value())

src/app/data-model-provider/MetadataTypes.h

+38-50
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <access/Privilege.h>
2323
#include <lib/core/DataModelTypes.h>
2424
#include <lib/support/BitFlags.h>
25-
#include <assert.h>
2625

2726
namespace chip {
2827
namespace app {
@@ -86,29 +85,13 @@ enum class AttributeQualityFlags : uint32_t
8685
};
8786

8887

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-
10688
// zero is not a valid privilege, just a default initial value for privileges
10789
constexpr std::underlying_type_t<Access::Privilege> kNoPrivilege(0) ;
10890

10991

11092
struct AttributeEntry
11193
{
94+
11295
AttributeId attributeId;
11396

11497
// Constructor
@@ -122,10 +105,6 @@ struct AttributeEntry
122105
sizeof(chip::to_underlying(r)),
123106
"Size of readPrivilege is not able to accomodate parameter (r).");
124107

125-
// ASSERT to validate entry parameter value.
126-
assert(kNoPrivilege != chip::to_underlying(r));
127-
128-
129108
mask.readPrivilege = chip::to_underlying(r);
130109
}
131110

@@ -141,9 +120,6 @@ struct AttributeEntry
141120
sizeof(chip::to_underlying(w)),
142121
"Size of writePrivilege is not able to accomodate parameter (w).");
143122

144-
// ASSERT to validate entry parameter value.
145-
assert(kNoPrivilege != chip::to_underlying(w));
146-
147123
mask.writePrivilege = chip::to_underlying(w);
148124
}
149125

@@ -169,13 +145,30 @@ struct AttributeEntry
169145

170146
constexpr bool FlagsHas(AttributeQualityFlags f) const { return (mask.flags & chip::to_underlying(f)) != 0; }
171147

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;}
174150

175151

176152
private:
177153

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;
179172

180173
};
181174

@@ -191,24 +184,6 @@ enum class CommandQualityFlags : uint32_t
191184

192185

193186

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-
212187
struct AcceptedCommandEntry
213188
{
214189
CommandId commandId;
@@ -226,9 +201,6 @@ struct AcceptedCommandEntry
226201
sizeof(chip::to_underlying(i)),
227202
"Size of invokePrivilege is not able to accomodate parameter (i).");
228203

229-
// ASSERT to validate entry parameter value.
230-
assert(kNoPrivilege != chip::to_underlying(i));
231-
232204
mask.invokePrivilege = chip::to_underlying(i);
233205
}
234206

@@ -258,7 +230,23 @@ struct AcceptedCommandEntry
258230

259231
private:
260232

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;
262250

263251
};
264252

src/app/reporting/Engine.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ std::optional<CHIP_ERROR> ValidateReadAttributeACL(DataModel::Provider * dataMod
7979
// privilege and default to kView (this is correct for global attributes and a reasonable check
8080
// for others)
8181
Privilege requiredPrivilege = Privilege::kView;
82-
if (info.has_value() && info->readPrivilegeHasValue())
82+
if (info.has_value() && info->ReadAllowed())
8383
{
8484
// attribute exists and is readable, set the correct read privilege
8585
requiredPrivilege = info->GetReadPrivilege();
@@ -108,7 +108,7 @@ std::optional<CHIP_ERROR> ValidateReadAttributeACL(DataModel::Provider * dataMod
108108
// this SHOULD be done here when info does not have a value. This was not done as a first pass to
109109
// minimize amount of delta in the initial PR.
110110
// - "write-only" attributes should return UNSUPPORTED_READ (this is done here)
111-
if (info.has_value() && !info->readPrivilegeHasValue())
111+
if (info.has_value() && !info->ReadAllowed())
112112
{
113113
return CHIP_IM_GLOBAL_STATUS(UnsupportedRead);
114114
}

src/data-model-providers/codegen/tests/TestCodegenModelViaMocks.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ TEST_F(TestCodegenModelViaMocks, FindAttribute)
11351135
ASSERT_TRUE(info.has_value());
11361136
EXPECT_FALSE(info->FlagsHas(AttributeQualityFlags::kListAttribute)); // NOLINT(bugprone-unchecked-optional-access)
11371137
EXPECT_EQ(info->GetReadPrivilege(), chip::Access::Privilege::kAdminister); // NOLINT(bugprone-unchecked-optional-access)
1138-
EXPECT_FALSE(info->writePrivilegeHasValue()); // NOLINT(bugprone-unchecked-optional-access)
1138+
EXPECT_FALSE(info->WriteAllowed()); // NOLINT(bugprone-unchecked-optional-access)
11391139
}
11401140

11411141
// global attributes are EXPLICITLY supported

0 commit comments

Comments
 (0)