Skip to content

Commit 95ff33b

Browse files
Improve the AreaStructureWrapper (project-chip#34814)
* Updated the golabl data type's XMLs, removing the cluster entries. * Zap generated after XML update. * Fixed namespaces used of global structs. * Restyled by clang-format * Renamed LocationInfoStruct to AreaInfoStruct. * Zap generated after XML update. * Renamed LocationStruct to AreaStruct and its LocationID and LocationDesc fields. * Zap generated after XML update. * Updated SDK and example code to match the new naming. * Updated the ProgressStruct's LocationID name to AreaID. * Zap generated after XML update. * Updated the SDK code following name changes. * Updated the SelectLocationsStatus and SkipLocationStatus enum names and some of their enums. * Zap generated after XML update. * Updated the SelectLocationsStatus and SkipCurrentLocationStatus names and their enum names. * Updated the names of the SupportedLocations, SelectedLocations and CurrentLocation attributes. * Zap generated after XML update. * Updated the changed names in the SDK. * Updated the service area command names in XML. * Zap generated after XML update. * Updated the service area command names in the SDK. * Updated the rvc-example zap file. * Refactored LocationStructureWrapper to AreaStructureWrapper. * Restyled by clang-format * Regenerated zap files due to changes upsteram. * Removed unused generated file. * Updated the Service Area XML marking previously nullabel attributes as not-nullable. * Zap generated after XML update. * Updated the attribute encoding and some server logic following the romoval of the nullable quality for some attributes. * Explicitly set the Service Area version. * Zap generated after XML update. * Updated the service area features in the XML to match the current spec. * Zap generated after XML update. * Updated the SupportedArea validation logic as if the MAPS feature is not supported, the Delegate may choose not to implement map related methods. * Change the type of the MapID to uint32 to match the spec. * Added the SkippedArea arg to the SkipArea command. * Zap generated after XML update. * Updated the Service Area server code to handle the new SkippedArea command arg. * Updated the service area XML to match the current spec. This includes the addition of the LandmarkInfoStruct and updates of AreaInfoStruct, SelectAreasStatus. * Zap generated after XML update. * Updated SDK server code and rvc-example after changes to the XML. * Restyled by whitespace * added vector include. * spacing changes form zap regen. * Fixed minor mistake during merge. * Restyled by clang-format * Applied suggestions from review. * Restyled by whitespace * Updated the LondmarkInfoSturct PositionTag type. * Zap generated after XML update. * Fixed SDK following update to the position type. * Restyled by clang-format * Updated the AeraStructWrapper to not contain methods with a large number of params. Updated some relate Instance and Delegate methods. * Restyled by whitespace * Restyled by clang-format * Missed a submudule update. * Made the setters reture a ref to the sturct to allow chaining. * simplified the = oporator and add the == operator. * Restyled by clang-format * minor change to get restyler going. * Restyled by clang-format * Fixed issue casued by a change in the way that registrations are made. --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 2040f26 commit 95ff33b

7 files changed

+315
-381
lines changed

examples/rvc-app/rvc-common/include/rvc-service-area-delegate.h

+9-12
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,24 @@ class RvcServiceAreaDelegate : public Delegate
4747
bool IsSetSelectedAreasAllowed(MutableCharSpan statusText) override;
4848

4949
bool IsValidSelectAreasSet(const ServiceArea::Commands::SelectAreas::DecodableType & req,
50-
ServiceArea::SelectAreasStatus & locationStatus, MutableCharSpan statusText) override;
50+
ServiceArea::SelectAreasStatus & areaStatus, MutableCharSpan statusText) override;
5151

5252
bool HandleSkipCurrentArea(uint32_t skippedArea, MutableCharSpan skipStatusText) override;
5353

5454
//*************************************************************************
55-
// Supported Locations accessors
55+
// Supported Areas accessors
5656

5757
bool IsSupportedAreasChangeAllowed() override;
5858

5959
uint32_t GetNumberOfSupportedAreas() override;
6060

