From 10737310a3a52aad02ddff21951e25db18bc13b0 Mon Sep 17 00:00:00 2001 From: Jean-Francois Penven <67962328+jepenven-silabs@users.noreply.github.com> Date: Tue, 25 Jan 2022 12:24:37 -0500 Subject: [PATCH] [Group] Add GroupDataProvider Persistence (#13714) * Added persistence for GroupDataProvider --- src/app/server/BUILD.gn | 7 +++++++ src/app/server/Server.cpp | 8 ++++---- src/app/server/Server.h | 17 ++++++++--------- src/lib/support/TestPersistentStorageDelegate.h | 17 +++++++++++++++-- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/app/server/BUILD.gn b/src/app/server/BUILD.gn index 7a9d332d888b9f..380b0d6413d1aa 100644 --- a/src/app/server/BUILD.gn +++ b/src/app/server/BUILD.gn @@ -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") { diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 2f35404a01a55e..5721659da0a118 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -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) @@ -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); diff --git a/src/app/server/Server.h b/src/app/server/Server.h index 33c56610cded88..a10e5bcf4695df 100644 --- a/src/app/server/Server.h +++ b/src/app/server/Server.h @@ -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 { @@ -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 @@ -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; diff --git a/src/lib/support/TestPersistentStorageDelegate.h b/src/lib/support/TestPersistentStorageDelegate.h index 70c70fd12d56f4..bd05826f9e9048 100644 --- a/src/lib/support/TestPersistentStorageDelegate.h +++ b/src/lib/support/TestPersistentStorageDelegate.h @@ -19,6 +19,7 @@ #pragma once #include +#include #include #include #include @@ -27,8 +28,8 @@ #include namespace chip { - -class TestPersistentStorageDelegate : public PersistentStorageDelegate +// TODO : Remove FabricStorage dependency +class TestPersistentStorageDelegate : public PersistentStorageDelegate, public FabricStorage { public: TestPersistentStorageDelegate() {} @@ -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> mStorage; };