Skip to content

Commit 4ba315a

Browse files
committed
Move out common fabric-scoped table-like storage from SceneTableImpl to a templatized class, chip::common::FabricTableImpl, to allow re-use in other clusters (specifically, TlsClientManagementServer)
1 parent 09dd3ac commit 4ba315a

File tree

9 files changed

+1264
-854
lines changed

9 files changed

+1264
-854
lines changed

src/app/clusters/scenes-server/BUILD.gn

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ static_library("scenes") {
2727
"SceneTableImpl.h",
2828
]
2929

30-
deps = [ "${chip_root}/src/app" ]
30+
deps = [
31+
"${chip_root}/src/app",
32+
"${chip_root}/src/app/common:fabric-table"
33+
]
3134

3235
cflags = [
3336
"-Wconversion",

src/app/clusters/scenes-server/SceneTable.h

+34-58
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
#pragma once
1818

19+
#include <app/common/FabricTable.h>
1920
#include <app-common/zap-generated/cluster-objects.h>
2021
#include <app/clusters/scenes-server/ExtensionFieldSets.h>
2122
#include <lib/support/CHIPMemString.h>
@@ -28,13 +29,12 @@ namespace chip {
2829
namespace scenes {
2930

3031
// Storage index for scenes in nvm
31-
typedef uint16_t SceneIndex;
32+
typedef app::common::EntryIndex SceneIndex;
3233

3334
typedef uint32_t TransitionTimeMs;
3435
typedef uint32_t SceneTransitionTime;
3536

3637
inline constexpr GroupId kGlobalGroupSceneId = 0x0000;
37-
inline constexpr SceneIndex kUndefinedSceneIndex = 0xffff;
3838
inline constexpr SceneId kUndefinedSceneId = 0xff;
3939

4040
static constexpr size_t kIteratorsMax = CHIP_CONFIG_MAX_SCENES_CONCURRENT_ITERATORS;
@@ -127,10 +127,7 @@ class SceneHandler : public IntrusiveListNodeBase<>
127127
TransitionTimeMs timeMs) = 0;
128128
};
129129

130-
template <class EFStype>
131-
class SceneTable
132-
{
133-
public:
130+
namespace scene_table_elements {
134131
/// @brief struct used to identify a scene in storage by 3 ids, endpoint, group and scene
135132
struct SceneStorageId
136133
{
@@ -160,6 +157,7 @@ class SceneTable
160157
/// mExtensionFieldSets: class holding the different field sets of each cluster values to store with the scene
161158
/// mTransitionTime100ms: Transition time in tenths of a second, allows for more precise transition when combiened with
162159
/// mSceneTransitionTimeSeconds in enhanced scene commands
160+
template <class EFStype>
163161
struct SceneData
164162
{
165163
char mName[kSceneNameMaxLength] = { 0 };
@@ -221,54 +219,42 @@ class SceneTable
221219
mSceneTransitionTimeMs = other.mSceneTransitionTimeMs;
222220
}
223221
};
222+
} // namespace scene_table_elements
224223

225-
/// @brief Struct combining both ID and data of a table entry
226-
struct SceneTableEntry
227-
{
228-
// ID
229-
SceneStorageId mStorageId;
230-
231-
// DATA
232-
SceneData mStorageData;
233-
234-
SceneTableEntry() = default;
235-
SceneTableEntry(SceneStorageId id) : mStorageId(id) {}
236-
SceneTableEntry(const SceneStorageId id, const SceneData data) : mStorageId(id), mStorageData(data) {}
237-
238-
bool operator==(const SceneTableEntry & other) const
239-
{
240-
return (mStorageId == other.mStorageId && mStorageData == other.mStorageData);
241-
}
242-
243-
void operator=(const SceneTableEntry & other)
244-
{
245-
mStorageId = other.mStorageId;
246-
mStorageData = other.mStorageData;
247-
}
248-
};
224+
template <class EFStype>
225+
class SceneTable : public virtual app::common::FabricTable<scene_table_elements::SceneStorageId, scene_table_elements::SceneData<EFStype>>
226+
{
227+
public:
228+
using Super = app::common::FabricTable<scene_table_elements::SceneStorageId, scene_table_elements::SceneData<EFStype>>;
229+
using SceneTableEntry = typename Super::TableEntry;
230+
using SceneStorageId = scene_table_elements::SceneStorageId;
231+
using SceneData = scene_table_elements::SceneData<EFStype>;
249232

250233
SceneTable(){};
251234

252235
virtual ~SceneTable(){};
253236

254-
// Not copyable
255-
SceneTable(const SceneTable &) = delete;
256-
257-
SceneTable & operator=(const SceneTable &) = delete;
258-
259-
virtual CHIP_ERROR Init(PersistentStorageDelegate * storage) = 0;
260-
virtual void Finish() = 0;
261-
262237
// Global scene count
263-
virtual CHIP_ERROR GetEndpointSceneCount(uint8_t & scene_count) = 0;
264-
virtual CHIP_ERROR GetFabricSceneCount(FabricIndex fabric_index, uint8_t & scene_count) = 0;
238+
inline CHIP_ERROR GetEndpointSceneCount(uint8_t & scene_count) {
239+
return this->GetEndpointEntryCount(scene_count);
240+
}
241+
inline CHIP_ERROR GetFabricSceneCount(FabricIndex fabric_index, uint8_t & scene_count) {
242+
return this->GetFabricEntryCount(fabric_index, scene_count);
243+
}
265244

266245
// Data
267-
virtual CHIP_ERROR GetRemainingCapacity(FabricIndex fabric_index, uint8_t & capacity) = 0;
268-
virtual CHIP_ERROR SetSceneTableEntry(FabricIndex fabric_index, const SceneTableEntry & entry) = 0;
269-
virtual CHIP_ERROR GetSceneTableEntry(FabricIndex fabric_index, SceneStorageId scene_id, SceneTableEntry & entry) = 0;
270-
virtual CHIP_ERROR RemoveSceneTableEntry(FabricIndex fabric_index, SceneStorageId scene_id) = 0;
271-
virtual CHIP_ERROR RemoveSceneTableEntryAtPosition(EndpointId endpoint, FabricIndex fabric_index, SceneIndex scene_idx) = 0;
246+
inline CHIP_ERROR SetSceneTableEntry(FabricIndex fabric_index, const SceneTableEntry & entry) {
247+
return this->SetTableEntry(fabric_index, entry);
248+
}
249+
inline CHIP_ERROR GetSceneTableEntry(FabricIndex fabric_index, SceneStorageId scene_id, SceneTableEntry & entry) {
250+
return this->GetTableEntry(fabric_index, scene_id, entry);
251+
}
252+
inline CHIP_ERROR RemoveSceneTableEntry(FabricIndex fabric_index, SceneStorageId scene_id) {
253+
return this->RemoveTableEntry(fabric_index, scene_id);
254+
}
255+
inline CHIP_ERROR RemoveSceneTableEntryAtPosition(EndpointId endpoint, FabricIndex fabric_index, SceneIndex scene_idx) {
256+
return this->RemoveTableEntryAtPosition(endpoint, fabric_index, scene_idx);
257+
}
272258

273259
// Groups
274260
virtual CHIP_ERROR GetAllSceneIdsInGroup(FabricIndex fabric_index, GroupId group_id, Span<SceneId> & scene_list) = 0;
@@ -283,22 +269,12 @@ class SceneTable
283269
virtual CHIP_ERROR SceneSaveEFS(SceneTableEntry & scene) = 0;
284270
virtual CHIP_ERROR SceneApplyEFS(const SceneTableEntry & scene) = 0;
285271

286-
// Fabrics
287-
288-
/**
289-
* @brief Removes all scenes associated with a fabric index and the stored FabricSceneData that maps them
290-
* @param fabric_index Fabric index to remove
291-
* @return CHIP_ERROR, CHIP_NO_ERROR if successful or if the Fabric was not found, specific CHIP_ERROR otherwise
292-
* @note This function is meant to be used after a fabric is removed from the device, the implementation MUST ensure that it
293-
* won't interact with the actual fabric table as it will be removed beforehand.
294-
*/
295-
virtual CHIP_ERROR RemoveFabric(FabricIndex fabric_index) = 0;
296-
virtual CHIP_ERROR RemoveEndpoint() = 0;
297-
298272
// Iterators
299273
using SceneEntryIterator = CommonIterator<SceneTableEntry>;
300274

301-
virtual SceneEntryIterator * IterateSceneEntries(FabricIndex fabric_index) = 0;
275+
SceneEntryIterator * IterateSceneEntries(FabricIndex fabric_index) {
276+
return this->IterateTableEntries(fabric_index);
277+
}
302278

303279
// Handlers
304280
virtual bool HandlerListEmpty() { return mHandlerList.Empty(); }

0 commit comments

Comments
 (0)