Skip to content

Commit

Permalink
Improve the AreaStructureWrapper (#34814)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Aug 12, 2024
1 parent fdfaf34 commit 2875961
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 381 deletions.
21 changes: 9 additions & 12 deletions examples/rvc-app/rvc-common/include/rvc-service-area-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,24 @@ class RvcServiceAreaDelegate : public Delegate
bool IsSetSelectedAreasAllowed(MutableCharSpan statusText) override;

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

bool HandleSkipCurrentArea(uint32_t skippedArea, MutableCharSpan skipStatusText) override;

//*************************************************************************
// Supported Locations accessors
// Supported Areas accessors

bool IsSupportedAreasChangeAllowed() override;

uint32_t GetNumberOfSupportedAreas() override;

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

bool GetSupportedLocationById(uint32_t aAreaId, uint32_t & listIndex,
ServiceArea::AreaStructureWrapper & supportedLocation) override;
bool GetSupportedAreaById(uint32_t aAreaId, uint32_t & listIndex, AreaStructureWrapper & supportedArea) override;

bool AddSupportedLocation(const ServiceArea::AreaStructureWrapper & newArea, uint32_t & listIndex) override;
bool AddSupportedArea(const AreaStructureWrapper & newArea, uint32_t & listIndex) override;

bool ModifySupportedLocation(uint32_t listIndex, const ServiceArea::AreaStructureWrapper & modifiedLocation) override;
bool ModifySupportedArea(uint32_t listIndex, const AreaStructureWrapper & modifiedArea) override;

bool ClearSupportedAreas() override;

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

//*************************************************************************
// Selected Locations accessors
// Selected Areas accessors

uint32_t GetNumberOfSelectedAreas() override;

bool GetSelectedLocationByIndex(uint32_t listIndex, uint32_t & selectedLocation) override;
bool GetSelectedAreaByIndex(uint32_t listIndex, uint32_t & selectedArea) override;

// IsSelectedLocation() no override

bool AddSelectedLocation(uint32_t aAreaId, uint32_t & listIndex) override;
bool AddSelectedArea(uint32_t aAreaId, uint32_t & listIndex) override;

bool ClearSelectedAreas() override;

Expand Down
105 changes: 55 additions & 50 deletions examples/rvc-app/rvc-common/src/rvc-service-area-delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,43 @@ CHIP_ERROR RvcServiceAreaDelegate::Init()
GetInstance()->AddSupportedMap(supportedMapId_XX, "My Map XX"_span);
GetInstance()->AddSupportedMap(supportedMapId_YY, "My Map YY"_span);

// hardcoded fill of SUPPORTED LOCATIONS for prototyping
// hardcoded fill of SUPPORTED AREAS for prototyping
uint32_t supportedAreaID_A = 7;
uint32_t supportedAreaID_B = 1234567;
uint32_t supportedAreaID_C = 10050;
uint32_t supportedAreaID_D = 0x88888888;

// Location A has name, floor number, uses map XX
GetInstance()->AddSupportedLocation(supportedAreaID_A, DataModel::Nullable<uint32_t>(supportedMapId_XX), "My Location A"_span,
DataModel::Nullable<int16_t>(4), DataModel::Nullable<Globals::AreaTypeTag>(),
DataModel::Nullable<Globals::LandmarkTag>(),
DataModel::Nullable<Globals::RelativePositionTag>());

// Location B has name, uses map XX
GetInstance()->AddSupportedLocation(supportedAreaID_B, DataModel::Nullable<uint32_t>(supportedMapId_XX), "My Location B"_span,
DataModel::Nullable<int16_t>(), DataModel::Nullable<Globals::AreaTypeTag>(),
DataModel::Nullable<Globals::LandmarkTag>(),
DataModel::Nullable<Globals::RelativePositionTag>());

// Location C has full SemData, no name, Map YY
GetInstance()->AddSupportedLocation(supportedAreaID_C, DataModel::Nullable<uint32_t>(supportedMapId_YY), CharSpan(),
DataModel::Nullable<int16_t>(-1),
DataModel::Nullable<Globals::AreaTypeTag>(Globals::AreaTypeTag::kPlayRoom),
DataModel::Nullable<Globals::LandmarkTag>(Globals::LandmarkTag::kBackDoor),
DataModel::Nullable<Globals::RelativePositionTag>(Globals::RelativePositionTag::kNextTo));

// Location D has null values for all HomeLocationStruct fields, Map YY
GetInstance()->AddSupportedLocation(supportedAreaID_D, DataModel::Nullable<uint32_t>(supportedMapId_YY), "My Location D"_span,
DataModel::Nullable<int16_t>(), DataModel::Nullable<Globals::AreaTypeTag>(),
DataModel::Nullable<Globals::LandmarkTag>(Globals::LandmarkTag::kCouch),
DataModel::Nullable<Globals::RelativePositionTag>(Globals::RelativePositionTag::kNextTo));

// Area A has name, floor number, uses map XX
auto areaA =
AreaStructureWrapper{}
.SetAreaId(supportedAreaID_A)
.SetMapId(supportedMapId_XX)
.SetLocationInfo("My Location A"_span, DataModel::Nullable<int16_t>(4), DataModel::Nullable<Globals::AreaTypeTag>());

// Area B has name, uses map XX
auto areaB = AreaStructureWrapper{}
.SetMapId(supportedAreaID_B)
.SetMapId(supportedMapId_XX)
.SetLocationInfo("My Location B"_span, DataModel::NullNullable, DataModel::NullNullable);

// Area C has full SemData, no name, Map YY
auto areaC = AreaStructureWrapper{}
.SetAreaId(supportedAreaID_C)
.SetMapId(supportedMapId_YY)
.SetLocationInfo(""_span, -1, Globals::AreaTypeTag::kPlayRoom)
.SetLandmarkInfo(Globals::LandmarkTag::kBackDoor, Globals::RelativePositionTag::kNextTo);

// Area D has null values for all landmark fields, Map YY
auto areaD = AreaStructureWrapper{}
.SetAreaId(supportedAreaID_D)
.SetMapId(supportedMapId_YY)
.SetLocationInfo("My Location D"_span, DataModel::NullNullable, DataModel::NullNullable)
.SetLandmarkInfo(Globals::LandmarkTag::kCouch, Globals::RelativePositionTag::kNextTo);

GetInstance()->AddSupportedArea(areaA);
GetInstance()->AddSupportedArea(areaB);
GetInstance()->AddSupportedArea(areaC);
GetInstance()->AddSupportedArea(areaD);
GetInstance()->SetCurrentArea(supportedAreaID_C);

return CHIP_NO_ERROR;
Expand All @@ -77,8 +83,8 @@ bool RvcServiceAreaDelegate::IsSetSelectedAreasAllowed(MutableCharSpan statusTex
return true;
};

bool RvcServiceAreaDelegate::IsValidSelectAreasSet(const Commands::SelectAreas::DecodableType & req,
SelectAreasStatus & locationStatus, MutableCharSpan statusText)
bool RvcServiceAreaDelegate::IsValidSelectAreasSet(const Commands::SelectAreas::DecodableType & req, SelectAreasStatus & areaStatus,
MutableCharSpan statusText)
{
// TODO IMPLEMENT
return true;
Expand All @@ -91,7 +97,7 @@ bool RvcServiceAreaDelegate::HandleSkipCurrentArea(uint32_t skippedArea, Mutable
};

//*************************************************************************
// Supported Locations accessors
// Supported Areas accessors

bool RvcServiceAreaDelegate::IsSupportedAreasChangeAllowed()
{
Expand All @@ -104,19 +110,18 @@ uint32_t RvcServiceAreaDelegate::GetNumberOfSupportedAreas()
return static_cast<uint32_t>(mSupportedAreas.size());
}

bool RvcServiceAreaDelegate::GetSupportedLocationByIndex(uint32_t listIndex, AreaStructureWrapper & aSupportedLocation)
bool RvcServiceAreaDelegate::GetSupportedAreaByIndex(uint32_t listIndex, AreaStructureWrapper & supportedArea)
{
if (listIndex < mSupportedAreas.size())
{
aSupportedLocation = mSupportedAreas[listIndex];
supportedArea = mSupportedAreas[listIndex];
return true;
}

return false;
};

bool RvcServiceAreaDelegate::GetSupportedLocationById(uint32_t aAreaID, uint32_t & listIndex,
AreaStructureWrapper & aSupportedLocation)
bool RvcServiceAreaDelegate::GetSupportedAreaById(uint32_t aAreaID, uint32_t & listIndex, AreaStructureWrapper & supportedArea)
{
// We do not need to reimplement this method as it's already done by the SDK.
// We are reimplementing this method, still using linear search, but with some optimization on the SDK implementation
Expand All @@ -127,7 +132,7 @@ bool RvcServiceAreaDelegate::GetSupportedLocationById(uint32_t aAreaID, uint32_t
{
if (mSupportedAreas[listIndex].areaID == aAreaID)
{
aSupportedLocation = mSupportedAreas[listIndex];
supportedArea = mSupportedAreas[listIndex];
return true;
}

Expand All @@ -137,41 +142,41 @@ bool RvcServiceAreaDelegate::GetSupportedLocationById(uint32_t aAreaID, uint32_t
return false;
};

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

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

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

return false;
}

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

// Double-check that areaID's match.
if (modifiedLocation.areaID != mSupportedAreas[listIndex].areaID)
if (modifiedArea.areaID != mSupportedAreas[listIndex].areaID)
{
ChipLogError(Zcl, "ModifySupportedLocation - areaID's do not match, new areaID %u, existing areaID %u",
modifiedLocation.areaID, mSupportedAreas[listIndex].areaID);
ChipLogError(Zcl, "ModifySupportedArea - areaID's do not match, new areaID %u, existing areaID %u", modifiedArea.areaID,
mSupportedAreas[listIndex].areaID);
return false;
}

// checks passed, update the attribute
mSupportedAreas[listIndex] = modifiedLocation;
mSupportedAreas[listIndex] = modifiedArea;
return true;
}

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

//*************************************************************************
// Selected Locations accessors
// Selected areas accessors

uint32_t RvcServiceAreaDelegate::GetNumberOfSelectedAreas()
{
return static_cast<uint32_t>(mSelectedAreas.size());
}

bool RvcServiceAreaDelegate::GetSelectedLocationByIndex(uint32_t listIndex, uint32_t & aSelectedLocation)
bool RvcServiceAreaDelegate::GetSelectedAreaByIndex(uint32_t listIndex, uint32_t & selectedArea)
{
if (listIndex < mSelectedAreas.size())
{
aSelectedLocation = mSelectedAreas[listIndex];
selectedArea = mSelectedAreas[listIndex];
return true;
}

return false;
};

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

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

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

0 comments on commit 2875961

Please sign in to comment.