61-
bool GetSupportedLocationByIndex(uint32_t listIndex, ServiceArea::AreaStructureWrapper & supportedLocation) override;
61+
bool GetSupportedAreaByIndex(uint32_t listIndex, AreaStructureWrapper & supportedArea) override;
6262

63-
bool GetSupportedLocationById(uint32_t aAreaId, uint32_t & listIndex,
64-
ServiceArea::AreaStructureWrapper & supportedLocation) override;
63+
bool GetSupportedAreaById(uint32_t aAreaId, uint32_t & listIndex, AreaStructureWrapper & supportedArea) override;
6564

66-
bool AddSupportedLocation(const ServiceArea::AreaStructureWrapper & newArea, uint32_t & listIndex) override;
65+
bool AddSupportedArea(const AreaStructureWrapper & newArea, uint32_t & listIndex) override;
6766

68-
bool ModifySupportedLocation(uint32_t listIndex, const ServiceArea::AreaStructureWrapper & modifiedLocation) override;
67+
bool ModifySupportedArea(uint32_t listIndex, const AreaStructureWrapper & modifiedArea) override;
6968

7069
bool ClearSupportedAreas() override;
7170

@@ -87,15 +86,13 @@ class RvcServiceAreaDelegate : public Delegate
8786
bool ClearSupportedMaps() override;
8887

8988
//*************************************************************************
90-
// Selected Locations accessors
89+
// Selected Areas accessors
9190

9291
uint32_t GetNumberOfSelectedAreas() override;
9392

94-
bool GetSelectedLocationByIndex(uint32_t listIndex, uint32_t & selectedLocation) override;
93+
bool GetSelectedAreaByIndex(uint32_t listIndex, uint32_t & selectedArea) override;
9594

96-
// IsSelectedLocation() no override
97-
98-
bool AddSelectedLocation(uint32_t aAreaId, uint32_t & listIndex) override;
95+
bool AddSelectedArea(uint32_t aAreaId, uint32_t & listIndex) override;
9996

10097
bool ClearSelectedAreas() override;
10198

examples/rvc-app/rvc-common/src/rvc-service-area-delegate.cpp

+55-50
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,43 @@ CHIP_ERROR RvcServiceAreaDelegate::Init()
3232
GetInstance()->AddSupportedMap(supportedMapId_XX, "My Map XX"_span);
3333
GetInstance()->AddSupportedMap(supportedMapId_YY, "My Map YY"_span);
3434

35-
// hardcoded fill of SUPPORTED LOCATIONS for prototyping
35+
// hardcoded fill of SUPPORTED AREAS for prototyping
3636
uint32_t supportedAreaID_A = 7;
3737
uint32_t supportedAreaID_B = 1234567;
3838
uint32_t supportedAreaID_C = 10050;
3939
uint32_t supportedAreaID_D = 0x88888888;
4040

