Skip to content

Commit 63dd9a9

Browse files
committed
more updates to cleanup code. I am a bit concerned about O(n^2) attribute access...
1 parent 4858fbc commit 63dd9a9

10 files changed

+56
-366
lines changed

src/app/AttributePathExpandIterator.cpp

+42-18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
#include "app/data-model-provider/MetadataSearch.h"
1718
#include <app/AttributePathExpandIterator.h>
1819

1920
#include <app/GlobalAttributes.h>
@@ -119,34 +120,58 @@ bool AttributePathExpandIterator::IsValidAttributeId(AttributeId attributeId)
119120
break;
120121
}
121122

123+
DataModel::AttributeFinder finder(mDataModelProvider);
124+
122125
const ConcreteAttributePath attributePath(mPosition.mOutputPath.mEndpointId, mPosition.mOutputPath.mClusterId, attributeId);
123-
return mDataModelProvider->GetAttributeInfo(attributePath).has_value();
126+
return finder.Find(attributePath).has_value();
124127
}
125128

126129
std::optional<AttributeId> AttributePathExpandIterator::NextAttributeId()
127130
{
128-
if (mPosition.mOutputPath.mAttributeId == kInvalidAttributeId)
131+
if (mPosition.mOutputPath.mAttributeId == kInvalidClusterId)
132+
{
133+
mAttributeIndex = kInvalidIndex;
134+
}
135+
136+
if (mAttributeIndex == kInvalidIndex)
129137
{
130-
if (mPosition.mAttributePath->mValue.HasWildcardAttributeId())
138+
// start a new iteration on the current endpoint
139+
mAttributes = mDataModelProvider->Attributes(mPosition.mOutputPath);
140+
141+
if (mPosition.mOutputPath.mAttributeId != kInvalidAttributeId)
131142
{
132-
AttributeEntry entry = mDataModelProvider->FirstAttribute(mPosition.mOutputPath);
133-
return entry.IsValid() //
134-
? entry.path.mAttributeId //
135-
: Clusters::Globals::Attributes::GeneratedCommandList::Id; //
143+
// Position on the correct cluster if we have a start point
144+
mAttributeIndex = 0;
145+
while ((mAttributeIndex < mAttributes.size()) &&
146+
(mAttributes[mAttributeIndex].attributeId != mPosition.mOutputPath.mAttributeId))
147+
{
148+
mAttributeIndex++;
149+
}
136150
}
151+
}
137152

138-
// At this point, the attributeID is NOT a wildcard (i.e. it is fixed).
139-
//
140-
// For wildcard expansion, we validate that this is a valid attribute for the given
141-
// cluster on the given endpoint. If not a wildcard expansion, return it as-is.
142-
if (mPosition.mAttributePath->mValue.IsWildcardPath())
153+
if (mPosition.mOutputPath.mAttributeId == kInvalidAttributeId)
154+
{
155+
if (!mPosition.mAttributePath->mValue.HasWildcardAttributeId())
143156
{
144-
if (!IsValidAttributeId(mPosition.mAttributePath->mValue.mAttributeId))
157+
// The attributeID is NOT a wildcard (i.e. it is fixed).
158+
//
159+
// For wildcard expansion, we validate that this is a valid attribute for the given
160+
// cluster on the given endpoint. If not a wildcard expansion, return it as-is.
161+
if (mPosition.mAttributePath->mValue.IsWildcardPath())
145162
{
146-
return std::nullopt;
163+
if (!IsValidAttributeId(mPosition.mAttributePath->mValue.mAttributeId))
164+
{
165+
return std::nullopt;
166+
}
147167
}
168+
return mPosition.mAttributePath->mValue.mAttributeId;
148169
}
149-
return mPosition.mAttributePath->mValue.mAttributeId;
170+
mAttributeIndex = 0;
171+
}
172+
else
173+
{
174+
mAttributeIndex++;
150175
}
151176

152177
// Advance the existing attribute id if it can be advanced.
@@ -171,10 +196,9 @@ std::optional<AttributeId> AttributePathExpandIterator::NextAttributeId()
171196
return std::nullopt;
172197
}
173198

174-
AttributeEntry entry = mDataModelProvider->NextAttribute(mPosition.mOutputPath);
175-
if (entry.IsValid())
199+
if (mAttributeIndex < mAttributes.size())
176200
{
177-
return entry.path.mAttributeId;
201+
return mAttributes[mAttributeIndex].attributeId;
178202
}
179203

180204
// Finished the data model, start with global attributes

src/app/AttributePathExpandIterator.h

+3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ class AttributePathExpandIterator
126126
DataModel::MetadataList<DataModel::ServerClusterEntry> mClusters; // all clustesr ON THE CURRENT endpoint
127127
size_t mClusterIndex = kInvalidIndex;
128128

129+
DataModel::MetadataList<DataModel::AttributeEntry2> mAttributes; // all clustesr ON THE CURRENT cluster
130+
size_t mAttributeIndex = kInvalidIndex;
131+
129132
/// Move to the next endpoint/cluster/attribute triplet that is valid given
130133
/// the current mOutputPath and mpAttributePath.
131134
///

