Skip to content

Commit

Permalink
[Scenes] Scenes-Server on Fabric Removal (#30419)
Browse files Browse the repository at this point in the history
Added Fabric Removal callback to the scenes-server
  • Loading branch information
lpbeliveau-silabs authored Nov 15, 2023
1 parent aeee127 commit 26ec08f
Show file tree
Hide file tree
Showing 5 changed files with 1,483 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/app/clusters/scenes-server/SceneTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ class SceneTable
virtual CHIP_ERROR SceneApplyEFS(const SceneTableEntry & scene) = 0;

// Fabrics

/**
* @brief Removes all scenes associated with a fabric index and the stored FabricSceneData that maps them
* @param fabric_index Fabric index to remove
* @return CHIP_ERROR, CHIP_NO_ERROR if successful or if the Fabric was not found, specific CHIP_ERROR otherwise
* @note This function is meant to be used after a fabric is removed from the device, the implementation MUST ensure that it
* won't interact with the actual fabric table as it will be removed beforehand.
*/
virtual CHIP_ERROR RemoveFabric(FabricIndex fabric_index) = 0;
virtual CHIP_ERROR RemoveEndpoint() = 0;

Expand Down
14 changes: 14 additions & 0 deletions src/app/clusters/scenes-server/scenes-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ ScenesServer & ScenesServer::Instance()
}
void ReportAttributeOnAllEndpoints(AttributeId attribute) {}

class ScenesClusterFabricDelegate : public chip::FabricTable::Delegate
{
void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex) override
{
SceneTable * sceneTable = scenes::GetSceneTableImpl();
VerifyOrReturn(nullptr != sceneTable);
// The implementation of SceneTable::RemoveFabric() must not call back into the FabricTable
sceneTable->RemoveFabric(fabricIndex);
}
};

static ScenesClusterFabricDelegate gFabricDelegate;

CHIP_ERROR ScenesServer::Init()
{
// Prevents re-initializing
Expand All @@ -115,6 +128,7 @@ CHIP_ERROR ScenesServer::Init()

SceneTable * sceneTable = scenes::GetSceneTableImpl();
ReturnErrorOnFailure(sceneTable->Init(&chip::Server::GetInstance().GetPersistentStorage()));
ReturnErrorOnFailure(chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&gFabricDelegate));

mIsInitialized = true;
return CHIP_NO_ERROR;
Expand Down
Loading

0 comments on commit 26ec08f

Please sign in to comment.