25
25
*/
26
26
27
27
#include " SMU2Manager.h"
28
+
28
29
#include < platform/CHIPDeviceLayer.h>
30
+ #include < platform/KeyValueStoreManager.h>
29
31
30
32
using namespace chip ::DeviceLayer;
31
33
using namespace chip ::DeviceLayer::Internal;
34
+ using namespace chip ::DeviceLayer::PersistedStorage;
32
35
33
36
namespace chip ::SMU2 {
34
37
namespace {
@@ -39,8 +42,6 @@ static const uint32_t AREA_SIZE = (AREA_END - AREA_START);
39
42
40
43
uint8_t mAreaId = 0 ;
41
44
42
- PersistentStorageDelegate * mStorage = nullptr ;
43
-
44
45
memAreaCfg_t mAreaDescriptor ;
45
46
bool mDeviceCommissioned = false ;
46
47
bool mUseAllocator = false ;
@@ -92,7 +93,7 @@ void EventHandler(const ChipDeviceEvent * event, intptr_t)
92
93
if (mDeviceCommissioned )
93
94
{
94
95
mUseAllocator = true ;
95
- mStorage -> SyncSetKeyValue (GetSMU2AllocatorKey ().KeyName (), (void *) &mUseAllocator , (uint16_t ) sizeof (mUseAllocator ));
96
+ KeyValueStoreMgr (). Put (GetSMU2AllocatorKey ().KeyName (), (void *) &mUseAllocator , (uint16_t ) sizeof (mUseAllocator ));
96
97
ResetBLEController ();
97
98
RegisterArea ();
98
99
}
@@ -103,22 +104,20 @@ void EventHandler(const ChipDeviceEvent * event, intptr_t)
103
104
104
105
} // anonymous namespace
105
106
106
- CHIP_ERROR Init (PersistentStorageDelegate * storage )
107
+ CHIP_ERROR Init ()
107
108
{
108
109
CHIP_ERROR err = CHIP_NO_ERROR;
109
110
uint16_t size = (uint16_t ) sizeof (mUseAllocator );
110
- mStorage = storage;
111
-
112
- VerifyOrReturnError (storage != nullptr , CHIP_ERROR_INCORRECT_STATE);
113
111
114
112
PlatformMgr ().AddEventHandler (EventHandler, reinterpret_cast <intptr_t >(nullptr ));
115
113
116
- err = mStorage ->SyncGetKeyValue (GetSMU2AllocatorKey ().KeyName (), (void *) &mUseAllocator , size);
114
+ size_t bytesRead = 0 ;
115
+ err = KeyValueStoreMgr ().Get (GetSMU2AllocatorKey ().KeyName (), (void *) &mUseAllocator , size, &bytesRead);
117
116
118
117
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
119
118
{
120
119
mUseAllocator = false ;
121
- err = mStorage -> SyncSetKeyValue (GetSMU2AllocatorKey ().KeyName (), (void *) &mUseAllocator , size);
120
+ err = KeyValueStoreMgr (). Put (GetSMU2AllocatorKey ().KeyName (), (void *) &mUseAllocator , size);
122
121
}
123
122
ReturnErrorOnFailure (err);
124
123
@@ -137,7 +136,7 @@ CHIP_ERROR Deactivate(void)
137
136
if (mUseAllocator )
138
137
{
139
138
mUseAllocator = false ;
140
- err = mStorage -> SyncDeleteKeyValue (GetSMU2AllocatorKey ().KeyName ());
139
+ err = KeyValueStoreMgr (). Delete (GetSMU2AllocatorKey ().KeyName ());
141
140
ReturnErrorOnFailure (err);
142
141
143
142
UnregisterArea ();
0 commit comments