Skip to content

Commit 1730204

Browse files
lpbeliveau-silabsbzbarsky-apple
authored andcommitted
Apply suggestions from code review
Co-authored-by: Boris Zbarsky <[email protected]>
1 parent 18dcf15 commit 1730204

File tree

6 files changed

+61
-44
lines changed

6 files changed

+61
-44
lines changed

src/app/clusters/scenes/ExtensionFieldSets.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static constexpr uint8_t kInvalidPosition = 0xff;
2727
static constexpr uint8_t kMaxClustersPerScene = CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENE;
2828
static constexpr uint8_t kMaxFieldBytesPerCluster = CHIP_CONFIG_SCENES_MAX_EXTENSION_FIELDSET_SIZE_PER_CLUSTER;
2929

30-
/// @brief class meant serialize all extension ßfield sets of a scene so it can be stored and retrieved from flash memory.
30+
/// @brief A way to serialize and deserialize all cluster attribute data for a scene.
3131
class ExtensionFieldSets
3232
{
3333
public:

src/app/clusters/scenes/ExtensionFieldSetsImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ CHIP_ERROR ExtensionFieldSetsImpl::InsertFieldSet(const ExtensionFieldSet & fiel
9999
}
100100
}
101101

102-
// if found, replace at found position, otherwise at insert first free position, otherwise return error
102+
// if found, replace at found position, otherwise insert at first free position, otherwise return error
103103
if (firstEmptyPosition < kMaxClusterPerScenes)
104104
{
105105
mEFS[firstEmptyPosition] = fieldSet;

src/app/clusters/scenes/ExtensionFieldSetsImpl.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct ExtensionFieldSet
8181
ReturnErrorOnFailure(
8282
writer.StartContainer(TLV::ContextTag(TagEFS::kIndividualContainer), TLV::kTLVType_Structure, container));
8383

84-
ReturnErrorOnFailure(writer.Put(TLV::ContextTag(TagEFS::kClusterID), static_cast<uint32_t>(mID)));
84+
ReturnErrorOnFailure(writer.Put(TLV::ContextTag(TagEFS::kClusterID), mID));
8585
ReturnErrorOnFailure(writer.PutBytes(TLV::ContextTag(TagEFS::kClusterFieldSetData), mBytesBuffer, mUsedBytes));
8686

8787
return writer.EndContainer(container);
@@ -113,12 +113,12 @@ struct ExtensionFieldSet
113113
mUsedBytes = 0;
114114
}
115115

116-
bool IsEmpty() const { return (this->mUsedBytes == 0); }
116+
bool IsEmpty() const { return (mUsedBytes == 0); }
117117

118118
bool operator==(const ExtensionFieldSet & other) const
119119
{
120-
return (this->mID == other.mID && this->mUsedBytes == other.mUsedBytes &&
121-
!memcmp(this->mBytesBuffer, other.mBytesBuffer, this->mUsedBytes));
120+
return (mID == other.mID && mUsedBytes == other.mUsedBytes &&
121+
!memcmp(mBytesBuffer, other.mBytesBuffer, mUsedBytes));
122122
}
123123
};
124124

@@ -164,7 +164,7 @@ class ExtensionFieldSetsImpl : public ExtensionFieldSets
164164
}
165165

166166
protected:
167-
ExtensionFieldSet mEFS[kMaxClusterPerScenes];
167+
ExtensionFieldSet mFieldSets[kMaxClusterPerScenes];
168168
uint8_t mFieldSetsCount = 0;
169169
};
170170
} // namespace scenes

src/app/clusters/scenes/SceneTable.h

+46-28
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,25 @@ typedef uint32_t SceneTransitionTime;
3636
constexpr GroupId kGlobalGroupSceneId = 0x0000;
3737
constexpr SceneIndex kUndefinedSceneIndex = 0xff;
3838
constexpr SceneId kUndefinedSceneId = 0xff;
39-
static constexpr uint8_t kMaxScenePerFabric = CHIP_CONFIG_SCENES_MAX_PER_FABRIC;
39+
static constexpr uint8_t kMaxScenesPerFabric = CHIP_CONFIG_SCENES_MAX_PER_FABRIC;
40+
4041
static constexpr size_t kIteratorsMax = CHIP_CONFIG_MAX_SCENES_CONCURRENT_ITERATORS;
41-
static constexpr size_t kSceneNameMax = CHIP_CONFIG_SCENES_CLUSTER_MAXIMUM_NAME_LENGTH;
42+
static constexpr size_t kSceneNameMaxLength = CHIP_CONFIG_SCENES_CLUSTER_MAXIMUM_NAME_LENGTH;
43+
4244

