Skip to content

Commit 9080cd3

Browse files
[NXP] Update smu2 manager api (project-chip#32799)
* [k32w1] Remove persistent storage delegate usage in SMU2 manager SMU2 manager can use the KeyValueStoreManager API directly, without needing a persistent storage delegate instance. Signed-off-by: marius-alex-tache <marius.tache@nxp.com> * [k32w1] Update SMU2 init usage in lighting app Signed-off-by: marius-alex-tache <marius.tache@nxp.com> --------- Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
1 parent 660c928 commit 9080cd3

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

examples/lighting-app/nxp/k32w/k32w1/main/AppTask.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void AppTask::InitServer(intptr_t arg)
236236
#endif
237237

238238
#if defined(USE_SMU2_DYNAMIC)
239-
VerifyOrDie(SMU2::Init(initParams.persistentStorageDelegate) == CHIP_NO_ERROR);
239+
VerifyOrDie(SMU2::Init() == CHIP_NO_ERROR);
240240
#endif
241241

242242
// Init ZCL Data Model and start server

src/platform/nxp/k32w/k32w1/SMU2Manager.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525
*/
2626

2727
#include "SMU2Manager.h"
28+
2829
#include <platform/CHIPDeviceLayer.h>
30+
#include <platform/KeyValueStoreManager.h>
2931

3032
using namespace chip::DeviceLayer;
3133
using namespace chip::DeviceLayer::Internal;
34+
using namespace chip::DeviceLayer::PersistedStorage;
3235

3336
namespace chip::SMU2 {
3437
namespace {
@@ -39,8 +42,6 @@ static const uint32_t AREA_SIZE = (AREA_END - AREA_START);
3942

4043
uint8_t mAreaId = 0;
4144

42-
PersistentStorageDelegate * mStorage = nullptr;
43-
4445
memAreaCfg_t mAreaDescriptor;
4546
bool mDeviceCommissioned = false;
4647
bool mUseAllocator = false;
@@ -92,7 +93,7 @@ void EventHandler(const ChipDeviceEvent * event, intptr_t)
9293
if (mDeviceCommissioned)
9394
{
9495
mUseAllocator = true;
95-
mStorage->SyncSetKeyValue(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, (uint16_t) sizeof(mUseAllocator));
96+
KeyValueStoreMgr().Put(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, (uint16_t) sizeof(mUseAllocator));
9697
ResetBLEController();
9798
RegisterArea();
9899
}
@@ -103,22 +104,20 @@ void EventHandler(const ChipDeviceEvent * event, intptr_t)
103104

104105
} // anonymous namespace
105106

106-
CHIP_ERROR Init(PersistentStorageDelegate * storage)
107+
CHIP_ERROR Init()
107108
{
108109
CHIP_ERROR err = CHIP_NO_ERROR;
109110
uint16_t size = (uint16_t) sizeof(mUseAllocator);
110-
mStorage = storage;
111-
112-
VerifyOrReturnError(storage != nullptr, CHIP_ERROR_INCORRECT_STATE);
113111

114112
PlatformMgr().AddEventHandler(EventHandler, reinterpret_cast<intptr_t>(nullptr));
115113

116-
err = mStorage->SyncGetKeyValue(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, size);
114+
size_t bytesRead = 0;
115+
err = KeyValueStoreMgr().Get(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, size, &bytesRead);
117116

118117
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
119118
{
120119
mUseAllocator = false;
121-
err = mStorage->SyncSetKeyValue(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, size);
120+
err = KeyValueStoreMgr().Put(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, size);
122121
}
123122
ReturnErrorOnFailure(err);
124123

@@ -137,7 +136,7 @@ CHIP_ERROR Deactivate(void)
137136
if (mUseAllocator)
138137
{
139138
mUseAllocator = false;
140-
err = mStorage->SyncDeleteKeyValue(GetSMU2AllocatorKey().KeyName());
139+
err = KeyValueStoreMgr().Delete(GetSMU2AllocatorKey().KeyName());
141140
ReturnErrorOnFailure(err);
142141

143142
UnregisterArea();

src/platform/nxp/k32w/k32w1/SMU2Manager.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@
2727
#pragma once
2828

2929
#include "fsl_component_mem_manager.h"
30-
#include <lib/core/CHIPPersistentStorageDelegate.h>
3130
#include <lib/support/DefaultStorageKeyAllocator.h>
3231

3332
namespace chip::SMU2 {
3433

35-
CHIP_ERROR Init(PersistentStorageDelegate * storage);
34+
CHIP_ERROR Init();
3635
CHIP_ERROR Deactivate(void);
3736
void * Allocate(size_t size);
3837

0 commit comments

Comments
 (0)