Skip to content

Commit

Permalink
Fix up logic for Deferred persistence providers
Browse files Browse the repository at this point in the history
  • Loading branch information
andreilitvin committed Nov 19, 2024
1 parent 7cad7d6 commit b4f465f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
13 changes: 9 additions & 4 deletions examples/lighting-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ 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(),
Span<DeferredAttribute>(&gCurrentLevelPersister, 1),
System::Clock::Milliseconds32(5000));

DeferredAttributePersistenceProvider gDeferredAttributePersister;

#ifdef CONFIG_CHIP_CRYPTO_PSA
chip::Crypto::PSAOperationalKeystore sPSAOperationalKeystore{};
Expand Down Expand Up @@ -278,7 +277,13 @@ CHIP_ERROR AppTask::Init()

gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage());
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);
app::SetAttributePersistenceProvider(&gDeferredAttributePersister);

// Server will initialize a persistence provider
VerifyOrDie(GetAttributePersistenceProvider() != nullptr);
VerifyOrDie(gDeferredAttributePersister.Init(*GetAttributePersistenceProvider(),
Span<DeferredAttribute>(&gCurrentLevelPersister, 1),
System::Clock::Milliseconds32(5000)) == CHIP_NO_ERROR);
SetAttributePersistenceProvider(&gDeferredAttributePersister);

ConfigurationMgr().LogDeviceConfig();
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE));
Expand Down
11 changes: 7 additions & 4 deletions examples/lighting-app/qpg/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <app/server/Dnssd.h>
#include <app/server/Server.h>
#include <app/util/attribute-storage.h>
#include <app/util/persistence/AttributePersistenceProvider.h>
#include <lib/support/TypeTraits.h>

#include <app/util/persistence/DeferredAttributePersistenceProvider.h>
Expand Down Expand Up @@ -113,9 +114,7 @@ DeferredAttribute gPersisters[] = {

};

DeferredAttributePersistenceProvider gDeferredAttributePersister(Server::GetInstance().GetDefaultAttributePersister(),
Span<DeferredAttribute>(gPersisters, 3),
System::Clock::Milliseconds32(5000));
DeferredAttributePersistenceProvider gDeferredAttributePersister;

/**********************************************************
* Identify Callbacks
Expand Down Expand Up @@ -277,7 +276,11 @@ void AppTask::InitServer(intptr_t arg)

chip::Server::GetInstance().Init(initParams);

app::SetAttributePersistenceProvider(&gDeferredAttributePersister);
// Server will initialize a persistence provider
VerifyOrDie(GetAttributePersistenceProvider() != nullptr);
VerifyOrDie(gDeferredAttributePersister.Init(*GetAttributePersistenceProvider(), Span<DeferredAttribute>(gPersisters, 3),
System::Clock::Milliseconds32(5000)) == CHIP_NO_ERROR);
SetAttributePersistenceProvider(&gDeferredAttributePersister);

#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
chip::app::DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(extDiscTimeoutSecs);
Expand Down

0 comments on commit b4f465f

Please sign in to comment.