43-
/// @brief Abstract class allowing different Endpoints interactions with the ExtensionFieldSets added to and retrieved from the
44-
/// scene Table. The Scene Handler's are meant as interface between various clusters and the Scene table. The expected behaviour of
45-
/// the table with the handler is: Once a scene command involving extension field set is received, the Scene Table will go through
46-
/// the list of handlers to either retrieve, populate or apply Extension field sets. Each handler is meant to retrieve an extension
47-
/// field set for a single cluster however it is also possible to use a single generic handler that handles all of them.
45+
/// @brief SceneHandlers are meant as interface between various clusters and the Scene table.
46+
/// When a scene command involving extension field sets is received, the Scene Table will go through
47+
/// the list of handlers to either retrieve, populate or apply those extension field sets.
48+
///
49+
/// Generally, for each specific <endpoint, cluster> pair there should be one and only one handler
50+
/// registered with the scene table that claims to handle that pair.
4851
///
49-
/// @note If more than one handler is implemented for a specific <endpoint, cluster> pair, ONLY THE FIRST HANDLER FOR THAT SPECIFIC
50-
/// PAIR will get called on executing extension field sets related ations on the scene table.
52+
/// A SceneHandler can handle a single <endpoint, cluster> pair, or many such pairs.
53+
///
54+
/// @note If more than one handler claims to handl a specific <endpoint, cluster> pair, only one of
55+
/// those handlers will get called when executing actions related to extension field sets on the scene
56+
/// table. It is not defined which handler will be selected.
57+
5158
class SceneHandler : public IntrusiveListNodeBase<>
5259
{
5360
public:
@@ -58,8 +65,10 @@ class SceneHandler : public IntrusiveListNodeBase<>
5865
/// supported clusters
5966
/// @param endpoint target endpoint
6067
/// @param clusterBuffer Buffer to hold the supported cluster IDs, cannot hold more than
61-
/// CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES, the function shall use the reduce_size() method in the event it is supporting
62-
/// less than CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENES clusters
68+
/// CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENE. The function shall use the reduce_size() method in the event it is supporting
69+
70+
/// less than CHIP_CONFIG_SCENES_MAX_CLUSTERS_PER_SCENE clusters.
71+
6372
virtual void GetSupportedClusters(EndpointId endpoint, Span<ClusterId> & clusterBuffer) = 0;
6473

6574
/// @brief Returns whether or not a cluster for scenes is supported on an endpoint
@@ -69,7 +78,8 @@ class SceneHandler : public IntrusiveListNodeBase<>
6978
/// @return true if supported, false if not supported
7079
virtual bool SupportsCluster(EndpointId endpoint, ClusterId cluster) = 0;
7180

72-
/// @brief From command AddScene, allows handler to filter through clusters in command to serialize only the supported ones.
81+
/// @brief Called when handling AddScene. Allows the handler to filter through the clusters in the command to serialize only the supported ones.
82+
7383
/// @param endpoint[in] Endpoint ID
7484
/// @param extensionFieldSet[in] ExtensionFieldSets provided by the AddScene Command, pre initialized
7585
/// @param cluster[out] Cluster in the Extension field set, filled by the function
@@ -79,10 +89,10 @@ class SceneHandler : public IntrusiveListNodeBase<>
7989
const app::Clusters::Scenes::Structs::ExtensionFieldSet::DecodableType & extensionFieldSet,
8090
ClusterId & cluster, MutableByteSpan & serialisedBytes) = 0;
8191

82-
/// @brief From command StoreScene, retrieves ExtensionField from currently active values, it is the function's responsibility
83-
/// to
92+
/// @brief Called when handling StoreScene, and only if the handler supports the given endpoint and cluster.
93+
///
94+
/// The implementation must write the actual scene data to store to serializedBytes as described below.
8495

85-
/// place the serialized data in serializedBytes as described below.
8696

8797
/// @param endpoint[in] Target Endpoint
8898
/// @param cluster[in] Target Cluster
@@ -92,7 +102,8 @@ class SceneHandler : public IntrusiveListNodeBase<>
92102
/// @return CHIP_NO_ERROR if successful, CHIP_ERROR value otherwise
93103
virtual CHIP_ERROR SerializeSave(EndpointId endpoint, ClusterId cluster, MutableByteSpan & serializedBytes) = 0;
94104

