@@ -128,6 +128,13 @@ EcosystemDeviceStruct::Builder & EcosystemDeviceStruct::Builder::AddUniqueLocati
128
128
return *this ;
129
129
}
130
130
131
+ EcosystemDeviceStruct::Builder & EcosystemDeviceStruct::Builder::SetFabricIndex (FabricIndex aFabricIndex)
132
+ {
133
+ VerifyOrDie (!mIsAlreadyBuilt );
134
+ mFabricIndex = aFabricIndex;
135
+ return *this ;
136
+ }
137
+
131
138
std::unique_ptr<EcosystemDeviceStruct> EcosystemDeviceStruct::Builder::Build ()
132
139
{
133
140
VerifyOrReturnValue (!mIsAlreadyBuilt , nullptr , ChipLogError (Zcl, " Build() already called" ));
@@ -136,6 +143,8 @@ std::unique_ptr<EcosystemDeviceStruct> EcosystemDeviceStruct::Builder::Build()
136
143
VerifyOrReturnValue (!mDeviceTypes .empty (), nullptr , ChipLogError (Zcl, " No device types added" ));
137
144
VerifyOrReturnValue (mUniqueLocationIds .size () <= kUniqueLocationIdsListMaxSize , nullptr ,
138
145
ChipLogError (Zcl, " Too many location ids" ));
146
+ VerifyOrReturnValue (mFabricIndex >= kMinValidFabricIndex , nullptr , ChipLogError (Zcl, " Fabric index is invalid" ));
147
+ VerifyOrReturnValue (mFabricIndex <= kMaxValidFabricIndex , nullptr , ChipLogError (Zcl, " Fabric index is invalid" ));
139
148
140
149
for (auto & locationId : mUniqueLocationIds )
141
150
{
@@ -145,12 +154,12 @@ std::unique_ptr<EcosystemDeviceStruct> EcosystemDeviceStruct::Builder::Build()
145
154
// std::make_unique does not have access to private constructor we workaround with using new
146
155
std::unique_ptr<EcosystemDeviceStruct> ret{ new EcosystemDeviceStruct (
147
156
std::move (mDeviceName ), mDeviceNameLastEditEpochUs , mBridgedEndpoint , mOriginalEndpoint , std::move (mDeviceTypes ),
148
- std::move (mUniqueLocationIds ), mUniqueLocationIdsLastEditEpochUs ) };
157
+ std::move (mUniqueLocationIds ), mUniqueLocationIdsLastEditEpochUs , mFabricIndex ) };
149
158
mIsAlreadyBuilt = true ;
150
159
return ret;
151
160
}
152
161
153
- CHIP_ERROR EcosystemDeviceStruct::Encode (const AttributeValueEncoder::ListEncodeHelper & aEncoder, const FabricIndex & aFabricIndex )
162
+ CHIP_ERROR EcosystemDeviceStruct::Encode (const AttributeValueEncoder::ListEncodeHelper & aEncoder)
154
163
{
155
164
Structs::EcosystemDeviceStruct::Type deviceStruct;
156
165
if (!mDeviceName .empty ())
@@ -172,9 +181,7 @@ CHIP_ERROR EcosystemDeviceStruct::Encode(const AttributeValueEncoder::ListEncode
172
181
deviceStruct.uniqueLocationIDs = DataModel::List<CharSpan>(locationIds.data (), locationIds.size ());
173
182
174
183
deviceStruct.uniqueLocationIDsLastEdit = mUniqueLocationIdsLastEditEpochUs ;
175
-
176
- // TODO(#33223) this is a hack, use mFabricIndex when it exists.
177
- deviceStruct.SetFabricIndex (aFabricIndex);
184
+ deviceStruct.SetFabricIndex (mFabricIndex );
178
185
return aEncoder.Encode (deviceStruct);
179
186
}
180
187
@@ -226,12 +233,9 @@ CHIP_ERROR EcosystemLocationStruct::Encode(const AttributeValueEncoder::ListEnco
226
233
const std::string & aUniqueLocationId, const FabricIndex & aFabricIndex)
227
234
{
228
235
Structs::EcosystemLocationStruct::Type locationStruct;
229
- VerifyOrDie (!aUniqueLocationId.empty ());
230
236
locationStruct.uniqueLocationID = CharSpan (aUniqueLocationId.c_str (), aUniqueLocationId.size ());
231
237
locationStruct.locationDescriptor = GetEncodableLocationDescriptorStruct (mLocationDescriptor );
232
238
locationStruct.locationDescriptorLastEdit = mLocationDescriptorLastEditEpochUs ;
233
-
234
- // TODO(#33223) this is a hack, use mFabricIndex when it exists.
235
239
locationStruct.SetFabricIndex (aFabricIndex);
236
240
return aEncoder.Encode (locationStruct);
237
241
}
@@ -266,16 +270,20 @@ CHIP_ERROR EcosystemInformationServer::AddDeviceInfo(EndpointId aEndpoint, std::
266
270
}
267
271
268
272
CHIP_ERROR EcosystemInformationServer::AddLocationInfo (EndpointId aEndpoint, const std::string & aLocationId,
269
- std::unique_ptr<EcosystemLocationStruct> aLocation)
273
+ FabricIndex aFabricIndex, std::unique_ptr<EcosystemLocationStruct> aLocation)
270
274
{
271
275
VerifyOrReturnError (aLocation, CHIP_ERROR_INVALID_ARGUMENT);
272
276
VerifyOrReturnError ((aEndpoint != kRootEndpointId && aEndpoint != kInvalidEndpointId ), CHIP_ERROR_INVALID_ARGUMENT);
277
+ VerifyOrReturnError (!aLocationId.empty (), CHIP_ERROR_INVALID_ARGUMENT);
278
+ VerifyOrReturnError (aFabricIndex >= kMinValidFabricIndex , CHIP_ERROR_INVALID_ARGUMENT);
279
+ VerifyOrReturnError (aFabricIndex <= kMaxValidFabricIndex , CHIP_ERROR_INVALID_ARGUMENT);
273
280
274
- auto & deviceInfo = mDevicesMap [aEndpoint];
275
- VerifyOrReturnError ((deviceInfo.mLocationDirectory .find (aLocationId) == deviceInfo.mLocationDirectory .end ()),
281
+ auto & deviceInfo = mDevicesMap [aEndpoint];
282
+ EcosystemLocationKey key = { .mUniqueLocationId = aLocationId, .mFabricIndex = aFabricIndex };
283
+ VerifyOrReturnError ((deviceInfo.mLocationDirectory .find (key) == deviceInfo.mLocationDirectory .end ()),
276
284
CHIP_ERROR_INVALID_ARGUMENT);
277
285
VerifyOrReturnError ((deviceInfo.mLocationDirectory .size () < kLocationDirectoryMaxSize ), CHIP_ERROR_NO_MEMORY);
278
- deviceInfo.mLocationDirectory [aLocationId ] = std::move (aLocation);
286
+ deviceInfo.mLocationDirectory [key ] = std::move (aLocation);
279
287
return CHIP_NO_ERROR;
280
288
}
281
289
@@ -352,11 +360,10 @@ CHIP_ERROR EcosystemInformationServer::EncodeDeviceDirectoryAttribute(EndpointId
352
360
return aEncoder.EncodeEmptyList ();
353
361
}
354
362
355
- FabricIndex fabricIndex = aEncoder.AccessingFabricIndex ();
356
363
return aEncoder.EncodeList ([&](const auto & encoder) -> CHIP_ERROR {
357
364
for (auto & device : deviceInfo.mDeviceDirectory )
358
365
{
359
- ReturnErrorOnFailure (device->Encode (encoder, fabricIndex ));
366
+ ReturnErrorOnFailure (device->Encode (encoder));
360
367
}
361
368
return CHIP_NO_ERROR;
362
369
});
@@ -379,11 +386,10 @@ CHIP_ERROR EcosystemInformationServer::EncodeLocationStructAttribute(EndpointId
379
386
return aEncoder.EncodeEmptyList ();
380
387
}
381
388
382
- FabricIndex fabricIndex = aEncoder.AccessingFabricIndex ();
383
389
return aEncoder.EncodeList ([&](const auto & encoder) -> CHIP_ERROR {
384
- for (auto & [id , device] : deviceInfo.mLocationDirectory )
390
+ for (auto & [key , device] : deviceInfo.mLocationDirectory )
385
391
{
386
- ReturnErrorOnFailure (device->Encode (encoder, id, fabricIndex ));
392
+ ReturnErrorOnFailure (device->Encode (encoder, key. mUniqueLocationId , key. mFabricIndex ));
387
393
}
388
394
return CHIP_NO_ERROR;
389
395
});
0 commit comments