Skip to content

Commit

Permalink
[Group] Add GroupDataProvider Persistence (#13714)
Browse files Browse the repository at this point in the history
* Added persistence for GroupDataProvider
  • Loading branch information
jepenven-silabs authored and pull[bot] committed Sep 22, 2023
1 parent 13fbd2f commit 2781175
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
7 changes: 7 additions & 0 deletions src/app/server/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ config("server_config") {
if (chip_enable_group_messaging_tests) {
defines += [ "CHIP_ENABLE_GROUP_MESSAGING_TESTS" ]
}

if (current_os == "mac" || current_os == "ios") {
# Using Non persistent storage delegate since
# persistence is also disable in Unit test for linux and MacOS
# Issue #12174 for Darwin
defines += [ "CHIP_USE_NON_PERSISTENT_STORAGE_DELEGATE" ]
}
}

static_library("server") {
Expand Down
8 changes: 4 additions & 4 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ Server::Server() :
.dnsCache = nullptr,
.devicePool = &mDevicePool,
.dnsResolver = nullptr,
}), mCommissioningWindowManager(this), mGroupsProvider(mGroupsStorage),
mAttributePersister(mServerStorage)
}), mCommissioningWindowManager(this), mGroupsProvider(mDeviceStorage),
mAttributePersister(mDeviceStorage)
{}

CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint16_t unsecureServicePort)
Expand Down Expand Up @@ -121,10 +121,10 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint

InitDataModelHandler(&mExchangeMgr);

err = mFabrics.Init(&mServerStorage);
err = mFabrics.Init(&mDeviceStorage);
SuccessOrExit(err);

// Group data provider must be initialized after mServerStorage
// Group data provider must be initialized after mDeviceStorage
err = mGroupsProvider.Init();
SuccessOrExit(err);
SetGroupDataProvider(&mGroupsProvider);
Expand Down
17 changes: 8 additions & 9 deletions src/app/server/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Server

static Server sServer;

class ServerStorageDelegate : public PersistentStorageDelegate, public FabricStorage
class DeviceStorageDelegate : public PersistentStorageDelegate, public FabricStorage
{
CHIP_ERROR SyncGetKeyValue(const char * key, void * buffer, uint16_t & size) override
{
Expand All @@ -114,16 +114,12 @@ class Server

CHIP_ERROR SyncSetKeyValue(const char * key, const void * value, uint16_t size) override
{
ReturnErrorOnFailure(DeviceLayer::PersistedStorage::KeyValueStoreMgr().Put(key, value, size));
ChipLogProgress(AppServer, "Saved into server storage: %s", key);
return CHIP_NO_ERROR;
return DeviceLayer::PersistedStorage::KeyValueStoreMgr().Put(key, value, size);
}

CHIP_ERROR SyncDeleteKeyValue(const char * key) override
{
ReturnErrorOnFailure(DeviceLayer::PersistedStorage::KeyValueStoreMgr().Delete(key));
ChipLogProgress(AppServer, "Deleted from server storage: %s", key);
return CHIP_NO_ERROR;
return DeviceLayer::PersistedStorage::KeyValueStoreMgr().Delete(key);
}

CHIP_ERROR SyncStore(FabricIndex fabricIndex, const char * key, const void * buffer, uint16_t size) override
Expand Down Expand Up @@ -163,10 +159,13 @@ class Server

// Both PersistentStorageDelegate, and GroupDataProvider should be injected by the applications
// See: https://github.com/project-chip/connectedhomeip/issues/12276
ServerStorageDelegate mServerStorage;
// Currently, the GroupDataProvider cannot use KeyValueStoreMgr() due to
// (https://github.com/project-chip/connectedhomeip/issues/12174)
TestPersistentStorageDelegate mGroupsStorage;
#ifdef CHIP_USE_NON_PERSISTENT_STORAGE_DELEGATE
TestPersistentStorageDelegate mDeviceStorage;
#else
DeviceStorageDelegate mDeviceStorage;
#endif
Credentials::GroupDataProviderImpl mGroupsProvider;
app::DefaultAttributePersistenceProvider mAttributePersister;

Expand Down
17 changes: 15 additions & 2 deletions src/lib/support/TestPersistentStorageDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include <algorithm>
#include <credentials/FabricTable.h>
#include <lib/core/CHIPCore.h>
#include <lib/core/CHIPPersistentStorageDelegate.h>
#include <lib/support/DLLUtil.h>
Expand All @@ -27,8 +28,8 @@
#include <vector>

namespace chip {

class TestPersistentStorageDelegate : public PersistentStorageDelegate
// TODO : Remove FabricStorage dependency
class TestPersistentStorageDelegate : public PersistentStorageDelegate, public FabricStorage
{
public:
TestPersistentStorageDelegate() {}
Expand Down Expand Up @@ -60,6 +61,18 @@ class TestPersistentStorageDelegate : public PersistentStorageDelegate
return CHIP_NO_ERROR;
}

CHIP_ERROR SyncStore(FabricIndex fabricIndex, const char * key, const void * buffer, uint16_t size) override
{
return SyncSetKeyValue(key, buffer, size);
};

CHIP_ERROR SyncLoad(FabricIndex fabricIndex, const char * key, void * buffer, uint16_t & size) override
{
return SyncGetKeyValue(key, buffer, size);
};

CHIP_ERROR SyncDelete(FabricIndex fabricIndex, const char * key) override { return SyncDeleteKeyValue(key); };

protected:
std::map<std::string, std::vector<uint8_t>> mStorage;
};
Expand Down

0 comments on commit 2781175

Please sign in to comment.