Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support const ClusterStateCache accessor calls. #19025

Merged
merged 1 commit into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/app/ClusterStateCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void ClusterStateCache::OnReportEnd()
mCallback.OnReportEnd();
}

CHIP_ERROR ClusterStateCache::Get(const ConcreteAttributePath & path, TLV::TLVReader & reader)
CHIP_ERROR ClusterStateCache::Get(const ConcreteAttributePath & path, TLV::TLVReader & reader) const
{
CHIP_ERROR err;
auto attributeState = GetAttributeState(path.mEndpointId, path.mClusterId, path.mAttributeId, err);
Expand All @@ -224,7 +224,7 @@ CHIP_ERROR ClusterStateCache::Get(const ConcreteAttributePath & path, TLV::TLVRe
return reader.Next();
}

CHIP_ERROR ClusterStateCache::Get(EventNumber eventNumber, TLV::TLVReader & reader)
CHIP_ERROR ClusterStateCache::Get(EventNumber eventNumber, TLV::TLVReader & reader) const
{
CHIP_ERROR err;

Expand All @@ -240,7 +240,7 @@ CHIP_ERROR ClusterStateCache::Get(EventNumber eventNumber, TLV::TLVReader & read
return CHIP_NO_ERROR;
}

ClusterStateCache::EndpointState * ClusterStateCache::GetEndpointState(EndpointId endpointId, CHIP_ERROR & err)
const ClusterStateCache::EndpointState * ClusterStateCache::GetEndpointState(EndpointId endpointId, CHIP_ERROR & err) const
{
auto endpointIter = mCache.find(endpointId);
if (endpointIter == mCache.end())
Expand All @@ -253,7 +253,8 @@ ClusterStateCache::EndpointState * ClusterStateCache::GetEndpointState(EndpointI
return &endpointIter->second;
}

ClusterStateCache::ClusterState * ClusterStateCache::GetClusterState(EndpointId endpointId, ClusterId clusterId, CHIP_ERROR & err)
const ClusterStateCache::ClusterState * ClusterStateCache::GetClusterState(EndpointId endpointId, ClusterId clusterId,
CHIP_ERROR & err) const
{
auto endpointState = GetEndpointState(endpointId, err);
if (err != CHIP_NO_ERROR)
Expand All @@ -273,7 +274,7 @@ ClusterStateCache::ClusterState * ClusterStateCache::GetClusterState(EndpointId
}

const ClusterStateCache::AttributeState * ClusterStateCache::GetAttributeState(EndpointId endpointId, ClusterId clusterId,
AttributeId attributeId, CHIP_ERROR & err)
AttributeId attributeId, CHIP_ERROR & err) const
{
auto clusterState = GetClusterState(endpointId, clusterId, err);
if (err != CHIP_NO_ERROR)
Expand All @@ -292,7 +293,7 @@ const ClusterStateCache::AttributeState * ClusterStateCache::GetAttributeState(E
return &attributeState->second;
}

const ClusterStateCache::EventData * ClusterStateCache::GetEventData(EventNumber eventNumber, CHIP_ERROR & err)
const ClusterStateCache::EventData * ClusterStateCache::GetEventData(EventNumber eventNumber, CHIP_ERROR & err) const
{
EventData compareKey;

Expand Down Expand Up @@ -338,7 +339,7 @@ void ClusterStateCache::OnAttributeData(const ConcreteDataAttributePath & aPath,
mCallback.OnAttributeData(aPath, apData ? &dataSnapshot : nullptr, aStatus);
}

CHIP_ERROR ClusterStateCache::GetVersion(const ConcreteClusterPath & aPath, Optional<DataVersion> & aVersion)
CHIP_ERROR ClusterStateCache::GetVersion(const ConcreteClusterPath & aPath, Optional<DataVersion> & aVersion) const
{
VerifyOrReturnError(aPath.IsValidConcreteClusterPath(), CHIP_ERROR_INVALID_ARGUMENT);
CHIP_ERROR err;
Expand All @@ -362,7 +363,7 @@ void ClusterStateCache::OnEventData(const EventHeader & aEventHeader, TLV::TLVRe
mCallback.OnEventData(aEventHeader, apData ? &dataSnapshot : nullptr, apStatus);
}

CHIP_ERROR ClusterStateCache::GetStatus(const ConcreteAttributePath & path, StatusIB & status)
CHIP_ERROR ClusterStateCache::GetStatus(const ConcreteAttributePath & path, StatusIB & status) const
{
CHIP_ERROR err;

Expand All @@ -378,7 +379,7 @@ CHIP_ERROR ClusterStateCache::GetStatus(const ConcreteAttributePath & path, Stat
return CHIP_NO_ERROR;
}

CHIP_ERROR ClusterStateCache::GetStatus(const ConcreteEventPath & path, StatusIB & status)
CHIP_ERROR ClusterStateCache::GetStatus(const ConcreteEventPath & path, StatusIB & status) const
{
auto statusIter = mEventStatusCache.find(path);
if (statusIter == mEventStatusCache.end())
Expand All @@ -390,7 +391,7 @@ CHIP_ERROR ClusterStateCache::GetStatus(const ConcreteEventPath & path, StatusIB
return CHIP_NO_ERROR;
}

void ClusterStateCache::GetSortedFilters(std::vector<std::pair<DataVersionFilter, size_t>> & aVector)
void ClusterStateCache::GetSortedFilters(std::vector<std::pair<DataVersionFilter, size_t>> & aVector) const
{
for (auto const & endpointIter : mCache)
{
Expand Down
38 changes: 20 additions & 18 deletions src/app/ClusterStateCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class ClusterStateCache : protected ReadClient::Callback
*
*/
template <typename AttributeObjectTypeT>
CHIP_ERROR Get(const ConcreteAttributePath & path, typename AttributeObjectTypeT::DecodableType & value)
CHIP_ERROR Get(const ConcreteAttributePath & path, typename AttributeObjectTypeT::DecodableType & value) const
{
TLV::TLVReader reader;

Expand All @@ -152,7 +152,7 @@ class ClusterStateCache : protected ReadClient::Callback
* - If data exists in the cache instead of status, CHIP_ERROR_INVALID_ARGUMENT shall be returned.
*
*/
CHIP_ERROR GetStatus(const ConcreteAttributePath & path, StatusIB & status);
CHIP_ERROR GetStatus(const ConcreteAttributePath & path, StatusIB & status) const;

/*
* Encapsulates a StatusIB and a ConcreteAttributePath pair.
Expand Down Expand Up @@ -184,7 +184,8 @@ class ClusterStateCache : protected ReadClient::Callback
*
*/
template <typename ClusterObjectTypeT>
CHIP_ERROR Get(EndpointId endpointId, ClusterId clusterId, ClusterObjectTypeT & value, std::list<AttributeStatus> & statusList)
CHIP_ERROR Get(EndpointId endpointId, ClusterId clusterId, ClusterObjectTypeT & value,
std::list<AttributeStatus> & statusList) const
{
statusList.clear();

Expand Down Expand Up @@ -228,15 +229,15 @@ class ClusterStateCache : protected ReadClient::Callback
* shall be returned from this call instead. The actual StatusIB can be retrieved using the GetStatus() API above.
*
*/
CHIP_ERROR Get(const ConcreteAttributePath & path, TLV::TLVReader & reader);
CHIP_ERROR Get(const ConcreteAttributePath & path, TLV::TLVReader & reader) const;

/*
* Retrieve the data version for the given cluster. If there is no data for the specified path in the cache,
* CHIP_ERROR_KEY_NOT_FOUND shall be returned. Otherwise aVersion will be set to the
* current data version for the cluster (which may have no value if we don't have a known data version
* for it, for example because none of our paths were wildcards that covered the whole cluster).
*/
CHIP_ERROR GetVersion(const ConcreteClusterPath & path, Optional<DataVersion> & aVersion);
CHIP_ERROR GetVersion(const ConcreteClusterPath & path, Optional<DataVersion> & aVersion) const;

/*
* Get highest received event number.
Expand Down Expand Up @@ -271,7 +272,7 @@ class ClusterStateCache : protected ReadClient::Callback
*/

template <typename EventObjectTypeT>
CHIP_ERROR Get(EventNumber eventNumber, EventObjectTypeT & value)
CHIP_ERROR Get(EventNumber eventNumber, EventObjectTypeT & value) const
{
TLV::TLVReader reader;
CHIP_ERROR err;
Expand All @@ -297,7 +298,7 @@ class ClusterStateCache : protected ReadClient::Callback
* shall be returned.
*
*/
CHIP_ERROR Get(EventNumber eventNumber, TLV::TLVReader & reader);
CHIP_ERROR Get(EventNumber eventNumber, TLV::TLVReader & reader) const;

/*
* Retrieve the StatusIB for a specific event from the event status cache (if one exists).
Expand All @@ -308,7 +309,7 @@ class ClusterStateCache : protected ReadClient::Callback
* NOTE: Receipt of a StatusIB does not affect any pre-existing or future event data entries in the cache (and vice-versa).
*
*/
CHIP_ERROR GetStatus(const ConcreteEventPath & path, StatusIB & status);
CHIP_ERROR GetStatus(const ConcreteEventPath & path, StatusIB & status) const;

/*
* Execute an iterator function that is called for every attribute
Expand All @@ -327,7 +328,7 @@ class ClusterStateCache : protected ReadClient::Callback
*
*/
template <typename IteratorFunc>
CHIP_ERROR ForEachAttribute(EndpointId endpointId, ClusterId clusterId, IteratorFunc func)
CHIP_ERROR ForEachAttribute(EndpointId endpointId, ClusterId clusterId, IteratorFunc func) const
{
CHIP_ERROR err;

Expand Down Expand Up @@ -357,7 +358,7 @@ class ClusterStateCache : protected ReadClient::Callback
*
*/
template <typename IteratorFunc>
CHIP_ERROR ForEachAttribute(ClusterId clusterId, IteratorFunc func)
CHIP_ERROR ForEachAttribute(ClusterId clusterId, IteratorFunc func) const
{
for (auto & endpointIter : mCache)
{
Expand Down Expand Up @@ -390,7 +391,7 @@ class ClusterStateCache : protected ReadClient::Callback
*
*/
template <typename IteratorFunc>
CHIP_ERROR ForEachCluster(EndpointId endpointId, IteratorFunc func)
CHIP_ERROR ForEachCluster(EndpointId endpointId, IteratorFunc func) const
{
auto endpointIter = mCache.find(endpointId);
if (endpointIter->first == endpointId)
Expand Down Expand Up @@ -426,7 +427,7 @@ class ClusterStateCache : protected ReadClient::Callback
*/
template <typename IteratorFunc>
CHIP_ERROR ForEachEventData(IteratorFunc func, EventPathParams pathFilter = EventPathParams(),
EventNumber minEventNumberFilter = 0)
EventNumber minEventNumberFilter = 0) const
{
for (const auto & item : mEventDataCache)
{
Expand All @@ -453,7 +454,7 @@ class ClusterStateCache : protected ReadClient::Callback
*
*/
template <typename IteratorFunc>
CHIP_ERROR ForEachEventStatus(IteratorFunc func)
CHIP_ERROR ForEachEventStatus(IteratorFunc func) const
{
for (const auto & item : mEventStatusCache)
{
Expand Down Expand Up @@ -532,11 +533,12 @@ class ClusterStateCache : protected ReadClient::Callback
* CHIP_ERROR_KEY_NOT_FOUND shall be returned.
*
*/
EndpointState * GetEndpointState(EndpointId endpointId, CHIP_ERROR & err);
ClusterState * GetClusterState(EndpointId endpointId, ClusterId clusterId, CHIP_ERROR & err);
const AttributeState * GetAttributeState(EndpointId endpointId, ClusterId clusterId, AttributeId attributeId, CHIP_ERROR & err);
const EndpointState * GetEndpointState(EndpointId endpointId, CHIP_ERROR & err) const;
const ClusterState * GetClusterState(EndpointId endpointId, ClusterId clusterId, CHIP_ERROR & err) const;
const AttributeState * GetAttributeState(EndpointId endpointId, ClusterId clusterId, AttributeId attributeId,
CHIP_ERROR & err) const;

const EventData * GetEventData(EventNumber number, CHIP_ERROR & err);
const EventData * GetEventData(EventNumber number, CHIP_ERROR & err) const;

/*
* Updates the state of an attribute in the cache given a reader. If the reader is null, the state is updated
Expand Down Expand Up @@ -589,7 +591,7 @@ class ClusterStateCache : protected ReadClient::Callback
// Get our list of data version filters, sorted from larges to smallest by the total size of the TLV
// payload for the filter's cluster. Applying filters in this order should maximize space savings
// on the wire if not all filters can be applied.
void GetSortedFilters(std::vector<std::pair<DataVersionFilter, size_t>> & aVector);
void GetSortedFilters(std::vector<std::pair<DataVersionFilter, size_t>> & aVector) const;

CHIP_ERROR GetElementTLVSize(TLV::TLVReader * apData, size_t & aSize);

Expand Down