Skip to content

Further improvements to FabricTableImpl #38846

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

Merged
merged 1 commit into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/app/SafeAttributePersistenceProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class SafeAttributePersistenceProvider
* Read an attribute of type intX, uintX or bool from non-volatile memory.
*
* @param [in] aPath the attribute path for the data being persisted.
* @param [in,out] aValue where to place the data.
* @param [out] aValue where to place the data.
*
* @retval CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND if no stored value exists for the attribute
*/
Expand Down Expand Up @@ -112,7 +112,7 @@ class SafeAttributePersistenceProvider
* Read an attribute of type nullable intX, uintX from non-volatile memory.
*
* @param [in] aPath the attribute path for the data being persisted.
* @param [in,out] aValue where to place the data.
* @param [out] aValue where to place the data.
*
* @retval CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND if no stored value exists for the attribute
*/
Expand Down
3 changes: 1 addition & 2 deletions src/app/clusters/scenes-server/SceneTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <app/clusters/scenes-server/ExtensionFieldSets.h>
#include <app/storage/TableEntry.h>
#include <lib/support/CHIPMemString.h>
#include <lib/support/CommonIterator.h>
#include <lib/support/IntrusiveList.h>
#include <lib/support/PersistentData.h>
#include <lib/support/Span.h>
Expand Down Expand Up @@ -233,7 +232,7 @@ class SceneTable

SceneTable & operator=(const SceneTable &) = delete;

virtual CHIP_ERROR Init(PersistentStorageDelegate * storage) = 0;
virtual CHIP_ERROR Init(PersistentStorageDelegate & storage) = 0;
virtual void Finish() = 0;

// Global scene count
Expand Down
9 changes: 3 additions & 6 deletions src/app/clusters/scenes-server/SceneTableImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ StorageKeyName Serializer::FabricEntryDataKey(FabricIndex fabric, EndpointId end

// Worst case tested: Add Scene Command with EFS using the default SerializeAdd Method. This yielded a serialized scene of 175 bytes
// when using the OnOff, Level Control and Color Control as well as the maximal name length of 16 bytes. Putting 256 gives some
// slack in case different clusters are used. Value obtained by using writer.GetLengthWritten at the end of the SceneTableData
// slack in case different clusters are used. Value obtained by using writer.GetLengthWritten at the end of the Serializer
// Serialize method.
template <>
constexpr size_t Serializer::kEntryMaxBytes()
Expand Down Expand Up @@ -83,7 +83,7 @@ namespace {
/// kGroupId: Tag for GroupID if the Scene is a Group Scene
/// kSceneId: Tag for the scene ID. Together with kGroupId, forms the SceneStorageId
/// kName: Tag for the name of the scene
/// kTransitionTime: Tag for the transition time of the scene in miliseconds
/// kTransitionTime: Tag for the transition time of the scene in milliseconds
enum class TagScene : uint8_t
{
kGroupId = static_cast<uint8_t>(TagEntry::kFabricTableFirstSpecializationReservedTag),
Expand All @@ -93,13 +93,12 @@ enum class TagScene : uint8_t
};
} // namespace

using SceneTableData = TableEntryData<SceneStorageId, SceneData, Serializer::kEntryMaxBytes()>;
using FabricSceneData =
FabricEntryData<SceneStorageId, SceneData, Serializer::kEntryMaxBytes(), Serializer::kFabricMaxBytes(), kMaxScenesPerFabric>;

template class chip::app::Storage::FabricTableImpl<SceneTableBase::SceneStorageId, SceneTableBase::SceneData, kIteratorsMax>;

CHIP_ERROR DefaultSceneTableImpl::Init(PersistentStorageDelegate * storage)
CHIP_ERROR DefaultSceneTableImpl::Init(PersistentStorageDelegate & storage)
{
return FabricTableImpl::Init(storage);
}
Expand Down Expand Up @@ -156,7 +155,6 @@ CHIP_ERROR DefaultSceneTableImpl::GetAllSceneIdsInGroup(FabricIndex fabric_index
VerifyOrReturnError(IsInitialized(), CHIP_ERROR_INTERNAL);

FabricSceneData fabric(mEndpointId, fabric_index, mMaxPerFabric, mMaxPerEndpoint);
SceneTableData scene(mEndpointId, fabric_index);

uint8_t scene_count = 0;
CHIP_ERROR err = fabric.Load(this->mStorage);
Expand Down Expand Up @@ -190,7 +188,6 @@ CHIP_ERROR DefaultSceneTableImpl::DeleteAllScenesInGroup(FabricIndex fabric_inde
VerifyOrReturnError(IsInitialized(), CHIP_ERROR_INTERNAL);

FabricSceneData fabric(mEndpointId, fabric_index, mMaxPerFabric, mMaxPerEndpoint);
SceneTableData scene(mEndpointId, fabric_index);

CHIP_ERROR err = fabric.Load(this->mStorage);
VerifyOrReturnValue(CHIP_ERROR_NOT_FOUND != err, CHIP_NO_ERROR);
Expand Down
3 changes: 1 addition & 2 deletions src/app/clusters/scenes-server/SceneTableImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <app/util/attribute-storage.h>
#include <app/util/config.h>
#include <lib/core/DataModelTypes.h>
#include <lib/support/CommonIterator.h>
#include <lib/support/PersistentData.h>
#include <lib/support/Pool.h>

Expand Down Expand Up @@ -61,7 +60,7 @@ class DefaultSceneTableImpl
DefaultSceneTableImpl() : Super(kMaxScenesPerFabric, kMaxScenesPerEndpoint) {}
~DefaultSceneTableImpl() { Finish(); };

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

// Scene count
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/scenes-server/scenes-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ CHIP_ERROR ScenesServer::Init()
mGroupProvider = Credentials::GetGroupDataProvider();

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

mIsInitialized = true;
Expand Down
2 changes: 1 addition & 1 deletion src/app/icd/server/ICDMonitoringTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ enum class Fields : uint8_t
kClientType = 5,
};

CHIP_ERROR ICDMonitoringEntry::UpdateKey(StorageKeyName & skey)
CHIP_ERROR ICDMonitoringEntry::UpdateKey(StorageKeyName & skey) const
{
VerifyOrReturnError(kUndefinedFabricIndex != this->fabricIndex, CHIP_ERROR_INVALID_FABRIC_INDEX);
skey = DefaultStorageKeyAllocator::ICDManagementTableEntry(this->fabricIndex, index);
Expand Down
2 changes: 1 addition & 1 deletion src/app/icd/server/ICDMonitoringTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct ICDMonitoringEntry : public PersistentData<kICDMonitoringBufferSize>
this->symmetricKeystore = keyStore;
}

CHIP_ERROR UpdateKey(StorageKeyName & key) override;
CHIP_ERROR UpdateKey(StorageKeyName & key) const override;
CHIP_ERROR Serialize(TLV::TLVWriter & writer) const override;
CHIP_ERROR Deserialize(TLV::TLVReader & reader) override;
void Clear() override;
Expand Down
5 changes: 4 additions & 1 deletion src/app/storage/FabricTableImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#pragma once

#include <app/storage/TableEntry.h>
#include <lib/support/CommonIterator.h>
#include <lib/support/PersistentData.h>
#include <lib/support/TypeTraits.h>

namespace chip {
Expand All @@ -41,7 +44,7 @@ class FabricTableImpl
public:
virtual ~FabricTableImpl() { Finish(); };

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

// Entry count
Expand Down
Loading
Loading