From 5b8a9b8ef47b99bd7cc3606de3adb268a6f559f7 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Thu, 8 Aug 2024 11:34:28 -0700 Subject: [PATCH 1/3] Update build instruction for fabric-admin (#34885) --- examples/fabric-admin/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/fabric-admin/README.md b/examples/fabric-admin/README.md index da2a4d6b21684e..7178ab2c2f8c94 100644 --- a/examples/fabric-admin/README.md +++ b/examples/fabric-admin/README.md @@ -14,7 +14,7 @@ fabrics. For Linux host example: ``` -./scripts/examples/gn_build_example.sh examples/fabric-admin out/debug/standalone chip_config_network_layer_ble=false 'import("//with_pw_rpc.gni")' +./scripts/examples/gn_build_example.sh examples/fabric-admin out/debug/standalone 'import("//with_pw_rpc.gni")' ``` For Raspberry Pi 4 example: From 2040f262203d1d88be89d094994010f03c79b48b Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Thu, 8 Aug 2024 14:37:56 -0400 Subject: [PATCH 2/3] Add ICD support (featuremap and commands) to FabricAdmin/FabricBridge samples (#34855) * Add extra attributes to the bridged device basic info structures, remove nonsense comments * Make use of AAI for BridgedDeviceBasicInformation cluster * Restyled by gn * Fix sizes for software version * Update the synchronized device proto to have more data in it * Switch to unique ptr in the registry, making sure memory management works (fixed memory leak on remove device) * Use more std::optional * Bump revision to 4 * Forward attributes from the create call into the bridged device * Make attribute mapping actually work * Restyle * Ensure unique IDs are generated * Restyle * Increase size to 33 to allow for a null terminator * make sure that the rpc structures are initialized * Restyle * Add some fake data to test moving the data around * Remove unused members that were likely just copied over * make the attributes optional * Prepare some device sync data - reading the basic info cluster * Prepare some device sync data - reading the basic info cluster * Full implementation of forwarding data * Restyle * Add missing file * Restyle * reset readclient, since this may reset the exchange manager ... seems cleaner * Add the verifyOrDie * Restyled by clang-format * Fix string size for HW and software versions * Move ICD support: set separate commands, handle feature mask * Restyle * Remove some of the spammier logs * Enfore RPC enabling for synchronized device addition * Add device sync in progress tracking * Undo submodule update * Fix up device sync progress tracking to better handle errors * Restyled by clang-format * Fix typo * Undo submodule update * Fix merge * Restyled by clang-format --------- Co-authored-by: Restyled.io Co-authored-by: Andrei Litvin --- .../commands/pairing/DeviceSynchronization.h | 2 +- .../include/BridgedDevice.h | 19 +++++++------ .../src/BridgedDevice.cpp | 13 +-------- .../src/BridgedDeviceBasicInformationImpl.cpp | 10 ++++--- .../src/BridgedDeviceManager.cpp | 27 +++++++++++++++---- .../fabric-bridge-app/linux/RpcServer.cpp | 1 + 6 files changed, 42 insertions(+), 30 deletions(-) diff --git a/examples/fabric-admin/commands/pairing/DeviceSynchronization.h b/examples/fabric-admin/commands/pairing/DeviceSynchronization.h index 16c0e264928639..6aca23f31cbeaa 100644 --- a/examples/fabric-admin/commands/pairing/DeviceSynchronization.h +++ b/examples/fabric-admin/commands/pairing/DeviceSynchronization.h @@ -26,7 +26,7 @@ #include "fabric_bridge_service/fabric_bridge_service.pb.h" #include "fabric_bridge_service/fabric_bridge_service.rpc.pb.h" -/// Ensures that device data is synchronized to the remove fabric bridge. +/// Ensures that device data is synchronized to the remote fabric bridge. /// /// Includes a state machine that: /// - initiates a "read basic information data" command to fetch basic information diff --git a/examples/fabric-bridge-app/fabric-bridge-common/include/BridgedDevice.h b/examples/fabric-bridge-app/fabric-bridge-common/include/BridgedDevice.h index a65ddb15a736f5..3dab8d3b16b2d6 100644 --- a/examples/fabric-bridge-app/fabric-bridge-common/include/BridgedDevice.h +++ b/examples/fabric-bridge-app/fabric-bridge-common/include/BridgedDevice.h @@ -43,11 +43,13 @@ class BridgedDevice BridgedDevice(chip::NodeId nodeId); virtual ~BridgedDevice() = default; + [[nodiscard]] bool IsReachable() const { return mReachable; } + void SetReachable(bool reachable); + void LogActiveChangeEvent(uint32_t promisedActiveDurationMs); - bool IsReachable(); - bool IsIcd(); - void SetReachable(bool reachable); + [[nodiscard]] bool IsIcd() const { return mIsIcd; } + void SetIcd(bool icd) { mIsIcd = icd; } inline void SetEndpointId(chip::EndpointId id) { mEndpointId = id; }; inline chip::EndpointId GetEndpointId() { return mEndpointId; }; @@ -63,11 +65,12 @@ class BridgedDevice void SetUniqueId(const std::string & value) { mAttributes.uniqueId = value; } protected: - bool mReachable; - bool mIsIcd = false; - chip::NodeId mNodeId; - chip::EndpointId mEndpointId; - chip::EndpointId mParentEndpointId; + bool mReachable = false; + bool mIsIcd = false; + + chip::NodeId mNodeId = 0; + chip::EndpointId mEndpointId = 0; + chip::EndpointId mParentEndpointId = 0; BridgedAttributes mAttributes; }; diff --git a/examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDevice.cpp b/examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDevice.cpp index a5e041b487d962..21f19189afefe6 100644 --- a/examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDevice.cpp +++ b/examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDevice.cpp @@ -19,7 +19,6 @@ #include "BridgedDevice.h" #include -#include #include #include @@ -32,7 +31,7 @@ struct ActiveChangeEventWorkData uint32_t mPromisedActiveDuration; }; -static void ActiveChangeEventWork(intptr_t arg) +void ActiveChangeEventWork(intptr_t arg) { ActiveChangeEventWorkData * data = reinterpret_cast(arg); @@ -68,16 +67,6 @@ void BridgedDevice::LogActiveChangeEvent(uint32_t promisedActiveDurationMs) chip::DeviceLayer::PlatformMgr().ScheduleWork(ActiveChangeEventWork, reinterpret_cast(workdata)); } -bool BridgedDevice::IsReachable() -{ - return mReachable; -} - -bool BridgedDevice::IsIcd() -{ - return mIsIcd; -} - void BridgedDevice::SetReachable(bool reachable) { mReachable = reachable; diff --git a/examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDeviceBasicInformationImpl.cpp b/examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDeviceBasicInformationImpl.cpp index c088935df30c59..7fa48a4a158ddd 100644 --- a/examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDeviceBasicInformationImpl.cpp +++ b/examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDeviceBasicInformationImpl.cpp @@ -24,7 +24,6 @@ #include static constexpr unsigned kBridgedDeviceBasicInformationClusterRevision = 4; -static constexpr unsigned kBridgedDeviceBasicInformationFeatureMap = 0; using namespace ::chip; using namespace ::chip::app; @@ -49,9 +48,12 @@ CHIP_ERROR BridgedDeviceBasicInformationImpl::Read(const ConcreteReadAttributePa case BasicInformation::Attributes::ClusterRevision::Id: encoder.Encode(kBridgedDeviceBasicInformationClusterRevision); break; - case BasicInformation::Attributes::FeatureMap::Id: - encoder.Encode(kBridgedDeviceBasicInformationFeatureMap); - break; + case BasicInformation::Attributes::FeatureMap::Id: { + BitMask features; + features.Set(Clusters::BridgedDeviceBasicInformation::Feature::kBridgedICDSupport, dev->IsIcd()); + encoder.Encode(features); + } + break; case BasicInformation::Attributes::UniqueID::Id: encoder.Encode(CharSpan::fromCharString(dev->GetBridgedAttributes().uniqueId.c_str())); break; diff --git a/examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDeviceManager.cpp b/examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDeviceManager.cpp index b361e6667278a4..8db44c3e8bfd9b 100644 --- a/examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDeviceManager.cpp +++ b/examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDeviceManager.cpp @@ -141,17 +141,31 @@ constexpr CommandId administratorCommissioningCommands[] = { kInvalidCommandId, }; +// clang-format off // Declare Cluster List for Bridged Node endpoint DECLARE_DYNAMIC_CLUSTER_LIST_BEGIN(bridgedNodeClusters) -DECLARE_DYNAMIC_CLUSTER(Descriptor::Id, descriptorAttrs, ZAP_CLUSTER_MASK(SERVER), nullptr, nullptr), + DECLARE_DYNAMIC_CLUSTER(Descriptor::Id, descriptorAttrs, ZAP_CLUSTER_MASK(SERVER), nullptr, nullptr), + DECLARE_DYNAMIC_CLUSTER(BridgedDeviceBasicInformation::Id, bridgedDeviceBasicAttrs, ZAP_CLUSTER_MASK(SERVER), nullptr, nullptr), + DECLARE_DYNAMIC_CLUSTER(EcosystemInformation::Id, ecosystemInformationBasicAttrs, ZAP_CLUSTER_MASK(SERVER), nullptr, nullptr), + DECLARE_DYNAMIC_CLUSTER(AdministratorCommissioning::Id, AdministratorCommissioningAttrs, ZAP_CLUSTER_MASK(SERVER), + administratorCommissioningCommands, nullptr) +DECLARE_DYNAMIC_CLUSTER_LIST_END; + +DECLARE_DYNAMIC_CLUSTER_LIST_BEGIN(icdBridgedNodeClusters) + DECLARE_DYNAMIC_CLUSTER(Descriptor::Id, descriptorAttrs, ZAP_CLUSTER_MASK(SERVER), nullptr, nullptr), DECLARE_DYNAMIC_CLUSTER(BridgedDeviceBasicInformation::Id, bridgedDeviceBasicAttrs, ZAP_CLUSTER_MASK(SERVER), bridgedDeviceBasicInformationCommands, nullptr), - DECLARE_DYNAMIC_CLUSTER(EcosystemInformation::Id, ecosystemInformationBasicAttrs, ZAP_CLUSTER_MASK(SERVER), nullptr, nullptr), DECLARE_DYNAMIC_CLUSTER(AdministratorCommissioning::Id, AdministratorCommissioningAttrs, ZAP_CLUSTER_MASK(SERVER), - administratorCommissioningCommands, nullptr) DECLARE_DYNAMIC_CLUSTER_LIST_END; + administratorCommissioningCommands, nullptr) +DECLARE_DYNAMIC_CLUSTER_LIST_END; +// clang-format on // Declare Bridged Node endpoint DECLARE_DYNAMIC_ENDPOINT(sBridgedNodeEndpoint, bridgedNodeClusters); +DECLARE_DYNAMIC_ENDPOINT(sIcdBridgedNodeEndpoint, icdBridgedNodeClusters); + +// TODO: this is a single version array, however we may have many +// different clusters that are independent. DataVersion sBridgedNodeDataVersions[ArraySize(bridgedNodeClusters)]; const EmberAfDeviceType sBridgedDeviceTypes[] = { { DEVICE_TYPE_BRIDGED_NODE, DEVICE_VERSION_DEFAULT } }; @@ -171,9 +185,12 @@ void BridgedDeviceManager::Init() std::optional BridgedDeviceManager::AddDeviceEndpoint(std::unique_ptr dev, chip::EndpointId parentEndpointId) { - EmberAfEndpointType * ep = &sBridgedNodeEndpoint; + EmberAfEndpointType * ep = dev->IsIcd() ? &sIcdBridgedNodeEndpoint : &sBridgedNodeEndpoint; + const chip::Span & deviceTypeList = Span(sBridgedDeviceTypes); - const chip::Span & dataVersionStorage = Span(sBridgedNodeDataVersions); + + // TODO: this shares data version among different clusters, which seems incorrect + const chip::Span & dataVersionStorage = Span(sBridgedNodeDataVersions); if (dev->GetBridgedAttributes().uniqueId.empty()) { diff --git a/examples/fabric-bridge-app/linux/RpcServer.cpp b/examples/fabric-bridge-app/linux/RpcServer.cpp index 8838360ee7b1e7..932d3288b9cb27 100644 --- a/examples/fabric-bridge-app/linux/RpcServer.cpp +++ b/examples/fabric-bridge-app/linux/RpcServer.cpp @@ -109,6 +109,7 @@ pw::Status FabricBridge::AddSynchronizedDevice(const chip_rpc_SynchronizedDevice } device->SetBridgedAttributes(attributes); + device->SetIcd(request.has_is_icd && request.is_icd); auto result = BridgeDeviceMgr().AddDeviceEndpoint(std::move(device), 1 /* parentEndpointId */); if (!result.has_value()) From 95ff33b091b233551c48396ae5cc8b7aac139442 Mon Sep 17 00:00:00 2001 From: William Date: Thu, 8 Aug 2024 20:18:05 +0100 Subject: [PATCH 3/3] Improve the AreaStructureWrapper (#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 --- .../include/rvc-service-area-delegate.h | 21 +- .../src/rvc-service-area-delegate.cpp | 105 +++++---- .../service-area-cluster-objects.h | 218 ++++++++---------- .../service-area-delegate.cpp | 16 +- .../service-area-delegate.h | 70 +++--- .../service-area-server.cpp | 200 ++++++++-------- .../service-area-server/service-area-server.h | 66 ++---- 7 files changed, 315 insertions(+), 381 deletions(-) diff --git a/examples/rvc-app/rvc-common/include/rvc-service-area-delegate.h b/examples/rvc-app/rvc-common/include/rvc-service-area-delegate.h index 759c22a4e609cb..5397e3096c14ae 100644 --- a/examples/rvc-app/rvc-common/include/rvc-service-area-delegate.h +++ b/examples/rvc-app/rvc-common/include/rvc-service-area-delegate.h @@ -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; @@ -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; diff --git a/examples/rvc-app/rvc-common/src/rvc-service-area-delegate.cpp b/examples/rvc-app/rvc-common/src/rvc-service-area-delegate.cpp index aca96da836151d..1bc60baa0774cd 100644 --- a/examples/rvc-app/rvc-common/src/rvc-service-area-delegate.cpp +++ b/examples/rvc-app/rvc-common/src/rvc-service-area-delegate.cpp @@ -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(supportedMapId_XX), "My Location A"_span, - DataModel::Nullable(4), DataModel::Nullable(), - DataModel::Nullable(), - DataModel::Nullable()); - - // Location B has name, uses map XX - GetInstance()->AddSupportedLocation(supportedAreaID_B, DataModel::Nullable(supportedMapId_XX), "My Location B"_span, - DataModel::Nullable(), DataModel::Nullable(), - DataModel::Nullable(), - DataModel::Nullable()); - - // Location C has full SemData, no name, Map YY - GetInstance()->AddSupportedLocation(supportedAreaID_C, DataModel::Nullable(supportedMapId_YY), CharSpan(), - DataModel::Nullable(-1), - DataModel::Nullable(Globals::AreaTypeTag::kPlayRoom), - DataModel::Nullable(Globals::LandmarkTag::kBackDoor), - DataModel::Nullable(Globals::RelativePositionTag::kNextTo)); - - // Location D has null values for all HomeLocationStruct fields, Map YY - GetInstance()->AddSupportedLocation(supportedAreaID_D, DataModel::Nullable(supportedMapId_YY), "My Location D"_span, - DataModel::Nullable(), DataModel::Nullable(), - DataModel::Nullable(Globals::LandmarkTag::kCouch), - DataModel::Nullable(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(4), DataModel::Nullable()); + + // 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; @@ -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; @@ -91,7 +97,7 @@ bool RvcServiceAreaDelegate::HandleSkipCurrentArea(uint32_t skippedArea, Mutable }; //************************************************************************* -// Supported Locations accessors +// Supported Areas accessors bool RvcServiceAreaDelegate::IsSupportedAreasChangeAllowed() { @@ -104,19 +110,18 @@ uint32_t RvcServiceAreaDelegate::GetNumberOfSupportedAreas() return static_cast(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 @@ -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; } @@ -137,7 +142,7 @@ 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. @@ -145,33 +150,33 @@ bool RvcServiceAreaDelegate::AddSupportedLocation(const AreaStructureWrapper & n // 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(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(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; } @@ -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(mSupportedMaps.size()) - 1; // new element is last in list return true; @@ -281,25 +286,25 @@ bool RvcServiceAreaDelegate::ClearSupportedMaps() } //************************************************************************* -// Selected Locations accessors +// Selected areas accessors uint32_t RvcServiceAreaDelegate::GetNumberOfSelectedAreas() { return static_cast(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. @@ -307,12 +312,12 @@ bool RvcServiceAreaDelegate::AddSelectedLocation(uint32_t aAreaID, uint32_t & li // 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(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(kMaxNumSelectedAreas)); return false; @@ -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(mProgressList.size()) - 1; // new element is last in list return true; diff --git a/src/app/clusters/service-area-server/service-area-cluster-objects.h b/src/app/clusters/service-area-server/service-area-cluster-objects.h index 2d2694e20dbd78..1b040c53cdc1bf 100644 --- a/src/app/clusters/service-area-server/service-area-cluster-objects.h +++ b/src/app/clusters/service-area-server/service-area-cluster-objects.h @@ -27,8 +27,8 @@ namespace Clusters { namespace ServiceArea { // These limits are defined in the spec. -inline constexpr size_t kLocationNameMaxSize = 128u; -inline constexpr size_t kMapNameMaxSize = 64u; +inline constexpr size_t kAreaNameMaxSize = 128u; +inline constexpr size_t kMapNameMaxSize = 64u; /** * This class is used to wrap the AreaStruct object and provide a more user-friendly interface for the data. @@ -36,35 +36,16 @@ inline constexpr size_t kMapNameMaxSize = 64u; */ struct AreaStructureWrapper : public chip::app::Clusters::ServiceArea::Structs::AreaStruct::Type { - AreaStructureWrapper() - { - Set(0, 0, CharSpan(), DataModel::Nullable(), DataModel::Nullable(), - DataModel::Nullable(), DataModel::Nullable()); - } - /** - * @brief This is a full constructor that initializes the location object with the given values. All values are deep copied. - * @param[in] aAreaID The unique identifier of this location. - * @param[in] aMapId The identifier of the supported map associated with this location. - * @param[in] aLocationName A human readable name for this location (empty string if not used). - * @param[in] aFloorNumber The floor level of this location - use negative values for below ground. - * @param[in] aAreaTypeTag A common namespace Area tag - indicates an association of the location with an indoor or outdoor area - * of a home. - * @param[in] aLandmarkTag A common namespace Landmark tag - indicates an association of the location with a home landmark. - * @param[in] aRelativePositionTag A common namespace Relative Position tag - indicates the position of the location with - * respect to the landmark. - * - * @note Requirements regarding what combinations of fields and values are valid are not checked by this class. - * @note If aLocationName is larger than kLocationNameMaxSize, it will be truncated. - * @note If aLocationName is an empty string and aFloorNumber and aAreaTypeTag are null, locationInfo will be set to null. + * @brief This is a default constructor that initializes the location object with the following + * values: areaID = 0, mapID = null, locationInfo = null, landmarkInfo = null. */ - AreaStructureWrapper(uint32_t aAreaID, const DataModel::Nullable & aMapId, const CharSpan & aLocationName, - const DataModel::Nullable & aFloorNumber, - const DataModel::Nullable & aAreaTypeTag, - const DataModel::Nullable & aLandmarkTag, - const DataModel::Nullable & aRelativePositionTag) + AreaStructureWrapper() { - Set(aAreaID, aMapId, aLocationName, aFloorNumber, aAreaTypeTag, aLandmarkTag, aRelativePositionTag); + areaID = 0; + mapID = DataModel::NullNullable; + SetLocationInfoNull(); + SetLandmarkInfoNull(); } /** @@ -87,124 +68,117 @@ struct AreaStructureWrapper : public chip::app::Clusters::ServiceArea::Structs:: { areaID = aOther.areaID; mapID = aOther.mapID; + SetLocationInfo(aOther.areaDesc.locationInfo); + SetLandmarkInfo(aOther.areaDesc.landmarkInfo); - if (aOther.areaDesc.locationInfo.IsNull()) - { - areaDesc.locationInfo.SetNull(); - } - else - { - areaDesc.locationInfo.SetNonNull(); + return *this; + } - // deep copy the name. - auto sizeToCopy = std::min(sizeof(mLocationNameBuffer), aOther.areaDesc.locationInfo.Value().locationName.size()); - memcpy(mLocationNameBuffer, aOther.areaDesc.locationInfo.Value().locationName.data(), sizeToCopy); - areaDesc.locationInfo.Value().locationName = CharSpan(mLocationNameBuffer, sizeToCopy); + bool operator==(const AreaStructureWrapper & aOther) const + { + BitMask config = 0; // Do not ignore the AreaID or the MapID. - areaDesc.locationInfo.Value().floorNumber = aOther.areaDesc.locationInfo.Value().floorNumber; - areaDesc.locationInfo.Value().areaType = aOther.areaDesc.locationInfo.Value().areaType; - } + return IsEqual(aOther, config); + } - if (aOther.areaDesc.landmarkInfo.IsNull()) - { - areaDesc.landmarkInfo.SetNull(); - } - else - { - areaDesc.landmarkInfo.SetNonNull(); - areaDesc.landmarkInfo.Value().landmarkTag = aOther.areaDesc.landmarkInfo.Value().landmarkTag; - if (aOther.areaDesc.landmarkInfo.Value().positionTag.IsNull()) - { - areaDesc.landmarkInfo.Value().positionTag.SetNull(); - } - else - { - areaDesc.landmarkInfo.Value().positionTag.SetNonNull(); - areaDesc.landmarkInfo.Value().positionTag.Value() = aOther.areaDesc.landmarkInfo.Value().positionTag.Value(); - } - } + AreaStructureWrapper & SetAreaId(uint32_t aAreaID) + { + areaID = aAreaID; + return *this; + } + AreaStructureWrapper & SetMapId(const DataModel::Nullable & aMapId) + { + mapID = aMapId; + return *this; + } + + AreaStructureWrapper & SetLocationInfoNull() + { + areaDesc.locationInfo.SetNull(); return *this; } /** - * @brief Set all fields of the location object. All values are deep copied. - * @param[in] aAreaID The unique identifier of this location. - * @param[in] aMapId The identifier of the supported map associated with this location. - * @param[in] aLocationName A human readable name for this location (empty string if not used). - * @param[in] aFloorNumber The floor level of this location - use negative values for below ground. - * @param[in] aAreaTypeTag A common namespace Area tag - indicates an association of the location with an indoor or outdoor area - * of a home. - * @param[in] aLandmarkTag A common namespace Landmark tag - indicates an association of the location with a home landmark. - * @param[in] aRelativePositionTag A common namespace Relative Position tag - indicates the position of the location with - * respect to the landmark. - * - * @note Requirements regarding what combinations of fields and values are valid are not checked by this class. - * @note If aLocationName is larger than kLocationNameMaxSize, it will be truncated. - * @note If aLocationName is an empty string and aFloorNumber and aAreaTypeTag are null, locationInfo will be set to null. + * @brief Set the location information. + * @param[in] locationName The name of the location. If the name is larger than kAreaNameMaxSize, it will be truncated. + * @param[in] floorNumber The floor number of the location. + * @param[in] areaType The type of the area. */ - void Set(uint32_t aAreaID, const DataModel::Nullable & aMapId, const CharSpan & aLocationName, - const DataModel::Nullable & aFloorNumber, const DataModel::Nullable & aAreaType, - const DataModel::Nullable & aLandmarkTag, - const DataModel::Nullable & aRelativePositionTag) + AreaStructureWrapper & SetLocationInfo(const CharSpan & locationName, const DataModel::Nullable & floorNumber, + const DataModel::Nullable & areaType) { - areaID = aAreaID; - mapID = aMapId; + areaDesc.locationInfo.SetNonNull(); + // Copy the name + auto sizeToCopy = std::min(sizeof(mAreaNameBuffer), locationName.size()); + memcpy(mAreaNameBuffer, locationName.data(), sizeToCopy); + areaDesc.locationInfo.Value().locationName = CharSpan(mAreaNameBuffer, sizeToCopy); + areaDesc.locationInfo.Value().floorNumber = floorNumber; + areaDesc.locationInfo.Value().areaType = areaType; - // If there is at least one non-null value for locationInfo, add it to the location structure. - if ((!aLocationName.empty()) || (!aFloorNumber.IsNull()) || (!aAreaType.IsNull())) - { - // Create a home location desc structure and fill it in except for the location name. This is done below. - areaDesc.locationInfo.SetNonNull(Globals::Structs::LocationDescriptorStruct::Type()); + return *this; + } - areaDesc.locationInfo.Value().floorNumber = aFloorNumber; - areaDesc.locationInfo.Value().areaType = aAreaType; - } - else + /** + * @brief Set the location information form a LocationDescriptorStruct object. + * + * @note If the locationName is larger than kAreaNameMaxSize, it will be truncated. + */ + AreaStructureWrapper & SetLocationInfo(DataModel::Nullable locationInfo) + { + if (locationInfo.IsNull()) { - areaDesc.locationInfo.SetNull(); + return SetLocationInfoNull(); } - // todo improve this when addressing issue https://github.com/project-chip/connectedhomeip/issues/34519 - if (aLandmarkTag.IsNull()) - { - areaDesc.landmarkInfo.SetNull(); - } - else - { - areaDesc.landmarkInfo.SetNonNull(); - areaDesc.landmarkInfo.Value().landmarkTag = aLandmarkTag.Value(); - if (aRelativePositionTag.IsNull()) - { - areaDesc.landmarkInfo.Value().positionTag.SetNull(); - } - else - { - areaDesc.landmarkInfo.Value().positionTag.SetNonNull(); - areaDesc.landmarkInfo.Value().positionTag.Value() = aRelativePositionTag.Value(); - } - } + return SetLocationInfo(locationInfo.Value().locationName, locationInfo.Value().floorNumber, locationInfo.Value().areaType); + } - // this assumes areaDesc structure was created above, if appropriate - if (!areaDesc.locationInfo.IsNull()) + AreaStructureWrapper & SetLandmarkInfoNull() + { + areaDesc.landmarkInfo.SetNull(); + return *this; + } + + /** + * @brief Set the landmark information. + * @param[in] landmarkTag The landmark tag. + * @param[in] relativePositionTag The relative position tag. + */ + AreaStructureWrapper & SetLandmarkInfo(const Globals::LandmarkTag & landmarkTag, + const DataModel::Nullable & relativePositionTag) + { + areaDesc.landmarkInfo.SetNonNull(); + areaDesc.landmarkInfo.Value().landmarkTag = landmarkTag; + areaDesc.landmarkInfo.Value().positionTag = relativePositionTag; + + return *this; + } + + /** + * @brief Set the landmark information from a LandmarkInfoStruct object. + */ + AreaStructureWrapper & SetLandmarkInfo(DataModel::Nullable landmarkInfo) + { + if (landmarkInfo.IsNull()) { - auto sizeToCopy = std::min(sizeof(mLocationNameBuffer), aLocationName.size()); - memcpy(mLocationNameBuffer, aLocationName.data(), sizeToCopy); - areaDesc.locationInfo.Value().locationName = CharSpan(mLocationNameBuffer, sizeToCopy); + return SetLandmarkInfoNull(); } + + return SetLandmarkInfo(landmarkInfo.Value().landmarkTag, landmarkInfo.Value().positionTag); } /** - * @brief Compare the location's name with the given text. - * @param[in] aLocationName The name to compare. - * @return true if the location structure's name field matches aLocationName. - * False otherwise, including if the location structure's HomeLocation structure is null. + * @brief Compare the area's name with the given text. + * @param[in] aAreaName The name to compare. + * @return true if the area structure's name field matches aAreaName. + * False otherwise, including if the location structure's LocationInfo structure is null. */ - bool IsNameEqual(const CharSpan & aLocationName) const + bool IsNameEqual(const CharSpan & aAreaName) const { if (!areaDesc.locationInfo.IsNull()) { - return areaDesc.locationInfo.Value().locationName.data_equal(aLocationName); + return areaDesc.locationInfo.Value().locationName.data_equal(aAreaName); } return false; @@ -291,14 +265,14 @@ struct AreaStructureWrapper : public chip::app::Clusters::ServiceArea::Structs:: { if (areaDesc.locationInfo.IsNull()) { - return { mLocationNameBuffer, 0 }; + return { mAreaNameBuffer, 0 }; } return areaDesc.locationInfo.Value().locationName; } private: - char mLocationNameBuffer[kLocationNameMaxSize] = { 0 }; + char mAreaNameBuffer[kAreaNameMaxSize] = { 0 }; }; /** diff --git a/src/app/clusters/service-area-server/service-area-delegate.cpp b/src/app/clusters/service-area-server/service-area-delegate.cpp index 262fe047d22a1b..9b63eb5b9f2496 100644 --- a/src/app/clusters/service-area-server/service-area-delegate.cpp +++ b/src/app/clusters/service-area-server/service-area-delegate.cpp @@ -3,14 +3,14 @@ using namespace chip::app::Clusters::ServiceArea; -bool Delegate::GetSupportedLocationById(uint32_t aAreaId, uint32_t & listIndex, AreaStructureWrapper & aSupportedLocation) +bool Delegate::GetSupportedAreaById(uint32_t aAreaId, uint32_t & listIndex, AreaStructureWrapper & aSupportedArea) { listIndex = 0; - // simple linear iteration to find the location with the desired areaId. - while (GetSupportedLocationByIndex(listIndex, aSupportedLocation)) + // simple linear iteration to find the area with the desired areaId. + while (GetSupportedAreaByIndex(listIndex, aSupportedArea)) { - if (aSupportedLocation.areaID == aAreaId) + if (aSupportedArea.areaID == aAreaId) { return true; } @@ -45,14 +45,14 @@ bool Delegate::GetSupportedMapById(uint32_t aMapId, uint32_t & listIndex, MapStr return false; } -bool Delegate::IsSelectedLocation(uint32_t aAreaId) +bool Delegate::IsSelectedArea(uint32_t aAreaId) { uint32_t listIndex = 0; - uint32_t selectedLocation; + uint32_t selectedArea; - while (GetSelectedLocationByIndex(listIndex, selectedLocation)) + while (GetSelectedAreaByIndex(listIndex, selectedArea)) { - if (selectedLocation == aAreaId) + if (selectedArea == aAreaId) { return true; } diff --git a/src/app/clusters/service-area-server/service-area-delegate.h b/src/app/clusters/service-area-server/service-area-delegate.h index 823eaf6b537f19..e31abf98f9e745 100644 --- a/src/app/clusters/service-area-server/service-area-delegate.h +++ b/src/app/clusters/service-area-server/service-area-delegate.h @@ -115,8 +115,8 @@ class Delegate * been completed, using a vendor defined order. If the server has completed operating at all locations on the SelectedAreas * attribute list, the server SHALL stop operating. * - * @note If the Status field is set to InvalidLocationList, the StatusText field SHALL be an empty string. - * If the Status field is not set to Success, or InvalidLocationList, the StatusText field SHALL include a vendor defined + * @note If the Status field is set to InvalidAreaList, the StatusText field SHALL be an empty string. + * If the Status field is not set to Success, or InvalidAreaList, the StatusText field SHALL include a vendor defined * error description which can be used to explain the error to the user. For example, if the Status field is set to * InvalidInMode, the StatusText field SHOULD indicate why the request is not allowed, given the current mode of the device, * which may involve other clusters. @@ -124,7 +124,7 @@ class Delegate virtual bool HandleSkipCurrentArea(uint32_t skippedArea, MutableCharSpan skipStatusText) { // device support of this command is optional - CopyCharSpanToMutableCharSpan("Skip Current Location command not supported by device"_span, skipStatusText); + CopyCharSpanToMutableCharSpan("Skip Current Area command not supported by device"_span, skipStatusText); return false; } @@ -148,45 +148,45 @@ class Delegate virtual uint32_t GetNumberOfSupportedAreas() = 0; /** - * @brief Get a supported location using the position in the list. + * @brief Get a supported area using the position in the list. * @param[in] listIndex the position in the list. - * @param[out] aSupportedLocation copy of the location contents, if found. - * @return true if location found, false otherwise. + * @param[out] aSupportedArea a copy of the area contents, if found. + * @return true if an area is found, false otherwise. */ - virtual bool GetSupportedLocationByIndex(uint32_t listIndex, AreaStructureWrapper & aSupportedLocation) = 0; + virtual bool GetSupportedAreaByIndex(uint32_t listIndex, AreaStructureWrapper & aSupportedArea) = 0; /** - * @brief Get a supported location that matches a areaID. + * @brief Get a supported area that matches a areaID. * @param[in] aAreaId the areaID to search for. - * @param[out] listIndex the location's index in the list, if found. - * @param[out] aSupportedLocation copy of the location contents, if found. - * @return true if location found, false otherwise. + * @param[out] listIndex the area's index in the list, if found. + * @param[out] aSupportedArea a copy of the area contents, if found. + * @return true if an area is found, false otherwise. * * @note may be overloaded in device implementation for optimization, if desired. */ - virtual bool GetSupportedLocationById(uint32_t aAreaId, uint32_t & listIndex, AreaStructureWrapper & aSupportedLocation); + virtual bool GetSupportedAreaById(uint32_t aAreaId, uint32_t & listIndex, AreaStructureWrapper & aSupportedArea); /** - * This method is called by the server instance to add a new location to the list. - * The server instance will ensure that the newArea is a valid, unique location. - * @param [in] newArea new location to add. - * @param [out] listIndex filled with the list index for the new location, if successful. + * This method is called by the server instance to add a new area to the list. + * The server instance will ensure that the newArea is a valid, unique area. + * @param [in] newArea new area to add. + * @param [out] listIndex filled with the list index for the new area, if successful. * @return true if successful, false otherwise. - * @note this function SHOULD double check that the added location won't exceed the maximum list size. + * @note this method SHOULD double check that the added area won't exceed the maximum list size. */ - virtual bool AddSupportedLocation(const AreaStructureWrapper & newArea, uint32_t & listIndex) = 0; + virtual bool AddSupportedArea(const AreaStructureWrapper & newArea, uint32_t & listIndex) = 0; /** - * This method is called by the server instance to modify an existing location in the list. - * The server instance will ensure that the modifiedLocation is a valid, unique location. - * @param[in] listIndex The index of the location being modified. - * @param[in] modifiedLocation A location with the modified contents. + * This method is called by the server instance to modify an existing area in the list. + * The server instance will ensure that the modifiedArea is a valid, unique area. + * @param[in] listIndex The index of the area being modified. + * @param[in] modifiedArea An area with the modified contents. * @return true if successful, false otherwise. * * @note this function SHOULD double check that newArea's areaID matches the object at listIndex. */ - virtual bool ModifySupportedLocation(uint32_t listIndex, const AreaStructureWrapper & modifiedLocation) = 0; + virtual bool ModifySupportedArea(uint32_t listIndex, const AreaStructureWrapper & modifiedArea) = 0; /** * @return true if supported locations was not already null, false otherwise. @@ -276,36 +276,36 @@ class Delegate virtual bool ClearSupportedMaps() = 0; //************************************************************************* - // Selected Locations accessors + // Selected Areas accessors virtual uint32_t GetNumberOfSelectedAreas() = 0; /** - * @brief Get a selected location using the position in the list. + * @brief Get a selected area using the position in the list. * @param[in] listIndex the position in the list. - * @param[out] selectedLocation the selected location value, if found. - * @return true if a selected location is found, false otherwise. + * @param[out] selectedArea the selected area value, if found. + * @return true if a selected area is found, false otherwise. */ - virtual bool GetSelectedLocationByIndex(uint32_t listIndex, uint32_t & selectedLocation) = 0; + virtual bool GetSelectedAreaByIndex(uint32_t listIndex, uint32_t & selectedArea) = 0; /** * @return true if the aAreaId areaID is found in the SelectedAreas list, false otherwise. * * @note may be overloaded in device implementation for optimization, if desired. */ - virtual bool IsSelectedLocation(uint32_t aAreaId); + virtual bool IsSelectedArea(uint32_t aAreaId); /** - * This method is called by the server instance to add a new selected location to the list. - * The server instance will ensure that the aAreaId references a SUPPORTED location, and is unique within selected - * locations. + * This method is called by the server instance to add a new selected area to the list. + * The server instance will ensure that the aAreaId references a SUPPORTED area, and is unique within selected + * areas. * @param[in] aAreaId The new areaID to add. - * @param[out] listIndex filled with the list index of the new location, if successful. + * @param[out] listIndex filled with the list index of the new area, if successful. * @return true if successful, false otherwise. * - * @note this function SHOULD double check that the added location won't exceed the maximum list size. + * @note this function SHOULD double check that the added area won't exceed the maximum list size. */ - virtual bool AddSelectedLocation(uint32_t aAreaId, uint32_t & listIndex) = 0; + virtual bool AddSelectedArea(uint32_t aAreaId, uint32_t & listIndex) = 0; /** * @return true if selected locations was not already null, false otherwise. diff --git a/src/app/clusters/service-area-server/service-area-server.cpp b/src/app/clusters/service-area-server/service-area-server.cpp index cb5c3b144ba640..d745c04b5d468e 100644 --- a/src/app/clusters/service-area-server/service-area-server.cpp +++ b/src/app/clusters/service-area-server/service-area-server.cpp @@ -57,7 +57,7 @@ Instance::Instance(Delegate * aDelegate, EndpointId aEndpointId, BitMaskInit(); } @@ -139,11 +139,11 @@ CHIP_ERROR Instance::ReadSupportedAreas(AttributeValueEncoder & aEncoder) return aEncoder.EncodeList([this](const auto & encoder) -> CHIP_ERROR { uint8_t locationIndex = 0; - AreaStructureWrapper supportedLocation; + AreaStructureWrapper supportedArea; - while (mDelegate->GetSupportedLocationByIndex(locationIndex++, supportedLocation)) + while (mDelegate->GetSupportedAreaByIndex(locationIndex++, supportedArea)) { - ReturnErrorOnFailure(encoder.Encode(supportedLocation)); + ReturnErrorOnFailure(encoder.Encode(supportedArea)); } return CHIP_NO_ERROR; }); @@ -177,11 +177,11 @@ CHIP_ERROR Instance::ReadSelectedAreas(AttributeValueEncoder & aEncoder) return aEncoder.EncodeList([this](const auto & encoder) -> CHIP_ERROR { uint32_t locationIndex = 0; - uint32_t selectedLocation; + uint32_t selectedArea; - while (mDelegate->GetSelectedLocationByIndex(locationIndex++, selectedLocation)) + while (mDelegate->GetSelectedAreaByIndex(locationIndex++, selectedArea)) { - ReturnErrorOnFailure(encoder.Encode(selectedLocation)); + ReturnErrorOnFailure(encoder.Encode(selectedArea)); } return CHIP_NO_ERROR; }); @@ -222,10 +222,10 @@ void Instance::HandleSelectAreasCmd(HandlerContext & ctx, const Commands::Select ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response); }; - size_t numberOfLocations = 0; - // Get the number of Selected Locations in the command parameter and check that it is valid. + size_t numberOfAreas = 0; + // Get the number of Selected Areas in the command parameter and check that it is valid. { - if (CHIP_NO_ERROR != req.newAreas.ComputeSize(&numberOfLocations)) + if (CHIP_NO_ERROR != req.newAreas.ComputeSize(&numberOfAreas)) { ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::InvalidCommand); return; @@ -233,7 +233,7 @@ void Instance::HandleSelectAreasCmd(HandlerContext & ctx, const Commands::Select // If the device determines that it can't operate at all locations from the list, // the SelectAreasResponse command's Status field SHALL indicate InvalidSet. - if (numberOfLocations > kMaxNumSelectedAreas) + if (numberOfAreas > kMaxNumSelectedAreas) { exitResponse(SelectAreasStatus::kInvalidSet, "invalid number of locations"_span); return; @@ -241,36 +241,35 @@ void Instance::HandleSelectAreasCmd(HandlerContext & ctx, const Commands::Select } // if number of selected locations in parameter matches number in attribute - the locations *might* be the same - bool matchesCurrentSelectedAreas = (numberOfLocations == mDelegate->GetNumberOfSelectedAreas()); + bool matchesCurrentSelectedAreas = (numberOfAreas == mDelegate->GetNumberOfSelectedAreas()); - if (numberOfLocations != 0) + if (numberOfAreas != 0) { // do as much parameter validation as we can { uint32_t ignoredIndex = 0; - uint32_t oldSelectedLocation; - uint32_t i = 0; - auto iLocationIter = req.newAreas.begin(); - while (iLocationIter.Next()) + uint32_t oldSelectedArea; + uint32_t i = 0; + auto iAreaIter = req.newAreas.begin(); + while (iAreaIter.Next()) { - uint32_t aSelectedLocation = iLocationIter.GetValue(); + uint32_t aSelectedArea = iAreaIter.GetValue(); // each item in this list SHALL match the AreaID field of an entry on the SupportedAreas attribute's list - // If the Status field is set to UnsupportedLocation, the StatusText field SHALL be an empty string. - if (!IsSupportedLocation(aSelectedLocation)) + // If the Status field is set to UnsupportedArea, the StatusText field SHALL be an empty string. + if (!IsSupportedArea(aSelectedArea)) { exitResponse(SelectAreasStatus::kUnsupportedArea, ""_span); return; } // Checking for duplicate locations. - uint32_t j = 0; - auto jLocationIter = req.newAreas.begin(); + uint32_t j = 0; + auto jAreaIter = req.newAreas.begin(); while (j < i) { - jLocationIter - .Next(); // Since j < i and i is valid, we can safely call Next() without checking the return value. - if (jLocationIter.GetValue() == aSelectedLocation) + jAreaIter.Next(); // Since j < i and i is valid, we can safely call Next() without checking the return value. + if (jAreaIter.GetValue() == aSelectedArea) { exitResponse(SelectAreasStatus::kDuplicatedAreas, ""_span); return; @@ -281,8 +280,7 @@ void Instance::HandleSelectAreasCmd(HandlerContext & ctx, const Commands::Select // check to see if parameter list and attribute still match if (matchesCurrentSelectedAreas) { - if (!mDelegate->GetSelectedLocationByIndex(ignoredIndex, oldSelectedLocation) || - (aSelectedLocation != oldSelectedLocation)) + if (!mDelegate->GetSelectedAreaByIndex(ignoredIndex, oldSelectedArea) || (aSelectedArea != oldSelectedArea)) { matchesCurrentSelectedAreas = false; } @@ -292,7 +290,7 @@ void Instance::HandleSelectAreasCmd(HandlerContext & ctx, const Commands::Select } // after iterating with Next through DecodableType - check for failure - if (CHIP_NO_ERROR != iLocationIter.GetStatus()) + if (CHIP_NO_ERROR != iAreaIter.GetStatus()) { ctx.mCommandHandler.AddStatus(ctx.mRequestPath, Status::InvalidCommand); return; @@ -342,13 +340,13 @@ void Instance::HandleSelectAreasCmd(HandlerContext & ctx, const Commands::Select // and the SelectedAreas attribute SHALL be set to the value of the newAreas field. mDelegate->ClearSelectedAreas(); - if (numberOfLocations != 0) + if (numberOfAreas != 0) { auto locationIter = req.newAreas.begin(); uint32_t ignored; while (locationIter.Next()) { - mDelegate->AddSelectedLocation(locationIter.GetValue(), ignored); + mDelegate->AddSelectedArea(locationIter.GetValue(), ignored); } } @@ -371,26 +369,26 @@ void Instance::HandleSkipCurrentAreaCmd(HandlerContext & ctx, const Commands::Sk ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response); }; - // If the SelectedAreas attribute is null, the response status should be set to InvalidLocationList. - // If the Status field is set to InvalidLocationList, the StatusText field SHALL be an empty string. + // If the SelectedAreas attribute is null, the response status should be set to InvalidAreaList. + // If the Status field is set to InvalidAreaList, the StatusText field SHALL be an empty string. if (mDelegate->GetNumberOfSelectedAreas() == 0) { - ChipLogError(Zcl, "Selected Locations attribute is null"); + ChipLogError(Zcl, "Selected Areas attribute is null"); exitResponse(SkipAreaStatus::kInvalidAreaList, ""_span); return; } // If the CurrentArea attribute is null, the status should be set to InvalidInMode. - // If the Status field is not set to Success, or InvalidLocationList, the StatusText field SHALL include a vendor defined error + // If the Status field is not set to Success, or InvalidAreaList, the StatusText field SHALL include a vendor defined error // description. if (mCurrentArea.IsNull()) { - exitResponse(SkipAreaStatus::kInvalidInMode, "Current Location attribute is null"_span); + exitResponse(SkipAreaStatus::kInvalidInMode, "Current Area attribute is null"_span); return; } // have the device attempt to skip - // If the Status field is not set to Success, or InvalidLocationList, the StatusText field SHALL include a vendor defined error + // If the Status field is not set to Success, or InvalidAreaList, the StatusText field SHALL include a vendor defined error // description. InvalidInMode | The received request cannot be handled due to the current mode of the device. (skipStatusText to // be filled out by delegated function on failure.) char skipStatusBuffer[kMaxSizeStatusText]; @@ -437,37 +435,35 @@ void Instance::NotifyProgressChanged() } // **************************************************************************** -// Supported Locations manipulators +// Supported Areas manipulators -bool Instance::IsSupportedLocation(uint32_t aAreaId) +bool Instance::IsSupportedArea(uint32_t aAreaId) { uint32_t ignoredIndex; - AreaStructureWrapper ignoredLocation; + AreaStructureWrapper ignoredArea; - return mDelegate->GetSupportedLocationById(aAreaId, ignoredIndex, ignoredLocation); + return mDelegate->GetSupportedAreaById(aAreaId, ignoredIndex, ignoredArea); } -bool Instance::IsValidSupportedLocation(const AreaStructureWrapper & aLocation) +bool Instance::IsValidSupportedArea(const AreaStructureWrapper & aArea) { // If the LocationInfo field is null, the LandmarkInfo field SHALL NOT be null. // If the LandmarkInfo field is null, the LocationInfo field SHALL NOT be null. - if (aLocation.areaDesc.locationInfo.IsNull() && aLocation.areaDesc.landmarkInfo.IsNull()) + if (aArea.areaDesc.locationInfo.IsNull() && aArea.areaDesc.landmarkInfo.IsNull()) { - ChipLogDetail(Zcl, "IsValidAsSupportedLocation %u - must have locationInfo and/or LandmarkInfo", aLocation.areaID); + ChipLogDetail(Zcl, "IsValidAsSupportedArea %u - must have locationInfo and/or LandmarkInfo", aArea.areaID); return false; } // If LocationInfo is not null, and its LocationName field is an empty string, at least one of the following SHALL NOT // be null: LocationInfo's FloorNumber field, LocationInfo's AreaType field, the LandmarkInfo - if (!aLocation.areaDesc.locationInfo.IsNull()) + if (!aArea.areaDesc.locationInfo.IsNull()) { - if (aLocation.areaDesc.locationInfo.Value().locationName.empty() && - aLocation.areaDesc.locationInfo.Value().floorNumber.IsNull() && - aLocation.areaDesc.locationInfo.Value().areaType.IsNull() && aLocation.areaDesc.landmarkInfo.IsNull()) + if (aArea.areaDesc.locationInfo.Value().locationName.empty() && aArea.areaDesc.locationInfo.Value().floorNumber.IsNull() && + aArea.areaDesc.locationInfo.Value().areaType.IsNull() && aArea.areaDesc.landmarkInfo.IsNull()) { - ChipLogDetail( - Zcl, "IsValidAsSupportedLocation %u - LocationName is empty string, FloorNumber, AreaType, LandmarkInfo are null", - aLocation.areaID); + ChipLogDetail(Zcl, "IsValidAsSupportedArea %u - AreaName is empty string, FloorNumber, AreaType, LandmarkInfo are null", + aArea.areaID); return false; } } @@ -488,20 +484,20 @@ bool Instance::IsValidSupportedLocation(const AreaStructureWrapper & aLocation) if (shouldMapsBeNull) { - if (!aLocation.mapID.IsNull()) + if (!aArea.mapID.IsNull()) { - ChipLogDetail(Zcl, "IsValidSupportedLocation %u - map Id %u is not in empty supported map list", aLocation.areaID, - aLocation.mapID.Value()); + ChipLogDetail(Zcl, "IsValidSupportedArea %u - map Id %u is not in empty supported map list", aArea.areaID, + aArea.mapID.Value()); return false; } } else { // If the SupportedMaps attribute is not null, mapID SHALL be the ID of an entry from the SupportedMaps attribute. - if (!IsSupportedMap(aLocation.mapID.Value())) + if (!IsSupportedMap(aArea.mapID.Value())) { - ChipLogError(Zcl, "IsValidSupportedLocation %u - map Id %u is not in supported map list", aLocation.areaID, - aLocation.mapID.Value()); + ChipLogError(Zcl, "IsValidSupportedArea %u - map Id %u is not in supported map list", aArea.areaID, + aArea.mapID.Value()); return false; } } @@ -509,7 +505,7 @@ bool Instance::IsValidSupportedLocation(const AreaStructureWrapper & aLocation) return true; } -bool Instance::IsUniqueSupportedLocation(const AreaStructureWrapper & aLocation, bool ignoreAreaId) +bool Instance::IsUniqueSupportedArea(const AreaStructureWrapper & aArea, bool ignoreAreaId) { BitMask config; @@ -528,9 +524,9 @@ bool Instance::IsUniqueSupportedLocation(const AreaStructureWrapper & aLocation, uint8_t locationIndex = 0; AreaStructureWrapper entry; - while (mDelegate->GetSupportedLocationByIndex(locationIndex++, entry)) + while (mDelegate->GetSupportedAreaByIndex(locationIndex++, entry)) { - if (aLocation.IsEqual(entry, config)) + if (aArea.IsEqual(entry, config)) { return false; } @@ -576,15 +572,8 @@ bool Instance::ReportEstimatedEndTimeChange(const DataModel::Nullable return (aEstimatedEndTime.Value() < mEstimatedEndTime.Value()); } -bool Instance::AddSupportedLocation(uint32_t aAreaId, const DataModel::Nullable & aMapId, const CharSpan & aLocationName, - const DataModel::Nullable & aFloorNumber, - const DataModel::Nullable & aAreaType, - const DataModel::Nullable & aLandmarkTag, - const DataModel::Nullable & aRelativePositionTag) +bool Instance::AddSupportedArea(AreaStructureWrapper & aNewArea) { - // Create location object for validation. - AreaStructureWrapper aNewArea(aAreaId, aMapId, aLocationName, aFloorNumber, aAreaType, aLandmarkTag, aRelativePositionTag); - // Does device mode allow this attribute to be updated? if (!mDelegate->IsSupportedAreasChangeAllowed()) { @@ -594,30 +583,30 @@ bool Instance::AddSupportedLocation(uint32_t aAreaId, const DataModel::Nullable< // Check there is space for the entry. if (mDelegate->GetNumberOfSupportedAreas() >= kMaxNumSupportedAreas) { - ChipLogError(Zcl, "AddSupportedLocation %u - too many entries", aAreaId); + ChipLogError(Zcl, "AddSupportedArea %u - too many entries", aNewArea.areaID); return false; } // Verify cluster requirements concerning valid fields and field relationships. - if (!IsValidSupportedLocation(aNewArea)) + if (!IsValidSupportedArea(aNewArea)) { - ChipLogError(Zcl, "AddSupportedLocation %u - not a valid location object", aNewArea.areaID); + ChipLogError(Zcl, "AddSupportedArea %u - not a valid location object", aNewArea.areaID); return false; } - // Each entry in Supported Locations SHALL have a unique value for the ID field. + // Each entry in Supported Areas SHALL have a unique value for the ID field. // If the SupportedMaps attribute is not null, each entry in this list SHALL have a unique value for the combination of the - // MapID and LocationInfo fields. If the SupportedMaps attribute is null, each entry in this list SHALL have a unique value for - // the LocationInfo field. - if (!IsUniqueSupportedLocation(aNewArea, false)) + // MapID and AreaInfo fields. If the SupportedMaps attribute is null, each entry in this list SHALL have a unique value for + // the AreaInfo field. + if (!IsUniqueSupportedArea(aNewArea, false)) { - ChipLogError(Zcl, "AddSupportedLocation %u - not a unique location object", aNewArea.areaID); + ChipLogError(Zcl, "AddSupportedArea %u - not a unique location object", aNewArea.areaID); return false; } - // Add the SupportedLocation to the SupportedAreas attribute. + // Add the SupportedArea to the SupportedAreas attribute. uint32_t ignoredIndex; - if (!mDelegate->AddSupportedLocation(aNewArea, ignoredIndex)) + if (!mDelegate->AddSupportedArea(aNewArea, ignoredIndex)) { return false; } @@ -626,27 +615,23 @@ bool Instance::AddSupportedLocation(uint32_t aAreaId, const DataModel::Nullable< return true; } -bool Instance::ModifySupportedLocation(uint32_t aAreaId, const DataModel::Nullable & aMapId, - const CharSpan & aLocationName, const DataModel::Nullable & aFloorNumber, - const DataModel::Nullable & aAreaType, - const DataModel::Nullable & aLandmarkTag, - const DataModel::Nullable & aRelativePositionTag) +bool Instance::ModifySupportedArea(AreaStructureWrapper & aNewArea) { bool mapIDChanged = false; uint32_t listIndex; // get existing supported location to modify - AreaStructureWrapper supportedLocation; - if (!mDelegate->GetSupportedLocationById(aAreaId, listIndex, supportedLocation)) + AreaStructureWrapper supportedArea; + if (!mDelegate->GetSupportedAreaById(aNewArea.areaID, listIndex, supportedArea)) { - ChipLogError(Zcl, "ModifySupportedLocation %u - not a supported areaID", aAreaId); + ChipLogError(Zcl, "ModifySupportedArea %u - not a supported areaID", aNewArea.areaID); return false; } { // check for mapID change - if ((aMapId.IsNull() != supportedLocation.mapID.IsNull()) || - (!aMapId.IsNull() && !supportedLocation.mapID.IsNull() && (aMapId.Value() != supportedLocation.mapID.Value()))) + if ((aNewArea.mapID.IsNull() != supportedArea.mapID.IsNull()) || + (!aNewArea.mapID.IsNull() && !supportedArea.mapID.IsNull() && (aNewArea.mapID.Value() != supportedArea.mapID.Value()))) { // does device mode allow this attribute to be updated? if (!mDelegate->IsSupportedAreasChangeAllowed()) @@ -656,26 +641,23 @@ bool Instance::ModifySupportedLocation(uint32_t aAreaId, const DataModel::Nullab mapIDChanged = true; } - // create new location object for validation - AreaStructureWrapper aNewArea(aAreaId, aMapId, aLocationName, aFloorNumber, aAreaType, aLandmarkTag, aRelativePositionTag); - // verify cluster requirements concerning valid fields and field relationships - if (!IsValidSupportedLocation(aNewArea)) + if (!IsValidSupportedArea(aNewArea)) { - ChipLogError(Zcl, "ModifySupportedLocation %u - not a valid location object", aNewArea.areaID); + ChipLogError(Zcl, "ModifySupportedArea %u - not a valid location object", aNewArea.areaID); return false; } // Updated location description must not match another existing location description. // We ignore comparing the area ID as one of the locations will match this one. - if (!IsUniqueSupportedLocation(aNewArea, true)) + if (!IsUniqueSupportedArea(aNewArea, true)) { - ChipLogError(Zcl, "ModifySupportedLocation %u - not a unique location object", aNewArea.areaID); + ChipLogError(Zcl, "ModifySupportedArea %u - not a unique location object", aNewArea.areaID); return false; } // Replace the supported location with the modified location. - if (!mDelegate->ModifySupportedLocation(listIndex, aNewArea)) + if (!mDelegate->ModifySupportedArea(listIndex, aNewArea)) { return false; } @@ -844,28 +826,28 @@ bool Instance::ClearSupportedMaps() } //************************************************************************* -// Selected Locations manipulators +// Selected Areas manipulators -bool Instance::AddSelectedLocation(uint32_t & aSelectedLocation) +bool Instance::AddSelectedArea(uint32_t & aSelectedArea) { // check max# of list entries if (mDelegate->GetNumberOfSelectedAreas() >= kMaxNumSelectedAreas) { - ChipLogError(Zcl, "AddSelectedLocation %u - maximum number of entries", aSelectedLocation); + ChipLogError(Zcl, "AddSelectedArea %u - maximum number of entries", aSelectedArea); return false; } // each item in this list SHALL match the AreaID field of an entry on the SupportedAreas attribute's list - if (!IsSupportedLocation(aSelectedLocation)) + if (!IsSupportedArea(aSelectedArea)) { - ChipLogError(Zcl, "AddSelectedLocation %u - not a supported location", aSelectedLocation); + ChipLogError(Zcl, "AddSelectedArea %u - not a supported location", aSelectedArea); return false; } // each entry in this list SHALL have a unique value - if (mDelegate->IsSelectedLocation(aSelectedLocation)) + if (mDelegate->IsSelectedArea(aSelectedArea)) { - ChipLogError(Zcl, "AddSelectedLocation %u - duplicated location", aSelectedLocation); + ChipLogError(Zcl, "AddSelectedArea %u - duplicated location", aSelectedArea); return false; } @@ -875,13 +857,13 @@ bool Instance::AddSelectedLocation(uint32_t & aSelectedLocation) if (!mDelegate->IsSetSelectedAreasAllowed(locationStatusText)) { - ChipLogError(Zcl, "AddSelectedLocation %u - %.*s", aSelectedLocation, static_cast(locationStatusText.size()), + ChipLogError(Zcl, "AddSelectedArea %u - %.*s", aSelectedArea, static_cast(locationStatusText.size()), locationStatusText.data()); return false; } uint32_t ignoredIndex; - return mDelegate->AddSelectedLocation(aSelectedLocation, ignoredIndex); + return mDelegate->AddSelectedArea(aSelectedArea, ignoredIndex); } bool Instance::ClearSelectedAreas() @@ -896,7 +878,7 @@ bool Instance::ClearSelectedAreas() } //************************************************************************* -// Current Location manipulators +// Current Area manipulators DataModel::Nullable Instance::GetCurrentArea() { @@ -907,7 +889,7 @@ bool Instance::SetCurrentArea(const DataModel::Nullable & aCurrentArea { // If not null, the value of this attribute SHALL match the AreaID field of an entry on the SupportedAreas attribute's // list. - if ((!aCurrentArea.IsNull()) && (!IsSupportedLocation(aCurrentArea.Value()))) + if ((!aCurrentArea.IsNull()) && (!IsSupportedArea(aCurrentArea.Value()))) { ChipLogError(Zcl, "SetCurrentArea %u - location is not supported", aCurrentArea.Value()); return false; @@ -943,7 +925,7 @@ bool Instance::SetEstimatedEndTime(const DataModel::Nullable & aEstima // EstimatedEndTime SHALL be null if the CurrentArea attribute is null. if (mCurrentArea.IsNull() && !aEstimatedEndTime.IsNull()) { - ChipLogError(Zcl, "SetEstimatedEndTime - must be null if Current Location is null"); + ChipLogError(Zcl, "SetEstimatedEndTime - must be null if Current Area is null"); return false; } @@ -976,7 +958,7 @@ bool Instance::AddPendingProgressElement(uint32_t aAreaId) } // For each entry in this list, the AreaID field SHALL match an entry on the SupportedAreas attribute's list. - if (!IsSupportedLocation(aAreaId)) + if (!IsSupportedArea(aAreaId)) { ChipLogError(Zcl, "AddPendingProgressElement - not a supported location %u", aAreaId); return false; diff --git a/src/app/clusters/service-area-server/service-area-server.h b/src/app/clusters/service-area-server/service-area-server.h index 815ff2ed0eac72..811499f3ff7fb2 100644 --- a/src/app/clusters/service-area-server/service-area-server.h +++ b/src/app/clusters/service-area-server/service-area-server.h @@ -137,28 +137,28 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface void NotifyProgressChanged(); //************************************************************************* - // Supported Locations manipulators + // Supported Areas manipulators /** - * @return true if a location with the aAreaId ID exists in the supported locations attribute. False otherwise. + * @return true if an area with the aAreaId ID exists in the supported areas attribute. False otherwise. */ - bool IsSupportedLocation(uint32_t aAreaId); + bool IsSupportedArea(uint32_t aAreaId); /** - * @brief Check if the given location adheres to the restrictions required by the supported locations attribute. - * @return true if the aLocation meets all checks. + * @brief Check if the given area adheres to the restrictions required by the supported areas attribute. + * @return true if the aArea meets all checks. */ - bool IsValidSupportedLocation(const AreaStructureWrapper & aLocation); + bool IsValidSupportedArea(const AreaStructureWrapper & aArea); /** - * @brief check if aLocation is unique with regard to supported locations. - * @param[in] aLocation the location to check. + * @brief check if aArea is unique with regard to supported areas. + * @param[in] aArea the area to check. * @param[out] ignoreAreaId if true, we do not check if the area ID is unique. - * @return true if there isn't a location in supported locations that matches aLocation. + * @return true if there isn't an area in supported areas that matches aArea. * * @note This method may ignore checking the MapId uniqueness. This depends on whether the SupportedMaps attribute is null. */ - bool IsUniqueSupportedLocation(const AreaStructureWrapper & aLocation, bool ignoreAreaId); + bool IsUniqueSupportedArea(const AreaStructureWrapper & aArea, bool ignoreAreaId); /** * @brief Check if changing the estimated end time attribute to aEstimatedEndTime requires the change to be reported. @@ -170,47 +170,23 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface public: /** * @brief Add new location to the supported locations list. - * @param[in] aAreaId unique identifier of this location. - * @param[in] aMapId identifier of supported map. - * @param[in] aLocationName human readable name for this location (empty string if not used). - * @param[in] aFloorNumber represents floor level - negative values for below ground. - * @param[in] aAreaType common namespace Area tag - indicates an association of the location with an indoor or outdoor area of a - * home. - * @param[in] aLandmarkTag common namespace Landmark tag - indicates an association of the location with a home landmark. - * @param[in] aRelativePositionTag common namespace Relative Position tag - indicates the position of the location with respect - * to the landmark. + * @param[in] aNewArea The area to add. * @return true if the new location passed validation checks and was successfully added to the list. * - * @note if aLocationName is larger than kLocationNameMaxSize, it will be truncated. + * @note if aNewArea is larger than kAreaNameMaxSize, it will be truncated. */ - bool AddSupportedLocation(uint32_t aAreaId, const DataModel::Nullable & aMapId, const CharSpan & aLocationName, - const DataModel::Nullable & aFloorNumber, - const DataModel::Nullable & aAreaType, - const DataModel::Nullable & aLandmarkTag, - const DataModel::Nullable & aRelativePositionTag); + bool AddSupportedArea(AreaStructureWrapper & aNewArea); /** * @brief Modify/replace an existing location in the supported locations list. - * @param[in] aAreaId unique identifier of this location. - * @param[in] aMapId identifier of supported map (will not be modified). - * @param[in] aLocationName human readable name for this location (empty string if not used). - * @param[in] aFloorNumber represents floor level - negative values for below ground. - * @param[in] aAreaType common namespace Area tag - indicates an association of the location with an indoor or outdoor area of a - * home. - * @param[in] aLandmarkTag common namespace Landmark tag - indicates an association of the location with a home landmark. - * @param[in] aRelativePositionTag common namespace Relative Position tag - indicates the position of the location with respect - * to the landmark. + * @param[in] aNewArea The area to add. * @return true if the location is a member of supported locations, the modifications pass all validation checks and the * location was modified. * - * @note if aLocationName is larger than kLocationNameMaxSize, it will be truncated. + * @note if aNewArea is larger than kAreaNameMaxSize, it will be truncated. * @note if mapID is changed, the delegate's HandleSupportedAreasUpdated method is called. */ - bool ModifySupportedLocation(uint32_t aAreaId, const DataModel::Nullable & aMapId, const CharSpan & aLocationName, - const DataModel::Nullable & aFloorNumber, - const DataModel::Nullable & aAreaType, - const DataModel::Nullable & aLandmarkTag, - const DataModel::Nullable & aRelativePositionTag); + bool ModifySupportedArea(AreaStructureWrapper & aNewArea); /** * @return true if the SupportedAreas attribute was not already null. @@ -253,14 +229,14 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface bool ClearSupportedMaps(); //************************************************************************* - // Selected Locations manipulators + // Selected Areas manipulators /** - * @brief Add a selected location. - * @param[in] aSelectedLocation The areaID to add. + * @brief Add a selected area. + * @param[in] aSelectedArea The areaID to add. * @bool true if successfully added. */ - bool AddSelectedLocation(uint32_t & aSelectedLocation); + bool AddSelectedArea(uint32_t & aSelectedArea); /** * @return true if the SelectedAreas attribute was not already null. @@ -268,7 +244,7 @@ class Instance : public AttributeAccessInterface, public CommandHandlerInterface bool ClearSelectedAreas(); //************************************************************************* - // Current Location manipulators + // Current Area manipulators DataModel::Nullable GetCurrentArea();