Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/scene save efs dynamical array #27078

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions src/app/clusters/scenes-server/SceneTableImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,11 +737,17 @@ CHIP_ERROR DefaultSceneTableImpl::SceneSaveEFS(SceneTableEntry & scene)
{
if (!HandlerListEmpty())
{
uint8_t clusterCount = 0;
clusterId cArray[kMaxClustersPerScene];
Span<clusterId> cSpan(cArray);
clusterCount = GetClustersFromEndpoint(cArray, kMaxClustersPerScene);
cSpan.reduce_size(clusterCount);
uint8_t clusterCount = GetClusterCountFromEndpoint();
lpbeliveau-silabs marked this conversation as resolved.
Show resolved Hide resolved
clusterId * cBuffer = static_cast<clusterId *>(chip::Platform::MemoryCalloc(sizeof(clusterId), clusterCount));
VerifyOrReturnError(nullptr != cBuffer, CHIP_ERROR_NO_MEMORY);

clusterCount = GetClustersFromEndpoint(cBuffer, clusterCount);
chip::Platform::MemoryRealloc(cBuffer, clusterCount);
lpbeliveau-silabs marked this conversation as resolved.
Show resolved Hide resolved

// If there were no supported clusters on the endpoint, returns no error
VerifyOrReturnError(nullptr != cBuffer, CHIP_NO_ERROR);
lpbeliveau-silabs marked this conversation as resolved.
Show resolved Hide resolved

Span<clusterId> cSpan(cBuffer, clusterCount);
for (clusterId cluster : cSpan)
{
ExtensionFieldSet EFS;
Expand All @@ -752,13 +758,24 @@ CHIP_ERROR DefaultSceneTableImpl::SceneSaveEFS(SceneTableEntry & scene)
{
if (handler.SupportsCluster(mEndpointId, cluster))
{
ReturnErrorOnFailure(handler.SerializeSave(mEndpointId, EFS.mID, EFSSpan));
CHIP_ERROR err = handler.SerializeSave(mEndpointId, EFS.mID, EFSSpan);
if (CHIP_NO_ERROR != err)
{
chip::Platform::MemoryFree(cBuffer);
lpbeliveau-silabs marked this conversation as resolved.
Show resolved Hide resolved
return err;
}
EFS.mUsedBytes = static_cast<uint8_t>(EFSSpan.size());
ReturnErrorOnFailure(scene.mStorageData.mExtensionFieldSets.InsertFieldSet(EFS));
err = scene.mStorageData.mExtensionFieldSets.InsertFieldSet(EFS);
if (CHIP_NO_ERROR != err)
{
chip::Platform::MemoryFree(cBuffer);
return err;
}
break;
}
}
}
chip::Platform::MemoryFree(cBuffer);
}

return CHIP_NO_ERROR;
Expand Down Expand Up @@ -836,6 +853,14 @@ uint8_t DefaultSceneTableImpl::GetClustersFromEndpoint(ClusterId * clusterList,
return emberAfGetClustersFromEndpoint(mEndpointId, clusterList, listLen, true);
}

/// @brief wrapper function around emberAfGetClusterCountForEndpoint to allow testing enforcing a specific count, shimmed in test
/// configuration because emberAfGetClusterCountForEndpoint relies on <app/util/attribute-storage.h>, which relies on zap generated
/// files
uint8_t DefaultSceneTableImpl::GetClusterCountFromEndpoint()
{
return emberAfGetClusterCountForEndpoint(mEndpointId);
}

void DefaultSceneTableImpl::SetEndpoint(EndpointId endpoint)
{
mEndpointId = endpoint;
Expand Down
3 changes: 3 additions & 0 deletions src/app/clusters/scenes-server/SceneTableImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ class DefaultSceneTableImpl : public SceneTable<scenes::ExtensionFieldSetsImpl>
// wrapper function around emberAfGetClustersFromEndpoint to allow override when testing
virtual uint8_t GetClustersFromEndpoint(ClusterId * clusterList, uint8_t listLen);

// wrapper function around emberAfGetClusterCountForEndpoint to allow override when testing
virtual uint8_t GetClusterCountFromEndpoint();

class SceneEntryIteratorImpl : public SceneEntryIterator
{
public:
Expand Down
2 changes: 2 additions & 0 deletions src/app/tests/TestSceneTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ class TestSceneTableImpl : public SceneTableImpl

return 0;
}

uint8_t GetClusterCountFromEndpoint() override { return 3; }
};

// Storage
Expand Down
7 changes: 6 additions & 1 deletion src/app/util/mock/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ uint16_t emberAfIndexFromEndpoint(chip::EndpointId endpoint)
return UINT16_MAX;
}

uint8_t emberAfClusterCount(chip::EndpointId endpoint, bool server)
uint8_t emberAfGetClusterCountForEndpoint(chip::EndpointId endpoint)
{
for (size_t i = 0; i < ArraySize(endpoints); i++)
{
Expand All @@ -128,6 +128,11 @@ uint8_t emberAfClusterCount(chip::EndpointId endpoint, bool server)
return 0;
}

uint8_t emberAfClusterCount(chip::EndpointId endpoint, bool server)
{
return emberAfGetClusterCountForEndpoint(endpoint);
}

uint16_t emberAfGetServerAttributeCount(chip::EndpointId endpoint, chip::ClusterId cluster)
{
uint16_t endpointIndex = emberAfIndexFromEndpoint(endpoint);
Expand Down