Skip to content

Commit

Permalink
Use AttributePathParams Pool, EventPathParams Pool and DataVersionFil…
Browse files Browse the repository at this point in the history
…ter Pool instead. Roughly there is no logical change. (#16467)
  • Loading branch information
yunhanw-google authored Mar 24, 2022
1 parent dcb6609 commit 07fc8cd
Show file tree
Hide file tree
Showing 32 changed files with 472 additions and 450 deletions.
3 changes: 1 addition & 2 deletions examples/common/pigweed/rpc_services/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ class Device : public pw_rpc::nanopb::Device::Service<Device>
virtual pw::Status SetPairingInfo(const chip_rpc_PairingInfo & request, pw_protobuf_Empty & response)
{
if (DeviceLayer::GetCommissionableDataProvider()->SetSetupPasscode(request.code) != CHIP_NO_ERROR ||
DeviceLayer::GetCommissionableDataProvider()->SetSetupDiscriminator(request.discriminator) !=
CHIP_NO_ERROR)
DeviceLayer::GetCommissionableDataProvider()->SetSetupDiscriminator(request.discriminator) != CHIP_NO_ERROR)
{
return pw::Status::Unknown();
}
Expand Down
1 change: 0 additions & 1 deletion src/app/AttributeAccessInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#pragma once

#include <access/SubjectDescriptor.h>
#include <app/ClusterInfo.h>
#include <app/ConcreteAttributePath.h>
#include <app/MessageDef/AttributeReportIBs.h>
#include <app/data-model/DecodableList.h>
Expand Down
46 changes: 23 additions & 23 deletions src/app/AttributePathExpandIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <app/AttributePathExpandIterator.h>

#include <app-common/zap-generated/att-storage.h>
#include <app/ClusterInfo.h>
#include <app/AttributePathParams.h>
#include <app/ConcreteAttributePath.h>
#include <app/EventManagement.h>
#include <app/GlobalAttributes.h>
Expand Down Expand Up @@ -52,9 +52,9 @@ extern bool emberAfEndpointIndexIsEnabled(uint16_t index);
namespace chip {
namespace app {

AttributePathExpandIterator::AttributePathExpandIterator(ClusterInfo * aClusterInfo)
AttributePathExpandIterator::AttributePathExpandIterator(ObjectList<AttributePathParams> * aAttributePath)
{
mpClusterInfo = aClusterInfo;
mpAttributePath = aAttributePath;

// Reset iterator state
mEndpointIndex = UINT16_MAX;
Expand All @@ -71,42 +71,42 @@ AttributePathExpandIterator::AttributePathExpandIterator(ClusterInfo * aClusterI
Next();
}

void AttributePathExpandIterator::PrepareEndpointIndexRange(const ClusterInfo & aClusterInfo)
void AttributePathExpandIterator::PrepareEndpointIndexRange(const AttributePathParams & aAttributePath)
{
if (aClusterInfo.HasWildcardEndpointId())
if (aAttributePath.HasWildcardEndpointId())
{
mEndpointIndex = 0;
mEndEndpointIndex = emberAfEndpointCount();
}
else
{
mEndpointIndex = emberAfIndexFromEndpoint(aClusterInfo.mEndpointId);
mEndpointIndex = emberAfIndexFromEndpoint(aAttributePath.mEndpointId);
// If the given cluster id does not exist on the given endpoint, it will return uint16(0xFFFF), then endEndpointIndex
// will be 0, means we should iterate a null endpoint set (skip it).
mEndEndpointIndex = static_cast<uint16_t>(mEndpointIndex + 1);
}
}

void AttributePathExpandIterator::PrepareClusterIndexRange(const ClusterInfo & aClusterInfo, EndpointId aEndpointId)
void AttributePathExpandIterator::PrepareClusterIndexRange(const AttributePathParams & aAttributePath, EndpointId aEndpointId)
{
if (aClusterInfo.HasWildcardClusterId())
if (aAttributePath.HasWildcardClusterId())
{
mClusterIndex = 0;
mEndClusterIndex = emberAfClusterCount(aEndpointId, true /* server */);
}
else
{
mClusterIndex = emberAfClusterIndex(aEndpointId, aClusterInfo.mClusterId, CLUSTER_MASK_SERVER);
mClusterIndex = emberAfClusterIndex(aEndpointId, aAttributePath.mClusterId, CLUSTER_MASK_SERVER);
// If the given cluster id does not exist on the given endpoint, it will return uint8(0xFF), then endClusterIndex
// will be 0, means we should iterate a null cluster set (skip it).
mEndClusterIndex = static_cast<uint8_t>(mClusterIndex + 1);
}
}

void AttributePathExpandIterator::PrepareAttributeIndexRange(const ClusterInfo & aClusterInfo, EndpointId aEndpointId,
void AttributePathExpandIterator::PrepareAttributeIndexRange(const AttributePathParams & aAttributePath, EndpointId aEndpointId,
ClusterId aClusterId)
{
if (aClusterInfo.HasWildcardAttributeId())
if (aAttributePath.HasWildcardAttributeId())
{
mAttributeIndex = 0;
mEndAttributeIndex = emberAfGetServerAttributeCount(aEndpointId, aClusterId);
Expand All @@ -115,7 +115,7 @@ void AttributePathExpandIterator::PrepareAttributeIndexRange(const ClusterInfo &
}
else
{
mAttributeIndex = emberAfGetServerAttributeIndexByAttributeId(aEndpointId, aClusterId, aClusterInfo.mAttributeId);
mAttributeIndex = emberAfGetServerAttributeIndexByAttributeId(aEndpointId, aClusterId, aAttributePath.mAttributeId);
// If the given attribute id does not exist on the given endpoint, it will return uint16(0xFFFF), then endAttributeIndex
// will be 0, means we should iterate a null attribute set (skip it).
mEndAttributeIndex = static_cast<uint16_t>(mAttributeIndex + 1);
Expand All @@ -129,7 +129,7 @@ void AttributePathExpandIterator::PrepareAttributeIndexRange(const ClusterInfo &
mGlobalAttributeIndex = UINT8_MAX;
for (uint8_t idx = 0; idx < ArraySize(GlobalAttributesNotInMetadata); ++idx)
{
if (GlobalAttributesNotInMetadata[idx] == aClusterInfo.mAttributeId)
if (GlobalAttributesNotInMetadata[idx] == aAttributePath.mAttributeId)
{
mGlobalAttributeIndex = idx;
break;
Expand All @@ -142,25 +142,25 @@ void AttributePathExpandIterator::PrepareAttributeIndexRange(const ClusterInfo &

bool AttributePathExpandIterator::Next()
{
for (; mpClusterInfo != nullptr; (mpClusterInfo = mpClusterInfo->mpNext, mEndpointIndex = UINT16_MAX))
for (; mpAttributePath != nullptr; (mpAttributePath = mpAttributePath->mpNext, mEndpointIndex = UINT16_MAX))
{
mOutputPath.mExpanded = mpClusterInfo->HasAttributeWildcard();
mOutputPath.mExpanded = mpAttributePath->mValue.HasAttributeWildcard();

if (mEndpointIndex == UINT16_MAX)
{
// Special case: If this is a concrete path, we just return its value as-is.
if (!mpClusterInfo->HasAttributeWildcard())
if (!mpAttributePath->mValue.HasAttributeWildcard())
{
mOutputPath.mEndpointId = mpClusterInfo->mEndpointId;
mOutputPath.mClusterId = mpClusterInfo->mClusterId;
mOutputPath.mAttributeId = mpClusterInfo->mAttributeId;
mOutputPath.mEndpointId = mpAttributePath->mValue.mEndpointId;
mOutputPath.mClusterId = mpAttributePath->mValue.mClusterId;
mOutputPath.mAttributeId = mpAttributePath->mValue.mAttributeId;

// Prepare for next iteration
mEndpointIndex = mEndEndpointIndex = 0;
return true;
}

PrepareEndpointIndexRange(*mpClusterInfo);
PrepareEndpointIndexRange(mpAttributePath->mValue);
mClusterIndex = UINT8_MAX;
}

Expand All @@ -177,7 +177,7 @@ bool AttributePathExpandIterator::Next()

if (mClusterIndex == UINT8_MAX)
{
PrepareClusterIndexRange(*mpClusterInfo, endpointId);
PrepareClusterIndexRange(mpAttributePath->mValue, endpointId);
mAttributeIndex = UINT16_MAX;
mGlobalAttributeIndex = UINT8_MAX;
}
Expand All @@ -190,7 +190,7 @@ bool AttributePathExpandIterator::Next()
ClusterId clusterId = emberAfGetNthClusterId(endpointId, mClusterIndex, true /* server */).Value();
if (mAttributeIndex == UINT16_MAX && mGlobalAttributeIndex == UINT8_MAX)
{
PrepareAttributeIndexRange(*mpClusterInfo, endpointId, clusterId);
PrepareAttributeIndexRange(mpAttributePath->mValue, endpointId, clusterId);
}

if (mAttributeIndex < mEndAttributeIndex)
Expand All @@ -202,7 +202,7 @@ bool AttributePathExpandIterator::Next()
mOutputPath.mEndpointId = endpointId;
mAttributeIndex++;
// We found a valid attribute path, now return and increase the attribute index for next iteration.
// Return true will skip the increment of mClusterIndex, mEndpointIndex and mpClusterInfo.
// Return true will skip the increment of mClusterIndex, mEndpointIndex and mpAttributePath.
return true;
}
if (mGlobalAttributeIndex < mGlobalAttributeEndIndex)
Expand Down
39 changes: 20 additions & 19 deletions src/app/AttributePathExpandIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

/**
* @file
* Defines an iterator for iterating all possible paths from a list of ClusterInfo-s according to spec section 8.9.2.2 (Valid
* Attribute Paths)
* Defines an iterator for iterating all possible paths from a list of AttributePathParams-s according to spec section 8.9.2.2
* (Valid Attribute Paths)
*/

#pragma once

#include <app/ClusterInfo.h>
#include <app/AttributePathParams.h>
#include <app/ConcreteAttributePath.h>
#include <app/EventManagement.h>
#include <lib/core/CHIPCore.h>
Expand All @@ -42,18 +42,18 @@ namespace chip {
namespace app {

/**
* AttributePathExpandIterator is used to iterate over a linked list of ClusterInfo-s.
* AttributePathExpandIterator is used to iterate over a linked list of AttributePathParams-s.
* The AttributePathExpandIterator is copiable, however, the given cluster info must be valid when calling Next().
*
* AttributePathExpandIterator will expand attribute paths with wildcards, and only emit existing paths for ClusterInfo with
* wildcards. For ClusterInfo with a concrete path (i.e. does not contain wildcards), AttributePathExpandIterator will emit them
* as-is.
* AttributePathExpandIterator will expand attribute paths with wildcards, and only emit existing paths for AttributePathParams with
* wildcards. For AttributePathParams with a concrete path (i.e. does not contain wildcards), AttributePathExpandIterator will emit
* them as-is.
*
* The typical use of AttributePathExpandIterator may look like:
* ConcreteAttributePath path;
* for (AttributePathExpandIterator iterator(clusterInfo); iterator.Get(path); iterator.Next()) {...}
* for (AttributePathExpandIterator iterator(AttributePathParams); iterator.Get(path); iterator.Next()) {...}
*
* The iterator does not copy the given ClusterInfo, The given ClusterInfo must be valid when using the iterator.
* The iterator does not copy the given AttributePathParams, The given AttributePathParams must be valid when using the iterator.
* If the set of endpoints, clusters, or attributes that are supported changes, AttributePathExpandIterator must be reinitialized.
*
* A initialized iterator will return the first valid path, no need to call Next() before calling Get() for the first time.
Expand All @@ -63,17 +63,18 @@ namespace app {
* - Chunk full, return
* - In a new chunk, Get()
*
* TODO: The ClusterInfo may support a group id, the iterator should be able to call group data provider to expand the group id.
* TODO: The AttributePathParams may support a group id, the iterator should be able to call group data provider to expand the group
* id.
*/
class AttributePathExpandIterator
{
public:
AttributePathExpandIterator(ClusterInfo * aClusterInfo);
AttributePathExpandIterator(ObjectList<AttributePathParams> * aAttributePath);

/**
* Proceed the iterator to the next attribute path in the given cluster info.
*
* Returns false if AttributePathExpandIterator has exhausted all paths in the given ClusterInfo list.
* Returns false if AttributePathExpandIterator has exhausted all paths in the given AttributePathParams list.
*/
bool Next();

Expand All @@ -90,12 +91,12 @@ class AttributePathExpandIterator
/**
* Returns if the iterator is valid (not exhausted). An iterator is exhausted if and only if:
* - Next() is called after iterating last path.
* - Iterator is initialized with a null ClusterInfo.
* - Iterator is initialized with a null AttributePathParams.
*/
inline bool Valid() const { return mpClusterInfo != nullptr; }
inline bool Valid() const { return mpAttributePath != nullptr; }

private:
ClusterInfo * mpClusterInfo;
ObjectList<AttributePathParams> * mpAttributePath;

uint16_t mEndpointIndex, mEndEndpointIndex;
// Note: should use decltype(EmberAfEndpointType::clusterCount) here, but af-types is including app specific generated files.
Expand All @@ -109,16 +110,16 @@ class AttributePathExpandIterator

/**
* Prepare*IndexRange will update mBegin*Index and mEnd*Index variables.
* If ClusterInfo contains a wildcard field, it will set mBegin*Index to 0 and mEnd*Index to count.
* If AttributePathParams contains a wildcard field, it will set mBegin*Index to 0 and mEnd*Index to count.
* Or it will set mBegin*Index to the index of the Endpoint/Cluster/Attribute, and mEnd*Index to mBegin*Index + 1.
*
* If the Endpoint/Cluster/Attribute does not exist, mBegin*Index will be UINT*_MAX, and mEnd*Inde will be 0.
*
* The index can be used with emberAfEndpointFromIndex, emberAfGetNthClusterId and emberAfGetServerAttributeIdByIndex.
*/
void PrepareEndpointIndexRange(const ClusterInfo & aClusterInfo);
void PrepareClusterIndexRange(const ClusterInfo & aClusterInfo, EndpointId aEndpointId);
void PrepareAttributeIndexRange(const ClusterInfo & aClusterInfo, EndpointId aEndpointId, ClusterId aClusterId);
void PrepareEndpointIndexRange(const AttributePathParams & aAttributePath);
void PrepareClusterIndexRange(const AttributePathParams & aAttributePath, EndpointId aEndpointId);
void PrepareAttributeIndexRange(const AttributePathParams & aAttributePath, EndpointId aEndpointId, ClusterId aClusterId);
};
} // namespace app
} // namespace chip
34 changes: 25 additions & 9 deletions src/app/AttributePathParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@

#pragma once

#include <app/ConcreteAttributePath.h>
#include <app/util/basic-types.h>

#include <app/ClusterInfo.h>

namespace chip {
namespace app {
struct AttributePathParams
Expand All @@ -30,8 +29,6 @@ struct AttributePathParams
// TODO: (Issue #10596) Need to ensure that we do not encode the NodeId over the wire
// if it is either not 'set', or is set to a value that matches accessing fabric
// on which the interaction is undertaken.
//
// TODO: (#11420) This class is overlapped with ClusterInfo class, need to do a clean up.
AttributePathParams(EndpointId aEndpointId, ClusterId aClusterId) :
AttributePathParams(aEndpointId, aClusterId, kInvalidAttributeId, kInvalidListIndex)
{}
Expand All @@ -45,7 +42,7 @@ struct AttributePathParams
{}

AttributePathParams(EndpointId aEndpointId, ClusterId aClusterId, AttributeId aAttributeId, ListIndex aListIndex) :
mEndpointId(aEndpointId), mClusterId(aClusterId), mAttributeId(aAttributeId), mListIndex(aListIndex)
mClusterId(aClusterId), mAttributeId(aAttributeId), mEndpointId(aEndpointId), mListIndex(aListIndex)
{}

AttributePathParams() {}
Expand All @@ -65,10 +62,29 @@ struct AttributePathParams
inline bool HasWildcardAttributeId() const { return mAttributeId == kInvalidAttributeId; }
inline bool HasWildcardListIndex() const { return mListIndex == kInvalidListIndex; }

EndpointId mEndpointId = kInvalidEndpointId;
ClusterId mClusterId = kInvalidClusterId;
AttributeId mAttributeId = kInvalidAttributeId;
ListIndex mListIndex = kInvalidListIndex;
bool IsAttributePathSupersetOf(const AttributePathParams & other) const
{
VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false);
VerifyOrReturnError(HasWildcardClusterId() || mClusterId == other.mClusterId, false);
VerifyOrReturnError(HasWildcardAttributeId() || mAttributeId == other.mAttributeId, false);
VerifyOrReturnError(HasWildcardListIndex() || mListIndex == other.mListIndex, false);

return true;
}

bool IsAttributePathSupersetOf(const ConcreteAttributePath & other) const
{
VerifyOrReturnError(HasWildcardEndpointId() || mEndpointId == other.mEndpointId, false);
VerifyOrReturnError(HasWildcardClusterId() || mClusterId == other.mClusterId, false);
VerifyOrReturnError(HasWildcardAttributeId() || mAttributeId == other.mAttributeId, false);

return true;
}

ClusterId mClusterId = kInvalidClusterId; // uint32
AttributeId mAttributeId = kInvalidAttributeId; // uint32
EndpointId mEndpointId = kInvalidEndpointId; // uint16
ListIndex mListIndex = kInvalidListIndex; // uint16
};
} // namespace app
} // namespace chip
Loading

0 comments on commit 07fc8cd

Please sign in to comment.