Skip to content

Commit

Permalink
Fix ecosystem information cluster when reading cluster revision (#34792)
Browse files Browse the repository at this point in the history
* Fix ecosystem information cluster when reading cluster revision

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Nov 7, 2024
1 parent 3231703 commit 1115972
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace Clusters {
namespace EcosystemInformation {
namespace {

#define ZCL_ECOSYSTEM_INFORMATION_CLUSTER_REVISION (1u)
#define ZCL_ECOSYSTEM_INFORMATION_FEATURE_MAP (0u)

constexpr size_t kDeviceNameMaxSize = 64;
constexpr size_t kUniqueLocationIdMaxSize = 64;
constexpr size_t kUniqueLocationIdsListMaxSize = 64;
Expand All @@ -46,18 +49,7 @@ class AttrAccess : public AttributeAccessInterface
CHIP_ERROR AttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
{
VerifyOrDie(aPath.mClusterId == Clusters::EcosystemInformation::Id);
switch (aPath.mAttributeId)
{
case Attributes::RemovedOn::Id:
return EcosystemInformationServer::Instance().EncodeRemovedOnAttribute(aPath.mEndpointId, aEncoder);
case Attributes::DeviceDirectory ::Id:
return EcosystemInformationServer::Instance().EncodeDeviceDirectoryAttribute(aPath.mEndpointId, aEncoder);
case Attributes::LocationDirectory ::Id:
return EcosystemInformationServer::Instance().EncodeLocationStructAttribute(aPath.mEndpointId, aEncoder);
default:
break;
}
return CHIP_NO_ERROR;
return EcosystemInformationServer::Instance().ReadAttribute(aPath, aEncoder);
}

// WARNING: caller is expected to use the returned LocationDescriptorStruct::Type immediately. Caller must
Expand Down Expand Up @@ -285,6 +277,30 @@ CHIP_ERROR EcosystemInformationServer::RemoveDevice(EndpointId aEndpoint, uint64
return CHIP_NO_ERROR;
}

CHIP_ERROR EcosystemInformationServer::ReadAttribute(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
{
switch (aPath.mAttributeId)
{
case Attributes::RemovedOn::Id:
return EcosystemInformationServer::Instance().EncodeRemovedOnAttribute(aPath.mEndpointId, aEncoder);
case Attributes::DeviceDirectory::Id:
return EcosystemInformationServer::Instance().EncodeDeviceDirectoryAttribute(aPath.mEndpointId, aEncoder);
case Attributes::LocationDirectory::Id:
return EcosystemInformationServer::Instance().EncodeLocationStructAttribute(aPath.mEndpointId, aEncoder);
case Attributes::ClusterRevision::Id: {
uint16_t rev = ZCL_ECOSYSTEM_INFORMATION_CLUSTER_REVISION;
return aEncoder.Encode(rev);
}
case Attributes::FeatureMap::Id: {
uint32_t featureMap = ZCL_ECOSYSTEM_INFORMATION_FEATURE_MAP;
return aEncoder.Encode(featureMap);
}
default:
break;
}
return CHIP_NO_ERROR;
}

CHIP_ERROR EcosystemInformationServer::EncodeRemovedOnAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder)
{
auto it = mDevicesMap.find(aEndpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ class EcosystemInformationServer
CHIP_ERROR RemoveDevice(EndpointId aEndpoint, uint64_t aEpochUs);
// TODO(#33223) Add removal and update counterparts to AddDeviceInfo and AddLocationInfo.

CHIP_ERROR EncodeRemovedOnAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);
CHIP_ERROR EncodeDeviceDirectoryAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);
CHIP_ERROR EncodeLocationStructAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);
CHIP_ERROR ReadAttribute(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder);

private:
struct DeviceInfo
Expand All @@ -194,6 +192,11 @@ class EcosystemInformationServer
// Map key is using the UniqueLocationId
std::map<std::string, std::unique_ptr<EcosystemLocationStruct>> mLocationDirectory;
};

CHIP_ERROR EncodeRemovedOnAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);
CHIP_ERROR EncodeDeviceDirectoryAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);
CHIP_ERROR EncodeLocationStructAttribute(EndpointId aEndpoint, AttributeValueEncoder & aEncoder);

std::map<EndpointId, DeviceInfo> mDevicesMap;

static EcosystemInformationServer mInstance;
Expand Down

0 comments on commit 1115972

Please sign in to comment.