95-
/// @brief From stored scene (e.g. ViewScene), deserialize ExtensionFieldSet into a cluster object
105+
/// @brief Deserialize an ExtensionFieldSet into a cluster object (e.g. when handling ViewScene).
106+
96107
/// @param endpoint[in] Endpoint ID
97108
/// @param cluster[in] Cluster ID to save
98109
/// @param serializedBytes[in] ExtensionFieldSet stored in NVM
@@ -103,7 +114,8 @@ class SceneHandler : public IntrusiveListNodeBase<>
103114

104115
app::Clusters::Scenes::Structs::ExtensionFieldSet::Type & extensionFieldSet) = 0;
105116

106-
/// @brief From stored scene (e.g RecallScene), applies EFS values to cluster at transition time
117+
/// @brief Restore a stored scene for the given cluster instance, over timeMs milliseconds (e.g. when handling RecallScene)
118+
107119
/// @param endpoint[in] Endpoint ID
108120
/// @param cluster[in] Cluster ID
109121
/// @param serializedBytes[in] ExtensionFieldSet stored in NVM
@@ -141,7 +153,8 @@ class SceneTable
141153

142154
bool operator==(const SceneStorageId & other)
143155
{
144-
return (this->mEndpointId == other.mEndpointId && this->mGroupId == other.mGroupId && this->mSceneId == other.mSceneId);
156+
return (mEndpointId == other.mEndpointId && mGroupId == other.mGroupId && mSceneId == other.mSceneId);
157+
145158
}
146159
};
147160

@@ -162,17 +175,20 @@ class SceneTable
162175

163176
SceneData(const CharSpan & sceneName = CharSpan(), SceneTransitionTime time = 0) : mSceneTransitionTimeMs(time)
164177
{
165-
this->SetName(sceneName);
178+
SetName(sceneName);
179+
166180
}
167181
SceneData(EFStype fields, const CharSpan & sceneName = CharSpan(), SceneTransitionTime time = 0) :
168182
mSceneTransitionTimeMs(time)
169183
{
170-
this->SetName(sceneName);
184+
SetName(sceneName);
185+
171186
mExtensionFieldSets = fields;
172187
}
173188
SceneData(const SceneData & other) : mSceneTransitionTimeMs(other.mSceneTransitionTimeMs)
174189
{
175-
this->SetName(CharSpan(other.mName, other.mNameLength));
190+
SetName(CharSpan(other.mName, other.mNameLength));
191+
176192
mExtensionFieldSets = other.mExtensionFieldSets;
177193
}
178194
~SceneData(){};
@@ -194,7 +210,8 @@ class SceneTable
194210

195211
void Clear()
196212
{
197-
this->SetName(CharSpan());
213+
SetName(CharSpan());
214+
198215
mSceneTransitionTimeMs = 0;
199216
mExtensionFieldSets.Clear();
200217
}
@@ -229,13 +246,15 @@ class SceneTable
229246

230247
bool operator==(const SceneTableEntry & other)
231248
{
232-
return (this->mStorageId == other.mStorageId && this->mStorageData == other.mStorageData);
249+
return (mStorageId == other.mStorageId && mStorageData == other.mStorageData);
250+
233251
}
234252

235253
void operator=(const SceneTableEntry & other)
236254
{
237-
this->mStorageId = other.mStorageId;
238-
this->mStorageData = other.mStorageData;
255+
mStorageId = other.mStorageId;
256+
mStorageData = other.mStorageData;
257+
239258
}
240259
};
241260

@@ -275,12 +294,11 @@ class SceneTable
275294
virtual SceneEntryIterator * IterateSceneEntries(FabricIndex fabric_index) = 0;
276295

277296
// Handlers
278-
virtual bool HandlerListEmpty() { return (mNumHandlers == 0); }
279-
virtual uint8_t GetHandlerNum() { return this->mNumHandlers; }
297+
virtual bool HandlerListEmpty() { return mHandlerList.Empty(); }
298+
280299

281300
// SceneHandler * mHandlers[kMaxSceneHandlers] = { nullptr };
282301
IntrusiveList<SceneHandler> mHandlerList;
283-
uint8_t mNumHandlers = 0;
284302
};
285303

286304
} // namespace scenes

