diff --git a/.github/workflows/java-tests.yaml b/.github/workflows/java-tests.yaml index 895e241e13dd10..c7730f2c27b32d 100644 --- a/.github/workflows/java-tests.yaml +++ b/.github/workflows/java-tests.yaml @@ -104,6 +104,8 @@ jobs: build \ " - name: Run Discover Commissionables Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_java_test.py \ @@ -115,6 +117,8 @@ jobs: --factoryreset \ ' - name: Run Pairing Onnetwork Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_java_test.py \ @@ -126,6 +130,8 @@ jobs: --factoryreset \ ' - name: Run IM Invoke Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_java_test.py \ @@ -137,6 +143,8 @@ jobs: --factoryreset \ ' - name: Run IM Extendable Invoke Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_java_test.py \ @@ -148,6 +156,8 @@ jobs: --factoryreset \ ' - name: Run IM Read Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_java_test.py \ @@ -159,6 +169,8 @@ jobs: --factoryreset \ ' - name: Run IM Write Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_java_test.py \ @@ -170,6 +182,8 @@ jobs: --factoryreset \ ' - name: Run IM Subscribe Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_java_test.py \ @@ -181,6 +195,8 @@ jobs: --factoryreset \ ' - name: Run Pairing AlreadyDiscovered Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_java_test.py \ @@ -205,6 +221,8 @@ jobs: --factoryreset \ ' - name: Run Pairing SetupQRCode Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_java_test.py \ @@ -216,6 +234,8 @@ jobs: --factoryreset \ ' - name: Run Pairing ManualCode Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_java_test.py \ @@ -227,6 +247,8 @@ jobs: --factoryreset \ ' - name: Run Pairing ICD Onnetwork Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_java_test.py \ @@ -252,6 +274,8 @@ jobs: --factoryreset \ ' - name: Run Pairing Onnetwork Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_kotlin_test.py \ @@ -263,6 +287,8 @@ jobs: --factoryreset \ ' - name: Run Kotlin IM Invoke Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_kotlin_test.py \ @@ -274,6 +300,8 @@ jobs: --factoryreset \ ' - name: Run Kotlin IM Read Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_kotlin_test.py \ @@ -285,6 +313,8 @@ jobs: --factoryreset \ ' - name: Run Kotlin IM Write Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_kotlin_test.py \ @@ -296,6 +326,8 @@ jobs: --factoryreset \ ' - name: Run Kotlin IM Subscribe Test + # Generally completes in seconds + timeout-minutes: 2 run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_kotlin_test.py \ diff --git a/docs/upgrading.md b/docs/upgrading.md index 517a83f6574dc9..e9e17239d50049 100644 --- a/docs/upgrading.md +++ b/docs/upgrading.md @@ -102,3 +102,8 @@ To preserve `codegen/zap` generated logic, use `CodegenDataModelProviderInstance` (see changes in [36558](https://github.com/project-chip/connectedhomeip/pull/36558) and [36613](https://github.com/project-chip/connectedhomeip/pull/36613) ). + +To use default attribute persistence, you need to pass in a +`PersistentStorageDelegate` to `CodegenDataModelProviderInstance`. See example +changes in [36658](https://github.com/project-chip/connectedhomeip/pull/36658) +). diff --git a/examples/air-purifier-app/ameba/main/chipinterface.cpp b/examples/air-purifier-app/ameba/main/chipinterface.cpp index 72563f987efdbe..368fa8eee05a8a 100644 --- a/examples/air-purifier-app/ameba/main/chipinterface.cpp +++ b/examples/air-purifier-app/ameba/main/chipinterface.cpp @@ -135,7 +135,7 @@ static void InitServer(intptr_t context) // Init ZCL Data Model and CHIP App Server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); #if CONFIG_ENABLE_AMEBA_CRYPTO ChipLogProgress(DeviceLayer, "platform crypto enabled!"); static chip::AmebaPersistentStorageOperationalKeystore sAmebaPersistentStorageOpKeystore; diff --git a/examples/air-purifier-app/cc32xx/main/AppTask.cpp b/examples/air-purifier-app/cc32xx/main/AppTask.cpp index e7527ef338f05a..a14ccbeff0a900 100644 --- a/examples/air-purifier-app/cc32xx/main/AppTask.cpp +++ b/examples/air-purifier-app/cc32xx/main/AppTask.cpp @@ -165,7 +165,7 @@ int AppTask::Init() PLAT_LOG("Initialize Server"); static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); // Initialize device attestation config diff --git a/examples/all-clusters-app/ameba/main/chipinterface.cpp b/examples/all-clusters-app/ameba/main/chipinterface.cpp index 06ba9f01cd8256..7ba25ed011cd41 100644 --- a/examples/all-clusters-app/ameba/main/chipinterface.cpp +++ b/examples/all-clusters-app/ameba/main/chipinterface.cpp @@ -150,7 +150,7 @@ static void InitServer(intptr_t context) initParams.appDelegate = &sAmebaObserver; initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); #if CONFIG_ENABLE_AMEBA_CRYPTO ChipLogProgress(DeviceLayer, "platform crypto enabled!"); diff --git a/examples/all-clusters-app/asr/BUILD.gn b/examples/all-clusters-app/asr/BUILD.gn index e27884810cbd8f..c9764e954189b2 100644 --- a/examples/all-clusters-app/asr/BUILD.gn +++ b/examples/all-clusters-app/asr/BUILD.gn @@ -111,6 +111,7 @@ asr_executable("clusters_app") { "${chip_root}/examples/all-clusters-app/all-clusters-common", "${chip_root}/examples/common/QRCode", "${chip_root}/examples/providers:device_info_provider", + "${chip_root}/src/app:attribute-persistence", "${chip_root}/src/lib", "${chip_root}/src/platform/logging:default", "${chip_root}/src/setup_payload", diff --git a/examples/all-clusters-app/infineon/psoc6/BUILD.gn b/examples/all-clusters-app/infineon/psoc6/BUILD.gn index aeb1fa0b6feb4d..bc250abd5c6e90 100644 --- a/examples/all-clusters-app/infineon/psoc6/BUILD.gn +++ b/examples/all-clusters-app/infineon/psoc6/BUILD.gn @@ -148,6 +148,7 @@ psoc6_executable("clusters_app") { "${chip_root}/examples/all-clusters-app/all-clusters-common", "${chip_root}/examples/common/QRCode", "${chip_root}/examples/providers:device_info_provider", + "${chip_root}/src/app:attribute-persistence", "${chip_root}/src/lib", "${chip_root}/src/platform/logging:default", "${chip_root}/src/setup_payload", diff --git a/examples/all-clusters-app/infineon/psoc6/src/AppTask.cpp b/examples/all-clusters-app/infineon/psoc6/src/AppTask.cpp index 3b127091f13277..3f56626cd97b59 100644 --- a/examples/all-clusters-app/infineon/psoc6/src/AppTask.cpp +++ b/examples/all-clusters-app/infineon/psoc6/src/AppTask.cpp @@ -130,7 +130,7 @@ static void InitServer(intptr_t context) // Init ZCL Data Model static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); // We only have network commissioning on endpoint 0. diff --git a/examples/all-clusters-app/linux/BUILD.gn b/examples/all-clusters-app/linux/BUILD.gn index 0e16c64c41de13..64dcf06e90736b 100644 --- a/examples/all-clusters-app/linux/BUILD.gn +++ b/examples/all-clusters-app/linux/BUILD.gn @@ -92,6 +92,7 @@ source_set("chip-all-clusters-common") { deps = [ "${chip_root}/examples/all-clusters-app/all-clusters-common", "${chip_root}/examples/platform/linux:app-main", + "${chip_root}/src/app:attribute-persistence", "${chip_root}/src/app/tests/suites/credentials:dac_provider", "${chip_root}/src/lib", "${chip_root}/third_party/jsoncpp", diff --git a/examples/all-clusters-app/linux/fuzzing-main.cpp b/examples/all-clusters-app/linux/fuzzing-main.cpp index 5056f08cce65f4..565e8198c26d25 100644 --- a/examples/all-clusters-app/linux/fuzzing-main.cpp +++ b/examples/all-clusters-app/linux/fuzzing-main.cpp @@ -57,7 +57,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t * aData, size_t aSize) // ChipLinuxAppMainLoop blocks, and we don't want that here. static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); VerifyOrDie(Server::GetInstance().Init(initParams) == CHIP_NO_ERROR); ApplicationInit(); diff --git a/examples/all-clusters-app/mbed/main/AppTask.cpp b/examples/all-clusters-app/mbed/main/AppTask.cpp index 98b8597ba43e5f..3a6686b517a78a 100644 --- a/examples/all-clusters-app/mbed/main/AppTask.cpp +++ b/examples/all-clusters-app/mbed/main/AppTask.cpp @@ -72,7 +72,7 @@ int AppTask::Init() // Init ZCL Data Model and start server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); error = Server::GetInstance().Init(initParams); if (error != CHIP_NO_ERROR) { diff --git a/examples/all-clusters-app/nrfconnect/main/AppTask.cpp b/examples/all-clusters-app/nrfconnect/main/AppTask.cpp index 9dcd4238240111..44a656279118a4 100644 --- a/examples/all-clusters-app/nrfconnect/main/AppTask.cpp +++ b/examples/all-clusters-app/nrfconnect/main/AppTask.cpp @@ -227,7 +227,7 @@ CHIP_ERROR AppTask::Init() initParams.operationalKeystore = &sPSAOperationalKeystore; #endif (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); AppFabricTableDelegate::Init(); diff --git a/examples/all-clusters-app/nxp/mw320/BUILD.gn b/examples/all-clusters-app/nxp/mw320/BUILD.gn index 89ba7f249719cc..73ea8cc02023ab 100644 --- a/examples/all-clusters-app/nxp/mw320/BUILD.gn +++ b/examples/all-clusters-app/nxp/mw320/BUILD.gn @@ -64,6 +64,7 @@ mw320_executable("shell_mw320") { ] deps = [ + "${chip_root}/src/app:attribute-persistence", "${chip_root}/src/platform:syscalls_stub", "${chip_root}/src/platform/logging:default", ] diff --git a/examples/all-clusters-app/nxp/mw320/main.cpp b/examples/all-clusters-app/nxp/mw320/main.cpp index bf0d6a282e9373..fbf99510c3cbfa 100644 --- a/examples/all-clusters-app/nxp/mw320/main.cpp +++ b/examples/all-clusters-app/nxp/mw320/main.cpp @@ -1069,7 +1069,7 @@ static void run_chip_srv(System::Layer * aSystemLayer, void * aAppState) static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); PRINTF("Done to call chip::Server() \r\n"); } diff --git a/examples/all-clusters-app/tizen/BUILD.gn b/examples/all-clusters-app/tizen/BUILD.gn index 332b03cbebaf00..59aac2228161d4 100644 --- a/examples/all-clusters-app/tizen/BUILD.gn +++ b/examples/all-clusters-app/tizen/BUILD.gn @@ -53,6 +53,7 @@ source_set("chip-all-clusters-common") { deps = [ "${chip_root}/examples/all-clusters-app/all-clusters-common", "${chip_root}/examples/platform/tizen:app-main", + "${chip_root}/src/app:attribute-persistence", "${chip_root}/src/lib/shell:shell_core", ] diff --git a/examples/all-clusters-minimal-app/ameba/main/chipinterface.cpp b/examples/all-clusters-minimal-app/ameba/main/chipinterface.cpp index cec1c457e04f04..7e2dc227f69b56 100644 --- a/examples/all-clusters-minimal-app/ameba/main/chipinterface.cpp +++ b/examples/all-clusters-minimal-app/ameba/main/chipinterface.cpp @@ -159,7 +159,7 @@ static void InitServer(intptr_t context) // Init ZCL Data Model and CHIP App Server static chip::CommonCaseDeviceServerInitParams initParams; initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); static AmebaObserver sAmebaObserver; initParams.appDelegate = &sAmebaObserver; diff --git a/examples/all-clusters-minimal-app/infineon/psoc6/src/AppTask.cpp b/examples/all-clusters-minimal-app/infineon/psoc6/src/AppTask.cpp index 29ad68b74241f1..893f585717dc9f 100644 --- a/examples/all-clusters-minimal-app/infineon/psoc6/src/AppTask.cpp +++ b/examples/all-clusters-minimal-app/infineon/psoc6/src/AppTask.cpp @@ -128,7 +128,7 @@ static void InitServer(intptr_t context) // Init ZCL Data Model static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); // We only have network commissioning on endpoint 0. diff --git a/examples/all-clusters-minimal-app/linux/fuzzing-main.cpp b/examples/all-clusters-minimal-app/linux/fuzzing-main.cpp index ccd2ffa782b4dd..df61dc538ad10c 100644 --- a/examples/all-clusters-minimal-app/linux/fuzzing-main.cpp +++ b/examples/all-clusters-minimal-app/linux/fuzzing-main.cpp @@ -44,7 +44,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t * aData, size_t aSize) // ChipLinuxAppMainLoop blocks, and we don't want that here. static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); VerifyOrDie(Server::GetInstance().Init(initParams) == CHIP_NO_ERROR); ApplicationInit(); diff --git a/examples/all-clusters-minimal-app/mbed/main/AppTask.cpp b/examples/all-clusters-minimal-app/mbed/main/AppTask.cpp index e516aee49e6e74..16e1a665da4518 100644 --- a/examples/all-clusters-minimal-app/mbed/main/AppTask.cpp +++ b/examples/all-clusters-minimal-app/mbed/main/AppTask.cpp @@ -68,7 +68,7 @@ int AppTask::Init() // Init ZCL Data Model and start server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); error = Server::GetInstance().Init(initParams); if (error != CHIP_NO_ERROR) { diff --git a/examples/all-clusters-minimal-app/nrfconnect/main/AppTask.cpp b/examples/all-clusters-minimal-app/nrfconnect/main/AppTask.cpp index 8d9771fa593204..7cad0ac8a13a00 100644 --- a/examples/all-clusters-minimal-app/nrfconnect/main/AppTask.cpp +++ b/examples/all-clusters-minimal-app/nrfconnect/main/AppTask.cpp @@ -174,7 +174,7 @@ CHIP_ERROR AppTask::Init() initParams.operationalKeystore = &sPSAOperationalKeystore; #endif (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); AppFabricTableDelegate::Init(); diff --git a/examples/chef/ameba/main/chipinterface.cpp b/examples/chef/ameba/main/chipinterface.cpp index 6b772bdba6977b..e54572c9be1fb0 100644 --- a/examples/chef/ameba/main/chipinterface.cpp +++ b/examples/chef/ameba/main/chipinterface.cpp @@ -106,7 +106,7 @@ static void InitServer(intptr_t context) // Init ZCL Data Model and CHIP App Server static chip::CommonCaseDeviceServerInitParams initParams; initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); static AmebaObserver sAmebaObserver; initParams.appDelegate = &sAmebaObserver; diff --git a/examples/chef/esp32/main/main.cpp b/examples/chef/esp32/main/main.cpp index ef5dd73dcabcf3..29de25b804d59a 100644 --- a/examples/chef/esp32/main/main.cpp +++ b/examples/chef/esp32/main/main.cpp @@ -160,7 +160,7 @@ void InitServer(intptr_t) // Start IM server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); // Device Attestation & Onboarding codes diff --git a/examples/chef/nrfconnect/main.cpp b/examples/chef/nrfconnect/main.cpp index e7e706409ff421..fa8cfc3820032b 100644 --- a/examples/chef/nrfconnect/main.cpp +++ b/examples/chef/nrfconnect/main.cpp @@ -126,7 +126,7 @@ int main() initParams.operationalKeystore = &sPSAOperationalKeystore; #endif (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); err = chip::Server::GetInstance().Init(initParams); if (err != CHIP_NO_ERROR) { diff --git a/examples/chip-tool/commands/common/CHIPCommand.cpp b/examples/chip-tool/commands/common/CHIPCommand.cpp index ffa873b49730f4..b37bed15afb3d7 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.cpp +++ b/examples/chip-tool/commands/common/CHIPCommand.cpp @@ -138,7 +138,7 @@ CHIP_ERROR CHIPCommand::MaybeSetUpStack() factoryInitParams.opCertStore = &mOpCertStore; factoryInitParams.enableServerInteractions = NeedsOperationalAdvertising(); factoryInitParams.sessionKeystore = &sSessionKeystore; - factoryInitParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(); + factoryInitParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(&mDefaultStorage); // Init group data provider that will be used for all group keys and IPKs for the // chip-tool-configured fabrics. This is OK to do once since the fabric tables diff --git a/examples/contact-sensor-app/nxp/k32w0/main/AppTask.cpp b/examples/contact-sensor-app/nxp/k32w0/main/AppTask.cpp index 5eb7696fc69b7d..9beea7e0487814 100644 --- a/examples/contact-sensor-app/nxp/k32w0/main/AppTask.cpp +++ b/examples/contact-sensor-app/nxp/k32w0/main/AppTask.cpp @@ -299,7 +299,7 @@ void AppTask::InitServer(intptr_t arg) { static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); auto & infoProvider = chip::DeviceLayer::DeviceInfoProviderImpl::GetDefaultInstance(); infoProvider.SetStorageDelegate(initParams.persistentStorageDelegate); diff --git a/examples/energy-management-app/linux/BUILD.gn b/examples/energy-management-app/linux/BUILD.gn index e742c05d692296..5fd24008e4f859 100644 --- a/examples/energy-management-app/linux/BUILD.gn +++ b/examples/energy-management-app/linux/BUILD.gn @@ -64,6 +64,7 @@ executable("chip-energy-management-app") { deps = [ "${chip_root}/examples/energy-management-app/energy-management-common", "${chip_root}/examples/platform/linux:app-main", + "${chip_root}/src/app:attribute-persistence", "${chip_root}/src/lib", ] diff --git a/examples/energy-management-app/silabs/BUILD.gn b/examples/energy-management-app/silabs/BUILD.gn index 1ed8a4473bd0d6..e15a377c9af8b0 100644 --- a/examples/energy-management-app/silabs/BUILD.gn +++ b/examples/energy-management-app/silabs/BUILD.gn @@ -195,6 +195,7 @@ silabs_executable("energy-management-app") { deps = [ ":sdk", + "${chip_root}/src/app:attribute-persistence", app_data_model, ] diff --git a/examples/fabric-admin/commands/common/CHIPCommand.cpp b/examples/fabric-admin/commands/common/CHIPCommand.cpp index 1f761fcbbeff8f..bf8da172d3aa1f 100644 --- a/examples/fabric-admin/commands/common/CHIPCommand.cpp +++ b/examples/fabric-admin/commands/common/CHIPCommand.cpp @@ -123,7 +123,7 @@ CHIP_ERROR CHIPCommand::MaybeSetUpStack() factoryInitParams.opCertStore = &mOpCertStore; factoryInitParams.enableServerInteractions = NeedsOperationalAdvertising(); factoryInitParams.sessionKeystore = &sSessionKeystore; - factoryInitParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(); + factoryInitParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(&mDefaultStorage); // Init group data provider that will be used for all group keys and IPKs for the // fabric-admin-configured fabrics. This is OK to do once since the fabric tables diff --git a/examples/light-switch-app/ameba/main/chipinterface.cpp b/examples/light-switch-app/ameba/main/chipinterface.cpp index 84fd4f86e31209..e892030933d06e 100644 --- a/examples/light-switch-app/ameba/main/chipinterface.cpp +++ b/examples/light-switch-app/ameba/main/chipinterface.cpp @@ -105,7 +105,7 @@ static void InitServer(intptr_t context) // Init ZCL Data Model and CHIP App Server static chip::CommonCaseDeviceServerInitParams initParams; initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); #if CONFIG_ENABLE_AMEBA_CRYPTO ChipLogProgress(DeviceLayer, "platform crypto enabled!"); static chip::AmebaPersistentStorageOperationalKeystore sAmebaPersistentStorageOpKeystore; diff --git a/examples/light-switch-app/cc13x4_26x4/src/AppTask.cpp b/examples/light-switch-app/cc13x4_26x4/src/AppTask.cpp index 3e2865b7b4c54b..31855e1621f7fe 100644 --- a/examples/light-switch-app/cc13x4_26x4/src/AppTask.cpp +++ b/examples/light-switch-app/cc13x4_26x4/src/AppTask.cpp @@ -325,7 +325,7 @@ int AppTask::Init() static DefaultTestEventTriggerDelegate sTestEventTriggerDelegate{ ByteSpan(sTestEventTriggerEnableKey) }; initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); // Initialize info provider sExampleDeviceInfoProvider.SetStorageDelegate(initParams.persistentStorageDelegate); diff --git a/examples/light-switch-app/genio/src/AppTask.cpp b/examples/light-switch-app/genio/src/AppTask.cpp index ed331c5c1c2fb1..2b3000e2ff9eb6 100644 --- a/examples/light-switch-app/genio/src/AppTask.cpp +++ b/examples/light-switch-app/genio/src/AppTask.cpp @@ -125,7 +125,7 @@ CHIP_ERROR AppTask::Init() // Init ZCL Data Model and start server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); // Initialize device attestation config diff --git a/examples/light-switch-app/nrfconnect/main/AppTask.cpp b/examples/light-switch-app/nrfconnect/main/AppTask.cpp index c10da5aba96f81..7f9ec93e05576a 100644 --- a/examples/light-switch-app/nrfconnect/main/AppTask.cpp +++ b/examples/light-switch-app/nrfconnect/main/AppTask.cpp @@ -236,7 +236,7 @@ CHIP_ERROR AppTask::Init() initParams.operationalKeystore = &sPSAOperationalKeystore; #endif (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); AppFabricTableDelegate::Init(); diff --git a/examples/light-switch-app/qpg/src/AppTask.cpp b/examples/light-switch-app/qpg/src/AppTask.cpp index 2b1a49a51dd8a3..1b57f10240ceaa 100644 --- a/examples/light-switch-app/qpg/src/AppTask.cpp +++ b/examples/light-switch-app/qpg/src/AppTask.cpp @@ -220,7 +220,7 @@ void AppTask::InitServer(intptr_t arg) VerifyOrDie(sTestEventTriggerDelegate.Init(ByteSpan(sTestEventTriggerEnableKey)) == CHIP_NO_ERROR); VerifyOrDie(sTestEventTriggerDelegate.AddHandler(&sFaultTestEventTriggerHandler) == CHIP_NO_ERROR); (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; chip::Server::GetInstance().Init(initParams); diff --git a/examples/lighting-app/ameba/main/chipinterface.cpp b/examples/lighting-app/ameba/main/chipinterface.cpp index c98545110e0acb..a12853e94de73d 100644 --- a/examples/lighting-app/ameba/main/chipinterface.cpp +++ b/examples/lighting-app/ameba/main/chipinterface.cpp @@ -125,7 +125,7 @@ static void InitServer(intptr_t context) // Init ZCL Data Model and CHIP App Server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); #if CONFIG_ENABLE_AMEBA_CRYPTO ChipLogProgress(DeviceLayer, "platform crypto enabled!"); static chip::AmebaPersistentStorageOperationalKeystore sAmebaPersistentStorageOpKeystore; diff --git a/examples/lighting-app/cc13x4_26x4/src/AppTask.cpp b/examples/lighting-app/cc13x4_26x4/src/AppTask.cpp index da48f6545dc2d8..3e949dc7ba3b57 100644 --- a/examples/lighting-app/cc13x4_26x4/src/AppTask.cpp +++ b/examples/lighting-app/cc13x4_26x4/src/AppTask.cpp @@ -316,7 +316,7 @@ int AppTask::Init() initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); // Initialize info provider sExampleDeviceInfoProvider.SetStorageDelegate(initParams.persistentStorageDelegate); diff --git a/examples/lighting-app/genio/src/AppTask.cpp b/examples/lighting-app/genio/src/AppTask.cpp index b07d4ee3d9a0b2..c5fa913e85d948 100644 --- a/examples/lighting-app/genio/src/AppTask.cpp +++ b/examples/lighting-app/genio/src/AppTask.cpp @@ -325,7 +325,7 @@ CHIP_ERROR AppTask::Init() // Init ZCL Data Model and start server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); // Initialize device attestation config diff --git a/examples/lighting-app/infineon/psoc6/src/AppTask.cpp b/examples/lighting-app/infineon/psoc6/src/AppTask.cpp index 0615b511888c3a..07c3024c0797ef 100644 --- a/examples/lighting-app/infineon/psoc6/src/AppTask.cpp +++ b/examples/lighting-app/infineon/psoc6/src/AppTask.cpp @@ -144,7 +144,7 @@ static void InitServer(intptr_t context) // Init ZCL Data Model static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); diff --git a/examples/lighting-app/mbed/main/AppTask.cpp b/examples/lighting-app/mbed/main/AppTask.cpp index ce4d45a3aa9758..bcae9d972f40fe 100644 --- a/examples/lighting-app/mbed/main/AppTask.cpp +++ b/examples/lighting-app/mbed/main/AppTask.cpp @@ -117,7 +117,7 @@ int AppTask::Init() // Init ZCL Data Model and start server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); error = Server::GetInstance().Init(initParams); if (error != CHIP_NO_ERROR) diff --git a/examples/lighting-app/nrfconnect/main/AppTask.cpp b/examples/lighting-app/nrfconnect/main/AppTask.cpp index b8464779d73f12..1427b811edb183 100644 --- a/examples/lighting-app/nrfconnect/main/AppTask.cpp +++ b/examples/lighting-app/nrfconnect/main/AppTask.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -112,7 +113,10 @@ chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; // be written, so it must live so long as the DeferredAttributePersistenceProvider object. DeferredAttribute gCurrentLevelPersister(ConcreteAttributePath(kLightEndpointId, Clusters::LevelControl::Id, Clusters::LevelControl::Attributes::CurrentLevel::Id)); -DeferredAttributePersistenceProvider gDeferredAttributePersister(Server::GetInstance().GetDefaultAttributePersister(), + +// Deferred persistence will be auto-initialized as soon as the default persistence is initialized +DefaultAttributePersistenceProvider gSimpleAttributePersistence; +DeferredAttributePersistenceProvider gDeferredAttributePersister(gSimpleAttributePersistence, Span(&gCurrentLevelPersister, 1), System::Clock::Milliseconds32(5000)); @@ -263,7 +267,9 @@ CHIP_ERROR AppTask::Init() initParams.operationalKeystore = &sPSAOperationalKeystore; #endif (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + VerifyOrDie(gSimpleAttributePersistence.Init(initParams.persistentStorageDelegate) == CHIP_NO_ERROR); + + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); AppFabricTableDelegate::Init(); diff --git a/examples/lighting-app/nxp/k32w0/main/AppTask.cpp b/examples/lighting-app/nxp/k32w0/main/AppTask.cpp index 191bfb9d0bf547..7c0f895845146b 100644 --- a/examples/lighting-app/nxp/k32w0/main/AppTask.cpp +++ b/examples/lighting-app/nxp/k32w0/main/AppTask.cpp @@ -283,7 +283,7 @@ void AppTask::InitServer(intptr_t arg) { static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); auto & infoProvider = chip::DeviceLayer::DeviceInfoProviderImpl::GetDefaultInstance(); infoProvider.SetStorageDelegate(initParams.persistentStorageDelegate); diff --git a/examples/lighting-app/qpg/src/AppTask.cpp b/examples/lighting-app/qpg/src/AppTask.cpp index 1047968ffe6f9d..27386a625be497 100644 --- a/examples/lighting-app/qpg/src/AppTask.cpp +++ b/examples/lighting-app/qpg/src/AppTask.cpp @@ -29,8 +29,6 @@ #include "AppTask.h" #include "ota.h" -#include - #include #include #include @@ -38,6 +36,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -114,7 +116,9 @@ DeferredAttribute gPersisters[] = { }; -DeferredAttributePersistenceProvider gDeferredAttributePersister(Server::GetInstance().GetDefaultAttributePersister(), +// Deferred persistence will be auto-initialized as soon as the default persistence is initialized +DefaultAttributePersistenceProvider gSimpleAttributePersistence; +DeferredAttributePersistenceProvider gDeferredAttributePersister(gSimpleAttributePersistence, Span(gPersisters, 3), System::Clock::Milliseconds32(5000)); @@ -122,12 +126,10 @@ DeferredAttributePersistenceProvider gDeferredAttributePersister(Server::GetInst * Identify Callbacks *********************************************************/ -namespace { void OnTriggerIdentifyEffectCompleted(chip::System::Layer * systemLayer, void * appState) { sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect; } -} // namespace void OnTriggerIdentifyEffect(Identify * identify) { @@ -259,7 +261,9 @@ void AppTask::InitServer(intptr_t arg) static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); + VerifyOrDie(gSimpleAttributePersistence.Init(initParams.persistentStorageDelegate) == CHIP_NO_ERROR); gExampleDeviceInfoProvider.SetStorageDelegate(initParams.persistentStorageDelegate); + chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); chip::Inet::EndPointStateOpenThread::OpenThreadEndpointInitParam nativeParams; @@ -274,7 +278,7 @@ void AppTask::InitServer(intptr_t arg) VerifyOrDie(sTestEventTriggerDelegate.Init(ByteSpan(sTestEventTriggerEnableKey)) == CHIP_NO_ERROR); VerifyOrDie(sTestEventTriggerDelegate.AddHandler(&sFaultTestEventTriggerHandler) == CHIP_NO_ERROR); (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; chip::Server::GetInstance().Init(initParams); diff --git a/examples/lighting-app/stm32/src/STM32WB5/AppTask.cpp b/examples/lighting-app/stm32/src/STM32WB5/AppTask.cpp index 49649144b9666b..be4a3c4984c307 100644 --- a/examples/lighting-app/stm32/src/STM32WB5/AppTask.cpp +++ b/examples/lighting-app/stm32/src/STM32WB5/AppTask.cpp @@ -153,7 +153,7 @@ CHIP_ERROR AppTask::Init() // Init ZCL Data Model static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); ReturnErrorOnFailure(mFactoryDataProvider.Init()); SetDeviceInstanceInfoProvider(&mFactoryDataProvider); SetCommissionableDataProvider(&mFactoryDataProvider); diff --git a/examples/lit-icd-app/nrfconnect/main/AppTask.cpp b/examples/lit-icd-app/nrfconnect/main/AppTask.cpp index 642947329579a5..49947fe9da3ef9 100644 --- a/examples/lit-icd-app/nrfconnect/main/AppTask.cpp +++ b/examples/lit-icd-app/nrfconnect/main/AppTask.cpp @@ -205,7 +205,7 @@ CHIP_ERROR AppTask::Init() initParams.operationalKeystore = &sPSAOperationalKeystore; #endif (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); AppFabricTableDelegate::Init(); diff --git a/examples/lock-app/cc13x4_26x4/src/AppTask.cpp b/examples/lock-app/cc13x4_26x4/src/AppTask.cpp index fd99c0c0c6990b..4a6e9466a0dc2d 100644 --- a/examples/lock-app/cc13x4_26x4/src/AppTask.cpp +++ b/examples/lock-app/cc13x4_26x4/src/AppTask.cpp @@ -309,7 +309,7 @@ int AppTask::Init() initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); // Initialize info provider sExampleDeviceInfoProvider.SetStorageDelegate(initParams.persistentStorageDelegate); diff --git a/examples/lock-app/cc32xx/main/AppTask.cpp b/examples/lock-app/cc32xx/main/AppTask.cpp index d610325b54a3fe..b783a862875fcd 100644 --- a/examples/lock-app/cc32xx/main/AppTask.cpp +++ b/examples/lock-app/cc32xx/main/AppTask.cpp @@ -152,7 +152,7 @@ int AppTask::Init() PLAT_LOG("Initialize Server"); static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); // Initialize device attestation config diff --git a/examples/lock-app/genio/src/AppTask.cpp b/examples/lock-app/genio/src/AppTask.cpp index fad169f9100abd..6897792d2ed4b7 100644 --- a/examples/lock-app/genio/src/AppTask.cpp +++ b/examples/lock-app/genio/src/AppTask.cpp @@ -138,7 +138,7 @@ CHIP_ERROR AppTask::Init() // Init ZCL Data Model and start server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); // Initialize device attestation config diff --git a/examples/lock-app/infineon/psoc6/src/AppTask.cpp b/examples/lock-app/infineon/psoc6/src/AppTask.cpp index 65ea49e769f681..6ce6f57315267b 100644 --- a/examples/lock-app/infineon/psoc6/src/AppTask.cpp +++ b/examples/lock-app/infineon/psoc6/src/AppTask.cpp @@ -156,7 +156,7 @@ static void InitServer(intptr_t context) // Init ZCL Data Model static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); diff --git a/examples/lock-app/mbed/main/AppTask.cpp b/examples/lock-app/mbed/main/AppTask.cpp index bfa4ae73c0b258..5e29d76b546e3f 100644 --- a/examples/lock-app/mbed/main/AppTask.cpp +++ b/examples/lock-app/mbed/main/AppTask.cpp @@ -120,7 +120,7 @@ int AppTask::Init() // Init ZCL Data Model and start server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); error = Server::GetInstance().Init(initParams); if (error != CHIP_NO_ERROR) diff --git a/examples/lock-app/nrfconnect/main/AppTask.cpp b/examples/lock-app/nrfconnect/main/AppTask.cpp index a495ca68334d39..3a9d375d80b86a 100644 --- a/examples/lock-app/nrfconnect/main/AppTask.cpp +++ b/examples/lock-app/nrfconnect/main/AppTask.cpp @@ -230,7 +230,7 @@ CHIP_ERROR AppTask::Init() initParams.operationalKeystore = &sPSAOperationalKeystore; #endif (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); AppFabricTableDelegate::Init(); diff --git a/examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp b/examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp index 14e7128791b5db..6faccbffd0d593 100644 --- a/examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp +++ b/examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp @@ -192,7 +192,7 @@ void AppTask::InitServer(intptr_t arg) { static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); auto & infoProvider = chip::DeviceLayer::DeviceInfoProviderImpl::GetDefaultInstance(); infoProvider.SetStorageDelegate(initParams.persistentStorageDelegate); diff --git a/examples/lock-app/qpg/src/AppTask.cpp b/examples/lock-app/qpg/src/AppTask.cpp index 74f6546f12ba04..cba2bfe569aa39 100644 --- a/examples/lock-app/qpg/src/AppTask.cpp +++ b/examples/lock-app/qpg/src/AppTask.cpp @@ -203,7 +203,7 @@ void AppTask::InitServer(intptr_t arg) { static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); gExampleDeviceInfoProvider.SetStorageDelegate(initParams.persistentStorageDelegate); chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); @@ -220,7 +220,7 @@ void AppTask::InitServer(intptr_t arg) VerifyOrDie(sTestEventTriggerDelegate.Init(ByteSpan(sTestEventTriggerEnableKey)) == CHIP_NO_ERROR); VerifyOrDie(sTestEventTriggerDelegate.AddHandler(&sFaultTestEventTriggerHandler) == CHIP_NO_ERROR); (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; chip::Server::GetInstance().Init(initParams); diff --git a/examples/log-source-app/linux/main.cpp b/examples/log-source-app/linux/main.cpp index fc46923f682143..a507d44741173b 100644 --- a/examples/log-source-app/linux/main.cpp +++ b/examples/log-source-app/linux/main.cpp @@ -106,7 +106,7 @@ int main(int argc, char * argv[]) chip::DeviceLayer::ConfigurationMgr().LogDeviceConfig(); static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); // Initialize device attestation config diff --git a/examples/ota-requestor-app/ameba/main/chipinterface.cpp b/examples/ota-requestor-app/ameba/main/chipinterface.cpp index 115441a2f9fd92..2a4dc911e6537c 100644 --- a/examples/ota-requestor-app/ameba/main/chipinterface.cpp +++ b/examples/ota-requestor-app/ameba/main/chipinterface.cpp @@ -79,7 +79,7 @@ static void InitServer(intptr_t context) static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); static AmebaObserver sAmebaObserver; - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.appDelegate = &sAmebaObserver; chip::Server::GetInstance().Init(initParams); gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); diff --git a/examples/ota-requestor-app/genio/src/AppTask.cpp b/examples/ota-requestor-app/genio/src/AppTask.cpp index 424d7b20cb0694..5130c5cf9a7c61 100644 --- a/examples/ota-requestor-app/genio/src/AppTask.cpp +++ b/examples/ota-requestor-app/genio/src/AppTask.cpp @@ -108,7 +108,7 @@ CHIP_ERROR AppTask::Init() // Init ZCL Data Model and start server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); // We only have network commissioning on endpoint 0. diff --git a/examples/ota-requestor-app/mbed/main/AppTask.cpp b/examples/ota-requestor-app/mbed/main/AppTask.cpp index 90436d57296acd..5b136311903079 100644 --- a/examples/ota-requestor-app/mbed/main/AppTask.cpp +++ b/examples/ota-requestor-app/mbed/main/AppTask.cpp @@ -107,7 +107,7 @@ int AppTask::Init() // Init ZCL Data Model and start server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); error = Server::GetInstance().Init(initParams); if (error != CHIP_NO_ERROR) diff --git a/examples/platform/asr/init_Matter.cpp b/examples/platform/asr/init_Matter.cpp index 8280618c2668e1..864823001ab53e 100644 --- a/examples/platform/asr/init_Matter.cpp +++ b/examples/platform/asr/init_Matter.cpp @@ -101,7 +101,7 @@ CHIP_ERROR MatterInitializer::Init_Matter_Server(void) chip::DeviceLayer::PlatformMgr().LockChipStack(); static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); chip::Server::GetInstance().Init(initParams); diff --git a/examples/platform/beken/common/BekenAppServer.cpp b/examples/platform/beken/common/BekenAppServer.cpp index 7db986538189a7..3216787463457a 100644 --- a/examples/platform/beken/common/BekenAppServer.cpp +++ b/examples/platform/beken/common/BekenAppServer.cpp @@ -39,7 +39,7 @@ void BekenAppServer::Init(AppDelegate * sAppDelegate) // Init ZCL Data Model and CHIP App Server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); if (sAppDelegate != nullptr) { initParams.appDelegate = sAppDelegate; diff --git a/examples/platform/bouffalolab/common/plat/platform.cpp b/examples/platform/bouffalolab/common/plat/platform.cpp index 723df8fa0d59de..4a422a9cdbc0ee 100644 --- a/examples/platform/bouffalolab/common/plat/platform.cpp +++ b/examples/platform/bouffalolab/common/plat/platform.cpp @@ -246,7 +246,7 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void) static CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); #if CHIP_DEVICE_CONFIG_ENABLE_THREAD chip::Inet::EndPointStateOpenThread::OpenThreadEndpointInitParam nativeParams; diff --git a/examples/platform/esp32/common/Esp32AppServer.cpp b/examples/platform/esp32/common/Esp32AppServer.cpp index e05817bfe0676d..e88ee966db2568 100644 --- a/examples/platform/esp32/common/Esp32AppServer.cpp +++ b/examples/platform/esp32/common/Esp32AppServer.cpp @@ -152,7 +152,7 @@ void Esp32AppServer::Init(AppDelegate * sAppDelegate) initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; #endif // CONFIG_TEST_EVENT_TRIGGER_ENABLED && CONFIG_ENABLE_OTA_REQUESTOR (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); if (sAppDelegate != nullptr) { initParams.appDelegate = sAppDelegate; diff --git a/examples/platform/infineon/cyw30739/matter_config.cpp b/examples/platform/infineon/cyw30739/matter_config.cpp index 42bc9f3d1dade5..0a244eabfbf37c 100644 --- a/examples/platform/infineon/cyw30739/matter_config.cpp +++ b/examples/platform/infineon/cyw30739/matter_config.cpp @@ -217,7 +217,7 @@ void CYW30739MatterConfig::InitApp(void) // Create initParams with SDK example defaults here static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; sExampleDeviceInfoProvider.SetStorageDelegate(initParams.persistentStorageDelegate); SetDeviceInfoProvider(&sExampleDeviceInfoProvider); diff --git a/examples/platform/linux/AppMain.cpp b/examples/platform/linux/AppMain.cpp index b9c0cdf771b772..2f69e4da048cd0 100644 --- a/examples/platform/linux/AppMain.cpp +++ b/examples/platform/linux/AppMain.cpp @@ -534,7 +534,7 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl) static chip::CommonCaseDeviceServerInitParams initParams; VerifyOrDie(initParams.InitializeStaticResourcesBeforeServerInit() == CHIP_NO_ERROR); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); #if defined(ENABLE_CHIP_SHELL) Engine::Root().Init(); diff --git a/examples/platform/linux/CommissionerMain.cpp b/examples/platform/linux/CommissionerMain.cpp index f54cfc4bd15d3b..aab4d6267c2e4c 100644 --- a/examples/platform/linux/CommissionerMain.cpp +++ b/examples/platform/linux/CommissionerMain.cpp @@ -133,7 +133,7 @@ CHIP_ERROR InitCommissioner(uint16_t commissionerPort, uint16_t udcListenPort, F factoryParams.fabricIndependentStorage = &gServerStorage; factoryParams.fabricTable = &Server::GetInstance().GetFabricTable(); factoryParams.sessionKeystore = &gSessionKeystore; - factoryParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(); + factoryParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(&gServerStorage); gGroupDataProvider.SetStorageDelegate(&gServerStorage); gGroupDataProvider.SetSessionKeystore(factoryParams.sessionKeystore); diff --git a/examples/platform/nxp/common/app_task/source/AppTaskBase.cpp b/examples/platform/nxp/common/app_task/source/AppTaskBase.cpp index 00ccbb9ea31269..596e4b8bcad78a 100644 --- a/examples/platform/nxp/common/app_task/source/AppTaskBase.cpp +++ b/examples/platform/nxp/common/app_task/source/AppTaskBase.cpp @@ -186,7 +186,7 @@ void chip::NXP::App::AppTaskBase::InitServer(intptr_t arg) initParams.operationalKeystore = chip::NXP::App::OperationalKeystore::GetInstance(); #endif (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); #if CONFIG_NET_L2_OPENTHREAD // Init ZCL Data Model and start server diff --git a/examples/platform/nxp/se05x/linux/AppMain.cpp b/examples/platform/nxp/se05x/linux/AppMain.cpp index 5baf36112b31b2..ffbdf5981fbab4 100644 --- a/examples/platform/nxp/se05x/linux/AppMain.cpp +++ b/examples/platform/nxp/se05x/linux/AppMain.cpp @@ -292,7 +292,7 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl) static chip::CommonCaseDeviceServerInitParams initParams; VerifyOrDie(initParams.InitializeStaticResourcesBeforeServerInit() == CHIP_NO_ERROR); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); #if defined(ENABLE_CHIP_SHELL) Engine::Root().Init(); diff --git a/examples/platform/openiotsdk/app/openiotsdk_platform.cpp b/examples/platform/openiotsdk/app/openiotsdk_platform.cpp index 705f35e86b2b29..f7df494997e751 100644 --- a/examples/platform/openiotsdk/app/openiotsdk_platform.cpp +++ b/examples/platform/openiotsdk/app/openiotsdk_platform.cpp @@ -275,7 +275,7 @@ int openiotsdk_chip_run(void) ChipLogError(NotSpecified, "Initialize static resources before server init failed: %s", err.AsString()); return EXIT_FAILURE; } - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.operationalServicePort = CHIP_PORT; initParams.userDirectedCommissioningPort = CHIP_UDC_PORT; diff --git a/examples/platform/silabs/MatterConfig.cpp b/examples/platform/silabs/MatterConfig.cpp index c382a3ab1aa98f..043cd6feda032e 100644 --- a/examples/platform/silabs/MatterConfig.cpp +++ b/examples/platform/silabs/MatterConfig.cpp @@ -276,7 +276,7 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName) // Initialize the remaining (not overridden) providers to the SDK example defaults (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); #if CHIP_ENABLE_OPENTHREAD // Set up OpenThread configuration when OpenThread is included diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 479e746a4aac62..7ee70c33f76bf1 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -302,7 +302,7 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void) VerifyOrDie(sTestEventTriggerDelegate.AddHandler(&sOtaTestEventTriggerHandler) == CHIP_NO_ERROR); #endif (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.appDelegate = &sCallbacks; initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); diff --git a/examples/pump-app/cc13x4_26x4/main/AppTask.cpp b/examples/pump-app/cc13x4_26x4/main/AppTask.cpp index bb5e212eeee511..87bfe05f83aedf 100644 --- a/examples/pump-app/cc13x4_26x4/main/AppTask.cpp +++ b/examples/pump-app/cc13x4_26x4/main/AppTask.cpp @@ -310,7 +310,7 @@ int AppTask::Init() initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); diff --git a/examples/pump-app/nrfconnect/main/AppTask.cpp b/examples/pump-app/nrfconnect/main/AppTask.cpp index f8939268f3d111..8961c2fafbd09f 100644 --- a/examples/pump-app/nrfconnect/main/AppTask.cpp +++ b/examples/pump-app/nrfconnect/main/AppTask.cpp @@ -206,7 +206,7 @@ CHIP_ERROR AppTask::Init() initParams.operationalKeystore = &sPSAOperationalKeystore; #endif (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); AppFabricTableDelegate::Init(); diff --git a/examples/pump-controller-app/cc13x4_26x4/main/AppTask.cpp b/examples/pump-controller-app/cc13x4_26x4/main/AppTask.cpp index 0a8de126a18965..1cb02ef522810f 100644 --- a/examples/pump-controller-app/cc13x4_26x4/main/AppTask.cpp +++ b/examples/pump-controller-app/cc13x4_26x4/main/AppTask.cpp @@ -302,7 +302,7 @@ int AppTask::Init() initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); ret = PlatformMgr().StartEventLoopTask(); diff --git a/examples/pump-controller-app/nrfconnect/main/AppTask.cpp b/examples/pump-controller-app/nrfconnect/main/AppTask.cpp index eb4d194d2f14b6..d8f47f0e1eff08 100644 --- a/examples/pump-controller-app/nrfconnect/main/AppTask.cpp +++ b/examples/pump-controller-app/nrfconnect/main/AppTask.cpp @@ -191,7 +191,7 @@ CHIP_ERROR AppTask::Init() VerifyOrDie(sTestEventTriggerDelegate.Init(ByteSpan(sTestEventTriggerEnableKey)) == CHIP_NO_ERROR); VerifyOrDie(sTestEventTriggerDelegate.AddHandler(&sOtaTestEventTriggerHandler) == CHIP_NO_ERROR); (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); AppFabricTableDelegate::Init(); diff --git a/examples/shell/cc13x4_26x4/main/AppTask.cpp b/examples/shell/cc13x4_26x4/main/AppTask.cpp index cc6122cef027bc..93fd5e826ae596 100644 --- a/examples/shell/cc13x4_26x4/main/AppTask.cpp +++ b/examples/shell/cc13x4_26x4/main/AppTask.cpp @@ -162,7 +162,7 @@ CHIP_ERROR AppTask::Init() // Init ZCL Data Model and start server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); ret = PlatformMgr().StartEventLoopTask(); diff --git a/examples/shell/shell_common/BUILD.gn b/examples/shell/shell_common/BUILD.gn index 645c8ddb510220..e41126d7b3c3b1 100644 --- a/examples/shell/shell_common/BUILD.gn +++ b/examples/shell/shell_common/BUILD.gn @@ -92,6 +92,8 @@ static_library("shell_common") { public_deps += [ "${chip_root}/examples/all-clusters-app/all-clusters-common" ] + + deps = [ "${chip_root}/src/app:attribute-persistence" ] } public_configs = [ ":shell_common_config" ] diff --git a/examples/shell/shell_common/cmd_server.cpp b/examples/shell/shell_common/cmd_server.cpp index 80884b9c042233..9f633158be76c6 100644 --- a/examples/shell/shell_common/cmd_server.cpp +++ b/examples/shell/shell_common/cmd_server.cpp @@ -59,7 +59,7 @@ static CHIP_ERROR CmdAppServerStart(int argc, char ** argv) // Init ZCL Data Model and CHIP App Server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.operationalServicePort = sServerPortOperational; initParams.userDirectedCommissioningPort = sServerPortCommissioning; diff --git a/examples/thermostat/genio/src/AppTask.cpp b/examples/thermostat/genio/src/AppTask.cpp index 3733b7f45989d2..67daf5d1ffd2bf 100644 --- a/examples/thermostat/genio/src/AppTask.cpp +++ b/examples/thermostat/genio/src/AppTask.cpp @@ -124,7 +124,7 @@ CHIP_ERROR AppTask::Init() // Init ZCL Data Model and start server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); chip::Server::GetInstance().Init(initParams); // Initialize device attestation config diff --git a/examples/thermostat/qpg/src/AppTask.cpp b/examples/thermostat/qpg/src/AppTask.cpp index f91db8b689919c..921fc220c6099b 100644 --- a/examples/thermostat/qpg/src/AppTask.cpp +++ b/examples/thermostat/qpg/src/AppTask.cpp @@ -174,7 +174,7 @@ void AppTask::InitServer(intptr_t arg) { static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); gExampleDeviceInfoProvider.SetStorageDelegate(initParams.persistentStorageDelegate); chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCommonCaseDeviceServerInitParamsProvider.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCommonCaseDeviceServerInitParamsProvider.h index 93b4edc783e431..511c7861c98161 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCommonCaseDeviceServerInitParamsProvider.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCommonCaseDeviceServerInitParamsProvider.h @@ -37,7 +37,8 @@ class MCCommonCaseDeviceServerInitParamsProvider : public matter::casting::suppo CHIP_ERROR err = serverInitParams.InitializeStaticResourcesBeforeServerInit(); VerifyOrReturnValue(err == CHIP_NO_ERROR, nullptr, ChipLogError(AppServer, "Initialization of ServerInitParams failed %" CHIP_ERROR_FORMAT, err.Format())); - serverInitParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(); + serverInitParams.dataModelProvider = + chip::app::CodegenDataModelProviderInstance(serverInitParams.persistentStorageDelegate); return &serverInitParams; } }; diff --git a/examples/tv-casting-app/linux/main.cpp b/examples/tv-casting-app/linux/main.cpp index 11e1c56e9f0d89..d73431d1fb97ea 100644 --- a/examples/tv-casting-app/linux/main.cpp +++ b/examples/tv-casting-app/linux/main.cpp @@ -182,7 +182,7 @@ int main(int argc, char * argv[]) // Enter commissioning mode, open commissioning window static chip::CommonCaseDeviceServerInitParams initParams; VerifyOrDie(CHIP_NO_ERROR == initParams.InitializeStaticResourcesBeforeServerInit()); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); VerifyOrDie(CHIP_NO_ERROR == chip::Server::GetInstance().Init(initParams)); if (argc > 1) diff --git a/examples/tv-casting-app/linux/simple-app.cpp b/examples/tv-casting-app/linux/simple-app.cpp index a0863fa9e4e35b..c41ebe0fc460a0 100644 --- a/examples/tv-casting-app/linux/simple-app.cpp +++ b/examples/tv-casting-app/linux/simple-app.cpp @@ -86,7 +86,8 @@ class CommonCaseDeviceServerInitParamsProvider : public ServerInitParamsProvider CHIP_ERROR err = serverInitParams.InitializeStaticResourcesBeforeServerInit(); VerifyOrReturnValue(err == CHIP_NO_ERROR, nullptr, ChipLogError(AppServer, "Initialization of ServerInitParams failed %" CHIP_ERROR_FORMAT, err.Format())); - serverInitParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(); + serverInitParams.dataModelProvider = + chip::app::CodegenDataModelProviderInstance(serverInitParams.persistentStorageDelegate); return &serverInitParams; } }; diff --git a/examples/window-app/nrfconnect/main/AppTask.cpp b/examples/window-app/nrfconnect/main/AppTask.cpp index 21438b76e9661b..06f21e0eaf8109 100644 --- a/examples/window-app/nrfconnect/main/AppTask.cpp +++ b/examples/window-app/nrfconnect/main/AppTask.cpp @@ -209,7 +209,7 @@ CHIP_ERROR AppTask::Init() initParams.operationalKeystore = &sPSAOperationalKeystore; #endif (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = CodegenDataModelProviderInstance(); + initParams.dataModelProvider = CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.testEventTriggerDelegate = &sTestEventTriggerDelegate; ReturnErrorOnFailure(chip::Server::GetInstance().Init(initParams)); AppFabricTableDelegate::Init(); diff --git a/src/BUILD.gn b/src/BUILD.gn index 3676c92c97e8a4..baf3c69720da9e 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -102,12 +102,9 @@ if (chip_build_tests) { if (chip_device_platform != "efr32") { tests += [ "${chip_root}/src/app/tests", - "${chip_root}/src/app/util/persistence/tests", - ] - # Disabled for EFR32 because _open is not implemented. - # https://github.com/project-chip/connectedhomeip/issues/35624 - tests += [ + # Disabled for EFR32 because _open is not implemented. + # https://github.com/project-chip/connectedhomeip/issues/35624 "${chip_root}/src/credentials/tests", "${chip_root}/src/lib/support/tests", ] diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index 2e017dd362d7eb..14fcfc96e45543 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -388,11 +388,28 @@ source_set("command-handler-impl") { ] } +source_set("storage-wrapper") { + sources = [ + "StorageDelegateWrapper.cpp", + "StorageDelegateWrapper.h", + ] + + public_deps = [ + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/support", + ] +} + source_set("attribute-persistence") { - sources = [ "SafeAttributePersistenceProvider.h" ] + sources = [ + "DefaultSafeAttributePersistenceProvider.h", + "SafeAttributePersistenceProvider.cpp", + "SafeAttributePersistenceProvider.h", + ] public_deps = [ ":paths", + ":storage-wrapper", "${chip_root}/src/app/data-model:nullable", "${chip_root}/src/app/util:types", "${chip_root}/src/lib/support", diff --git a/src/app/DefaultSafeAttributePersistenceProvider.h b/src/app/DefaultSafeAttributePersistenceProvider.h new file mode 100644 index 00000000000000..ae6a3566d2a017 --- /dev/null +++ b/src/app/DefaultSafeAttributePersistenceProvider.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include +#include + +namespace chip { +namespace app { + +class DefaultSafeAttributePersistenceProvider : protected StorageDelegateWrapper, public SafeAttributePersistenceProvider +{ +public: + DefaultSafeAttributePersistenceProvider() = default; + + CHIP_ERROR Init(PersistentStorageDelegate * storage) { return StorageDelegateWrapper::Init(storage); } + + CHIP_ERROR SafeWriteValue(const ConcreteAttributePath & aPath, const ByteSpan & aValue) override + { + return StorageDelegateWrapper::WriteValue( + DefaultStorageKeyAllocator::SafeAttributeValue(aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId), aValue); + } + + CHIP_ERROR SafeReadValue(const ConcreteAttributePath & aPath, MutableByteSpan & aValue) override + { + return StorageDelegateWrapper::ReadValue( + DefaultStorageKeyAllocator::SafeAttributeValue(aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId), aValue); + } +}; + +} // namespace app +} // namespace chip diff --git a/src/app/SafeAttributePersistenceProvider.cpp b/src/app/SafeAttributePersistenceProvider.cpp new file mode 100644 index 00000000000000..071a44415f5ba7 --- /dev/null +++ b/src/app/SafeAttributePersistenceProvider.cpp @@ -0,0 +1,24 @@ +#include + +namespace chip { +namespace app { + +namespace { + +SafeAttributePersistenceProvider * gSafeAttributeSaver = nullptr; + +} // anonymous namespace + +SafeAttributePersistenceProvider * GetSafeAttributePersistenceProvider() +{ + return gSafeAttributeSaver; +} + +void SetSafeAttributePersistenceProvider(SafeAttributePersistenceProvider * aProvider) +{ + VerifyOrReturn(aProvider != nullptr); + gSafeAttributeSaver = aProvider; +} + +} // namespace app +} // namespace chip diff --git a/src/app/StorageDelegateWrapper.cpp b/src/app/StorageDelegateWrapper.cpp new file mode 100644 index 00000000000000..d3f9dda42e4ea6 --- /dev/null +++ b/src/app/StorageDelegateWrapper.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +#include + +namespace chip { +namespace app { + +CHIP_ERROR StorageDelegateWrapper::WriteValue(const StorageKeyName & aKey, const ByteSpan & aValue) +{ + VerifyOrReturnError(mStorage != nullptr, CHIP_ERROR_INCORRECT_STATE); + + // TODO: we may want to have a small cache for values that change a lot, so + // we only write them once a bunch of changes happen or on timer or + // shutdown. + if (!CanCastTo(aValue.size())) + { + return CHIP_ERROR_BUFFER_TOO_SMALL; + } + return mStorage->SyncSetKeyValue(aKey.KeyName(), aValue.data(), static_cast(aValue.size())); +} + +CHIP_ERROR StorageDelegateWrapper::ReadValue(const StorageKeyName & aKey, MutableByteSpan & aValue) +{ + VerifyOrReturnError(mStorage != nullptr, CHIP_ERROR_INCORRECT_STATE); + + uint16_t size = static_cast(std::min(aValue.size(), static_cast(UINT16_MAX))); + ReturnErrorOnFailure(mStorage->SyncGetKeyValue(aKey.KeyName(), aValue.data(), size)); + aValue.reduce_size(size); + return CHIP_NO_ERROR; +} + +} // namespace app +} // namespace chip diff --git a/src/app/StorageDelegateWrapper.h b/src/app/StorageDelegateWrapper.h new file mode 100644 index 00000000000000..7e2ce0c6af0019 --- /dev/null +++ b/src/app/StorageDelegateWrapper.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include +#include +#include + +namespace chip { +namespace app { + +/** + * Wraps around a PersistentStorageDelegate to perform ByteSpan I/O over StorageKey + */ +class StorageDelegateWrapper +{ +public: + StorageDelegateWrapper() = default; + + // Passed-in storage must outlive this object. + CHIP_ERROR Init(PersistentStorageDelegate * storage) + { + VerifyOrReturnError(storage != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + mStorage = storage; + return CHIP_NO_ERROR; + } + + CHIP_ERROR WriteValue(const StorageKeyName & aKey, const ByteSpan & aValue); + CHIP_ERROR ReadValue(const StorageKeyName & aKey, MutableByteSpan & aValue); + +private: + PersistentStorageDelegate * mStorage; +}; + +} // namespace app +} // namespace chip diff --git a/src/app/chip_data_model.cmake b/src/app/chip_data_model.cmake index 0f628428952da8..5afb1735e46207 100644 --- a/src/app/chip_data_model.cmake +++ b/src/app/chip_data_model.cmake @@ -78,6 +78,8 @@ function(chip_configure_data_model APP_TARGET) # CMAKE data model auto-includes the server side implementation target_sources(${APP_TARGET} ${SCOPE} + ${CHIP_APP_BASE_DIR}/SafeAttributePersistenceProvider.cpp + ${CHIP_APP_BASE_DIR}/StorageDelegateWrapper.cpp ${CHIP_APP_BASE_DIR}/server/AclStorage.cpp ${CHIP_APP_BASE_DIR}/server/DefaultAclStorage.cpp ${CHIP_APP_BASE_DIR}/server/CommissioningWindowManager.cpp @@ -164,6 +166,7 @@ function(chip_configure_data_model APP_TARGET) ${CHIP_APP_BASE_DIR}/util/generic-callback-stubs.cpp ${CHIP_APP_BASE_DIR}/util/privilege-storage.cpp ${CHIP_APP_BASE_DIR}/util/util.cpp + ${CHIP_APP_BASE_DIR}/util/persistence/AttributePersistenceProvider.cpp ${CHIP_APP_BASE_DIR}/util/persistence/DefaultAttributePersistenceProvider.cpp ${CODEGEN_DATA_MODEL_SOURCES} ${APP_GEN_FILES} diff --git a/src/app/chip_data_model.gni b/src/app/chip_data_model.gni index bd1950842a3a80..7d8cfac7f7b0d9 100644 --- a/src/app/chip_data_model.gni +++ b/src/app/chip_data_model.gni @@ -457,11 +457,14 @@ template("chip_data_model") { } } + deps += [ "${chip_root}/src/app:attribute-persistence" ] + public_deps += [ ":${_data_model_name}_codegen", ":${_data_model_name}_zapgen", "${chip_root}/src/access", "${chip_root}/src/app", + "${chip_root}/src/app:attribute-persistence", "${chip_root}/src/app/cluster-building-blocks", "${chip_root}/src/app/common:attribute-type", "${chip_root}/src/app/common:cluster-objects", diff --git a/src/app/codegen-data-model-provider/CodegenDataModelProvider.cpp b/src/app/codegen-data-model-provider/CodegenDataModelProvider.cpp index f4e1190d614b45..b30490d4f6d762 100644 --- a/src/app/codegen-data-model-provider/CodegenDataModelProvider.cpp +++ b/src/app/codegen-data-model-provider/CodegenDataModelProvider.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include #include @@ -405,8 +407,39 @@ std::optional FindNextSemanticTagIndex(EndpointId endpoint, const Data return std::nullopt; } +DefaultAttributePersistenceProvider gDefaultAttributePersistence; + } // namespace +CHIP_ERROR CodegenDataModelProvider::Startup(DataModel::InteractionModelContext context) +{ + ReturnErrorOnFailure(DataModel::Provider::Startup(context)); + + // Ember NVM requires have a data model provider. attempt to create one if one is not available + // + // It is not a critical failure to not have one, however if one is not set up, ember NVM operations + // will error out with a `persistence not available`. + if (GetAttributePersistenceProvider() == nullptr) + { +#if CHIP_CONFIG_DATA_MODEL_EXTRA_LOGGING + ChipLogProgress(DataManagement, "Ember attribute persistence requires setting up"); +#endif + if (mPersistentStorageDelegate != nullptr) + { + ReturnErrorOnFailure(gDefaultAttributePersistence.Init(mPersistentStorageDelegate)); + SetAttributePersistenceProvider(&gDefaultAttributePersistence); +#if CHIP_CONFIG_DATA_MODEL_EXTRA_LOGGING + } + else + { + ChipLogError(DataManagement, "No storage delegate available, will not set up attribute persistence."); +#endif + } + } + + return CHIP_NO_ERROR; +} + std::optional CodegenDataModelProvider::EmberCommandListIterator::First(const CommandId * list) { VerifyOrReturnValue(list != nullptr, std::nullopt); diff --git a/src/app/codegen-data-model-provider/CodegenDataModelProvider.h b/src/app/codegen-data-model-provider/CodegenDataModelProvider.h index 35193a492f819b..26e130ea1f3851 100644 --- a/src/app/codegen-data-model-provider/CodegenDataModelProvider.h +++ b/src/app/codegen-data-model-provider/CodegenDataModelProvider.h @@ -22,6 +22,7 @@ #include #include #include +#include namespace chip { namespace app { @@ -134,6 +135,9 @@ class CodegenDataModelProvider : public chip::app::DataModel::Provider mPreviouslyFoundCluster = std::nullopt; } + void SetPersistentStorageDelegate(PersistentStorageDelegate * delegate) { mPersistentStorageDelegate = delegate; } + PersistentStorageDelegate * GetPersistentStorageDelegate() { return mPersistentStorageDelegate; } + /// Generic model implementations CHIP_ERROR Shutdown() override { @@ -141,6 +145,8 @@ class CodegenDataModelProvider : public chip::app::DataModel::Provider return CHIP_NO_ERROR; } + CHIP_ERROR Startup(DataModel::InteractionModelContext context) override; + DataModel::ActionReturnStatus ReadAttribute(const DataModel::ReadAttributeRequest & request, AttributeValueEncoder & encoder) override; DataModel::ActionReturnStatus WriteAttribute(const DataModel::WriteAttributeRequest & request, @@ -210,6 +216,9 @@ class CodegenDataModelProvider : public chip::app::DataModel::Provider std::optional mPreviouslyFoundCluster; unsigned mEmberMetadataStructureGeneration = 0; + // Ember requires a persistence provider, so we make sure we can always have something + PersistentStorageDelegate * mPersistentStorageDelegate = nullptr; + /// Finds the specified ember cluster /// /// Effectively the same as `emberAfFindServerCluster` except with some caching capabilities diff --git a/src/app/codegen-data-model-provider/Instance.cpp b/src/app/codegen-data-model-provider/Instance.cpp index 30a52dd5fb219a..3321106dd90ade 100644 --- a/src/app/codegen-data-model-provider/Instance.cpp +++ b/src/app/codegen-data-model-provider/Instance.cpp @@ -14,15 +14,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "lib/core/CHIPPersistentStorageDelegate.h" #include #include namespace chip { namespace app { -DataModel::Provider * CodegenDataModelProviderInstance() +DataModel::Provider * CodegenDataModelProviderInstance(PersistentStorageDelegate * delegate) { static CodegenDataModelProvider gCodegenModel; + + if (delegate != nullptr) + { + gCodegenModel.SetPersistentStorageDelegate(delegate); + } + return &gCodegenModel; } diff --git a/src/app/codegen-data-model-provider/Instance.h b/src/app/codegen-data-model-provider/Instance.h index 37f891280424f7..1e266744208512 100644 --- a/src/app/codegen-data-model-provider/Instance.h +++ b/src/app/codegen-data-model-provider/Instance.h @@ -16,12 +16,20 @@ */ #pragma once +#include "lib/core/CHIPPersistentStorageDelegate.h" #include namespace chip { namespace app { -DataModel::Provider * CodegenDataModelProviderInstance(); +/// Gets an instance of a global data model provider that is based off a code generated +/// (i.e. ember framework) data storage +/// +/// @param delegate - determines the storage delegate to be used by the returned provider +/// in case default ember storage is required. Applications can also +/// call SetAttributeStorageProvider themselves and provide nullptr here +/// if required. +DataModel::Provider * CodegenDataModelProviderInstance(PersistentStorageDelegate * delegate); } // namespace app } // namespace chip diff --git a/src/app/codegen-data-model-provider/model.gni b/src/app/codegen-data-model-provider/model.gni index f134d51fdd6a33..12c2711fdadf7f 100644 --- a/src/app/codegen-data-model-provider/model.gni +++ b/src/app/codegen-data-model-provider/model.gni @@ -40,4 +40,5 @@ codegen_data_model_PUBLIC_DEPS = [ "${chip_root}/src/app/common:attribute-type", "${chip_root}/src/app/data-model-provider", "${chip_root}/src/app/codegen-data-model-provider:instance-header", + "${chip_root}/src/app/util/persistence", ] diff --git a/src/app/server/BUILD.gn b/src/app/server/BUILD.gn index 43c970843ba66d..fb25ae0f38bf6b 100644 --- a/src/app/server/BUILD.gn +++ b/src/app/server/BUILD.gn @@ -55,10 +55,10 @@ static_library("server") { "${chip_root}/src/access", "${chip_root}/src/access:provider-impl", "${chip_root}/src/app", + "${chip_root}/src/app:attribute-persistence", "${chip_root}/src/app:test-event-trigger", "${chip_root}/src/app/icd/server:icd-server-config", "${chip_root}/src/app/icd/server:observer", - "${chip_root}/src/app/util/persistence", "${chip_root}/src/lib/address_resolve", "${chip_root}/src/lib/dnssd", "${chip_root}/src/lib/dnssd:naming", diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index e9475fdbf906e8..7363d519b5c5a4 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -131,7 +132,7 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams) if (initParams.dataModelProvider == nullptr) { ChipLogError(AppServer, "Application Server requires a `initParams.dataModelProvider` value."); - ChipLogError(AppServer, "For backwards compatibility, you likely can use `CodegenDataModelProviderInstance()`"); + ChipLogError(AppServer, "For backwards compatibility, you likely can use `CodegenDataModelProviderInstance(...)`"); } VerifyOrExit(initParams.dataModelProvider != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); @@ -167,7 +168,6 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams) // Set up attribute persistence before we try to bring up the data model // handler. SuccessOrExit(err = mAttributePersister.Init(mDeviceStorage)); - SetAttributePersistenceProvider(&mAttributePersister); SetSafeAttributePersistenceProvider(&mAttributePersister); // SetDataModelProvider() actually initializes/starts the provider. We need @@ -665,7 +665,7 @@ void Server::Shutdown() } mICDManager.Shutdown(); #endif // CHIP_CONFIG_ENABLE_ICD_SERVER - mAttributePersister.Shutdown(); + // TODO(16969): Remove chip::Platform::MemoryInit() call from Server class, it belongs to outer code chip::Platform::MemoryShutdown(); } diff --git a/src/app/server/Server.h b/src/app/server/Server.h index 5c5068d7902be1..315b65977329d7 100644 --- a/src/app/server/Server.h +++ b/src/app/server/Server.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -80,11 +81,6 @@ #endif // CHIP_CONFIG_ENABLE_ICD_CIP #endif // CHIP_CONFIG_ENABLE_ICD_SERVER -// TODO: https://github.com/project-chip/connectedhomeip/issues/36472 -// this strongly couples Server to Ember and this dependency should -// be removed -#include - namespace chip { inline constexpr size_t kMaxBlePendingPackets = 1; @@ -416,7 +412,7 @@ class Server Credentials::OperationalCertificateStore * GetOpCertStore() { return mOpCertStore; } - app::DefaultAttributePersistenceProvider & GetDefaultAttributePersister() { return mAttributePersister; } + app::DefaultSafeAttributePersistenceProvider & GetDefaultAttributePersister() { return mAttributePersister; } app::reporting::ReportScheduler * GetReportScheduler() { return mReportScheduler; } @@ -689,7 +685,7 @@ class Server app::SubscriptionResumptionStorage * mSubscriptionResumptionStorage; Credentials::GroupDataProvider * mGroupsProvider; Crypto::SessionKeystore * mSessionKeystore; - app::DefaultAttributePersistenceProvider mAttributePersister; + app::DefaultSafeAttributePersistenceProvider mAttributePersister; GroupDataProviderListener mListener; ServerFabricDelegate mFabricDelegate; app::reporting::ReportScheduler * mReportScheduler; diff --git a/src/app/server/java/AndroidAppServerWrapper.cpp b/src/app/server/java/AndroidAppServerWrapper.cpp index 5e205b7d82fb8a..1c0264eb6af244 100644 --- a/src/app/server/java/AndroidAppServerWrapper.cpp +++ b/src/app/server/java/AndroidAppServerWrapper.cpp @@ -52,7 +52,7 @@ CHIP_ERROR ChipAndroidAppInit(AppDelegate * appDelegate) // Init ZCL Data Model and CHIP App Server static chip::CommonCaseDeviceServerInitParams initParams; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); if (appDelegate != nullptr) { initParams.appDelegate = appDelegate; diff --git a/src/app/tests/BUILD.gn b/src/app/tests/BUILD.gn index 18856d40a12f1f..92ba164b7cddf1 100644 --- a/src/app/tests/BUILD.gn +++ b/src/app/tests/BUILD.gn @@ -210,6 +210,7 @@ chip_test_suite("tests") { "TestConcreteAttributePath.cpp", "TestDataModelSerialization.cpp", "TestDefaultOTARequestorStorage.cpp", + "TestDefaultSafeAttributePersistenceProvider.cpp", "TestDefaultThreadNetworkDirectoryStorage.cpp", "TestEcosystemInformationCluster.cpp", "TestEventLoggingNoUTCTime.cpp", @@ -246,6 +247,7 @@ chip_test_suite("tests") { ":thread-network-directory-test-srcs", ":time-sync-data-provider-test-srcs", "${chip_root}/src/app", + "${chip_root}/src/app:attribute-persistence", "${chip_root}/src/app/codegen-data-model-provider:instance-header", "${chip_root}/src/app/common:cluster-objects", "${chip_root}/src/app/data-model-provider/tests:encode-decode", diff --git a/src/app/tests/TestAclEvent.cpp b/src/app/tests/TestAclEvent.cpp index 13b3e36491f359..4607d48d618ccc 100644 --- a/src/app/tests/TestAclEvent.cpp +++ b/src/app/tests/TestAclEvent.cpp @@ -218,7 +218,7 @@ TEST_F(TestAclEvent, TestReadRoundtripWithEventStatusIBInEventReport) auto * engine = chip::app::InteractionModelEngine::GetInstance(); - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(engine->Init(&GetExchangeManager(), &GetFabricTable(), app::reporting::GetDefaultReportScheduler()), CHIP_NO_ERROR); // A custom AccessControl::Delegate has been installed that grants privilege to any cluster except the test cluster. diff --git a/src/app/tests/TestAttributePathExpandIterator.cpp b/src/app/tests/TestAttributePathExpandIterator.cpp index 5478c45a0db4e7..fb8fa9b2c9621f 100644 --- a/src/app/tests/TestAttributePathExpandIterator.cpp +++ b/src/app/tests/TestAttributePathExpandIterator.cpp @@ -106,7 +106,8 @@ TEST(TestAttributePathExpandIterator, TestAllWildcard) size_t index = 0; - for (app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(), &clusInfo); iter.Get(path); iter.Next()) + for (app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo); iter.Get(path); + iter.Next()) { ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId)); @@ -130,7 +131,8 @@ TEST(TestAttributePathExpandIterator, TestWildcardEndpoint) size_t index = 0; - for (app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(), &clusInfo); iter.Get(path); iter.Next()) + for (app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo); iter.Get(path); + iter.Next()) { ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId)); @@ -157,7 +159,8 @@ TEST(TestAttributePathExpandIterator, TestWildcardCluster) size_t index = 0; - for (app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(), &clusInfo); iter.Get(path); iter.Next()) + for (app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo); iter.Get(path); + iter.Next()) { ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId)); @@ -184,7 +187,8 @@ TEST(TestAttributePathExpandIterator, TestWildcardClusterGlobalAttributeNotInMet size_t index = 0; - for (app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(), &clusInfo); iter.Get(path); iter.Next()) + for (app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo); iter.Get(path); + iter.Next()) { ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId)); @@ -215,7 +219,8 @@ TEST(TestAttributePathExpandIterator, TestWildcardAttribute) size_t index = 0; - for (app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(), &clusInfo); iter.Get(path); iter.Next()) + for (app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo); iter.Get(path); + iter.Next()) { ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId)); @@ -240,7 +245,8 @@ TEST(TestAttributePathExpandIterator, TestNoWildcard) size_t index = 0; - for (app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(), &clusInfo); iter.Get(path); iter.Next()) + for (app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo); iter.Get(path); + iter.Next()) { ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId)); @@ -354,7 +360,8 @@ TEST(TestAttributePathExpandIterator, TestMultipleClusInfo) size_t index = 0; - for (app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(), &clusInfo1); iter.Get(path); iter.Next()) + for (app::AttributePathExpandIterator iter(CodegenDataModelProviderInstance(nullptr /* delegate */), &clusInfo1); + iter.Get(path); iter.Next()) { ChipLogDetail(AppServer, "Visited Attribute: 0x%04X / " ChipLogFormatMEI " / " ChipLogFormatMEI, path.mEndpointId, ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId)); diff --git a/src/app/tests/TestCommissioningWindowManager.cpp b/src/app/tests/TestCommissioningWindowManager.cpp index 7a2e127324348c..e6a9069b533e55 100644 --- a/src/app/tests/TestCommissioningWindowManager.cpp +++ b/src/app/tests/TestCommissioningWindowManager.cpp @@ -114,7 +114,7 @@ class TestCommissioningWindowManager : public ::testing::Test static chip::SimpleTestEventTriggerDelegate sSimpleTestEventTriggerDelegate; initParams.testEventTriggerDelegate = &sSimpleTestEventTriggerDelegate; (void) initParams.InitializeStaticResourcesBeforeServerInit(); - initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); // Use whatever server port the kernel decides to give us. initParams.operationalServicePort = 0; diff --git a/src/app/util/persistence/tests/TestAttributePersistenceProvider.cpp b/src/app/tests/TestDefaultSafeAttributePersistenceProvider.cpp similarity index 90% rename from src/app/util/persistence/tests/TestAttributePersistenceProvider.cpp rename to src/app/tests/TestDefaultSafeAttributePersistenceProvider.cpp index 1324f37a7138c3..3b3c62ce48ea7a 100644 --- a/src/app/util/persistence/tests/TestAttributePersistenceProvider.cpp +++ b/src/app/tests/TestDefaultSafeAttributePersistenceProvider.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include #include #include #include @@ -30,7 +30,7 @@ const ConcreteAttributePath TestConcretePath = ConcreteAttributePath(1, 1, 1); namespace { -class TestAttributePersistenceProvider : public ::testing::Test +class TestDefaultSafeAttributePersistenceProvider : public ::testing::Test { public: static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); } @@ -40,10 +40,10 @@ class TestAttributePersistenceProvider : public ::testing::Test /** * Tests the storage and retrival of data from the KVS as ByteSpan */ -TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalByteSpans) +TEST_F(TestDefaultSafeAttributePersistenceProvider, TestStorageAndRetrivalByteSpans) { TestPersistentStorageDelegate storageDelegate; - DefaultAttributePersistenceProvider persistenceProvider; + DefaultSafeAttributePersistenceProvider persistenceProvider; // Init ChipError err = persistenceProvider.Init(&storageDelegate); @@ -66,9 +66,6 @@ TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalByteSpans) err = persistenceProvider.SafeReadValue(TestConcretePath, valueReadBack2); EXPECT_EQ(err, CHIP_NO_ERROR); EXPECT_TRUE(valueReadBack2.data_equal(value)); - - // Finishing - persistenceProvider.Shutdown(); } /** @@ -77,7 +74,7 @@ TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalByteSpans) * @param testValue The test value to store and retrieve */ template -void testHelperStorageAndRetrivalScalarValues(DefaultAttributePersistenceProvider & persistenceProvider, T testValue) +void testHelperStorageAndRetrivalScalarValues(DefaultSafeAttributePersistenceProvider & persistenceProvider, T testValue) { CHIP_ERROR err = persistenceProvider.WriteScalarValue(TestConcretePath, testValue); EXPECT_EQ(err, CHIP_NO_ERROR); @@ -95,7 +92,7 @@ void testHelperStorageAndRetrivalScalarValues(DefaultAttributePersistenceProvide * @param testValue The test value to store and retrieve */ template -void testHelperStorageAndRetrivalScalarValues(DefaultAttributePersistenceProvider & persistenceProvider, +void testHelperStorageAndRetrivalScalarValues(DefaultSafeAttributePersistenceProvider & persistenceProvider, DataModel::Nullable testValue) { CHIP_ERROR err = persistenceProvider.WriteScalarValue(TestConcretePath, testValue); @@ -111,10 +108,10 @@ void testHelperStorageAndRetrivalScalarValues(DefaultAttributePersistenceProvide /** * Tests the storage and retrival of data from the KVS of types bool, uint8_t, uint16_t, uint32_t, uint64_t. */ -TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalScalarValues) +TEST_F(TestDefaultSafeAttributePersistenceProvider, TestStorageAndRetrivalScalarValues) { TestPersistentStorageDelegate storageDelegate; - DefaultAttributePersistenceProvider persistenceProvider; + DefaultSafeAttributePersistenceProvider persistenceProvider; // Init CHIP_ERROR err = persistenceProvider.Init(&storageDelegate); @@ -144,18 +141,15 @@ TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalScalarValues) testHelperStorageAndRetrivalScalarValues(persistenceProvider, uint64_t(0)); testHelperStorageAndRetrivalScalarValues(persistenceProvider, uint64_t(0x0100000001)); testHelperStorageAndRetrivalScalarValues(persistenceProvider, uint64_t(0xffffffffffffffff)); - - // Finishing - persistenceProvider.Shutdown(); } /** * Tests the storage and retrival of data from the KVS of types int8_t, int16_t, int32_t, int64_t. */ -TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalSignedScalarValues) +TEST_F(TestDefaultSafeAttributePersistenceProvider, TestStorageAndRetrivalSignedScalarValues) { TestPersistentStorageDelegate storageDelegate; - DefaultAttributePersistenceProvider persistenceProvider; + DefaultSafeAttributePersistenceProvider persistenceProvider; // Init CHIP_ERROR err = persistenceProvider.Init(&storageDelegate); @@ -180,18 +174,15 @@ TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalSignedScalarValue testHelperStorageAndRetrivalScalarValues(persistenceProvider, int64_t(0)); testHelperStorageAndRetrivalScalarValues(persistenceProvider, int64_t(0x7fffffffffffffff)); testHelperStorageAndRetrivalScalarValues(persistenceProvider, int64_t(0x8000000000000000)); - - // Finishing - persistenceProvider.Shutdown(); } /** * Tests the storage and retrival of data from the KVS of DataModel::Nullable types bool, uint8_t, uint16_t, uint32_t, uint64_t. */ -TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalNullableScalarValues) +TEST_F(TestDefaultSafeAttributePersistenceProvider, TestStorageAndRetrivalNullableScalarValues) { TestPersistentStorageDelegate storageDelegate; - DefaultAttributePersistenceProvider persistenceProvider; + DefaultSafeAttributePersistenceProvider persistenceProvider; // Init CHIP_ERROR err = persistenceProvider.Init(&storageDelegate); @@ -236,18 +227,15 @@ TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalNullableScalarVal auto nullVal64 = DataModel::Nullable(); nullVal64.SetNull(); testHelperStorageAndRetrivalScalarValues(persistenceProvider, nullVal64); - - // Finishing - persistenceProvider.Shutdown(); } /** * Tests the storage and retrival of data from the KVS of DataModel::Nullable types int8_t, int16_t, int32_t, int64_t. */ -TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalSignedNullableScalarValues) +TEST_F(TestDefaultSafeAttributePersistenceProvider, TestStorageAndRetrivalSignedNullableScalarValues) { TestPersistentStorageDelegate storageDelegate; - DefaultAttributePersistenceProvider persistenceProvider; + DefaultSafeAttributePersistenceProvider persistenceProvider; // Init CHIP_ERROR err = persistenceProvider.Init(&storageDelegate); @@ -284,18 +272,15 @@ TEST_F(TestAttributePersistenceProvider, TestStorageAndRetrivalSignedNullableSca auto nullVal64 = DataModel::Nullable(); nullVal64.SetNull(); testHelperStorageAndRetrivalScalarValues(persistenceProvider, nullVal64); - - // Finishing - persistenceProvider.Shutdown(); } /** * Test that the correct error is given when trying to read a value with a buffer that's too small. */ -TEST_F(TestAttributePersistenceProvider, TestBufferTooSmallErrors) +TEST_F(TestDefaultSafeAttributePersistenceProvider, TestBufferTooSmallErrors) { TestPersistentStorageDelegate storageDelegate; - DefaultAttributePersistenceProvider persistenceProvider; + DefaultSafeAttributePersistenceProvider persistenceProvider; // Init CHIP_ERROR err = persistenceProvider.Init(&storageDelegate); @@ -346,9 +331,6 @@ TEST_F(TestAttributePersistenceProvider, TestBufferTooSmallErrors) uint64_t valueReadBack64; err = persistenceProvider.ReadScalarValue(TestConcretePath, valueReadBack64); EXPECT_EQ(err, CHIP_ERROR_BUFFER_TOO_SMALL); - - // Finishing - persistenceProvider.Shutdown(); } } // anonymous namespace diff --git a/src/app/tests/TestInteractionModelEngine.cpp b/src/app/tests/TestInteractionModelEngine.cpp index 88b3c07a6db178..2778d924abee78 100644 --- a/src/app/tests/TestInteractionModelEngine.cpp +++ b/src/app/tests/TestInteractionModelEngine.cpp @@ -90,7 +90,7 @@ TEST_F(TestInteractionModelEngine, TestAttributePathParamsPushRelease) InteractionModelEngine * engine = InteractionModelEngine::GetInstance(); - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(engine->Init(&GetExchangeManager(), &GetFabricTable(), app::reporting::GetDefaultReportScheduler()), CHIP_NO_ERROR); SingleLinkedListNode * attributePathParamsList = nullptr; @@ -126,7 +126,7 @@ TEST_F(TestInteractionModelEngine, TestRemoveDuplicateConcreteAttribute) InteractionModelEngine * engine = InteractionModelEngine::GetInstance(); - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(CHIP_NO_ERROR, engine->Init(&GetExchangeManager(), &GetFabricTable(), app::reporting::GetDefaultReportScheduler())); SingleLinkedListNode * attributePathParamsList = nullptr; @@ -263,16 +263,16 @@ TEST_F_FROM_FIXTURE(TestInteractionModelEngine, TestSubjectHasActiveSubscription ASSERT_TRUE(exchangeCtx1); // InteractionModelEngine init - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(CHIP_NO_ERROR, engine->Init(&GetExchangeManager(), &GetFabricTable(), reporting::GetDefaultReportScheduler())); // Verify that there are no active subscriptions EXPECT_FALSE(engine->SubjectHasActiveSubscription(bobFabricIndex, bobNodeId)); // Create and setup readHandler 1 - ReadHandler * readHandler1 = - engine->GetReadHandlerPool().CreateObject(nullCallback, exchangeCtx1, ReadHandler::InteractionType::Subscribe, - reporting::GetDefaultReportScheduler(), CodegenDataModelProviderInstance()); + ReadHandler * readHandler1 = engine->GetReadHandlerPool().CreateObject( + nullCallback, exchangeCtx1, ReadHandler::InteractionType::Subscribe, reporting::GetDefaultReportScheduler(), + CodegenDataModelProviderInstance(nullptr /* delegate */)); // Verify that Bob still doesn't have an active subscription EXPECT_FALSE(engine->SubjectHasActiveSubscription(bobFabricIndex, bobNodeId)); @@ -311,7 +311,7 @@ TEST_F_FROM_FIXTURE(TestInteractionModelEngine, TestSubjectHasActiveSubscription ASSERT_TRUE(exchangeCtx1); // InteractionModelEngine init - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(CHIP_NO_ERROR, engine->Init(&GetExchangeManager(), &GetFabricTable(), reporting::GetDefaultReportScheduler())); // Verify that both Alice and Bob have no active subscriptions @@ -319,15 +319,16 @@ TEST_F_FROM_FIXTURE(TestInteractionModelEngine, TestSubjectHasActiveSubscription // Create readHandler 1 engine->GetReadHandlerPool().CreateObject(nullCallback, exchangeCtx1, ReadHandler::InteractionType::Subscribe, - reporting::GetDefaultReportScheduler(), CodegenDataModelProviderInstance()); + reporting::GetDefaultReportScheduler(), + CodegenDataModelProviderInstance(nullptr /* delegate */)); // Verify that Bob still doesn't have an active subscription EXPECT_FALSE(engine->SubjectHasActiveSubscription(bobFabricIndex, bobNodeId)); // Create and setup readHandler 2 - ReadHandler * readHandler2 = - engine->GetReadHandlerPool().CreateObject(nullCallback, exchangeCtx2, ReadHandler::InteractionType::Subscribe, - reporting::GetDefaultReportScheduler(), CodegenDataModelProviderInstance()); + ReadHandler * readHandler2 = engine->GetReadHandlerPool().CreateObject( + nullCallback, exchangeCtx2, ReadHandler::InteractionType::Subscribe, reporting::GetDefaultReportScheduler(), + CodegenDataModelProviderInstance(nullptr /* delegate */)); // Verify that Bob still doesn't have an active subscription EXPECT_FALSE(engine->SubjectHasActiveSubscription(bobFabricIndex, bobNodeId)); @@ -370,7 +371,7 @@ TEST_F_FROM_FIXTURE(TestInteractionModelEngine, TestSubjectHasActiveSubscription ASSERT_TRUE(exchangeCtx2); // InteractionModelEngine init - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(CHIP_NO_ERROR, engine->Init(&GetExchangeManager(), &GetFabricTable(), reporting::GetDefaultReportScheduler())); // Verify that both Alice and Bob have no active subscriptions @@ -378,14 +379,14 @@ TEST_F_FROM_FIXTURE(TestInteractionModelEngine, TestSubjectHasActiveSubscription EXPECT_FALSE(engine->SubjectHasActiveSubscription(aliceFabricIndex, aliceNodeId)); // Create and setup readHandler 1 - ReadHandler * readHandler1 = - engine->GetReadHandlerPool().CreateObject(nullCallback, exchangeCtx1, ReadHandler::InteractionType::Subscribe, - reporting::GetDefaultReportScheduler(), CodegenDataModelProviderInstance()); + ReadHandler * readHandler1 = engine->GetReadHandlerPool().CreateObject( + nullCallback, exchangeCtx1, ReadHandler::InteractionType::Subscribe, reporting::GetDefaultReportScheduler(), + CodegenDataModelProviderInstance(nullptr /* delegate */)); // Create and setup readHandler 2 - ReadHandler * readHandler2 = - engine->GetReadHandlerPool().CreateObject(nullCallback, exchangeCtx2, ReadHandler::InteractionType::Subscribe, - reporting::GetDefaultReportScheduler(), CodegenDataModelProviderInstance()); + ReadHandler * readHandler2 = engine->GetReadHandlerPool().CreateObject( + nullCallback, exchangeCtx2, ReadHandler::InteractionType::Subscribe, reporting::GetDefaultReportScheduler(), + CodegenDataModelProviderInstance(nullptr /* delegate */)); // Verify that Bob still doesn't have an active subscription EXPECT_FALSE(engine->SubjectHasActiveSubscription(bobFabricIndex, bobNodeId)); @@ -453,7 +454,7 @@ TEST_F_FROM_FIXTURE(TestInteractionModelEngine, TestSubjectHasActiveSubscription ASSERT_TRUE(exchangeCtx22); // InteractionModelEngine init - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(CHIP_NO_ERROR, engine->Init(&GetExchangeManager(), &GetFabricTable(), reporting::GetDefaultReportScheduler())); // Verify that both Alice and Bob have no active subscriptions @@ -462,21 +463,23 @@ TEST_F_FROM_FIXTURE(TestInteractionModelEngine, TestSubjectHasActiveSubscription // Create and setup readHandler 1-1 engine->GetReadHandlerPool().CreateObject(nullCallback, exchangeCtx11, ReadHandler::InteractionType::Subscribe, - reporting::GetDefaultReportScheduler(), CodegenDataModelProviderInstance()); + reporting::GetDefaultReportScheduler(), + CodegenDataModelProviderInstance(nullptr /* delegate */)); // Create and setup readHandler 1-2 - ReadHandler * readHandler12 = - engine->GetReadHandlerPool().CreateObject(nullCallback, exchangeCtx12, ReadHandler::InteractionType::Subscribe, - reporting::GetDefaultReportScheduler(), CodegenDataModelProviderInstance()); + ReadHandler * readHandler12 = engine->GetReadHandlerPool().CreateObject( + nullCallback, exchangeCtx12, ReadHandler::InteractionType::Subscribe, reporting::GetDefaultReportScheduler(), + CodegenDataModelProviderInstance(nullptr /* delegate */)); // Create and setup readHandler 2-1 engine->GetReadHandlerPool().CreateObject(nullCallback, exchangeCtx21, ReadHandler::InteractionType::Subscribe, - reporting::GetDefaultReportScheduler(), CodegenDataModelProviderInstance()); + reporting::GetDefaultReportScheduler(), + CodegenDataModelProviderInstance(nullptr /* delegate */)); // Create and setup readHandler 2-2 - ReadHandler * readHandler22 = - engine->GetReadHandlerPool().CreateObject(nullCallback, exchangeCtx22, ReadHandler::InteractionType::Subscribe, - reporting::GetDefaultReportScheduler(), CodegenDataModelProviderInstance()); + ReadHandler * readHandler22 = engine->GetReadHandlerPool().CreateObject( + nullCallback, exchangeCtx22, ReadHandler::InteractionType::Subscribe, reporting::GetDefaultReportScheduler(), + CodegenDataModelProviderInstance(nullptr /* delegate */)); // Verify that both Alice and Bob have no active subscriptions EXPECT_FALSE(engine->SubjectHasActiveSubscription(bobFabricIndex, bobNodeId)); @@ -533,7 +536,7 @@ TEST_F_FROM_FIXTURE(TestInteractionModelEngine, TestSubjectHasActiveSubscription FabricIndex bobFabricIndex = 1; // InteractionModelEngine init - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(CHIP_NO_ERROR, engine->Init(&GetExchangeManager(), &GetFabricTable(), reporting::GetDefaultReportScheduler())); // Make sure we are using CASE sessions, because there is no defunct-marking for PASE. @@ -547,9 +550,9 @@ TEST_F_FROM_FIXTURE(TestInteractionModelEngine, TestSubjectHasActiveSubscription ASSERT_TRUE(exchangeCtx); // Create readHandler - ReadHandler * readHandler = - engine->GetReadHandlerPool().CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, - reporting::GetDefaultReportScheduler(), CodegenDataModelProviderInstance()); + ReadHandler * readHandler = engine->GetReadHandlerPool().CreateObject( + nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, reporting::GetDefaultReportScheduler(), + CodegenDataModelProviderInstance(nullptr /* delegate */)); // Verify there are not active subscriptions EXPECT_FALSE(engine->SubjectHasActiveSubscription(bobFabricIndex, valideSubjectId)); @@ -584,7 +587,7 @@ TEST_F(TestInteractionModelEngine, TestSubjectHasPersistedSubscription) EXPECT_EQ(subscriptionStorage.Init(&storage), CHIP_NO_ERROR); - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(CHIP_NO_ERROR, engine->Init(&GetExchangeManager(), &GetFabricTable(), app::reporting::GetDefaultReportScheduler(), nullptr, &subscriptionStorage)); @@ -640,7 +643,7 @@ TEST_F_FROM_FIXTURE(TestInteractionModelEngine, TestSubscriptionResumptionTimer) InteractionModelEngine * engine = InteractionModelEngine::GetInstance(); - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(engine->Init(&GetExchangeManager(), &GetFabricTable(), app::reporting::GetDefaultReportScheduler()), CHIP_NO_ERROR); uint32_t timeTillNextResubscriptionMs; @@ -672,7 +675,7 @@ TEST_F_FROM_FIXTURE(TestInteractionModelEngine, TestDecrementNumSubscriptionsToR constexpr uint8_t kNumberOfSubsToResume = 5; uint8_t numberOfSubsRemaining = kNumberOfSubsToResume; - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(engine->Init(&GetExchangeManager(), &GetFabricTable(), app::reporting::GetDefaultReportScheduler()), CHIP_NO_ERROR); #if CHIP_CONFIG_ENABLE_ICD_CIP && !CHIP_CONFIG_SUBSCRIPTION_TIMEOUT_RESUMPTION @@ -745,9 +748,9 @@ TEST_F_FROM_FIXTURE(TestInteractionModelEngine, TestFabricHasAtLeastOneActiveSub EXPECT_FALSE(engine->FabricHasAtLeastOneActiveSubscription(fabricIndex2)); // Create and setup readHandler 1 - ReadHandler * readHandler1 = - engine->GetReadHandlerPool().CreateObject(nullCallback, exchangeCtx1, ReadHandler::InteractionType::Subscribe, - reporting::GetDefaultReportScheduler(), CodegenDataModelProviderInstance()); + ReadHandler * readHandler1 = engine->GetReadHandlerPool().CreateObject( + nullCallback, exchangeCtx1, ReadHandler::InteractionType::Subscribe, reporting::GetDefaultReportScheduler(), + CodegenDataModelProviderInstance(nullptr /* delegate */)); // Verify that fabric 1 still doesn't have an active subscription EXPECT_FALSE(engine->FabricHasAtLeastOneActiveSubscription(fabricIndex1)); @@ -762,9 +765,9 @@ TEST_F_FROM_FIXTURE(TestInteractionModelEngine, TestFabricHasAtLeastOneActiveSub EXPECT_FALSE(engine->FabricHasAtLeastOneActiveSubscription(fabricIndex2)); // Create and setup readHandler 2 - ReadHandler * readHandler2 = - engine->GetReadHandlerPool().CreateObject(nullCallback, exchangeCtx2, ReadHandler::InteractionType::Subscribe, - reporting::GetDefaultReportScheduler(), CodegenDataModelProviderInstance()); + ReadHandler * readHandler2 = engine->GetReadHandlerPool().CreateObject( + nullCallback, exchangeCtx2, ReadHandler::InteractionType::Subscribe, reporting::GetDefaultReportScheduler(), + CodegenDataModelProviderInstance(nullptr /* delegate */)); // Set readHandler2 to active readHandler2->SetStateFlag(ReadHandler::ReadHandlerFlags::ActiveSubscription, true); @@ -801,9 +804,9 @@ TEST_F_FROM_FIXTURE(TestInteractionModelEngine, TestFabricHasAtLeastOneActiveSub EXPECT_FALSE(engine->FabricHasAtLeastOneActiveSubscription(fabricIndex)); // Create and setup readHandler 1 - ReadHandler * readHandler1 = - engine->GetReadHandlerPool().CreateObject(nullCallback, exchangeCtx1, ReadHandler::InteractionType::Subscribe, - reporting::GetDefaultReportScheduler(), CodegenDataModelProviderInstance()); + ReadHandler * readHandler1 = engine->GetReadHandlerPool().CreateObject( + nullCallback, exchangeCtx1, ReadHandler::InteractionType::Subscribe, reporting::GetDefaultReportScheduler(), + CodegenDataModelProviderInstance(nullptr /* delegate */)); // Verify that the fabric still doesn't have an active subscription EXPECT_FALSE(engine->FabricHasAtLeastOneActiveSubscription(fabricIndex)); @@ -815,9 +818,9 @@ TEST_F_FROM_FIXTURE(TestInteractionModelEngine, TestFabricHasAtLeastOneActiveSub EXPECT_TRUE(engine->FabricHasAtLeastOneActiveSubscription(fabricIndex)); // Create and setup readHandler 2 - ReadHandler * readHandler2 = - engine->GetReadHandlerPool().CreateObject(nullCallback, exchangeCtx2, ReadHandler::InteractionType::Subscribe, - reporting::GetDefaultReportScheduler(), CodegenDataModelProviderInstance()); + ReadHandler * readHandler2 = engine->GetReadHandlerPool().CreateObject( + nullCallback, exchangeCtx2, ReadHandler::InteractionType::Subscribe, reporting::GetDefaultReportScheduler(), + CodegenDataModelProviderInstance(nullptr /* delegate */)); // Verify that the fabric still has an active subscription EXPECT_TRUE(engine->FabricHasAtLeastOneActiveSubscription(fabricIndex)); diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index f997266b935c09..564320b67f17ce 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -566,7 +566,7 @@ void TestReadInteraction::TestReadHandler() { Messaging::ExchangeContext * exchangeCtx = NewExchangeToAlice(nullptr, false); ReadHandler readHandler(nullCallback, exchangeCtx, chip::app::ReadHandler::InteractionType::Read, gReportScheduler, - CodegenDataModelProviderInstance()); + CodegenDataModelProviderInstance(nullptr /* delegate */)); GenerateReportData(reportDatabuf, ReportType::kValid, false /* aSuppressResponse*/); EXPECT_EQ(readHandler.SendReportData(std::move(reportDatabuf), false), CHIP_ERROR_INCORRECT_STATE); @@ -625,7 +625,7 @@ void TestReadInteraction::TestReadHandlerSetMaxReportingInterval() // Configure ReadHandler ReadHandler readHandler(*engine, exchangeCtx, chip::app::ReadHandler::InteractionType::Read, gReportScheduler, - CodegenDataModelProviderInstance()); + CodegenDataModelProviderInstance(nullptr /* delegate */)); writer.Init(std::move(subscribeRequestbuf)); EXPECT_EQ(subscribeRequestBuilder.Init(&writer), CHIP_NO_ERROR); @@ -843,7 +843,7 @@ void TestReadInteraction::TestReadHandlerInvalidAttributePath() { Messaging::ExchangeContext * exchangeCtx = NewExchangeToAlice(nullptr, false); ReadHandler readHandler(nullCallback, exchangeCtx, chip::app::ReadHandler::InteractionType::Read, gReportScheduler, - CodegenDataModelProviderInstance()); + CodegenDataModelProviderInstance(nullptr /* delegate */)); GenerateReportData(reportDatabuf, ReportType::kValid, false /* aSuppressResponse*/); EXPECT_EQ(readHandler.SendReportData(std::move(reportDatabuf), false), CHIP_ERROR_INCORRECT_STATE); @@ -1593,7 +1593,7 @@ void TestReadInteraction::TestProcessSubscribeRequest() { ReadHandler readHandler(*engine, exchangeCtx, chip::app::ReadHandler::InteractionType::Read, gReportScheduler, - CodegenDataModelProviderInstance()); + CodegenDataModelProviderInstance(nullptr /* delegate */)); writer.Init(std::move(subscribeRequestbuf)); EXPECT_EQ(subscribeRequestBuilder.Init(&writer), CHIP_NO_ERROR); @@ -1655,7 +1655,7 @@ void TestReadInteraction::TestICDProcessSubscribeRequestSupMaxIntervalCeiling() { ReadHandler readHandler(*engine, exchangeCtx, chip::app::ReadHandler::InteractionType::Read, gReportScheduler, - CodegenDataModelProviderInstance()); + CodegenDataModelProviderInstance(nullptr /* delegate */)); writer.Init(std::move(subscribeRequestbuf)); EXPECT_EQ(subscribeRequestBuilder.Init(&writer), CHIP_NO_ERROR); @@ -1725,7 +1725,7 @@ void TestReadInteraction::TestICDProcessSubscribeRequestInfMaxIntervalCeiling() { ReadHandler readHandler(*engine, exchangeCtx, chip::app::ReadHandler::InteractionType::Read, gReportScheduler, - CodegenDataModelProviderInstance()); + CodegenDataModelProviderInstance(nullptr /* delegate */)); writer.Init(std::move(subscribeRequestbuf)); EXPECT_EQ(subscribeRequestBuilder.Init(&writer), CHIP_NO_ERROR); @@ -1795,7 +1795,7 @@ void TestReadInteraction::TestICDProcessSubscribeRequestSupMinInterval() { ReadHandler readHandler(*engine, exchangeCtx, chip::app::ReadHandler::InteractionType::Read, gReportScheduler, - CodegenDataModelProviderInstance()); + CodegenDataModelProviderInstance(nullptr /* delegate */)); writer.Init(std::move(subscribeRequestbuf)); EXPECT_EQ(subscribeRequestBuilder.Init(&writer), CHIP_NO_ERROR); @@ -1865,7 +1865,7 @@ void TestReadInteraction::TestICDProcessSubscribeRequestMaxMinInterval() { ReadHandler readHandler(*engine, exchangeCtx, chip::app::ReadHandler::InteractionType::Read, gReportScheduler, - CodegenDataModelProviderInstance()); + CodegenDataModelProviderInstance(nullptr /* delegate */)); writer.Init(std::move(subscribeRequestbuf)); EXPECT_EQ(subscribeRequestBuilder.Init(&writer), CHIP_NO_ERROR); @@ -1933,7 +1933,7 @@ void TestReadInteraction::TestICDProcessSubscribeRequestInvalidIdleModeDuration( { ReadHandler readHandler(*engine, exchangeCtx, chip::app::ReadHandler::InteractionType::Read, gReportScheduler, - CodegenDataModelProviderInstance()); + CodegenDataModelProviderInstance(nullptr /* delegate */)); writer.Init(std::move(subscribeRequestbuf)); EXPECT_EQ(subscribeRequestBuilder.Init(&writer), CHIP_NO_ERROR); diff --git a/src/app/tests/TestReportScheduler.cpp b/src/app/tests/TestReportScheduler.cpp index 79ff67ec9bff25..49cd2ba07230a9 100644 --- a/src/app/tests/TestReportScheduler.cpp +++ b/src/app/tests/TestReportScheduler.cpp @@ -275,8 +275,9 @@ TEST_F_FROM_FIXTURE(TestReportScheduler, TestReadHandlerList) for (size_t i = 0; i < kNumMaxReadHandlers; i++) { - ReadHandler * readHandler = readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, - &sScheduler, CodegenDataModelProviderInstance()); + ReadHandler * readHandler = + readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, &sScheduler, + CodegenDataModelProviderInstance(nullptr /* delegate */)); sScheduler.OnSubscriptionEstablished(readHandler); ASSERT_NE(nullptr, readHandler); ASSERT_NE(nullptr, sScheduler.FindReadHandlerNode(readHandler)); @@ -339,20 +340,23 @@ TEST_F_FROM_FIXTURE(TestReportScheduler, TestReportTiming) // Dirty read handler, will be triggered at min interval // Test OnReadHandler created - ReadHandler * readHandler1 = readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, - &sScheduler, CodegenDataModelProviderInstance()); + ReadHandler * readHandler1 = + readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, &sScheduler, + CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(CHIP_NO_ERROR, MockReadHandlerSubscriptionTransaction(readHandler1, &sScheduler, 1, 2)); readHandler1->ForceDirtyState(); // Clean read handler, will be triggered at max interval - ReadHandler * readHandler2 = readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, - &sScheduler, CodegenDataModelProviderInstance()); + ReadHandler * readHandler2 = + readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, &sScheduler, + CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(CHIP_NO_ERROR, MockReadHandlerSubscriptionTransaction(readHandler2, &sScheduler, 0, 3)); // Clean read handler, will be triggered at max interval, but will be cancelled before - ReadHandler * readHandler3 = readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, - &sScheduler, CodegenDataModelProviderInstance()); + ReadHandler * readHandler3 = + readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, &sScheduler, + CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(CHIP_NO_ERROR, MockReadHandlerSubscriptionTransaction(readHandler3, &sScheduler, 0, 3)); // Confirms that none of the ReadHandlers are currently reportable @@ -406,7 +410,7 @@ TEST_F_FROM_FIXTURE(TestReportScheduler, TestObserverCallbacks) sTestTimerDelegate.SetMockSystemTimestamp(Milliseconds64(0)); ReadHandler * readHandler = readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, - &sScheduler, CodegenDataModelProviderInstance()); + &sScheduler, CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(CHIP_NO_ERROR, MockReadHandlerSubscriptionTransaction(readHandler, &sScheduler, 1, 2)); @@ -481,14 +485,16 @@ TEST_F_FROM_FIXTURE(TestReportScheduler, TestSynchronizedScheduler) // Initialize the mock system time sTestTimerSynchronizedDelegate.SetMockSystemTimestamp(System::Clock::Milliseconds64(0)); - ReadHandler * readHandler1 = readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, - &syncScheduler, CodegenDataModelProviderInstance()); + ReadHandler * readHandler1 = + readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, &syncScheduler, + CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(CHIP_NO_ERROR, MockReadHandlerSubscriptionTransaction(readHandler1, &syncScheduler, 0, 2)); ReadHandlerNode * node1 = syncScheduler.FindReadHandlerNode(readHandler1); - ReadHandler * readHandler2 = readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, - &syncScheduler, CodegenDataModelProviderInstance()); + ReadHandler * readHandler2 = + readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, &syncScheduler, + CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(CHIP_NO_ERROR, MockReadHandlerSubscriptionTransaction(readHandler2, &syncScheduler, 1, 3)); ReadHandlerNode * node2 = syncScheduler.FindReadHandlerNode(readHandler2); @@ -615,8 +621,9 @@ TEST_F_FROM_FIXTURE(TestReportScheduler, TestSynchronizedScheduler) // Wait for 1 second, nothing should happen here sTestTimerSynchronizedDelegate.IncrementMockTimestamp(System::Clock::Milliseconds64(1000)); - ReadHandler * readHandler3 = readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, - &syncScheduler, CodegenDataModelProviderInstance()); + ReadHandler * readHandler3 = + readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, &syncScheduler, + CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(CHIP_NO_ERROR, MockReadHandlerSubscriptionTransaction(readHandler3, &syncScheduler, 2, 3)); ReadHandlerNode * node3 = syncScheduler.FindReadHandlerNode(readHandler3); @@ -669,8 +676,9 @@ TEST_F_FROM_FIXTURE(TestReportScheduler, TestSynchronizedScheduler) EXPECT_EQ(syncScheduler.mNextReportTimestamp, node1->GetMaxTimestamp()); // Now simulate a new readHandler being added with a max forcing a conflict - ReadHandler * readHandler4 = readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, - &syncScheduler, CodegenDataModelProviderInstance()); + ReadHandler * readHandler4 = + readHandlerPool.CreateObject(nullCallback, exchangeCtx, ReadHandler::InteractionType::Subscribe, &syncScheduler, + CodegenDataModelProviderInstance(nullptr /* delegate */)); EXPECT_EQ(CHIP_NO_ERROR, MockReadHandlerSubscriptionTransaction(readHandler4, &syncScheduler, 0, 1)); ReadHandlerNode * node4 = syncScheduler.FindReadHandlerNode(readHandler4); diff --git a/src/app/tests/TestReportingEngine.cpp b/src/app/tests/TestReportingEngine.cpp index 3a16e43e6481f4..dc33e30c042a53 100644 --- a/src/app/tests/TestReportingEngine.cpp +++ b/src/app/tests/TestReportingEngine.cpp @@ -209,7 +209,8 @@ TEST_F_FROM_FIXTURE(TestReportingEngine, TestBuildAndSendSingleReportData) EXPECT_EQ(readRequestBuilder.GetError(), CHIP_NO_ERROR); EXPECT_EQ(writer.Finalize(&readRequestbuf), CHIP_NO_ERROR); app::ReadHandler readHandler(dummy, exchangeCtx, chip::app::ReadHandler::InteractionType::Read, - app::reporting::GetDefaultReportScheduler(), CodegenDataModelProviderInstance()); + app::reporting::GetDefaultReportScheduler(), + CodegenDataModelProviderInstance(nullptr /* delegate */)); readHandler.OnInitialRequest(std::move(readRequestbuf)); EXPECT_EQ(InteractionModelEngine::GetInstance()->GetReportingEngine().BuildAndSendSingleReportData(&readHandler), diff --git a/src/app/tests/test-interaction-model-api.cpp b/src/app/tests/test-interaction-model-api.cpp index 867d4c895ebf55..71e7d93036005a 100644 --- a/src/app/tests/test-interaction-model-api.cpp +++ b/src/app/tests/test-interaction-model-api.cpp @@ -151,17 +151,17 @@ std::optional TestImCustomDataModel::Invoke(const InvokeRequ DataModel::EndpointEntry TestImCustomDataModel::FirstEndpoint() { - return CodegenDataModelProviderInstance()->FirstEndpoint(); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->FirstEndpoint(); } DataModel::EndpointEntry TestImCustomDataModel::NextEndpoint(EndpointId before) { - return CodegenDataModelProviderInstance()->NextEndpoint(before); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->NextEndpoint(before); } std::optional TestImCustomDataModel::GetEndpointInfo(EndpointId endpoint) { - return CodegenDataModelProviderInstance()->GetEndpointInfo(endpoint); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->GetEndpointInfo(endpoint); } std::optional TestImCustomDataModel::FirstDeviceType(EndpointId endpoint) @@ -188,67 +188,67 @@ std::optional TestImCustomDataModel::GetNextSe ClusterEntry TestImCustomDataModel::FirstServerCluster(EndpointId endpoint) { - return CodegenDataModelProviderInstance()->FirstServerCluster(endpoint); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->FirstServerCluster(endpoint); } ClusterEntry TestImCustomDataModel::NextServerCluster(const ConcreteClusterPath & before) { - return CodegenDataModelProviderInstance()->NextServerCluster(before); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->NextServerCluster(before); } std::optional TestImCustomDataModel::GetServerClusterInfo(const ConcreteClusterPath & path) { - return CodegenDataModelProviderInstance()->GetServerClusterInfo(path); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->GetServerClusterInfo(path); } ConcreteClusterPath TestImCustomDataModel::FirstClientCluster(EndpointId endpoint) { - return CodegenDataModelProviderInstance()->FirstClientCluster(endpoint); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->FirstClientCluster(endpoint); } ConcreteClusterPath TestImCustomDataModel::NextClientCluster(const ConcreteClusterPath & before) { - return CodegenDataModelProviderInstance()->NextClientCluster(before); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->NextClientCluster(before); } AttributeEntry TestImCustomDataModel::FirstAttribute(const ConcreteClusterPath & cluster) { - return CodegenDataModelProviderInstance()->FirstAttribute(cluster); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->FirstAttribute(cluster); } AttributeEntry TestImCustomDataModel::NextAttribute(const ConcreteAttributePath & before) { - return CodegenDataModelProviderInstance()->NextAttribute(before); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->NextAttribute(before); } std::optional TestImCustomDataModel::GetAttributeInfo(const ConcreteAttributePath & path) { - return CodegenDataModelProviderInstance()->GetAttributeInfo(path); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->GetAttributeInfo(path); } CommandEntry TestImCustomDataModel::FirstAcceptedCommand(const ConcreteClusterPath & cluster) { - return CodegenDataModelProviderInstance()->FirstAcceptedCommand(cluster); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->FirstAcceptedCommand(cluster); } CommandEntry TestImCustomDataModel::NextAcceptedCommand(const ConcreteCommandPath & before) { - return CodegenDataModelProviderInstance()->NextAcceptedCommand(before); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->NextAcceptedCommand(before); } std::optional TestImCustomDataModel::GetAcceptedCommandInfo(const ConcreteCommandPath & path) { - return CodegenDataModelProviderInstance()->GetAcceptedCommandInfo(path); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->GetAcceptedCommandInfo(path); } ConcreteCommandPath TestImCustomDataModel::FirstGeneratedCommand(const ConcreteClusterPath & cluster) { - return CodegenDataModelProviderInstance()->FirstGeneratedCommand(cluster); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->FirstGeneratedCommand(cluster); } ConcreteCommandPath TestImCustomDataModel::NextGeneratedCommand(const ConcreteCommandPath & before) { - return CodegenDataModelProviderInstance()->NextGeneratedCommand(before); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->NextGeneratedCommand(before); } } // namespace app diff --git a/src/app/util/persistence/AttributePersistenceProvider.cpp b/src/app/util/persistence/AttributePersistenceProvider.cpp new file mode 100644 index 00000000000000..0f15474de6ba46 --- /dev/null +++ b/src/app/util/persistence/AttributePersistenceProvider.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +namespace chip { +namespace app { + +namespace { + +AttributePersistenceProvider * gAttributeSaver = nullptr; + +} // anonymous namespace + +AttributePersistenceProvider * GetAttributePersistenceProvider() +{ + return gAttributeSaver; +} + +void SetAttributePersistenceProvider(AttributePersistenceProvider * aProvider) +{ + VerifyOrReturn(aProvider != nullptr); + gAttributeSaver = aProvider; +} + +} // namespace app +} // namespace chip diff --git a/src/app/util/persistence/AttributePersistenceProvider.h b/src/app/util/persistence/AttributePersistenceProvider.h index 527582907ab15e..c26bb2e0a46b94 100644 --- a/src/app/util/persistence/AttributePersistenceProvider.h +++ b/src/app/util/persistence/AttributePersistenceProvider.h @@ -78,6 +78,10 @@ class AttributePersistenceProvider * Callers have to externally synchronize usage of this function. * * @return The global AttributePersistenceProvider. This must never be null. + * + * Note: When storing cluster attributes that are managed via AttributeAccessInterface, it is recommended to + * use SafeAttributePersistenceProvider. See AttributePersistenceProvider and SafeAttributePersistenceProvider + * class documentation for more information. */ AttributePersistenceProvider * GetAttributePersistenceProvider(); diff --git a/src/app/util/persistence/BUILD.gn b/src/app/util/persistence/BUILD.gn index dbc8dbe31b0c58..edba9178fca135 100644 --- a/src/app/util/persistence/BUILD.gn +++ b/src/app/util/persistence/BUILD.gn @@ -16,14 +16,15 @@ import("//build_overrides/chip.gni") source_set("persistence") { sources = [ + "AttributePersistenceProvider.cpp", "AttributePersistenceProvider.h", "DefaultAttributePersistenceProvider.cpp", "DefaultAttributePersistenceProvider.h", ] public_deps = [ - "${chip_root}/src/app:attribute-persistence", "${chip_root}/src/app:paths", + "${chip_root}/src/app:storage-wrapper", "${chip_root}/src/app/util:types", "${chip_root}/src/lib/core", "${chip_root}/src/lib/support", diff --git a/src/app/util/persistence/DefaultAttributePersistenceProvider.cpp b/src/app/util/persistence/DefaultAttributePersistenceProvider.cpp index 70488e80e7e1d7..38fd830b133853 100644 --- a/src/app/util/persistence/DefaultAttributePersistenceProvider.cpp +++ b/src/app/util/persistence/DefaultAttributePersistenceProvider.cpp @@ -23,34 +23,10 @@ namespace chip { namespace app { -CHIP_ERROR DefaultAttributePersistenceProvider::InternalWriteValue(const StorageKeyName & aKey, const ByteSpan & aValue) -{ - VerifyOrReturnError(mStorage != nullptr, CHIP_ERROR_INCORRECT_STATE); - - // TODO: we may want to have a small cache for values that change a lot, so - // we only write them once a bunch of changes happen or on timer or - // shutdown. - if (!CanCastTo(aValue.size())) - { - return CHIP_ERROR_BUFFER_TOO_SMALL; - } - return mStorage->SyncSetKeyValue(aKey.KeyName(), aValue.data(), static_cast(aValue.size())); -} - -CHIP_ERROR DefaultAttributePersistenceProvider::InternalReadValue(const StorageKeyName & aKey, MutableByteSpan & aValue) -{ - VerifyOrReturnError(mStorage != nullptr, CHIP_ERROR_INCORRECT_STATE); - - uint16_t size = static_cast(std::min(aValue.size(), static_cast(UINT16_MAX))); - ReturnErrorOnFailure(mStorage->SyncGetKeyValue(aKey.KeyName(), aValue.data(), size)); - aValue.reduce_size(size); - return CHIP_NO_ERROR; -} - CHIP_ERROR DefaultAttributePersistenceProvider::InternalReadValue(const StorageKeyName & aKey, EmberAfAttributeType aType, size_t aExpectedSize, MutableByteSpan & aValue) { - ReturnErrorOnFailure(InternalReadValue(aKey, aValue)); + ReturnErrorOnFailure(StorageDelegateWrapper::ReadValue(aKey, aValue)); size_t size = aValue.size(); if (emberAfIsStringAttributeType(aType)) { @@ -76,8 +52,8 @@ CHIP_ERROR DefaultAttributePersistenceProvider::InternalReadValue(const StorageK CHIP_ERROR DefaultAttributePersistenceProvider::WriteValue(const ConcreteAttributePath & aPath, const ByteSpan & aValue) { - return InternalWriteValue(DefaultStorageKeyAllocator::AttributeValue(aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId), - aValue); + return StorageDelegateWrapper::WriteValue( + DefaultStorageKeyAllocator::AttributeValue(aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId), aValue); } CHIP_ERROR DefaultAttributePersistenceProvider::ReadValue(const ConcreteAttributePath & aPath, @@ -87,65 +63,5 @@ CHIP_ERROR DefaultAttributePersistenceProvider::ReadValue(const ConcreteAttribut aMetadata->attributeType, aMetadata->size, aValue); } -CHIP_ERROR DefaultAttributePersistenceProvider::SafeWriteValue(const ConcreteAttributePath & aPath, const ByteSpan & aValue) -{ - return InternalWriteValue( - DefaultStorageKeyAllocator::SafeAttributeValue(aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId), aValue); -} - -CHIP_ERROR DefaultAttributePersistenceProvider::SafeReadValue(const ConcreteAttributePath & aPath, MutableByteSpan & aValue) -{ - return InternalReadValue( - DefaultStorageKeyAllocator::SafeAttributeValue(aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId), aValue); -} - -namespace { - -AttributePersistenceProvider * gAttributeSaver = nullptr; - -} // anonymous namespace - -/** - * Gets the global attribute saver. - * - * Note: When storing cluster attributes that are managed via AttributeAccessInterface, it is recommended to - * use SafeAttributePersistenceProvider. See AttributePersistenceProvider and SafeAttributePersistenceProvider - * class documentation for more information. - */ -AttributePersistenceProvider * GetAttributePersistenceProvider() -{ - return gAttributeSaver; -} - -void SetAttributePersistenceProvider(AttributePersistenceProvider * aProvider) -{ - if (aProvider != nullptr) - { - gAttributeSaver = aProvider; - } -} - -namespace { - -SafeAttributePersistenceProvider * gSafeAttributeSaver = nullptr; - -} // anonymous namespace - -/** - * Gets the global attribute safe saver. - */ -SafeAttributePersistenceProvider * GetSafeAttributePersistenceProvider() -{ - return gSafeAttributeSaver; -} - -void SetSafeAttributePersistenceProvider(SafeAttributePersistenceProvider * aProvider) -{ - if (aProvider != nullptr) - { - gSafeAttributeSaver = aProvider; - } -} - } // namespace app } // namespace chip diff --git a/src/app/util/persistence/DefaultAttributePersistenceProvider.h b/src/app/util/persistence/DefaultAttributePersistenceProvider.h index a4796f2b63b11d..29aac15ba90ac4 100644 --- a/src/app/util/persistence/DefaultAttributePersistenceProvider.h +++ b/src/app/util/persistence/DefaultAttributePersistenceProvider.h @@ -15,7 +15,7 @@ */ #pragma once -#include +#include #include #include #include @@ -31,39 +31,19 @@ namespace app { * of this class, since it can't be constructed automatically without knowing * what PersistentStorageDelegate is to be used. */ -class DefaultAttributePersistenceProvider : public AttributePersistenceProvider, public SafeAttributePersistenceProvider +class DefaultAttributePersistenceProvider : protected StorageDelegateWrapper, public AttributePersistenceProvider { public: - DefaultAttributePersistenceProvider() {} + DefaultAttributePersistenceProvider() = default; - // Passed-in storage must outlive this object. - CHIP_ERROR Init(PersistentStorageDelegate * storage) - { - if (storage == nullptr) - { - return CHIP_ERROR_INVALID_ARGUMENT; - } - mStorage = storage; - return CHIP_NO_ERROR; - } - - void Shutdown() {} + CHIP_ERROR Init(PersistentStorageDelegate * storage) { return StorageDelegateWrapper::Init(storage); } // AttributePersistenceProvider implementation. CHIP_ERROR WriteValue(const ConcreteAttributePath & aPath, const ByteSpan & aValue) override; CHIP_ERROR ReadValue(const ConcreteAttributePath & aPath, const EmberAfAttributeMetadata * aMetadata, MutableByteSpan & aValue) override; - // SafeAttributePersistenceProvider implementation. - CHIP_ERROR SafeWriteValue(const ConcreteAttributePath & aPath, const ByteSpan & aValue) override; - CHIP_ERROR SafeReadValue(const ConcreteAttributePath & aPath, MutableByteSpan & aValue) override; - -protected: - PersistentStorageDelegate * mStorage; - private: - CHIP_ERROR InternalWriteValue(const StorageKeyName & aKey, const ByteSpan & aValue); - CHIP_ERROR InternalReadValue(const StorageKeyName & aKey, MutableByteSpan & aValue); CHIP_ERROR InternalReadValue(const StorageKeyName & aKey, EmberAfAttributeType aType, size_t aExpectedSize, MutableByteSpan & aValue); }; diff --git a/src/app/util/persistence/tests/BUILD.gn b/src/app/util/persistence/tests/BUILD.gn deleted file mode 100644 index 7a0bd524305623..00000000000000 --- a/src/app/util/persistence/tests/BUILD.gn +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (c) 2024 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build_overrides/build.gni") -import("//build_overrides/chip.gni") -import("//build_overrides/pigweed.gni") - -import("${chip_root}/build/chip/chip_test_suite.gni") - -chip_test_suite("tests") { - output_name = "libAppUtilPersistenceTests" - - test_sources = [ "TestAttributePersistenceProvider.cpp" ] - - cflags = [ "-Wconversion" ] - - public_deps = [ - "${chip_root}/src/app/common:cluster-objects", - "${chip_root}/src/app/util/persistence", - "${chip_root}/src/lib/core:string-builder-adapters", - "${chip_root}/src/lib/support:testing", - ] -} diff --git a/src/controller/CHIPDeviceControllerFactory.cpp b/src/controller/CHIPDeviceControllerFactory.cpp index a5fe94dcd451e4..649c3a37408a26 100644 --- a/src/controller/CHIPDeviceControllerFactory.cpp +++ b/src/controller/CHIPDeviceControllerFactory.cpp @@ -135,7 +135,7 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params) if (params.dataModelProvider == nullptr) { ChipLogError(AppServer, "Device Controller Factory requires a `dataModelProvider` value."); - ChipLogError(AppServer, "For backwards compatibility, you likely can use `CodegenDataModelProviderInstance()`"); + ChipLogError(AppServer, "For backwards compatibility, you likely can use `CodegenDataModelProviderInstance(...)`"); } VerifyOrReturnError(params.dataModelProvider != nullptr, CHIP_ERROR_INVALID_ARGUMENT); diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index 2582e8f0e7afd5..704d9bacd29570 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -209,7 +209,7 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew( setupParams.defaultCommissioner = &wrapper->mAutoCommissioner; initParams.fabricIndependentStorage = wrapperStorage; initParams.sessionKeystore = &wrapper->mSessionKeystore; - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(wrapperStorage); wrapper->mGroupDataProvider.SetStorageDelegate(wrapperStorage); wrapper->mGroupDataProvider.SetSessionKeystore(initParams.sessionKeystore); diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp index b5dab55f84b6d8..6430776a6e8b0d 100644 --- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp +++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp @@ -272,7 +272,7 @@ PyChipError pychip_DeviceController_StackInit(Controller::Python::StorageAdapter factoryParams.fabricIndependentStorage = storageAdapter; factoryParams.sessionKeystore = &sSessionKeystore; - factoryParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + factoryParams.dataModelProvider = app::CodegenDataModelProviderInstance(storageAdapter); sICDClientStorage.Init(storageAdapter, &sSessionKeystore); diff --git a/src/controller/python/chip/internal/CommissionerImpl.cpp b/src/controller/python/chip/internal/CommissionerImpl.cpp index 92596af704050b..b86dad3f916084 100644 --- a/src/controller/python/chip/internal/CommissionerImpl.cpp +++ b/src/controller/python/chip/internal/CommissionerImpl.cpp @@ -137,7 +137,7 @@ extern "C" chip::Controller::DeviceCommissioner * pychip_internal_Commissioner_N factoryParams.fabricIndependentStorage = &gServerStorage; factoryParams.sessionKeystore = &gSessionKeystore; - factoryParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(); + factoryParams.dataModelProvider = chip::app::CodegenDataModelProviderInstance(&gServerStorage); // Initialize group data provider for local group key state and IPKs gGroupDataProvider.SetStorageDelegate(&gServerStorage); diff --git a/src/controller/python/chip/server/ServerInit.cpp b/src/controller/python/chip/server/ServerInit.cpp index 83bb8acefecd89..9089237aa41c7e 100644 --- a/src/controller/python/chip/server/ServerInit.cpp +++ b/src/controller/python/chip/server/ServerInit.cpp @@ -162,7 +162,7 @@ PyChipError pychip_server_native_init() // Init ZCL Data Model and CHIP App Server static chip::CommonCaseDeviceServerInitParams initParams; PyReturnErrorOnFailure(ToPyChipError(initParams.InitializeStaticResourcesBeforeServerInit())); - initParams.dataModelProvider = app::CodegenDataModelProviderInstance(); + initParams.dataModelProvider = app::CodegenDataModelProviderInstance(initParams.persistentStorageDelegate); initParams.operationalServicePort = CHIP_PORT; initParams.userDirectedCommissioningPort = CHIP_UDC_PORT; diff --git a/src/controller/tests/TestEventChunking.cpp b/src/controller/tests/TestEventChunking.cpp index 17e8ece034f1b3..8fa260da41c712 100644 --- a/src/controller/tests/TestEventChunking.cpp +++ b/src/controller/tests/TestEventChunking.cpp @@ -287,8 +287,8 @@ TEST_F(TestEventChunking, TestEventChunking) app::InteractionModelEngine * engine = app::InteractionModelEngine::GetInstance(); // Initialize the ember side server logic - CodegenDataModelProviderInstance()->Shutdown(); - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + CodegenDataModelProviderInstance(nullptr /* delegate */)->Shutdown(); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); InitDataModelHandler(); // Register our fake dynamic endpoint. @@ -355,8 +355,8 @@ TEST_F(TestEventChunking, TestMixedEventsAndAttributesChunking) app::InteractionModelEngine * engine = app::InteractionModelEngine::GetInstance(); // Initialize the ember side server logic - CodegenDataModelProviderInstance()->Shutdown(); - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + CodegenDataModelProviderInstance(nullptr /* delegate */)->Shutdown(); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); InitDataModelHandler(); // Register our fake dynamic endpoint. @@ -433,8 +433,8 @@ TEST_F(TestEventChunking, TestMixedEventsAndLargeAttributesChunking) app::InteractionModelEngine * engine = app::InteractionModelEngine::GetInstance(); // Initialize the ember side server logic - CodegenDataModelProviderInstance()->Shutdown(); - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + CodegenDataModelProviderInstance(nullptr /* delegate */)->Shutdown(); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); InitDataModelHandler(); // Register our fake dynamic endpoint. diff --git a/src/controller/tests/TestReadChunking.cpp b/src/controller/tests/TestReadChunking.cpp index 8614b6acf4ad7d..d05c1fe522c42d 100644 --- a/src/controller/tests/TestReadChunking.cpp +++ b/src/controller/tests/TestReadChunking.cpp @@ -482,7 +482,7 @@ TEST_F(TestReadChunking, TestChunking) app::InteractionModelEngine * engine = app::InteractionModelEngine::GetInstance(); // Initialize the ember side server logic - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); InitDataModelHandler(); // Register our fake dynamic endpoint. @@ -545,7 +545,7 @@ TEST_F(TestReadChunking, TestListChunking) app::InteractionModelEngine * engine = app::InteractionModelEngine::GetInstance(); // Initialize the ember side server logic - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); InitDataModelHandler(); // Register our fake dynamic endpoint. @@ -647,7 +647,7 @@ TEST_F(TestReadChunking, TestBadChunking) app::InteractionModelEngine * engine = app::InteractionModelEngine::GetInstance(); // Initialize the ember side server logic - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); InitDataModelHandler(); app::InteractionModelEngine::GetInstance()->GetReportingEngine().SetWriterReserved(0); @@ -699,7 +699,7 @@ TEST_F(TestReadChunking, TestDynamicEndpoint) app::InteractionModelEngine * engine = app::InteractionModelEngine::GetInstance(); // Initialize the ember side server logic - engine->SetDataModelProvider(CodegenDataModelProviderInstance()); + engine->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); InitDataModelHandler(); // Register our fake dynamic endpoint. diff --git a/src/controller/tests/TestWriteChunking.cpp b/src/controller/tests/TestWriteChunking.cpp index f2f5a0822b48d2..39c73c7e7b28aa 100644 --- a/src/controller/tests/TestWriteChunking.cpp +++ b/src/controller/tests/TestWriteChunking.cpp @@ -212,7 +212,7 @@ TEST_F(TestWriteChunking, TestListChunking) auto sessionHandle = GetSessionBobToAlice(); // Initialize the ember side server logic - app::InteractionModelEngine::GetInstance()->SetDataModelProvider(CodegenDataModelProviderInstance()); + app::InteractionModelEngine::GetInstance()->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); InitDataModelHandler(); // Register our fake dynamic endpoint. @@ -286,7 +286,7 @@ TEST_F(TestWriteChunking, TestBadChunking) bool atLeastOneRequestFailed = false; // Initialize the ember side server logic - app::InteractionModelEngine::GetInstance()->SetDataModelProvider(CodegenDataModelProviderInstance()); + app::InteractionModelEngine::GetInstance()->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); InitDataModelHandler(); // Register our fake dynamic endpoint. @@ -366,7 +366,7 @@ TEST_F(TestWriteChunking, TestConflictWrite) auto sessionHandle = GetSessionBobToAlice(); // Initialize the ember side server logic - app::InteractionModelEngine::GetInstance()->SetDataModelProvider(CodegenDataModelProviderInstance()); + app::InteractionModelEngine::GetInstance()->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); InitDataModelHandler(); // Register our fake dynamic endpoint. @@ -441,7 +441,7 @@ TEST_F(TestWriteChunking, TestNonConflictWrite) auto sessionHandle = GetSessionBobToAlice(); // Initialize the ember side server logic - app::InteractionModelEngine::GetInstance()->SetDataModelProvider(CodegenDataModelProviderInstance()); + app::InteractionModelEngine::GetInstance()->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); InitDataModelHandler(); // Register our fake dynamic endpoint. @@ -590,7 +590,7 @@ void TestWriteChunking::RunTest(Instructions instructions) TEST_F(TestWriteChunking, TestTransactionalList) { // Initialize the ember side server logic - app::InteractionModelEngine::GetInstance()->SetDataModelProvider(CodegenDataModelProviderInstance()); + app::InteractionModelEngine::GetInstance()->SetDataModelProvider(CodegenDataModelProviderInstance(nullptr /* delegate */)); InitDataModelHandler(); // Register our fake dynamic endpoint. diff --git a/src/controller/tests/data_model/DataModelFixtures.cpp b/src/controller/tests/data_model/DataModelFixtures.cpp index 7ef9975bdfddcd..c0054043fe4bbf 100644 --- a/src/controller/tests/data_model/DataModelFixtures.cpp +++ b/src/controller/tests/data_model/DataModelFixtures.cpp @@ -476,17 +476,17 @@ std::optional CustomDataModel::Invoke(const InvokeRequest & DataModel::EndpointEntry CustomDataModel::FirstEndpoint() { - return CodegenDataModelProviderInstance()->FirstEndpoint(); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->FirstEndpoint(); } DataModel::EndpointEntry CustomDataModel::NextEndpoint(EndpointId before) { - return CodegenDataModelProviderInstance()->NextEndpoint(before); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->NextEndpoint(before); } std::optional CustomDataModel::GetEndpointInfo(EndpointId endpoint) { - return CodegenDataModelProviderInstance()->GetEndpointInfo(endpoint); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->GetEndpointInfo(endpoint); } std::optional CustomDataModel::FirstDeviceType(EndpointId endpoint) @@ -513,67 +513,67 @@ std::optional CustomDataModel::GetNextSemantic ClusterEntry CustomDataModel::FirstServerCluster(EndpointId endpoint) { - return CodegenDataModelProviderInstance()->FirstServerCluster(endpoint); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->FirstServerCluster(endpoint); } ClusterEntry CustomDataModel::NextServerCluster(const ConcreteClusterPath & before) { - return CodegenDataModelProviderInstance()->NextServerCluster(before); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->NextServerCluster(before); } std::optional CustomDataModel::GetServerClusterInfo(const ConcreteClusterPath & path) { - return CodegenDataModelProviderInstance()->GetServerClusterInfo(path); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->GetServerClusterInfo(path); } ConcreteClusterPath CustomDataModel::FirstClientCluster(EndpointId endpoint) { - return CodegenDataModelProviderInstance()->FirstClientCluster(endpoint); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->FirstClientCluster(endpoint); } ConcreteClusterPath CustomDataModel::NextClientCluster(const ConcreteClusterPath & before) { - return CodegenDataModelProviderInstance()->NextClientCluster(before); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->NextClientCluster(before); } AttributeEntry CustomDataModel::FirstAttribute(const ConcreteClusterPath & cluster) { - return CodegenDataModelProviderInstance()->FirstAttribute(cluster); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->FirstAttribute(cluster); } AttributeEntry CustomDataModel::NextAttribute(const ConcreteAttributePath & before) { - return CodegenDataModelProviderInstance()->NextAttribute(before); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->NextAttribute(before); } std::optional CustomDataModel::GetAttributeInfo(const ConcreteAttributePath & path) { - return CodegenDataModelProviderInstance()->GetAttributeInfo(path); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->GetAttributeInfo(path); } CommandEntry CustomDataModel::FirstAcceptedCommand(const ConcreteClusterPath & cluster) { - return CodegenDataModelProviderInstance()->FirstAcceptedCommand(cluster); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->FirstAcceptedCommand(cluster); } CommandEntry CustomDataModel::NextAcceptedCommand(const ConcreteCommandPath & before) { - return CodegenDataModelProviderInstance()->NextAcceptedCommand(before); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->NextAcceptedCommand(before); } std::optional CustomDataModel::GetAcceptedCommandInfo(const ConcreteCommandPath & path) { - return CodegenDataModelProviderInstance()->GetAcceptedCommandInfo(path); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->GetAcceptedCommandInfo(path); } ConcreteCommandPath CustomDataModel::FirstGeneratedCommand(const ConcreteClusterPath & cluster) { - return CodegenDataModelProviderInstance()->FirstGeneratedCommand(cluster); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->FirstGeneratedCommand(cluster); } ConcreteCommandPath CustomDataModel::NextGeneratedCommand(const ConcreteCommandPath & before) { - return CodegenDataModelProviderInstance()->NextGeneratedCommand(before); + return CodegenDataModelProviderInstance(nullptr /* delegate */)->NextGeneratedCommand(before); } } // namespace app diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm index 4eb7328949ec0a..e0c5f8283aa189 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm @@ -399,7 +399,7 @@ - (BOOL)_startControllerFactory:(MTRDeviceControllerFactoryParams *)startupParam params.opCertStore = _opCertStore; params.certificateValidityPolicy = &_certificateValidityPolicy; params.sessionResumptionStorage = _sessionResumptionStorage; - params.dataModelProvider = app::CodegenDataModelProviderInstance(); + params.dataModelProvider = app::CodegenDataModelProviderInstance(_persistentStorageDelegate); SuccessOrExit(err = _controllerFactory->Init(params)); } diff --git a/src/darwin/Framework/Matter.xcodeproj/project.pbxproj b/src/darwin/Framework/Matter.xcodeproj/project.pbxproj index 8510fc3456fed0..2420581978c855 100644 --- a/src/darwin/Framework/Matter.xcodeproj/project.pbxproj +++ b/src/darwin/Framework/Matter.xcodeproj/project.pbxproj @@ -261,6 +261,14 @@ 5AE6D4E427A99041001F2493 /* MTRDeviceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AE6D4E327A99041001F2493 /* MTRDeviceTests.m */; }; 75139A6F2B7FE5E900E3A919 /* MTRDeviceControllerLocalTestStorage.mm in Sources */ = {isa = PBXBuildFile; fileRef = 75139A6E2B7FE5E900E3A919 /* MTRDeviceControllerLocalTestStorage.mm */; }; 75139A702B7FE68C00E3A919 /* MTRDeviceControllerLocalTestStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 75139A6D2B7FE5D600E3A919 /* MTRDeviceControllerLocalTestStorage.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 7534D1782CF8CDDF00F64654 /* AttributePersistenceProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7534D1772CF8CDDF00F64654 /* AttributePersistenceProvider.cpp */; }; + 7534D1792CF8CDDF00F64654 /* AttributePersistenceProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 7534D1762CF8CDDF00F64654 /* AttributePersistenceProvider.h */; }; + 7534D17A2CF8CDDF00F64654 /* AttributePersistenceProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7534D1772CF8CDDF00F64654 /* AttributePersistenceProvider.cpp */; }; + 7534D17B2CF8CDDF00F64654 /* AttributePersistenceProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 7534D1762CF8CDDF00F64654 /* AttributePersistenceProvider.h */; }; + 7534D17E2CF8CE2000F64654 /* DefaultAttributePersistenceProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 7534D17C2CF8CE2000F64654 /* DefaultAttributePersistenceProvider.h */; }; + 7534D17F2CF8CE2000F64654 /* DefaultAttributePersistenceProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7534D17D2CF8CE2000F64654 /* DefaultAttributePersistenceProvider.cpp */; }; + 7534D1802CF8CE2000F64654 /* DefaultAttributePersistenceProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7534D17D2CF8CE2000F64654 /* DefaultAttributePersistenceProvider.cpp */; }; + 7534D1812CF8CE2000F64654 /* DefaultAttributePersistenceProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 7534D17C2CF8CE2000F64654 /* DefaultAttributePersistenceProvider.h */; }; 7534F12828BFF20300390851 /* MTRDeviceAttestationDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7534F12628BFF20300390851 /* MTRDeviceAttestationDelegate.mm */; }; 7534F12928BFF20300390851 /* MTRDeviceAttestationDelegate_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 7534F12728BFF20300390851 /* MTRDeviceAttestationDelegate_Internal.h */; }; 754784652BFE65CB0089C372 /* MTRDeviceStorageBehaviorConfiguration.mm in Sources */ = {isa = PBXBuildFile; fileRef = 754784642BFE65CB0089C372 /* MTRDeviceStorageBehaviorConfiguration.mm */; }; @@ -751,6 +759,10 @@ 75139A6C2B7FE19100E3A919 /* MTRTestDeclarations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MTRTestDeclarations.h; sourceTree = ""; }; 75139A6D2B7FE5D600E3A919 /* MTRDeviceControllerLocalTestStorage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MTRDeviceControllerLocalTestStorage.h; sourceTree = ""; }; 75139A6E2B7FE5E900E3A919 /* MTRDeviceControllerLocalTestStorage.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MTRDeviceControllerLocalTestStorage.mm; sourceTree = ""; }; + 7534D1762CF8CDDF00F64654 /* AttributePersistenceProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = AttributePersistenceProvider.h; path = ../../app/util/persistence/AttributePersistenceProvider.h; sourceTree = ""; }; + 7534D1772CF8CDDF00F64654 /* AttributePersistenceProvider.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = AttributePersistenceProvider.cpp; path = ../../app/util/persistence/AttributePersistenceProvider.cpp; sourceTree = ""; }; + 7534D17C2CF8CE2000F64654 /* DefaultAttributePersistenceProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DefaultAttributePersistenceProvider.h; path = ../../app/util/persistence/DefaultAttributePersistenceProvider.h; sourceTree = ""; }; + 7534D17D2CF8CE2000F64654 /* DefaultAttributePersistenceProvider.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = DefaultAttributePersistenceProvider.cpp; path = ../../app/util/persistence/DefaultAttributePersistenceProvider.cpp; sourceTree = ""; }; 7534F12628BFF20300390851 /* MTRDeviceAttestationDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MTRDeviceAttestationDelegate.mm; sourceTree = ""; }; 7534F12728BFF20300390851 /* MTRDeviceAttestationDelegate_Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTRDeviceAttestationDelegate_Internal.h; sourceTree = ""; }; 754784632BFE65B70089C372 /* MTRDeviceStorageBehaviorConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MTRDeviceStorageBehaviorConfiguration.h; sourceTree = ""; }; @@ -1172,6 +1184,7 @@ 1E857311265519DE0050A4D9 /* app */ = { isa = PBXGroup; children = ( + 7534D1822CF8CE2C00F64654 /* persistence */, 7521D2932CBECE3F00218E16 /* codegen-data-model-provider */, 75A202E72BA8DBB700A771DD /* reporting */, 5143041F2914CED9004DC7FE /* generic-callback-stubs.cpp */, @@ -1349,6 +1362,17 @@ path = "codegen-data-model-provider"; sourceTree = ""; }; + 7534D1822CF8CE2C00F64654 /* persistence */ = { + isa = PBXGroup; + children = ( + 7534D17C2CF8CE2000F64654 /* DefaultAttributePersistenceProvider.h */, + 7534D17D2CF8CE2000F64654 /* DefaultAttributePersistenceProvider.cpp */, + 7534D1762CF8CDDF00F64654 /* AttributePersistenceProvider.h */, + 7534D1772CF8CDDF00F64654 /* AttributePersistenceProvider.cpp */, + ); + path = persistence; + sourceTree = ""; + }; 75A202E72BA8DBB700A771DD /* reporting */ = { isa = PBXGroup; children = ( @@ -1766,6 +1790,7 @@ B43B39EC2CB859A5006AA284 /* DumpMemoryGraphCommand.h in Headers */, B43B39ED2CB859A5006AA284 /* Commands.h in Headers */, B43B39EE2CB859A5006AA284 /* LeaksTool.h in Headers */, + 7534D17E2CF8CE2000F64654 /* DefaultAttributePersistenceProvider.h in Headers */, 037C3DBD2991BD5000B7EEE2 /* OTAProviderDelegate.h in Headers */, B4FCD5702B603A6300832859 /* Commands.h in Headers */, 037C3DB02991BD4F00B7EEE2 /* Commands.h in Headers */, @@ -1778,6 +1803,7 @@ 037C3DCC2991BD5100B7EEE2 /* MTRError_Utils.h in Headers */, 7592BD002CBEE98C00EB74A0 /* Instance.h in Headers */, 7592BD012CBEE98C00EB74A0 /* EmberMetadata.h in Headers */, + 7534D17B2CF8CDDF00F64654 /* AttributePersistenceProvider.h in Headers */, 7592BD022CBEE98C00EB74A0 /* CodegenDataModelProvider.h in Headers */, 037C3DAD2991BD4F00B7EEE2 /* PairingCommandBridge.h in Headers */, 037C3DBB2991BD5000B7EEE2 /* Commands.h in Headers */, @@ -1831,8 +1857,10 @@ 7534F12928BFF20300390851 /* MTRDeviceAttestationDelegate_Internal.h in Headers */, D4772A46285AE98400383630 /* MTRClusterConstants.h in Headers */, 3DA1A3552ABAB3B4004F0BB9 /* MTRAsyncWorkQueue.h in Headers */, + 7534D1792CF8CDDF00F64654 /* AttributePersistenceProvider.h in Headers */, B289D4212639C0D300D4E314 /* MTROnboardingPayloadParser.h in Headers */, 513DDB862761F69300DAA01A /* MTRAttributeTLVValueDecoder_Internal.h in Headers */, + 7534D1812CF8CE2000F64654 /* DefaultAttributePersistenceProvider.h in Headers */, 2CB7163F252F731E0026E2BB /* MTRDeviceControllerDelegate.h in Headers */, 88EBF8CE27FABDD500686BC1 /* MTRDeviceAttestationDelegate.h in Headers */, 2C222AD0255C620600E446B9 /* MTRBaseDevice.h in Headers */, @@ -2154,6 +2182,7 @@ 0395469F2991DFC5006D42A8 /* json_reader.cpp in Sources */, 514C79F42B62ED5500DD6D7B /* attribute-storage.cpp in Sources */, 0395469E2991DFC5006D42A8 /* json_writer.cpp in Sources */, + 7534D17F2CF8CE2000F64654 /* DefaultAttributePersistenceProvider.cpp in Sources */, 03FB93E02A46200A0048CB35 /* DiscoverCommissionablesCommand.mm in Sources */, 516411332B6BF77700E67C05 /* MTRServerAccessControl.mm in Sources */, 037C3DD52991C2E200B7EEE2 /* CHIPCommandBridge.mm in Sources */, @@ -2179,6 +2208,7 @@ 512431292BA0C8BF000BC136 /* ResetMRPParametersCommand.mm in Sources */, 037C3DB32991BD5000B7EEE2 /* OpenCommissioningWindowCommand.mm in Sources */, 037C3DAE2991BD4F00B7EEE2 /* PairingCommandBridge.mm in Sources */, + 7534D17A2CF8CDDF00F64654 /* AttributePersistenceProvider.cpp in Sources */, 514C79FD2B62F94C00DD6D7B /* ota-provider.cpp in Sources */, 037C3DCA2991BD5100B7EEE2 /* CHIPCommandStorageDelegate.mm in Sources */, 037C3DCF2991BD5200B7EEE2 /* MTRError.mm in Sources */, @@ -2263,6 +2293,7 @@ 9B231B052C62EF650030EB37 /* MTRDeviceController_Concrete.mm in Sources */, 5ACDDD7D27CD16D200EFD68A /* MTRClusterStateCacheContainer.mm in Sources */, 75B3269E2BCDB9EA00E17C4E /* MTRDeviceConnectivityMonitor.mm in Sources */, + 7534D1802CF8CE2000F64654 /* DefaultAttributePersistenceProvider.cpp in Sources */, 9B5CCB5C2C6EC890009DD99B /* MTRDevice_XPC.mm in Sources */, 513DDB8A2761F6F900DAA01A /* MTRAttributeTLVValueDecoder.mm in Sources */, 5117DD3829A931AE00FFA1AA /* MTROperationalBrowser.mm in Sources */, @@ -2277,6 +2308,7 @@ 3CF134AD289D8E570017A19E /* MTRDeviceAttestationInfo.mm in Sources */, 2C1B027A2641DB4E00780EF1 /* MTROperationalCredentialsDelegate.mm in Sources */, 754784652BFE65CB0089C372 /* MTRDeviceStorageBehaviorConfiguration.mm in Sources */, + 7534D1782CF8CDDF00F64654 /* AttributePersistenceProvider.cpp in Sources */, 7560FD1C27FBBD3F005E85B3 /* MTREventTLVValueDecoder.mm in Sources */, 5178E67E2AE098210069DF72 /* MTRCommandTimedCheck.mm in Sources */, 7596A84928762783004DAE0E /* MTRAsyncCallbackWorkQueue.mm in Sources */, diff --git a/src/python_testing/test_metadata.yaml b/src/python_testing/test_metadata.yaml index 3ff104a1a51f6b..a6f0ba5bf6174e 100644 --- a/src/python_testing/test_metadata.yaml +++ b/src/python_testing/test_metadata.yaml @@ -81,6 +81,8 @@ slow_tests: - { name: mobile-device-test.py, duration: 3 minutes } - { name: TC_AccessChecker.py, duration: 1.5 minutes } - { name: TC_BRBINFO_4_1.py, duration: 2 minutes } + - { name: TC_CADMIN_1_19.py, duration: 30 seconds } + - { name: TC_CADMIN_1_22_24.py, duration: 3 minutes } - { name: TC_CADMIN_1_9.py, duration: 40 seconds } - { name: TC_CC_2_2.py, duration: 1.5 minutes } - { name: TC_DEM_2_10.py, duration: 40 seconds }