41-
// Location A has name, floor number, uses map XX
42-
GetInstance()->AddSupportedLocation(supportedAreaID_A, DataModel::Nullable<uint32_t>(supportedMapId_XX), "My Location A"_span,
43-
DataModel::Nullable<int16_t>(4), DataModel::Nullable<Globals::AreaTypeTag>(),
44-
DataModel::Nullable<Globals::LandmarkTag>(),
45-
DataModel::Nullable<Globals::RelativePositionTag>());
46-
47-
// Location B has name, uses map XX
48-
GetInstance()->AddSupportedLocation(supportedAreaID_B, DataModel::Nullable<uint32_t>(supportedMapId_XX), "My Location B"_span,
49-
DataModel::Nullable<int16_t>(), DataModel::Nullable<Globals::AreaTypeTag>(),
50-
DataModel::Nullable<Globals::LandmarkTag>(),
51-
DataModel::Nullable<Globals::RelativePositionTag>());
52-
53-
// Location C has full SemData, no name, Map YY
54-
GetInstance()->AddSupportedLocation(supportedAreaID_C, DataModel::Nullable<uint32_t>(supportedMapId_YY), CharSpan(),
55-
DataModel::Nullable<int16_t>(-1),
56-
DataModel::Nullable<Globals::AreaTypeTag>(Globals::AreaTypeTag::kPlayRoom),
57-
DataModel::Nullable<Globals::LandmarkTag>(Globals::LandmarkTag::kBackDoor),
58-
DataModel::Nullable<Globals::RelativePositionTag>(Globals::RelativePositionTag::kNextTo));
59-
60-
// Location D has null values for all HomeLocationStruct fields, Map YY
61-
GetInstance()->AddSupportedLocation(supportedAreaID_D, DataModel::Nullable<uint32_t>(supportedMapId_YY), "My Location D"_span,
62-
DataModel::Nullable<int16_t>(), DataModel::Nullable<Globals::AreaTypeTag>(),
63-
DataModel::Nullable<Globals::LandmarkTag>(Globals::LandmarkTag::kCouch),
64-
DataModel::Nullable<Globals::RelativePositionTag>(Globals::RelativePositionTag::kNextTo));
65-
41+
// Area A has name, floor number, uses map XX
42+
auto areaA =
43+
AreaStructureWrapper{}
44+
.SetAreaId(supportedAreaID_A)
45+
.SetMapId(supportedMapId_XX)
46+
.SetLocationInfo("My Location A"_span, DataModel::Nullable<int16_t>(4), DataModel::Nullable<Globals::AreaTypeTag>());
47+
48+
// Area B has name, uses map XX
49+
auto areaB = AreaStructureWrapper{}
50+
.SetMapId(supportedAreaID_B)
51+
.SetMapId(supportedMapId_XX)
52+
.SetLocationInfo("My Location B"_span, DataModel::NullNullable, DataModel::NullNullable);
53+
54+
// Area C has full SemData, no name, Map YY
55+
auto areaC = AreaStructureWrapper{}
56+
.SetAreaId(supportedAreaID_C)
57+
.SetMapId(supportedMapId_YY)
58+
.SetLocationInfo(""_span, -1, Globals::AreaTypeTag::kPlayRoom)
59+
.SetLandmarkInfo(Globals::LandmarkTag::kBackDoor, Globals::RelativePositionTag::kNextTo);
60+
61+
// Area D has null values for all landmark fields, Map YY
62+
auto areaD = AreaStructureWrapper{}
63+
.SetAreaId(supportedAreaID_D)
64+
.SetMapId(supportedMapId_YY)
65+
.SetLocationInfo("My Location D"_span, DataModel::NullNullable, DataModel::NullNullable)
66+
.SetLandmarkInfo(Globals::LandmarkTag::kCouch, Globals::RelativePositionTag::kNextTo);
67+
68+
GetInstance()->AddSupportedArea(areaA);
69+
GetInstance()->AddSupportedArea(areaB);
70+
GetInstance()->AddSupportedArea(areaC);
71+
GetInstance()->AddSupportedArea(areaD);
6672
GetInstance()->SetCurrentArea(supportedAreaID_C);
6773

6874
return CHIP_NO_ERROR;
@@ -77,8 +83,8 @@ bool RvcServiceAreaDelegate::IsSetSelectedAreasAllowed(MutableCharSpan statusTex
7783
return true;
7884
};
7985

