Skip to content

Commit

Permalink
Migrated to persistent storage delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
swan-amazon committed Jun 6, 2024
1 parent 3ccec30 commit f0e1c75
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
1 change: 1 addition & 0 deletions examples/all-clusters-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ if (is_libfuzzer) {
deps = [
":chip-all-clusters-common",
"${chip_root}/examples/platform/linux:app-main",
"${chip_root}/src/app/server:server-full",
]

cflags = [ "-Wconversion" ]
Expand Down
39 changes: 21 additions & 18 deletions src/app/server/DefaultTermsAndConditionsProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,39 @@
#include <CHIPProjectConfig.h>
#include <platform/KeyValueStoreManager.h>

#ifndef CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS
#error "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS is not defined!"
#endif

#ifndef CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION
#error "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION is not defined!"
#endif

CHIP_ERROR
chip::app::DefaultTermsAndConditionsProvider::Init(chip::DeviceLayer::PersistedStorage::KeyValueStoreManager * const inKvsManager)
chip::app::DefaultTermsAndConditionsProvider::Init(chip::PersistentStorageDelegate * inPersistentStorageDelegate)
{
mKeyValueStoreManager = inKvsManager;
mPersistentStorageDelegate = inPersistentStorageDelegate;
return CHIP_NO_ERROR;
}

CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetAcceptance(uint16_t & outAcknowledgementsValue,
uint16_t & outAcknowledgementsVersionValue)
{
uint16_t acknowledgements = 0;
uint16_t acknowledgementsVersion = 0;
uint16_t acknowledgements = 0;
uint16_t acknowledgementsSize = sizeof(acknowledgementsSize);
uint16_t acknowledgementsVersion = 0;
uint16_t acknowledgementsVersionSize = sizeof(acknowledgementsVersion);

mKeyValueStoreManager->Get(kAcceptedAcknowledgementsKeyName, &acknowledgements, sizeof(acknowledgements));
mKeyValueStoreManager->Get(kAcceptedAcknowledgementsVersionKeyName, &acknowledgementsVersion, sizeof(acknowledgementsVersion));
mPersistentStorageDelegate->SyncGetKeyValue(kAcceptedAcknowledgementsKeyName, &acknowledgements, acknowledgementsSize);
mPersistentStorageDelegate->SyncGetKeyValue(kAcceptedAcknowledgementsVersionKeyName, &acknowledgementsVersion,
acknowledgementsVersionSize);

outAcknowledgementsValue = acknowledgements;
outAcknowledgementsVersionValue = acknowledgementsVersion;

return CHIP_NO_ERROR;
}

#ifndef CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS
#error "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS is not defined!"
#endif

#ifndef CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION
#error "CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION is not defined!"
#endif

CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetRequirements(uint16_t & outAcknowledgementsValue,
uint16_t & outAcknowledgementsVersionValue)
{
Expand All @@ -62,9 +65,9 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetRequirements(uint16_
CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::SetAcceptance(uint16_t inAcceptedAcknowledgementsValue,
uint16_t inAcceptedAcknowledgementsVersionValue)
{
mKeyValueStoreManager->Put(kAcceptedAcknowledgementsKeyName, &inAcceptedAcknowledgementsValue,
sizeof(inAcceptedAcknowledgementsValue));
mKeyValueStoreManager->Put(kAcceptedAcknowledgementsVersionKeyName, &inAcceptedAcknowledgementsVersionValue,
sizeof(inAcceptedAcknowledgementsVersionValue));
mPersistentStorageDelegate->SyncSetKeyValue(kAcceptedAcknowledgementsKeyName, &inAcceptedAcknowledgementsValue,
sizeof(inAcceptedAcknowledgementsValue));
mPersistentStorageDelegate->SyncSetKeyValue(kAcceptedAcknowledgementsVersionKeyName, &inAcceptedAcknowledgementsVersionValue,
sizeof(inAcceptedAcknowledgementsVersionValue));
return CHIP_NO_ERROR;
}
8 changes: 4 additions & 4 deletions src/app/server/DefaultTermsAndConditionsProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <stdint.h>

#include <lib/core/CHIPError.h>
#include <platform/KeyValueStoreManager.h>
#include <lib/core/CHIPPersistentStorageDelegate.h>

namespace chip {
namespace app {
Expand All @@ -36,10 +36,10 @@ class DefaultTermsAndConditionsProvider : public TermsAndConditionsProvider
/**
* @brief Initializes the TermsAndConditionsProvider.
*
* @param[in] inKvsManager The KVS manager dependency.
* @param[in] inPersistentStorageDelegate Persistent storage delegate dependency.
* @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code.
*/
virtual CHIP_ERROR Init(chip::DeviceLayer::PersistedStorage::KeyValueStoreManager * inKvsManager);
virtual CHIP_ERROR Init(chip::PersistentStorageDelegate * inPersistentStorageDelegate);

/**
* @brief Retrieves the acceptance status of the required terms and conditions.
Expand Down Expand Up @@ -69,7 +69,7 @@ class DefaultTermsAndConditionsProvider : public TermsAndConditionsProvider
virtual CHIP_ERROR SetAcceptance(uint16_t inAcknowledgementsValue, uint16_t inAcknowledgementsVersionValue);

private:
chip::DeviceLayer::PersistedStorage::KeyValueStoreManager * mKeyValueStoreManager;
chip::PersistentStorageDelegate * mPersistentStorageDelegate;
};

}; // namespace app
Expand Down
2 changes: 1 addition & 1 deletion src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ CHIP_ERROR CommonCaseDeviceServerInitParams::InitializeStaticResourcesBeforeServ

if (this->termsAndConditionsProvider == nullptr)
{
ReturnErrorOnFailure(sDefaultTermsAndConditionsProviderInstance.Init(&kvsManager));
ReturnErrorOnFailure(sDefaultTermsAndConditionsProviderInstance.Init(this->persistentStorageDelegate));
this->termsAndConditionsProvider = sDefaultTermsAndConditionsProvider;
}

Expand Down
2 changes: 1 addition & 1 deletion src/controller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static_library("controller") {

public_deps = [
"${chip_root}/src/app",
"${chip_root}/src/app/server:server-full",
"${chip_root}/src/app/server:server",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/dnssd",
"${chip_root}/src/lib/support",
Expand Down

0 comments on commit f0e1c75

Please sign in to comment.