Skip to content

Commit fb24b90

Browse files
wqx6restyled-commitsandy31415bzbarsky-apple
authored
Decouple ember-specific functions from descriptor cluster (project-chip#36493)
* descriptor: decouple from ember * Restyled by clang-format * fix shadow error * fix test build * fix test build * use Client cluster iteration * Restyled by clang-format * fix CI building error * fix android build * review changes * Restyled by clang-format * review changes * some doc changes * Fix the semantic tags iterator and add unit tests for the new functions * Restyled by clang-format * fix clang tidy check * add composition test * Restyled by clang-format * Update src/app/data-model-provider/MetadataTypes.h Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Update src/app/codegen-data-model-provider/CodegenDataModelProvider.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Andrei Litvin <andy314@gmail.com> Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent 19cbdf4 commit fb24b90

22 files changed

+802
-219
lines changed

examples/common/pigweed/rpc_services/Attributes.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class Attributes : public pw_rpc::nanopb::Attributes::Service<Attributes>
221221
request.operationFlags.Set(app::DataModel::OperationFlags::kInternal);
222222
request.subjectDescriptor = &subjectDescriptor;
223223

224-
std::optional<app::DataModel::ClusterInfo> info = provider->GetClusterInfo(path);
224+
std::optional<app::DataModel::ClusterInfo> info = provider->GetServerClusterInfo(path);
225225
if (!info.has_value())
226226
{
227227
return ::pw::Status::NotFound();

src/app/AttributePathExpandIterator.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ std::optional<ClusterId> AttributePathExpandIterator::NextClusterId()
115115
{
116116
if (mpAttributePath->mValue.HasWildcardClusterId())
117117
{
118-
ClusterEntry entry = mDataModelProvider->FirstCluster(mOutputPath.mEndpointId);
118+
ClusterEntry entry = mDataModelProvider->FirstServerCluster(mOutputPath.mEndpointId);
119119
return entry.IsValid() ? std::make_optional(entry.path.mClusterId) : std::nullopt;
120120
}
121121

122122
// only return a cluster if it is valid
123123
const ConcreteClusterPath clusterPath(mOutputPath.mEndpointId, mpAttributePath->mValue.mClusterId);
124-
if (!mDataModelProvider->GetClusterInfo(clusterPath).has_value())
124+
if (!mDataModelProvider->GetServerClusterInfo(clusterPath).has_value())
125125
{
126126
return std::nullopt;
127127
}
@@ -131,7 +131,7 @@ std::optional<ClusterId> AttributePathExpandIterator::NextClusterId()
131131

132132
VerifyOrReturnValue(mpAttributePath->mValue.HasWildcardClusterId(), std::nullopt);
133133

134-
ClusterEntry entry = mDataModelProvider->NextCluster(mOutputPath);
134+
ClusterEntry entry = mDataModelProvider->NextServerCluster(mOutputPath);
135135
return entry.IsValid() ? std::make_optional(entry.path.mClusterId) : std::nullopt;
136136
}
137137

@@ -141,17 +141,17 @@ std::optional<ClusterId> AttributePathExpandIterator::NextEndpointId()
141141
{
142142
if (mpAttributePath->mValue.HasWildcardEndpointId())
143143
{
144-
EndpointId id = mDataModelProvider->FirstEndpoint();
145-
return (id != kInvalidEndpointId) ? std::make_optional(id) : std::nullopt;
144+
EndpointEntry ep = mDataModelProvider->FirstEndpoint();
145+
return (ep.id != kInvalidEndpointId) ? std::make_optional(ep.id) : std::nullopt;
146146
}
147147

148148
return mpAttributePath->mValue.mEndpointId;
149149
}
150150

151151
VerifyOrReturnValue(mpAttributePath->mValue.HasWildcardEndpointId(), std::nullopt);
152152

153-
EndpointId id = mDataModelProvider->NextEndpoint(mOutputPath.mEndpointId);
154-
return (id != kInvalidEndpointId) ? std::make_optional(id) : std::nullopt;
153+
EndpointEntry ep = mDataModelProvider->NextEndpoint(mOutputPath.mEndpointId);
154+
return (ep.id != kInvalidEndpointId) ? std::make_optional(ep.id) : std::nullopt;
155155
}
156156

157157
void AttributePathExpandIterator::ResetCurrentCluster()

src/app/InteractionModelEngine.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ bool MayHaveAccessibleEventPathForEndpoint(DataModel::Provider * aProvider, Endp
8989
aSubjectDescriptor);
9090
}
9191

