Skip to content

Commit

Permalink
SceneTable functionnalities (#25849)
Browse files Browse the repository at this point in the history
* Added a Global scene count, GetAllSceneIdsInGroup and RemoveAllScenesInGroup along with their test. Fixed line endings from SceneTable.h
Added automaticall removal of scene when it can't be loaded due to number of supported cluster being reduced by OTA
Added tests for OTA with changes in max scenes number (global and per fabric)

* fixed comparison on wrong variable causing un-initialized member

* Added Isnit verification to all scene table operation requiring permanent storage access, added check on table capacity to prevent creation of table table with capacity above max

* Update src/app/clusters/scenes/SceneTableImpl.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/app/clusters/scenes/SceneTableImpl.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/app/clusters/scenes/SceneTableImpl.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/app/clusters/scenes/SceneTableImpl.h

Co-authored-by: Boris Zbarsky <[email protected]>

* Removed dupplicate of Deserialize for Scene Fabric Data, added test for GetAllSceneIdsInGroup for the corner case of a list of size = 0 and for BUFFER_TOO_SMALL other situations, added comments for the size of the global count in storage

* Restyled by clang-format

* Update src/app/clusters/scenes/SceneTableImpl.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/app/clusters/scenes/SceneTableImpl.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/app/clusters/scenes/SceneTableImpl.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* Update src/app/clusters/scenes/SceneTableImpl.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* Stubed Deserialize and re-implemented DeserializeAdjust to avoid duplicating code

* Apply suggestions from code review

Co-authored-by: Boris Zbarsky <[email protected]>

* Changed return of Stubbed Deserialize to return error if used, Changed DeserializeAdjust->Deserialize and moved adjustment to GlobalSceneCount out of Deserialize into Load function to adjust the count in the case where a failure would happen after scenes are deleted

* Update src/app/clusters/scenes/SceneTableImpl.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* Fixed return of load in the event of a failiure to Deserialize when deleting scenes, explicited deleted_scenes_count value on failure to deserialize

* Update src/app/clusters/scenes/SceneTableImpl.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* Removed redundant returns in Load() method

---------

Co-authored-by: Boris Zbarsky <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed Jan 20, 2024
1 parent 114183a commit 3812806
Show file tree
Hide file tree
Showing 7 changed files with 1,058 additions and 361 deletions.
2 changes: 1 addition & 1 deletion src/app/clusters/scenes/ExtensionFieldSetsImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ CHIP_ERROR ExtensionFieldSetsImpl::InsertFieldSet(const ExtensionFieldSet & fiel

CHIP_ERROR ExtensionFieldSetsImpl::GetFieldSetAtPosition(ExtensionFieldSet & fieldSet, uint8_t position) const
{
VerifyOrReturnError(position < mFieldSetsCount, CHIP_ERROR_BUFFER_TOO_SMALL);
VerifyOrReturnError(position < mFieldSetsCount, CHIP_ERROR_INVALID_ARGUMENT);

fieldSet = mFieldSets[position];

Expand Down
611 changes: 310 additions & 301 deletions src/app/clusters/scenes/SceneTable.h

Large diffs are not rendered by default.

380 changes: 336 additions & 44 deletions src/app/clusters/scenes/SceneTableImpl.cpp

Large diffs are not rendered by default.

30 changes: 27 additions & 3 deletions src/app/clusters/scenes/SceneTableImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,27 @@ class DefaultSceneHandlerImpl : public scenes::SceneHandler
class DefaultSceneTableImpl : public SceneTable<scenes::ExtensionFieldSetsImpl>
{
public:
DefaultSceneTableImpl() = default;
DefaultSceneTableImpl() {}

~DefaultSceneTableImpl() override {}

CHIP_ERROR Init(PersistentStorageDelegate * storage) override;
void Finish() override;

// Scene access by Id
// Global scene count
CHIP_ERROR GetGlobalSceneCount(uint8_t & scene_count) override;

// Data
CHIP_ERROR GetRemainingCapacity(FabricIndex fabric_index, uint8_t & capacity) override;
CHIP_ERROR SetSceneTableEntry(FabricIndex fabric_index, const SceneTableEntry & entry) override;
CHIP_ERROR GetSceneTableEntry(FabricIndex fabric_index, SceneStorageId scene_id, SceneTableEntry & entry) override;
CHIP_ERROR RemoveSceneTableEntry(FabricIndex fabric_index, SceneStorageId scene_id) override;
CHIP_ERROR RemoveSceneTableEntryAtPosition(FabricIndex fabric_index, SceneIndex scene_idx) override;

// Groups
CHIP_ERROR GetAllSceneIdsInGroup(FabricIndex fabric_index, GroupId group_id, Span<SceneId> & scene_list) override;
CHIP_ERROR DeleteAllScenesInGroup(FabricIndex fabric_index, GroupId group_id) override;

// SceneHandlers
void RegisterHandler(SceneHandler * handler) override;
void UnregisterHandler(SceneHandler * handler) override;
Expand All @@ -208,13 +216,25 @@ class DefaultSceneTableImpl : public SceneTable<scenes::ExtensionFieldSetsImpl>
SceneEntryIterator * IterateSceneEntries(FabricIndex fabric_index) override;

protected:
// This constructor is meant for test purposes, it allows to change the defined max for scenes per fabric and global, which
// allows to simulate OTA where this value was changed
DefaultSceneTableImpl(uint8_t maxScenesPerFabric = scenes::kMaxScenesPerFabric,
uint8_t maxScenesGlobal = scenes::kMaxScenesGlobal) :
mMaxScenesPerFabric(maxScenesPerFabric),
mMaxScenesGlobal(maxScenesGlobal)
{}

// Global scene count
CHIP_ERROR SetGlobalSceneCount(const uint8_t & scene_count);

// wrapper function around emberAfGetClustersFromEndpoint to allow override when testing
virtual uint8_t GetClustersFromEndpoint(EndpointId endpoint, ClusterId * clusterList, uint8_t listLen);

class SceneEntryIteratorImpl : public SceneEntryIterator
{
public:
SceneEntryIteratorImpl(DefaultSceneTableImpl & provider, FabricIndex fabric_index);
SceneEntryIteratorImpl(DefaultSceneTableImpl & provider, FabricIndex fabric_index, uint8_t maxScenesPerFabric,
uint8_t maxScenesGlobal);
size_t Count() override;
bool Next(SceneTableEntry & output) override;
void Release() override;
Expand All @@ -225,9 +245,13 @@ class DefaultSceneTableImpl : public SceneTable<scenes::ExtensionFieldSetsImpl>
SceneIndex mNextSceneIdx;
SceneIndex mSceneIndex = 0;
uint8_t mTotalScenes = 0;
uint8_t mMaxScenesPerFabric;
uint8_t mMaxScenesGlobal;
};
bool IsInitialized() { return (mStorage != nullptr); }

const uint8_t mMaxScenesPerFabric = kMaxScenesPerFabric;
const uint8_t mMaxScenesGlobal = kMaxScenesGlobal;
chip::PersistentStorageDelegate * mStorage = nullptr;
ObjectPool<SceneEntryIteratorImpl, kIteratorsMax> mSceneEntryIterators;
}; // class DefaultSceneTableImpl
Expand Down
Loading

0 comments on commit 3812806

Please sign in to comment.