src/app/InteractionModelEngine.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,8 @@ CHIP_ERROR InteractionModelEngine::PushFrontAttributePathList(SingleLinkedListNo
15671567

15681568
bool InteractionModelEngine::IsExistentAttributePath(const ConcreteAttributePath & path)
15691569
{
1570-
return GetDataModelProvider()->GetAttributeInfo(path).has_value();
1570+
DataModel::AttributeFinder finder(mDataModelProvider);
1571+
return finder.Find(path).has_value();
15711572
}
15721573

15731574
void InteractionModelEngine::RemoveDuplicateConcreteAttributePath(SingleLinkedListNode<AttributePathParams> *& aAttributePaths)

src/app/WriteHandler.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19+
#include "app/data-model-provider/MetadataSearch.h"
1920
#include <app/AppConfig.h>
2021
#include <app/AttributeAccessInterfaceRegistry.h>
2122
#include <app/AttributeValueDecoder.h>
@@ -110,7 +111,9 @@ std::optional<bool> WriteHandler::IsListAttributePath(const ConcreteAttributePat
110111
return std::nullopt;
111112
}
112113

113-
auto info = mDataModelProvider->GetAttributeInfo(path);
114+
DataModel::AttributeFinder finder(mDataModelProvider);
115+
std::optional<DataModel::AttributeEntry2> info = finder.Find(path);
116+
114117
if (!info.has_value())
115118
{
116119
return std::nullopt;

src/app/data-model-provider/BUILD.gn

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ source_set("data-model-provider") {
2323
"EventsGenerator.h",
2424
"MetadataList.h",
2525
"MetadataSearch.h",
26-
"MetadataTypes.cpp",
2726
"MetadataTypes.h",
2827
"OperationTypes.h",
2928
"Provider.h",

src/app/data-model-provider/MetadataTypes.cpp

-33
This file was deleted.

src/app/data-model-provider/MetadataTypes.h

-38
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,6 @@ struct ClusterInfo
8484
ClusterInfo(DataVersion version) : dataVersion(version) {}
8585
};
8686

87-
struct ClusterEntry
88-
{
89-
ConcreteClusterPath path;
90-
ClusterInfo info;
91-
92-
bool IsValid() const { return path.HasValidIds(); }
93-
94-
static const ClusterEntry kInvalid;
95-
};
96-
9787
enum class AttributeQualityFlags : uint32_t
9888
{
9989
kListAttribute = 0x0004, // This attribute is a list attribute
@@ -103,25 +93,6 @@ enum class AttributeQualityFlags : uint32_t
10393
kTimed = 0x0040, // `T` quality on attributes (writes require timed interactions)
10494
};
10595

106-
struct AttributeInfo
107-
{
108-
BitFlags<AttributeQualityFlags> flags;
109-
110-
// read/write access will be missing if read/write is NOT allowed
111-
std::optional<Access::Privilege> readPrivilege; // generally defaults to View if readable
112-
std::optional<Access::Privilege> writePrivilege; // generally defaults to Operate if writable
113-
};
114-
115-
struct AttributeEntry
116-
{
117-
ConcreteAttributePath path;
118-
AttributeInfo info;
119-
120-
bool IsValid() const { return path.HasValidIds(); }
121-
122-
static const AttributeEntry kInvalid;
123-
};
124-
12596
struct AttributeEntry2
12697
{
12798
AttributeId attributeId;
@@ -185,15 +156,6 @@ class ProviderMetadataTree
185156
public:
186157
virtual ~ProviderMetadataTree() = default;
187158

188-
// Attribute iteration and accessors provide cluster-level access over
189-
// attributes
190-
virtual AttributeEntry FirstAttribute(const ConcreteClusterPath & cluster) = 0;
191-
virtual AttributeEntry NextAttribute(const ConcreteAttributePath & before) = 0;
192-
virtual std::optional<AttributeInfo> GetAttributeInfo(const ConcreteAttributePath & path) = 0;
193-
194-
/// List metadata capabilties
195-
///
196-
/// TODO: convert ALL items above to the new format
197159
using SemanticTag = Clusters::Descriptor::Structs::SemanticTagStruct::Type;
198160

199161
virtual MetadataList<EndpointEntry> Endpoints() = 0;

src/app/reporting/Engine.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ std::optional<CHIP_ERROR> ValidateReadAttributeACL(DataModel::Provider * dataMod
8282
.requestType = RequestType::kAttributeReadRequest,
8383
.entityId = path.mAttributeId };
8484

85-
std::optional<DataModel::AttributeInfo> info = dataModel->GetAttributeInfo(path);
85+
DataModel::AttributeFinder finder(dataModel);
86+
87+
std::optional<DataModel::AttributeEntry2> info = finder.Find(path);
8688

8789
// If the attribute exists, we know whether it is readable (readPrivilege has value)
8890
// and what the required access privilege is. However for attributes missing from the metatada

0 commit comments

Comments
 (0)