From 9963bfefb03fa47359bcc4d2e5130b7282d72832 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Fri, 7 Jan 2022 11:36:40 -0800 Subject: [PATCH] Rename LabelList to AttributeList to be used by all clusters (#13355) --- .../fixed-label-server/fixed-label-server.cpp | 2 +- .../user-label-server/user-label-server.cpp | 4 +- .../platform/{LabelList.h => AttributeList.h} | 42 +++++++++---------- src/include/platform/PlatformManager.h | 20 +++++---- .../internal/GenericPlatformManagerImpl.h | 15 +++---- src/platform/Darwin/PlatformManagerImpl.cpp | 4 +- src/platform/Darwin/PlatformManagerImpl.h | 2 +- src/platform/Linux/PlatformManagerImpl.cpp | 10 ++--- src/platform/Linux/PlatformManagerImpl.h | 9 ++-- src/platform/fake/PlatformManagerImpl.h | 6 +-- 10 files changed, 58 insertions(+), 56 deletions(-) rename src/include/platform/{LabelList.h => AttributeList.h} (62%) diff --git a/src/app/clusters/fixed-label-server/fixed-label-server.cpp b/src/app/clusters/fixed-label-server/fixed-label-server.cpp index 76cf27dfa919ef..497c92108f3f52 100644 --- a/src/app/clusters/fixed-label-server/fixed-label-server.cpp +++ b/src/app/clusters/fixed-label-server/fixed-label-server.cpp @@ -53,7 +53,7 @@ class FixedLabelAttrAccess : public AttributeAccessInterface CHIP_ERROR FixedLabelAttrAccess::ReadLabelList(EndpointId endpoint, AttributeValueEncoder & aEncoder) { CHIP_ERROR err = CHIP_NO_ERROR; - DeviceLayer::LabelList labelList; + DeviceLayer::AttributeList labelList; if (DeviceLayer::PlatformMgr().GetFixedLabelList(endpoint, labelList) == CHIP_NO_ERROR) { diff --git a/src/app/clusters/user-label-server/user-label-server.cpp b/src/app/clusters/user-label-server/user-label-server.cpp index 56bca08f6654b5..311eb8027c10b0 100644 --- a/src/app/clusters/user-label-server/user-label-server.cpp +++ b/src/app/clusters/user-label-server/user-label-server.cpp @@ -57,7 +57,7 @@ UserLabelAttrAccess gAttrAccess; CHIP_ERROR UserLabelAttrAccess::ReadLabelList(EndpointId endpoint, AttributeValueEncoder & aEncoder) { CHIP_ERROR err = CHIP_NO_ERROR; - DeviceLayer::LabelList labelList; + DeviceLayer::AttributeList labelList; if (DeviceLayer::PlatformMgr().GetUserLabelList(endpoint, labelList) == CHIP_NO_ERROR) { @@ -80,7 +80,7 @@ CHIP_ERROR UserLabelAttrAccess::ReadLabelList(EndpointId endpoint, AttributeValu CHIP_ERROR UserLabelAttrAccess::WriteLabelList(EndpointId endpoint, AttributeValueDecoder & aDecoder) { - DeviceLayer::LabelList labelList; + DeviceLayer::AttributeList labelList; LabelList::TypeInfo::DecodableType decodablelist; ReturnErrorOnFailure(aDecoder.Decode(decodablelist)); diff --git a/src/include/platform/LabelList.h b/src/include/platform/AttributeList.h similarity index 62% rename from src/include/platform/LabelList.h rename to src/include/platform/AttributeList.h index 98096441db0ab6..1a1a133a0b7688 100644 --- a/src/include/platform/LabelList.h +++ b/src/include/platform/AttributeList.h @@ -17,7 +17,7 @@ /** * @file - * This is a list of string tuples. Each entry is a LabelStruct. + * This is a list of attribute. Each entry is an attribute of type T. */ #pragma once @@ -28,30 +28,27 @@ namespace chip { namespace DeviceLayer { -static constexpr size_t kMaxFixedLabels = 10; -static constexpr size_t kMaxUserLabels = 10; - template -class LabelList +class AttributeList { public: /* The iterator */ class Iterator { public: - Iterator(const LabelList * LabelList, int index); + Iterator(const AttributeList * AttributeList, int index); T operator*() const; Iterator & operator++(); bool operator!=(const Iterator & other) const; private: - const LabelList * mLabelListPtr; + const AttributeList * mAttributeListPtr; int mIndex = -1; }; public: - LabelList() = default; - ~LabelList() { mSize = 0; } + AttributeList() = default; + ~AttributeList() { mSize = 0; } CHIP_ERROR add(const T & label); @@ -67,10 +64,10 @@ class LabelList }; /* - * LabelList methods + * AttributeList methods **/ template -inline CHIP_ERROR LabelList::add(const T & label) +inline CHIP_ERROR AttributeList::add(const T & label) { if (mSize == N) { @@ -84,52 +81,53 @@ inline CHIP_ERROR LabelList::add(const T & label) } template -inline size_t LabelList::size() const +inline size_t AttributeList::size() const { return static_cast(mSize); } template -inline const T & LabelList::operator[](int index) const +inline const T & AttributeList::operator[](int index) const { VerifyOrDie(index < mSize); return mList[index]; } template -inline typename LabelList::Iterator LabelList::begin() const +inline typename AttributeList::Iterator AttributeList::begin() const { - return LabelList::Iterator{ this, 0 }; + return AttributeList::Iterator{ this, 0 }; } template -inline typename LabelList::Iterator LabelList::end() const +inline typename AttributeList::Iterator AttributeList::end() const { - return LabelList::Iterator{ this, mSize }; + return AttributeList::Iterator{ this, mSize }; } /* * Iterator methods **/ template -inline LabelList::Iterator::Iterator(const LabelList * pLabelList, int index) : mLabelListPtr(pLabelList), mIndex(index) +inline AttributeList::Iterator::Iterator(const AttributeList * pAttributeList, int index) : + mAttributeListPtr(pAttributeList), mIndex(index) {} template -inline T LabelList::Iterator::operator*() const +inline T AttributeList::Iterator::operator*() const { - return mLabelListPtr->operator[](mIndex); + return mAttributeListPtr->operator[](mIndex); } template -inline typename LabelList::Iterator & LabelList::Iterator::operator++() +inline typename AttributeList::Iterator & AttributeList::Iterator::operator++() { ++mIndex; return *this; } template -inline bool LabelList::Iterator::operator!=(const LabelList::Iterator & other) const +inline bool AttributeList::Iterator::operator!=(const AttributeList::Iterator & other) const { return mIndex != other.mIndex; } diff --git a/src/include/platform/PlatformManager.h b/src/include/platform/PlatformManager.h index 429cad2f1a237f..8e935e165e3945 100644 --- a/src/include/platform/PlatformManager.h +++ b/src/include/platform/PlatformManager.h @@ -23,9 +23,9 @@ #pragma once +#include #include #include -#include #include #include @@ -37,6 +37,9 @@ class DiscoveryImplPlatform; namespace DeviceLayer { +static constexpr size_t kMaxFixedLabels = 10; +static constexpr size_t kMaxUserLabels = 10; + class PlatformManagerImpl; class ConnectivityManagerImpl; class ConfigurationManagerImpl; @@ -179,11 +182,11 @@ class PlatformManager #endif CHIP_ERROR GetFixedLabelList(EndpointId endpoint, - LabelList & labelList); + AttributeList & labelList); CHIP_ERROR SetUserLabelList(EndpointId endpoint, - LabelList & labelList); + AttributeList & labelList); CHIP_ERROR GetUserLabelList(EndpointId endpoint, - LabelList & labelList); + AttributeList & labelList); private: bool mInitialized = false; @@ -425,23 +428,22 @@ inline CHIP_ERROR PlatformManager::StartChipTimer(System::Clock::Timeout duratio return static_cast(this)->_StartChipTimer(duration); } -inline CHIP_ERROR -PlatformManager::GetFixedLabelList(EndpointId endpoint, - LabelList & labelList) +inline CHIP_ERROR PlatformManager::GetFixedLabelList( + EndpointId endpoint, AttributeList & labelList) { return static_cast(this)->_GetFixedLabelList(endpoint, labelList); } inline CHIP_ERROR PlatformManager::SetUserLabelList(EndpointId endpoint, - LabelList & labelList) + AttributeList & labelList) { return static_cast(this)->_SetUserLabelList(endpoint, labelList); } inline CHIP_ERROR PlatformManager::GetUserLabelList(EndpointId endpoint, - LabelList & labelList) + AttributeList & labelList) { return static_cast(this)->_GetUserLabelList(endpoint, labelList); } diff --git a/src/include/platform/internal/GenericPlatformManagerImpl.h b/src/include/platform/internal/GenericPlatformManagerImpl.h index eb738bf7887a11..cd058dea30c461 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl.h +++ b/src/include/platform/internal/GenericPlatformManagerImpl.h @@ -58,12 +58,13 @@ class GenericPlatformManagerImpl void _ScheduleWork(AsyncWorkFunct workFunct, intptr_t arg); void _DispatchEvent(const ChipDeviceEvent * event); - CHIP_ERROR _GetFixedLabelList(EndpointId endpoint, - LabelList & labelList); + CHIP_ERROR + _GetFixedLabelList(EndpointId endpoint, + AttributeList & labelList); CHIP_ERROR _SetUserLabelList(EndpointId endpoint, - LabelList & labelList); + AttributeList & labelList); CHIP_ERROR _GetUserLabelList(EndpointId endpoint, - LabelList & labelList); + AttributeList & labelList); // ===== Support methods that can be overridden by the implementation subclass. @@ -82,21 +83,21 @@ extern template class GenericPlatformManagerImpl; template inline CHIP_ERROR GenericPlatformManagerImpl::_GetFixedLabelList( - EndpointId endpoint, LabelList & labelList) + EndpointId endpoint, AttributeList & labelList) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } template inline CHIP_ERROR GenericPlatformManagerImpl::_SetUserLabelList( - EndpointId endpoint, LabelList & labelList) + EndpointId endpoint, AttributeList & labelList) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } template inline CHIP_ERROR GenericPlatformManagerImpl::_GetUserLabelList( - EndpointId endpoint, LabelList & labelList) + EndpointId endpoint, AttributeList & labelList) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } diff --git a/src/platform/Darwin/PlatformManagerImpl.cpp b/src/platform/Darwin/PlatformManagerImpl.cpp index 28454d4bf2f902..f67445ef255b15 100644 --- a/src/platform/Darwin/PlatformManagerImpl.cpp +++ b/src/platform/Darwin/PlatformManagerImpl.cpp @@ -127,8 +127,8 @@ CHIP_ERROR PlatformManagerImpl::_PostEvent(const ChipDeviceEvent * event) } CHIP_ERROR -PlatformManagerImpl::_SetUserLabelList(EndpointId endpoint, - LabelList & labelList) +PlatformManagerImpl::_SetUserLabelList( + EndpointId endpoint, AttributeList & labelList) { return CHIP_NO_ERROR; } diff --git a/src/platform/Darwin/PlatformManagerImpl.h b/src/platform/Darwin/PlatformManagerImpl.h index b7dd12fae2bb17..7a69e07f0d49d4 100644 --- a/src/platform/Darwin/PlatformManagerImpl.h +++ b/src/platform/Darwin/PlatformManagerImpl.h @@ -63,7 +63,7 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener CHIP_ERROR _StopEventLoopTask(); CHIP_ERROR _SetUserLabelList(EndpointId endpoint, - LabelList & labelList); + AttributeList & labelList); void _RunEventLoop(); void _LockChipStack(){}; diff --git a/src/platform/Linux/PlatformManagerImpl.cpp b/src/platform/Linux/PlatformManagerImpl.cpp index 3bd94d6bf8f4a2..7ff96b9de8e34e 100644 --- a/src/platform/Linux/PlatformManagerImpl.cpp +++ b/src/platform/Linux/PlatformManagerImpl.cpp @@ -273,7 +273,7 @@ CHIP_ERROR PlatformManagerImpl::_Shutdown() } CHIP_ERROR PlatformManagerImpl::_GetFixedLabelList( - EndpointId endpoint, LabelList & labelList) + EndpointId endpoint, AttributeList & labelList) { // In Linux simulation, return following hardcoded labelList on all endpoints. FixedLabel::Structs::LabelStruct::Type room; @@ -302,16 +302,16 @@ CHIP_ERROR PlatformManagerImpl::_GetFixedLabelList( } CHIP_ERROR -PlatformManagerImpl::_SetUserLabelList(EndpointId endpoint, - LabelList & labelList) +PlatformManagerImpl::_SetUserLabelList( + EndpointId endpoint, AttributeList & labelList) { // TODO:: store the user labelList, and read back stored user labelList if it has been set. Add yaml test to verify this. return CHIP_NO_ERROR; } CHIP_ERROR -PlatformManagerImpl::_GetUserLabelList(EndpointId endpoint, - LabelList & labelList) +PlatformManagerImpl::_GetUserLabelList( + EndpointId endpoint, AttributeList & labelList) { // In Linux simulation, return following hardcoded labelList on all endpoints. UserLabel::Structs::LabelStruct::Type room; diff --git a/src/platform/Linux/PlatformManagerImpl.h b/src/platform/Linux/PlatformManagerImpl.h index 6757b93108f079..9655772f8f5b02 100644 --- a/src/platform/Linux/PlatformManagerImpl.h +++ b/src/platform/Linux/PlatformManagerImpl.h @@ -65,12 +65,13 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener CHIP_ERROR _InitChipStack(); CHIP_ERROR _Shutdown(); - CHIP_ERROR _GetFixedLabelList(EndpointId endpoint, - LabelList & labelList); + CHIP_ERROR + _GetFixedLabelList(EndpointId endpoint, + AttributeList & labelList); CHIP_ERROR _SetUserLabelList(EndpointId endpoint, - LabelList & labelList); + AttributeList & labelList); CHIP_ERROR _GetUserLabelList(EndpointId endpoint, - LabelList & labelList); + AttributeList & labelList); // ===== Members for internal use by the following friends. diff --git a/src/platform/fake/PlatformManagerImpl.h b/src/platform/fake/PlatformManagerImpl.h index a3e8cf30ae59c4..ab92669c4f3c73 100644 --- a/src/platform/fake/PlatformManagerImpl.h +++ b/src/platform/fake/PlatformManagerImpl.h @@ -99,19 +99,19 @@ class PlatformManagerImpl final : public PlatformManager CHIP_ERROR _StartChipTimer(System::Clock::Timeout duration) { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR _GetFixedLabelList(EndpointId endpoint, - LabelList & labelList) + AttributeList & labelList) { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR _SetUserLabelList(EndpointId endpoint, - LabelList & labelList) + AttributeList & labelList) { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR _GetUserLabelList(EndpointId endpoint, - LabelList & labelList) + AttributeList & labelList) { return CHIP_ERROR_NOT_IMPLEMENTED; }