diff --git a/src/app/clusters/scenes/SceneTable.h b/src/app/clusters/scenes/SceneTable.h index 1c3cbf3ccdbebb..df2008c37e9361 100644 --- a/src/app/clusters/scenes/SceneTable.h +++ b/src/app/clusters/scenes/SceneTable.h @@ -34,7 +34,7 @@ static constexpr uint8_t kMaxScenePerFabric = CHIP_CONFIG_SCENES_MAX_PER_FABRIC; class SceneTable { public: - static constexpr size_t kIteratorsMax = CHIP_CONFIG_MAX_GROUP_CONCURRENT_ITERATORS; + static constexpr size_t kIteratorsMax = CHIP_CONFIG_MAX_SCENES_CONCURRENT_ITERATORS; static constexpr size_t kSceneNameMax = CHIP_CONFIG_SCENES_CLUSTER_MAXIMUM_NAME_LENGTH; /// @brief struct used to identify a scene in storage by 3 ids, endpoint, group and scene diff --git a/src/app/tests/TestSceneTable.cpp b/src/app/tests/TestSceneTable.cpp index 284072201f8fe3..2ca7e5c4be4839 100644 --- a/src/app/tests/TestSceneTable.cpp +++ b/src/app/tests/TestSceneTable.cpp @@ -272,6 +272,8 @@ void TestIterateScenes(nlTestSuite * aSuite, void * aContext) SceneTableEntry scene; auto * iterator = sceneTable->IterateSceneEntry(kFabric1); + NL_TEST_ASSERT(aSuite, iterator != nullptr); + if (iterator) { NL_TEST_ASSERT(aSuite, iterator->Count() == 8); @@ -311,6 +313,7 @@ void TestRemoveScenes(nlTestSuite * aSuite, void * aContext) NL_TEST_ASSERT(aSuite, iterator->Count() == 7); NL_TEST_ASSERT(aSuite, iterator->Next(scene)); NL_TEST_ASSERT(aSuite, scene == scene10); + iterator->Release(); // Adde scene in middle, a spot should have been freed NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->SetSceneTableEntry(kFabric1, scene9)); @@ -318,6 +321,7 @@ void TestRemoveScenes(nlTestSuite * aSuite, void * aContext) NL_TEST_ASSERT(aSuite, iterator->Count() == 8); NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->GetSceneTableEntry(kFabric1, sceneId9, scene)); NL_TEST_ASSERT(aSuite, scene == scene9); + iterator->Release(); // Remove the recently added scene 9 NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene9.mStorageId)); @@ -325,6 +329,7 @@ void TestRemoveScenes(nlTestSuite * aSuite, void * aContext) NL_TEST_ASSERT(aSuite, iterator->Count() == 7); NL_TEST_ASSERT(aSuite, iterator->Next(scene)); NL_TEST_ASSERT(aSuite, scene == scene10); + iterator->Release(); // Remove first NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene1.mStorageId)); @@ -332,6 +337,7 @@ void TestRemoveScenes(nlTestSuite * aSuite, void * aContext) NL_TEST_ASSERT(aSuite, iterator->Count() == 6); NL_TEST_ASSERT(aSuite, iterator->Next(scene)); NL_TEST_ASSERT(aSuite, scene == scene2); + iterator->Release(); // Remove Next NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene3.mStorageId)); @@ -341,36 +347,42 @@ void TestRemoveScenes(nlTestSuite * aSuite, void * aContext) NL_TEST_ASSERT(aSuite, scene == scene2); NL_TEST_ASSERT(aSuite, iterator->Next(scene)); NL_TEST_ASSERT(aSuite, scene == scene4); + iterator->Release(); NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene2.mStorageId)); iterator = sceneTable->IterateSceneEntry(kFabric1); NL_TEST_ASSERT(aSuite, iterator->Count() == 4); NL_TEST_ASSERT(aSuite, iterator->Next(scene)); NL_TEST_ASSERT(aSuite, scene == scene4); + iterator->Release(); NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene4.mStorageId)); iterator = sceneTable->IterateSceneEntry(kFabric1); NL_TEST_ASSERT(aSuite, iterator->Count() == 3); NL_TEST_ASSERT(aSuite, iterator->Next(scene)); NL_TEST_ASSERT(aSuite, scene == scene6); + iterator->Release(); NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene6.mStorageId)); iterator = sceneTable->IterateSceneEntry(kFabric1); NL_TEST_ASSERT(aSuite, iterator->Count() == 2); NL_TEST_ASSERT(aSuite, iterator->Next(scene)); NL_TEST_ASSERT(aSuite, scene == scene7); + iterator->Release(); NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene7.mStorageId)); iterator = sceneTable->IterateSceneEntry(kFabric1); NL_TEST_ASSERT(aSuite, iterator->Count() == 1); NL_TEST_ASSERT(aSuite, iterator->Next(scene)); NL_TEST_ASSERT(aSuite, scene == scene12); + iterator->Release(); // Remove last NL_TEST_ASSERT(aSuite, CHIP_NO_ERROR == sceneTable->RemoveSceneTableEntry(kFabric1, scene8.mStorageId)); iterator = sceneTable->IterateSceneEntry(kFabric1); NL_TEST_ASSERT(aSuite, iterator->Count() == 0); NL_TEST_ASSERT(aSuite, iterator->Next(scene) == false); + iterator->Release(); NL_TEST_ASSERT(aSuite, CHIP_ERROR_NOT_FOUND == sceneTable->RemoveSceneTableEntry(kFabric1, scene8.mStorageId)); diff --git a/src/lib/core/CHIPConfig.h b/src/lib/core/CHIPConfig.h index 05976b1d73687c..6bbb1208c49b47 100644 --- a/src/lib/core/CHIPConfig.h +++ b/src/lib/core/CHIPConfig.h @@ -1427,6 +1427,17 @@ extern const char CHIP_NON_PRODUCTION_MARKER[]; #define CHIP_CONFIG_SCENES_MAX_EXTENSION_FIELDSET_SIZE_PER_CLUSTER 15 #endif +/** + * @def CHIP_CONFIG_MAX_SCENES_CONCURRENT_ITERATORS + * + * @brief Defines the number of simultaneous Scenes iterators that can be allocated + * + * Number of iterator instances that can be allocated at any one time + */ +#ifndef CHIP_CONFIG_MAX_SCENES_CONCURRENT_ITERATORS +#define CHIP_CONFIG_MAX_SCENES_CONCURRENT_ITERATORS 2 +#endif + /** * @} */