Skip to content

Commit 3cdd1d5

Browse files
authored
Merge branch 'master' into feature/app-install-flow-public
2 parents 8951403 + 707e431 commit 3cdd1d5

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/darwin/Framework/CHIP/MTRBaseSubscriptionCallback.h

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <app/BufferedReadCallback.h>
2323
#include <app/ClusterStateCache.h>
2424
#include <app/ConcreteAttributePath.h>
25+
#include <app/ConcreteClusterPath.h>
2526
#include <app/EventHeader.h>
2627
#include <app/MessageDef/StatusIB.h>
2728
#include <app/ReadClient.h>
@@ -93,6 +94,12 @@ class MTRBaseSubscriptionCallback : public chip::app::ClusterStateCache::Callbac
9394

9495
chip::app::BufferedReadCallback & GetBufferedCallback() { return mBufferedReadAdapter; }
9596

97+
// Methods to clear state from our cluster state cache. Must be called on
98+
// the Matter queue.
99+
void ClearCachedAttributeState(chip::EndpointId aEndpoint);
100+
void ClearCachedAttributeState(const chip::app::ConcreteClusterPath & aCluster);
101+
void ClearCachedAttributeState(const chip::app::ConcreteAttributePath & aAttribute);
102+
96103
// We need to exist to get a ReadClient, so can't take this as a constructor argument.
97104
void AdoptReadClient(std::unique_ptr<chip::app::ReadClient> aReadClient) { mReadClient = std::move(aReadClient); }
98105
void AdoptClusterStateCache(std::unique_ptr<chip::app::ClusterStateCache> aClusterStateCache)

src/darwin/Framework/CHIP/MTRBaseSubscriptionCallback.mm

+24
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,27 @@
201201
});
202202
}
203203
}
204+
205+
void MTRBaseSubscriptionCallback::ClearCachedAttributeState(EndpointId aEndpoint)
206+
{
207+
assertChipStackLockedByCurrentThread();
208+
if (mClusterStateCache) {
209+
mClusterStateCache->ClearAttributes(aEndpoint);
210+
}
211+
}
212+
213+
void MTRBaseSubscriptionCallback::ClearCachedAttributeState(const ConcreteClusterPath & aCluster)
214+
{
215+
assertChipStackLockedByCurrentThread();
216+
if (mClusterStateCache) {
217+
mClusterStateCache->ClearAttributes(aCluster);
218+
}
219+
}
220+
221+
void MTRBaseSubscriptionCallback::ClearCachedAttributeState(const ConcreteAttributePath & aAttribute)
222+
{
223+
assertChipStackLockedByCurrentThread();
224+
if (mClusterStateCache) {
225+
mClusterStateCache->ClearAttribute(aAttribute);
226+
}
227+
}

src/darwin/Framework/CHIP/MTRDevice.mm

+30
Original file line numberDiff line numberDiff line change
@@ -3441,6 +3441,13 @@ - (void)_pruneEndpointsIn:(MTRDeviceDataValueDictionary)previousPartsListValue
34413441
}
34423442
[self _removeClusters:clusterPathsToRemove doRemoveFromDataStore:NO];
34433443
[self.deviceController.controllerDataStore clearStoredClusterDataForNodeID:self.nodeID endpointID:endpoint];
3444+
3445+
[_deviceController asyncDispatchToMatterQueue:^{
3446+
std::lock_guard lock(self->_lock);
3447+
if (self->_currentSubscriptionCallback) {
3448+
self->_currentSubscriptionCallback->ClearCachedAttributeState(static_cast<EndpointId>(endpoint.unsignedLongLongValue));
3449+
}
3450+
} errorHandler:nil];
34443451
}
34453452
}
34463453

@@ -3461,6 +3468,17 @@ - (void)_pruneClustersIn:(MTRDeviceDataValueDictionary)previousServerListValue
34613468
}
34623469
}
34633470
[self _removeClusters:clusterPathsToRemove doRemoveFromDataStore:YES];
3471+
3472+
[_deviceController asyncDispatchToMatterQueue:^{
3473+
std::lock_guard lock(self->_lock);
3474+
if (self->_currentSubscriptionCallback) {
3475+
for (NSNumber * cluster in toBeRemovedClusters) {
3476+
ConcreteClusterPath clusterPath(static_cast<EndpointId>(endpointID.unsignedLongLongValue),
3477+
static_cast<ClusterId>(cluster.unsignedLongLongValue));
3478+
self->_currentSubscriptionCallback->ClearCachedAttributeState(clusterPath);
3479+
}
3480+
}
3481+
} errorHandler:nil];
34643482
}
34653483

34663484
- (void)_pruneAttributesIn:(MTRDeviceDataValueDictionary)previousAttributeListValue
@@ -3474,6 +3492,18 @@ - (void)_pruneAttributesIn:(MTRDeviceDataValueDictionary)previousAttributeListVa
34743492

34753493
[toBeRemovedAttributes minusSet:attributesStillInCluster];
34763494
[self _removeAttributes:toBeRemovedAttributes fromCluster:clusterPath];
3495+
3496+
[_deviceController asyncDispatchToMatterQueue:^{
3497+
std::lock_guard lock(self->_lock);
3498+
if (self->_currentSubscriptionCallback) {
3499+
for (NSNumber * attribute in toBeRemovedAttributes) {
3500+
ConcreteAttributePath attributePath(static_cast<EndpointId>(clusterPath.endpoint.unsignedLongLongValue),
3501+
static_cast<ClusterId>(clusterPath.cluster.unsignedLongLongValue),
3502+
static_cast<AttributeId>(attribute.unsignedLongLongValue));
3503+
self->_currentSubscriptionCallback->ClearCachedAttributeState(attributePath);
3504+
}
3505+
}
3506+
} errorHandler:nil];
34773507
}
34783508

34793509
- (void)_pruneStoredDataForPath:(MTRAttributePath *)attributePath

0 commit comments

Comments
 (0)