80-
bool RvcServiceAreaDelegate::IsValidSelectAreasSet(const Commands::SelectAreas::DecodableType & req,
81-
SelectAreasStatus & locationStatus, MutableCharSpan statusText)
86+
bool RvcServiceAreaDelegate::IsValidSelectAreasSet(const Commands::SelectAreas::DecodableType & req, SelectAreasStatus & areaStatus,
87+
MutableCharSpan statusText)
8288
{
8389
// TODO IMPLEMENT
8490
return true;
@@ -91,7 +97,7 @@ bool RvcServiceAreaDelegate::HandleSkipCurrentArea(uint32_t skippedArea, Mutable
9197
};
9298

9399
//*************************************************************************
94-
// Supported Locations accessors
100+
// Supported Areas accessors
95101

96102
bool RvcServiceAreaDelegate::IsSupportedAreasChangeAllowed()
97103
{
@@ -104,19 +110,18 @@ uint32_t RvcServiceAreaDelegate::GetNumberOfSupportedAreas()
104110
return static_cast<uint32_t>(mSupportedAreas.size());
105111
}
106112

107-
bool RvcServiceAreaDelegate::GetSupportedLocationByIndex(uint32_t listIndex, AreaStructureWrapper & aSupportedLocation)
113+
bool RvcServiceAreaDelegate::GetSupportedAreaByIndex(uint32_t listIndex, AreaStructureWrapper & supportedArea)
108114
{
109115
if (listIndex < mSupportedAreas.size())
110116
{
111-
aSupportedLocation = mSupportedAreas[listIndex];
117+
supportedArea = mSupportedAreas[listIndex];
112118
return true;
113119
}
114120

115121
return false;
116122
};
117123

118-
bool RvcServiceAreaDelegate::GetSupportedLocationById(uint32_t aAreaID, uint32_t & listIndex,
119-
AreaStructureWrapper & aSupportedLocation)
124+
bool RvcServiceAreaDelegate::GetSupportedAreaById(uint32_t aAreaID, uint32_t & listIndex, AreaStructureWrapper & supportedArea)
120125
{
121126
// We do not need to reimplement this method as it's already done by the SDK.
122127
// We are reimplementing this method, still using linear search, but with some optimization on the SDK implementation
@@ -127,7 +132,7 @@ bool RvcServiceAreaDelegate::GetSupportedLocationById(uint32_t aAreaID, uint32_t
127132
{
128133
if (mSupportedAreas[listIndex].areaID == aAreaID)
129134
{
130-
aSupportedLocation = mSupportedAreas[listIndex];
135+
supportedArea = mSupportedAreas[listIndex];
131136
return true;
132137
}
133138

@@ -137,41 +142,41 @@ bool RvcServiceAreaDelegate::GetSupportedLocationById(uint32_t aAreaID, uint32_t
137142
return false;
138143
};
139144

140-
bool RvcServiceAreaDelegate::AddSupportedLocation(const AreaStructureWrapper & newArea, uint32_t & listIndex)
145+
bool RvcServiceAreaDelegate::AddSupportedArea(const AreaStructureWrapper & newArea, uint32_t & listIndex)
141146
{
142147
// The server instance (caller) is responsible for ensuring that there are no duplicate area IDs, list size not exceeded,
143148
// etc.
144149

145150
// Double-check list size to ensure there no memory issues.
146151
if (mSupportedAreas.size() < kMaxNumSupportedAreas)
147152
{
148-
// not sorting list, number of locations normally expected to be small, max 255
153+
// not sorting list, number of areas normally expected to be small, max 255
149154
mSupportedAreas.push_back(newArea);
150155
listIndex = static_cast<uint32_t>(mSupportedMaps.size()) - 1; // new element is last in list
151156
return true;
152157
}
153158

154-
ChipLogError(Zcl, "AddSupportedLocation %u - supported locations list is already at maximum size %u", newArea.areaID,
159+
ChipLogError(Zcl, "AddSupportedArea %u - supported areas list is already at maximum size %u", newArea.areaID,
155160
static_cast<uint32_t>(kMaxNumSupportedAreas));
156161

157162
return false;
158163
}
159164

160-
bool RvcServiceAreaDelegate::ModifySupportedLocation(uint32_t listIndex, const AreaStructureWrapper & modifiedLocation)
165+
bool RvcServiceAreaDelegate::ModifySupportedArea(uint32_t listIndex, const AreaStructureWrapper & modifiedArea)
161166
{
162167
// The server instance (caller) is responsible for ensuring that there are no duplicate area IDs, list size not exceeded,
163168
// etc.
164169

165170
// Double-check that areaID's match.
166-
if (modifiedLocation.areaID != mSupportedAreas[listIndex].areaID)
171+
if (modifiedArea.areaID != mSupportedAreas[listIndex].areaID)
167172
{
168-
ChipLogError(Zcl, "ModifySupportedLocation - areaID's do not match, new areaID %u, existing areaID %u",
169-
modifiedLocation.areaID, mSupportedAreas[listIndex].areaID);
173+
ChipLogError(Zcl, "ModifySupportedArea - areaID's do not match, new areaID %u, existing areaID %u", modifiedArea.areaID,
174+
mSupportedAreas[listIndex].areaID);
170175
return false;
171176
}
172177

173178
// checks passed, update the attribute
174-
mSupportedAreas[listIndex] = modifiedLocation;
179+
mSupportedAreas[listIndex] = modifiedArea;
175180
return true;
176181
}
177182

@@ -240,7 +245,7 @@ bool RvcServiceAreaDelegate::AddSupportedMap(const MapStructureWrapper & newMap,
240245
// Double-check list size to ensure there no memory issues.
241246
if (mSupportedMaps.size() < kMaxNumSupportedMaps)
242247
{
243-
// not sorting list, number of locations normally expected to be small, max 255
248+
// not sorting list, number of areas normally expected to be small, max 255
244249
mSupportedMaps.push_back(newMap);
245250
listIndex = static_cast<uint32_t>(mSupportedMaps.size()) - 1; // new element is last in list
246251
return true;
@@ -281,38 +286,38 @@ bool RvcServiceAreaDelegate::ClearSupportedMaps()
281286
}
282287

283288
//*************************************************************************
284-
// Selected Locations accessors
289+
// Selected areas accessors
285290

286291
uint32_t RvcServiceAreaDelegate::GetNumberOfSelectedAreas()
287292
{
288293
return static_cast<uint32_t>(mSelectedAreas.size());
289294
}
290295

291-
bool RvcServiceAreaDelegate::GetSelectedLocationByIndex(uint32_t listIndex, uint32_t & aSelectedLocation)
296+
bool RvcServiceAreaDelegate::GetSelectedAreaByIndex(uint32_t listIndex, uint32_t & selectedArea)
292297
{
293298
if (listIndex < mSelectedAreas.size())
294299
{
295-
aSelectedLocation = mSelectedAreas[listIndex];
300+
selectedArea = mSelectedAreas[listIndex];
296301
return true;
297302
}
298303

299304
return false;
300305
};
301306

302-
bool RvcServiceAreaDelegate::AddSelectedLocation(uint32_t aAreaID, uint32_t & listIndex)
307+
bool RvcServiceAreaDelegate::AddSelectedArea(uint32_t aAreaID, uint32_t & listIndex)
303308
{
304309
// The server instance (caller) is responsible for ensuring that there are no duplicate area IDs, list size not exceeded,
305310
// etc.
306311

307312
// Double-check list size to ensure there no memory issues.
308313
if (mSelectedAreas.size() < kMaxNumSelectedAreas)
309314
{
310-
// not sorting list, number of locations normally expected to be small, max 255
315+
// not sorting list, number of areas normally expected to be small, max 255
311316
mSelectedAreas.push_back(aAreaID);
312317
listIndex = static_cast<uint32_t>(mSelectedAreas.size()) - 1; // new element is last in list
313318
return true;
314319
}
315-
ChipLogError(Zcl, "AddSelectedLocation %u - selected locations list is already at maximum size %u", aAreaID,
320+
ChipLogError(Zcl, "AddSelectedArea %u - selected areas list is already at maximum size %u", aAreaID,
316321
static_cast<uint32_t>(kMaxNumSelectedAreas));
317322

318323
return false;
@@ -378,7 +383,7 @@ bool RvcServiceAreaDelegate::AddProgressElement(const Structs::ProgressStruct::T
378383
// Double-check list size to ensure there no memory issues.
379384
if (mProgressList.size() < kMaxNumProgressElements)
380385
{
381-
// not sorting list, number of locations normally expected to be small, max 255
386+
// not sorting list, number of areas normally expected to be small, max 255
382387
mProgressList.push_back(newProgressElement);
383388
listIndex = static_cast<uint32_t>(mProgressList.size()) - 1; // new element is last in list
384389
return true;

0 commit comments

Comments
 (0)