16
16
*/
17
17
#pragma once
18
18
19
+ #include < app/common/FabricTable.h>
19
20
#include < app-common/zap-generated/cluster-objects.h>
20
21
#include < app/clusters/scenes-server/ExtensionFieldSets.h>
21
22
#include < lib/support/CHIPMemString.h>
@@ -28,13 +29,12 @@ namespace chip {
28
29
namespace scenes {
29
30
30
31
// Storage index for scenes in nvm
31
- typedef uint16_t SceneIndex;
32
+ typedef app::common::EntryIndex SceneIndex;
32
33
33
34
typedef uint32_t TransitionTimeMs;
34
35
typedef uint32_t SceneTransitionTime;
35
36
36
37
inline constexpr GroupId kGlobalGroupSceneId = 0x0000 ;
37
- inline constexpr SceneIndex kUndefinedSceneIndex = 0xffff ;
38
38
inline constexpr SceneId kUndefinedSceneId = 0xff ;
39
39
40
40
static constexpr size_t kIteratorsMax = CHIP_CONFIG_MAX_SCENES_CONCURRENT_ITERATORS;
@@ -127,10 +127,7 @@ class SceneHandler : public IntrusiveListNodeBase<>
127
127
TransitionTimeMs timeMs) = 0;
128
128
};
129
129
130
- template <class EFStype >
131
- class SceneTable
132
- {
133
- public:
130
+ namespace scene_table_elements {
134
131
// / @brief struct used to identify a scene in storage by 3 ids, endpoint, group and scene
135
132
struct SceneStorageId
136
133
{
@@ -160,6 +157,7 @@ class SceneTable
160
157
// / mExtensionFieldSets: class holding the different field sets of each cluster values to store with the scene
161
158
// / mTransitionTime100ms: Transition time in tenths of a second, allows for more precise transition when combiened with
162
159
// / mSceneTransitionTimeSeconds in enhanced scene commands
160
+ template <class EFStype >
163
161
struct SceneData
164
162
{
165
163
char mName [kSceneNameMaxLength ] = { 0 };
@@ -221,54 +219,42 @@ class SceneTable
221
219
mSceneTransitionTimeMs = other.mSceneTransitionTimeMs ;
222
220
}
223
221
};
222
+ } // namespace scene_table_elements
224
223
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>;
249
232
250
233
SceneTable (){};
251
234
252
235
virtual ~SceneTable (){};
253
236
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
-
262
237
// 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
+ }
265
244
266
245
// 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
+ }
272
258
273
259
// Groups
274
260
virtual CHIP_ERROR GetAllSceneIdsInGroup (FabricIndex fabric_index, GroupId group_id, Span<SceneId> & scene_list) = 0;
@@ -283,22 +269,12 @@ class SceneTable
283
269
virtual CHIP_ERROR SceneSaveEFS (SceneTableEntry & scene) = 0;
284
270
virtual CHIP_ERROR SceneApplyEFS (const SceneTableEntry & scene) = 0;
285
271
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
-
298
272
// Iterators
299
273
using SceneEntryIterator = CommonIterator<SceneTableEntry>;
300
274
301
- virtual SceneEntryIterator * IterateSceneEntries (FabricIndex fabric_index) = 0;
275
+ SceneEntryIterator * IterateSceneEntries (FabricIndex fabric_index) {
276
+ return this ->IterateTableEntries (fabric_index);
277
+ }
302
278
303
279
// Handlers
304
280
virtual bool HandlerListEmpty () { return mHandlerList .Empty (); }
0 commit comments