92-
DataModel::ClusterEntry clusterEntry = aProvider->FirstCluster(aEventPath.mEndpointId);
92+
DataModel::ClusterEntry clusterEntry = aProvider->FirstServerCluster(aEventPath.mEndpointId);
9393
while (clusterEntry.IsValid())
9494
{
9595
if (MayHaveAccessibleEventPathForEndpointAndCluster(clusterEntry.path, aEventPath, aSubjectDescriptor))
9696
{
9797
return true;
9898
}
99-
clusterEntry = aProvider->NextCluster(clusterEntry.path);
99+
clusterEntry = aProvider->NextServerCluster(clusterEntry.path);
100100
}
101101

102102
return false;
@@ -112,10 +112,9 @@ bool MayHaveAccessibleEventPath(DataModel::Provider * aProvider, const EventPath
112112
return MayHaveAccessibleEventPathForEndpoint(aProvider, aEventPath.mEndpointId, aEventPath, subjectDescriptor);
113113
}
114114

115-
for (EndpointId endpointId = aProvider->FirstEndpoint(); endpointId != kInvalidEndpointId;
116-
endpointId = aProvider->NextEndpoint(endpointId))
115+
for (DataModel::EndpointEntry ep = aProvider->FirstEndpoint(); ep.IsValid(); ep = aProvider->NextEndpoint(ep.id))
117116
{
118-
if (MayHaveAccessibleEventPathForEndpoint(aProvider, endpointId, aEventPath, subjectDescriptor))
117+
if (MayHaveAccessibleEventPathForEndpoint(aProvider, ep.id, aEventPath, subjectDescriptor))
119118
{
120119
return true;
121120
}
@@ -1793,17 +1792,16 @@ Protocols::InteractionModel::Status InteractionModelEngine::CheckCommandExistenc
17931792

17941793
// We failed, figure out why ...
17951794
//
1796-
if (provider->GetClusterInfo(aCommandPath).has_value())
1795+
if (provider->GetServerClusterInfo(aCommandPath).has_value())
17971796
{
17981797
return Protocols::InteractionModel::Status::UnsupportedCommand; // cluster exists, so command is invalid
17991798
}
18001799

18011800
// At this point either cluster or endpoint does not exist. If we find the endpoint, then the cluster
18021801
// is invalid
1803-
for (EndpointId endpoint = provider->FirstEndpoint(); endpoint != kInvalidEndpointId;
1804-
endpoint = provider->NextEndpoint(endpoint))
1802+
for (DataModel::EndpointEntry ep = provider->FirstEndpoint(); ep.IsValid(); ep = provider->NextEndpoint(ep.id))
18051803
{
1806-
if (endpoint == aCommandPath.mEndpointId)
1804+
if (ep.id == aCommandPath.mEndpointId)
18071805
{
18081806
// endpoint exists, so cluster is invalid
18091807
return Protocols::InteractionModel::Status::UnsupportedCluster;

src/app/clusters/descriptor/descriptor.cpp

+56-53
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <app-common/zap-generated/ids/Clusters.h>
2626
#include <app/AttributeAccessInterface.h>
2727
#include <app/AttributeAccessInterfaceRegistry.h>
28+
#include <app/InteractionModelEngine.h>
29+
#include <app/data-model-provider/MetadataTypes.h>
2830
#include <app/util/attribute-storage.h>
2931
#include <app/util/endpoint-config-api.h>
3032
#include <lib/support/CodeUtils.h>
@@ -73,87 +75,77 @@ CHIP_ERROR DescriptorAttrAccess::ReadFeatureMap(EndpointId endpoint, AttributeVa
7375
CHIP_ERROR DescriptorAttrAccess::ReadTagListAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder)
7476
{
7577
return aEncoder.EncodeList([&endpoint](const auto & encoder) -> CHIP_ERROR {
76-
Clusters::Descriptor::Structs::SemanticTagStruct::Type tag;
77-
size_t index = 0;
78-
CHIP_ERROR err = CHIP_NO_ERROR;
79-
while ((err = GetSemanticTagForEndpointAtIndex(endpoint, index, tag)) == CHIP_NO_ERROR)
78+
auto tag = InteractionModelEngine::GetInstance()->GetDataModelProvider()->GetFirstSemanticTag(endpoint);
79+
while (tag.has_value())
8080
{
81-
ReturnErrorOnFailure(encoder.Encode(tag));
82-
index++;
81+
ReturnErrorOnFailure(encoder.Encode(tag.value()));
82+
tag = InteractionModelEngine::GetInstance()->GetDataModelProvider()->GetNextSemanticTag(endpoint, tag.value());
8383
}
84-
if (err == CHIP_ERROR_NOT_FOUND)
85-
{
86-
return CHIP_NO_ERROR;
87-
}
88-
return err;
84+
return CHIP_NO_ERROR;
8985
});
9086
}
9187

9288
CHIP_ERROR DescriptorAttrAccess::ReadPartsAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder)
9389
{
9490
CHIP_ERROR err = CHIP_NO_ERROR;
9591

92+
auto endpointInfo = InteractionModelEngine::GetInstance()->GetDataModelProvider()->GetEndpointInfo(endpoint);
9693
if (endpoint == 0x00)
9794
{
9895
err = aEncoder.EncodeList([](const auto & encoder) -> CHIP_ERROR {
99-
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
96+
auto endpointEntry = InteractionModelEngine::GetInstance()->GetDataModelProvider()->FirstEndpoint();
97+
while (endpointEntry.IsValid())
10098
{
101-
if (emberAfEndpointIndexIsEnabled(index))
99+
if (endpointEntry.id != 0)
102100
{
103-
EndpointId endpointId = emberAfEndpointFromIndex(index);
104-
if (endpointId == 0)
105-
continue;
106-
107-
ReturnErrorOnFailure(encoder.Encode(endpointId));
101+
ReturnErrorOnFailure(encoder.Encode(endpointEntry.id));
108102
}
103+
endpointEntry = InteractionModelEngine::GetInstance()->GetDataModelProvider()->NextEndpoint(endpointEntry.id);
109104
}
110-
111105
return CHIP_NO_ERROR;
112106
});
113107
}
114-
else if (IsFlatCompositionForEndpoint(endpoint))
108+
else if (endpointInfo.has_value() &&
109+
endpointInfo->compositionPattern == DataModel::EndpointCompositionPattern::kFullFamilyPattern)
115110
{
116111
err = aEncoder.EncodeList([endpoint](const auto & encoder) -> CHIP_ERROR {
117-
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
112+
auto endpointEntry = InteractionModelEngine::GetInstance()->GetDataModelProvider()->FirstEndpoint();
113+
while (endpointEntry.IsValid())
118114
{
119-
if (!emberAfEndpointIndexIsEnabled(index))
120-
continue;
121-
122-
uint16_t childIndex = index;
123-
while (childIndex != chip::kInvalidListIndex)
115+
EndpointId parentEndpointId = endpointEntry.info.parentId;
116+
while (parentEndpointId != chip::kInvalidEndpointId)
124117
{
125-
EndpointId parentEndpointId = emberAfParentEndpointFromIndex(childIndex);
126-
if (parentEndpointId == chip::kInvalidEndpointId)
127-
break;
128-
129118
if (parentEndpointId == endpoint)
130119
{
131-
ReturnErrorOnFailure(encoder.Encode(emberAfEndpointFromIndex(index)));
120+
ReturnErrorOnFailure(encoder.Encode(endpointEntry.id));
132121
break;
133122
}
134-
135-
childIndex = emberAfIndexFromEndpoint(parentEndpointId);
123+
auto parentEndpointInfo =
124+
InteractionModelEngine::GetInstance()->GetDataModelProvider()->GetEndpointInfo(parentEndpointId);
125+
if (!parentEndpointInfo.has_value())
126+
{
127+
break;
128+
}
129+
parentEndpointId = parentEndpointInfo->parentId;
136130
}
131+
endpointEntry = InteractionModelEngine::GetInstance()->GetDataModelProvider()->NextEndpoint(endpointEntry.id);
137132
}
138133

139134
return CHIP_NO_ERROR;
140135
});
141136
}
142-
else if (IsTreeCompositionForEndpoint(endpoint))
137+
else if (endpointInfo.has_value() && endpointInfo->compositionPattern == DataModel::EndpointCompositionPattern::kTreePattern)
143138
{
144139
err = aEncoder.EncodeList([endpoint](const auto & encoder) -> CHIP_ERROR {
145-
for (uint16_t index = 0; index < emberAfEndpointCount(); index++)
140+
auto endpointEntry = InteractionModelEngine::GetInstance()->GetDataModelProvider()->FirstEndpoint();
141+
while (endpointEntry.IsValid())
146142
{
147-
if (!emberAfEndpointIndexIsEnabled(index))
148-
continue;
149-
150-
EndpointId parentEndpointId = emberAfParentEndpointFromIndex(index);
151-
if (parentEndpointId == endpoint)
143+
if (endpointEntry.info.parentId == endpoint)
152144
{
153-
ReturnErrorOnFailure(encoder.Encode(emberAfEndpointFromIndex(index)));
145+
ReturnErrorOnFailure(encoder.Encode(endpointEntry.id));
154146
}
147+
endpointEntry = InteractionModelEngine::GetInstance()->GetDataModelProvider()->NextEndpoint(endpointEntry.id);
155148
}
156-
157149
return CHIP_NO_ERROR;
158150
});
159151
}
@@ -165,16 +157,15 @@ CHIP_ERROR DescriptorAttrAccess::ReadDeviceAttribute(EndpointId endpoint, Attrib
165157
{
166158
CHIP_ERROR err = aEncoder.EncodeList([&endpoint](const auto & encoder) -> CHIP_ERROR {
167159
Descriptor::Structs::DeviceTypeStruct::Type deviceStruct;
168-
CHIP_ERROR err2;
169160

170-
auto deviceTypeList = emberAfDeviceTypeListFromEndpoint(endpoint, err2);
171-
ReturnErrorOnFailure(err2);
161+
auto deviceType = InteractionModelEngine::GetInstance()->GetDataModelProvider()->FirstDeviceType(endpoint);
172162

173-
for (auto & deviceType : deviceTypeList)
163+
while (deviceType.has_value())
174164
{
175-
deviceStruct.deviceType = deviceType.deviceId;
176-
deviceStruct.revision = deviceType.deviceVersion;
165+
deviceStruct.deviceType = deviceType->deviceTypeId;
166+
deviceStruct.revision = deviceType->deviceTypeRevision;
177167
ReturnErrorOnFailure(encoder.Encode(deviceStruct));
168+
deviceType = InteractionModelEngine::GetInstance()->GetDataModelProvider()->NextDeviceType(endpoint, *deviceType);
178169
}
179170

180171
return CHIP_NO_ERROR;
@@ -186,12 +177,24 @@ CHIP_ERROR DescriptorAttrAccess::ReadDeviceAttribute(EndpointId endpoint, Attrib
186177
CHIP_ERROR DescriptorAttrAccess::ReadClientServerAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder, bool server)
187178
{
188179
CHIP_ERROR err = aEncoder.EncodeList([&endpoint, server](const auto & encoder) -> CHIP_ERROR {
189-
uint8_t clusterCount = emberAfClusterCount(endpoint, server);
190-
191-
for (uint8_t clusterIndex = 0; clusterIndex < clusterCount; clusterIndex++)
180+
if (server)
192181
{
193-
const EmberAfCluster * cluster = emberAfGetNthCluster(endpoint, clusterIndex, server);
194-
ReturnErrorOnFailure(encoder.Encode(cluster->clusterId));
182+
auto clusterEntry = InteractionModelEngine::GetInstance()->GetDataModelProvider()->FirstServerCluster(endpoint);
183+
while (clusterEntry.IsValid())
184+
{
185+
ReturnErrorOnFailure(encoder.Encode(clusterEntry.path.mClusterId));
186+
clusterEntry = InteractionModelEngine::GetInstance()->GetDataModelProvider()->NextServerCluster(clusterEntry.path);
187+
}
188+
}
189+
else
190+
{
191+
ConcreteClusterPath clusterPath =
192+
InteractionModelEngine::GetInstance()->GetDataModelProvider()->FirstClientCluster(endpoint);
193+
while (clusterPath.HasValidIds())
194+
{
195+
ReturnErrorOnFailure(encoder.Encode(clusterPath.mClusterId));
196+
clusterPath = InteractionModelEngine::GetInstance()->GetDataModelProvider()->NextClientCluster(clusterPath);
197+
}
195198
}
196199

197200
return CHIP_NO_ERROR;

0 commit comments

Comments
 (0)