src/app/clusters/scenes/SceneTableImpl.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ struct FabricSceneData : public PersistentData<kPersistentFabricBufferMax>
167167
TLV::TLVType container;
168168
ReturnErrorOnFailure(writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, container));
169169

170-
ReturnErrorOnFailure(writer.Put(TLV::ContextTag(TagSceneImpl::kSceneCount), (scene_count)));
170+
ReturnErrorOnFailure(writer.Put(TLV::ContextTag(TagSceneImpl::kSceneCount), scene_count));
171171
// Storing the scene map
172172
for (uint8_t i = 0; i < kMaxScenePerFabric; i++)
173173
{
@@ -387,7 +387,7 @@ void DefaultSceneTableImpl::RegisterHandler(SceneHandler * handler)
387387
void DefaultSceneTableImpl::UnregisterHandler(SceneHandler * handler)
388388
{
389389
// Verify list is populated and handler is not null
390-
VerifyOrReturn(!this->HandlerListEmpty() && !(handler == nullptr));
390+
VerifyOrReturn(!HandlerListEmpty() && !(handler == nullptr));
391391
mHandlerList.Remove(handler);
392392
mNumHandlers--;
393393
}
@@ -398,7 +398,7 @@ void DefaultSceneTableImpl::UnregisterAllHandlers()
398398
{
399399
IntrusiveList<SceneHandler>::Iterator foo = mHandlerList.begin();
400400
SceneHandler * handle = &(*foo);
401-
mHandlerList.Remove((handle));
401+
mHandlerList.Remove(handle);
402402
mNumHandlers--;
403403
}
404404
}
@@ -409,7 +409,7 @@ void DefaultSceneTableImpl::UnregisterAllHandlers()
409409
CHIP_ERROR DefaultSceneTableImpl::SceneSaveEFS(SceneTableEntry & scene)
410410
{
411411

412-
if (!this->HandlerListEmpty())
412+
if (!HandlerListEmpty())
413413
{
414414
uint8_t clusterCount = 0;
415415
clusterId cArray[kMaxClusterPerScenes];
@@ -422,10 +422,9 @@ CHIP_ERROR DefaultSceneTableImpl::SceneSaveEFS(SceneTableEntry & scene)
422422
MutableByteSpan EFSSpan = MutableByteSpan(EFS.mBytesBuffer, kMaxFieldBytesPerCluster);
423423
EFS.mID = cluster;
424424

425-
IntrusiveList<SceneHandler>::Iterator iter = mHandlerList.begin();
426-
while (iter != mHandlerList.end())
425+
for (auto & handler : mHandlerList)
427426
{
428-
if (iter->SupportsCluster(scene.mStorageId.mEndpointId, cluster))
427+
if (handler.SupportsCluster(scene.mStorageId.mEndpointId, cluster))
429428
{
430429
ReturnErrorOnFailure(iter->SerializeSave(scene.mStorageId.mEndpointId, EFS.mID, EFSSpan));
431430
EFS.mUsedBytes = static_cast<uint8_t>(EFSSpan.size());
@@ -495,7 +494,7 @@ CHIP_ERROR DefaultSceneTableImpl::RemoveFabric(FabricIndex fabric_index)
495494
return fabric.Delete(mStorage);
496495
}
497496

498-
/// @brief wrapper function around emberAfGetClustersFromEndpoint to allow testing, shimed in test configuration because
497+
/// @brief wrapper function around emberAfGetClustersFromEndpoint to allow testing, shimmed in test configuration because
499498
/// emberAfGetClusterFromEndpoint relies on <app/util/attribute-storage.h>, which relies on zap generated files
500499
uint8_t DefaultSceneTableImpl::GetClustersFromEndpoint(EndpointId endpoint, ClusterId * clusterList, uint8_t listLen)
501500
{

src/app/util/mock/attribute-storage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ chip::Optional<chip::ClusterId> emberAfGetNthClusterId(chip::EndpointId endpoint
188188
// for the given endpoint and client/server polarity
189189
uint8_t emberAfGetClustersFromEndpoint(EndpointId endpoint, ClusterId * clusterList, uint8_t listLen, bool server)
190190
{
191-
uint8_t cluster_Count = emberAfClusterCount(endpoint, server);
191+
uint8_t cluster_count = emberAfClusterCount(endpoint, server);
192192
uint8_t i;
193193

194194
if (cluster_Count > listLen)

0 commit comments

Comments
 (0)