From 3535643db9779e427364ffff35e6bdcbb637c71d Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Thu, 14 Apr 2022 11:31:57 -0700 Subject: [PATCH] =?UTF-8?q?[linux]=20Use=20generic=20PersistentStorageDele?= =?UTF-8?q?gate=20instead=20of=20ChipLinuxSto=E2=80=A6=20(#17371)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [linux] Use generic PersistentStorageDelegate instead of ChipLinuxStorage for userlabel * Update src/platform/Linux/DeviceInfoProviderImpl.cpp Co-authored-by: Boris Zbarsky Co-authored-by: Boris Zbarsky --- .../Darwin/DeviceInfoProviderImpl.cpp | 1 - src/platform/Linux/DeviceInfoProviderImpl.cpp | 51 ++++++++++++------- src/platform/Linux/DeviceInfoProviderImpl.h | 11 ---- src/platform/Linux/PlatformManagerImpl.cpp | 1 - 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/platform/Darwin/DeviceInfoProviderImpl.cpp b/src/platform/Darwin/DeviceInfoProviderImpl.cpp index 3ea2236809eb31..841b488083d398 100644 --- a/src/platform/Darwin/DeviceInfoProviderImpl.cpp +++ b/src/platform/Darwin/DeviceInfoProviderImpl.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include diff --git a/src/platform/Linux/DeviceInfoProviderImpl.cpp b/src/platform/Linux/DeviceInfoProviderImpl.cpp index 395da9eadf801a..6abddf2aeba63e 100644 --- a/src/platform/Linux/DeviceInfoProviderImpl.cpp +++ b/src/platform/Linux/DeviceInfoProviderImpl.cpp @@ -33,11 +33,6 @@ constexpr TLV::Tag kLabelNameTag = TLV::ContextTag(0); constexpr TLV::Tag kLabelValueTag = TLV::ContextTag(1); } // anonymous namespace -CHIP_ERROR DeviceInfoProviderImpl::Init() -{ - return mStorage.Init(CHIP_DEVICE_INFO_PATH); -} - DeviceInfoProviderImpl & DeviceInfoProviderImpl::GetDefaultInstance() { static DeviceInfoProviderImpl sInstance; @@ -62,6 +57,8 @@ size_t DeviceInfoProviderImpl::FixedLabelIteratorImpl::Count() bool DeviceInfoProviderImpl::FixedLabelIteratorImpl::Next(FixedLabelType & output) { + bool retval = true; + // In Linux Simulation, use the following hardcoded labelList on all endpoints. CHIP_ERROR err = CHIP_NO_ERROR; @@ -108,26 +105,29 @@ bool DeviceInfoProviderImpl::FixedLabelIteratorImpl::Next(FixedLabelType & outpu mIndex++; - return true; + retval = true; + } + else + { + retval = false; } - return false; + return retval; } CHIP_ERROR DeviceInfoProviderImpl::SetUserLabelLength(EndpointId endpoint, size_t val) { DefaultStorageKeyAllocator keyAlloc; - ReturnErrorOnFailure(mStorage.WriteValue(keyAlloc.UserLabelLengthKey(endpoint), val)); - - return mStorage.Commit(); + return mStorage->SyncSetKeyValue(keyAlloc.UserLabelLengthKey(endpoint), &val, static_cast(sizeof(val))); } CHIP_ERROR DeviceInfoProviderImpl::GetUserLabelLength(EndpointId endpoint, size_t & val) { DefaultStorageKeyAllocator keyAlloc; + uint16_t len = static_cast(sizeof(val)); - return mStorage.ReadValue(keyAlloc.UserLabelLengthKey(endpoint), val); + return mStorage->SyncGetKeyValue(keyAlloc.UserLabelLengthKey(endpoint), &val, len); } CHIP_ERROR DeviceInfoProviderImpl::SetUserLabelAt(EndpointId endpoint, size_t index, const UserLabelType & userLabel) @@ -142,9 +142,9 @@ CHIP_ERROR DeviceInfoProviderImpl::SetUserLabelAt(EndpointId endpoint, size_t in ReturnErrorOnFailure(writer.PutString(kLabelNameTag, userLabel.label)); ReturnErrorOnFailure(writer.PutString(kLabelValueTag, userLabel.value)); ReturnErrorOnFailure(writer.EndContainer(outerType)); - ReturnErrorOnFailure(mStorage.WriteValueBin(keyAlloc.UserLabelIndexKey(endpoint, index), buf, writer.GetLengthWritten())); - return mStorage.Commit(); + return mStorage->SyncSetKeyValue(keyAlloc.UserLabelIndexKey(endpoint, index), buf, + static_cast(writer.GetLengthWritten())); } DeviceInfoProvider::UserLabelIterator * DeviceInfoProviderImpl::IterateUserLabel(EndpointId endpoint) @@ -170,8 +170,9 @@ bool DeviceInfoProviderImpl::UserLabelIteratorImpl::Next(UserLabelType & output) DefaultStorageKeyAllocator keyAlloc; uint8_t buf[UserLabelTLVMaxSize()]; - size_t outLen; - err = mProvider.mStorage.ReadValueBin(keyAlloc.UserLabelIndexKey(mEndpoint, mIndex), buf, sizeof(buf), outLen); + uint16_t len = static_cast(sizeof(buf)); + + err = mProvider.mStorage->SyncGetKeyValue(keyAlloc.UserLabelIndexKey(mEndpoint, mIndex), buf, len); VerifyOrReturnError(err == CHIP_NO_ERROR, false); TLV::ContiguousBufferTLVReader reader; @@ -220,6 +221,8 @@ size_t DeviceInfoProviderImpl::SupportedLocalesIteratorImpl::Count() bool DeviceInfoProviderImpl::SupportedLocalesIteratorImpl::Next(CharSpan & output) { + bool retval = true; + // In Linux simulation, return following hardcoded list of Strings that are valid values for the ActiveLocale. CHIP_ERROR err = CHIP_NO_ERROR; @@ -268,10 +271,14 @@ bool DeviceInfoProviderImpl::SupportedLocalesIteratorImpl::Next(CharSpan & outpu mIndex++; - return true; + retval = true; + } + else + { + retval = false; } - return false; + return retval; } DeviceInfoProvider::SupportedCalendarTypesIterator * DeviceInfoProviderImpl::IterateSupportedCalendarTypes() @@ -290,6 +297,8 @@ size_t DeviceInfoProviderImpl::SupportedCalendarTypesIteratorImpl::Count() bool DeviceInfoProviderImpl::SupportedCalendarTypesIteratorImpl::Next(CalendarType & output) { + bool retval = true; + // In Linux Simulation, return following hardcoded list of Strings that are valid values for the Calendar Types. CHIP_ERROR err = CHIP_NO_ERROR; @@ -341,10 +350,14 @@ bool DeviceInfoProviderImpl::SupportedCalendarTypesIteratorImpl::Next(CalendarTy if (err == CHIP_NO_ERROR) { mIndex++; - return true; + retval = true; + } + else + { + retval = false; } - return false; + return retval; } } // namespace DeviceLayer diff --git a/src/platform/Linux/DeviceInfoProviderImpl.h b/src/platform/Linux/DeviceInfoProviderImpl.h index 35572aa6a3cd7c..063cd13d1242c2 100644 --- a/src/platform/Linux/DeviceInfoProviderImpl.h +++ b/src/platform/Linux/DeviceInfoProviderImpl.h @@ -29,15 +29,6 @@ class DeviceInfoProviderImpl : public DeviceInfoProvider DeviceInfoProviderImpl() = default; ~DeviceInfoProviderImpl() override {} - /** - * Initialize the DeviceInfoProvider, including possibly any persistent - * data store initialization done by the implementation. Must be called once - * before any other API succeeds. - * - * @retval #CHIP_NO_ERROR on success - */ - CHIP_ERROR Init(); - // Iterators FixedLabelIterator * IterateFixedLabel(EndpointId endpoint) override; UserLabelIterator * IterateUserLabel(EndpointId endpoint) override; @@ -109,8 +100,6 @@ class DeviceInfoProviderImpl : public DeviceInfoProvider CHIP_ERROR SetUserLabelAt(EndpointId endpoint, size_t index, const UserLabelType & userLabel) override; private: - DeviceLayer::Internal::ChipLinuxStorage mStorage; - static constexpr size_t UserLabelTLVMaxSize() { return TLV::EstimateStructOverhead(kMaxLabelNameLength, kMaxLabelValueLength); } }; diff --git a/src/platform/Linux/PlatformManagerImpl.cpp b/src/platform/Linux/PlatformManagerImpl.cpp index 3d00570fed940e..60deabe3b2da91 100644 --- a/src/platform/Linux/PlatformManagerImpl.cpp +++ b/src/platform/Linux/PlatformManagerImpl.cpp @@ -203,7 +203,6 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack() SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); SetDiagnosticDataProvider(&DiagnosticDataProviderImpl::GetDefaultInstance()); SetDeviceInfoProvider(&DeviceInfoProviderImpl::GetDefaultInstance()); - ReturnErrorOnFailure(DeviceInfoProviderImpl::GetDefaultInstance().Init()); // Call _InitChipStack() on the generic implementation base class // to finish the initialization process.