Skip to content

Commit 7a0ebfa

Browse files
committed
Issue 37140 - new getters and setters
1 parent ca1a6be commit 7a0ebfa

File tree

3 files changed

+40
-28
lines changed

3 files changed

+40
-28
lines changed

src/app/InteractionModelEngine.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1761,8 +1761,8 @@ Protocols::InteractionModel::Status InteractionModelEngine::CheckCommandAccess(c
17611761
Protocols::InteractionModel::Status InteractionModelEngine::CheckCommandFlags(const DataModel::InvokeRequest & aRequest,
17621762
const DataModel::AcceptedCommandEntry & entry)
17631763
{
1764-
const bool commandNeedsTimedInvoke = entry.FlagsHas(DataModel::CommandQualityFlags::kTimed);
1765-
const bool commandIsFabricScoped = entry.FlagsHas(DataModel::CommandQualityFlags::kFabricScoped);
1764+
const bool commandNeedsTimedInvoke = entry.HasFlags(DataModel::CommandQualityFlags::kTimed);
1765+
const bool commandIsFabricScoped = entry.HasFlags(DataModel::CommandQualityFlags::kFabricScoped);
17661766

17671767
if (commandNeedsTimedInvoke && !aRequest.invokeFlags.Has(DataModel::InvokeFlags::kTimed))
17681768
{

src/app/WriteHandler.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ std::optional<bool> WriteHandler::IsListAttributePath(const ConcreteAttributePat
125125
return std::nullopt;
126126
}
127127

128-
return info->FlagsHas(DataModel::AttributeQualityFlags::kListAttribute);
128+
return info->HasFlags(DataModel::AttributeQualityFlags::kListAttribute);
129129
}
130130

131131
Status WriteHandler::HandleWriteRequestMessage(Messaging::ExchangeContext * apExchangeContext,
@@ -823,7 +823,7 @@ DataModel::ActionReturnStatus WriteHandler::CheckWriteAllowed(const Access::Subj
823823
}
824824

825825
// validate that timed write is enforced
826-
VerifyOrReturnValue(IsTimedWrite() || !attributeEntry->FlagsHas(DataModel::AttributeQualityFlags::kTimed),
826+
VerifyOrReturnValue(IsTimedWrite() || !attributeEntry->HasFlags(DataModel::AttributeQualityFlags::kTimed),
827827
Status::NeedsTimedInteraction);
828828

829829
return Status::Success;

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

+36-24
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,10 @@ enum class AttributeQualityFlags : uint32_t
8585
};
8686

8787

88-
// zero is not a valid privilege, just a default initial value for privileges
89-
constexpr std::underlying_type_t<Access::Privilege> kNoPrivilege(0) ;
9088

9189

9290
struct AttributeEntry
9391
{
94-
9592
AttributeId attributeId;
9693

9794
// Constructor
@@ -102,29 +99,37 @@ struct AttributeEntry
10299
) : attributeId(id), mask{ attrQualityFlags, readPriv, writePriv } {}
103100

104101

102+
enum class ReadWriteFlag : uint8_t
103+
{
104+
AssignReadPrivilege = 1 << 0,
105+
AssignWritePrivilege = 1 << 1
106+
};
107+
108+
ReadWriteFlag opFlag {ReadWriteFlag::AssignReadPrivilege};
105109

106-
// Overload assignment operator for mask.readPrivilege
110+
111+
// Overload assignment operator for privileges
107112
AttributeEntry& operator=(Access::Privilege value)
108113
{
109114
// Static ASSERT to check size of readPrivilege type vs entry parameter.
110115
static_assert(sizeof(std::underlying_type_t<Access::Privilege>) >=
111116
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+
128133
return *this;
129134
}
130135

@@ -157,14 +162,18 @@ struct AttributeEntry
157162
}
158163

159164

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

162167
bool ReadAllowed() {return mask.readPrivilege != kNoPrivilege;}
163168
bool WriteAllowed() {return mask.writePrivilege != kNoPrivilege;}
164169

165170

166171
private:
167172

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+
168177
struct attribute_entry_mask_t {
169178

170179
// attribute quality flags
@@ -200,7 +209,6 @@ enum class CommandQualityFlags : uint32_t
200209

201210
struct AcceptedCommandEntry
202211
{
203-
204212
CommandId commandId;
205213

206214
// Constructor
@@ -222,7 +230,7 @@ struct AcceptedCommandEntry
222230
this->mask.invokePrivilege = chip::to_underlying(value);
223231
return *this;
224232
}
225-
233+
226234

227235
// Getter for mask.invokePrivilege
228236
Access::Privilege GetInvokePrivilege() const
@@ -245,11 +253,15 @@ struct AcceptedCommandEntry
245253
}
246254

247255

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

250258

251259
private:
252260

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+
253265
struct accepted_command_entry_mask_t {
254266

255267
// command quality flags

0 commit comments

Comments
 (0)