Skip to content

Commit 1250872

Browse files
authored
Merge 00584c2 into 4706914
2 parents 4706914 + 00584c2 commit 1250872

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/darwin/Framework/CHIP/MTRDeviceClusterData.h

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
2626
MTR_TESTABLE
2727
@interface MTRDeviceClusterData : NSObject <NSSecureCoding, NSCopying>
2828
@property (nonatomic, nullable) NSNumber * dataVersion;
29+
@property (nonatomic, nullable) NSNumber * pendingDataVersion; // for holding new data version during a report, and not encoded
2930
@property (nonatomic, readonly) NSDictionary<NSNumber *, MTRDeviceDataValueDictionary> * attributes; // attributeID => data-value dictionary
3031

3132
- (void)storeValue:(MTRDeviceDataValueDictionary _Nullable)value forAttribute:(NSNumber *)attribute;

src/darwin/Framework/CHIP/MTRDevice_Concrete.mm

+33-2
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,11 @@ - (void)_persistClusterDataAsNeeded
18551855
return;
18561856
}
18571857

1858+
// Do not persist partial data in the middle of receiving a report. _handleReportEnd will schedule next persistence
1859+
if (_receivingReport) {
1860+
return;
1861+
}
1862+
18581863
NSDate * lastReportTime = [_mostRecentReportTimes lastObject];
18591864
NSTimeInterval intervalSinceLastReport = -[lastReportTime timeIntervalSinceNow];
18601865
if (intervalSinceLastReport < [self _reportToPersistenceDelayTimeAfterMutiplier]) {
@@ -2054,6 +2059,7 @@ - (void)_handleReportEnd
20542059
_receivingPrimingReport = NO;
20552060
_estimatedStartTimeFromGeneralDiagnosticsUpTime = nil;
20562061

2062+
[self _commitPendingDataVersions];
20572063
[self _scheduleClusterDataPersistence];
20582064

20592065
// After the handling of the report, if we detected a device configuration change, notify the delegate
@@ -2519,6 +2525,30 @@ - (nullable MTRDeviceClusterData *)_clusterDataForPath:(MTRClusterPath *)cluster
25192525
return dataVersions;
25202526
}
25212527

2528+
- (void)_commitPendingDataVersionsForClusterPath:(MTRClusterPath *)path
2529+
{
2530+
os_unfair_lock_assert_owner(&self->_lock);
2531+
MTRDeviceClusterData * clusterData = _clusterDataToPersist[path];
2532+
if (clusterData.pendingDataVersion) {
2533+
clusterData.dataVersion = clusterData.pendingDataVersion;
2534+
clusterData.pendingDataVersion = nil;
2535+
}
2536+
}
2537+
2538+
- (void)_commitPendingDataVersions
2539+
{
2540+
os_unfair_lock_assert_owner(&self->_lock);
2541+
2542+
if (!_clusterDataToPersist) {
2543+
// nothing to do
2544+
return;
2545+
}
2546+
2547+
for (MTRClusterPath * path in _clusterDataToPersist) {
2548+
[self _commitPendingDataVersionsForClusterPath:path];
2549+
}
2550+
}
2551+
25222552
- (MTRDeviceDataValueDictionary _Nullable)_cachedAttributeValueForPath:(MTRAttributePath *)path
25232553
{
25242554
os_unfair_lock_assert_owner(&self->_lock);
@@ -3919,10 +3949,11 @@ - (void)_noteDataVersion:(NSNumber *)dataVersion forClusterPath:(MTRClusterPath
39193949
// Update data version used for subscription filtering
39203950
MTRDeviceClusterData * clusterData = [self _clusterDataForPath:clusterPath];
39213951
if (!clusterData) {
3922-
clusterData = [[MTRDeviceClusterData alloc] initWithDataVersion:dataVersion attributes:nil];
3952+
clusterData = [[MTRDeviceClusterData alloc] init];
3953+
clusterData.pendingDataVersion = dataVersion;
39233954
dataVersionChanged = YES;
39243955
} else if (![clusterData.dataVersion isEqualToNumber:dataVersion]) {
3925-
clusterData.dataVersion = dataVersion;
3956+
clusterData.pendingDataVersion = dataVersion;
39263957
dataVersionChanged = YES;
39273958
}
39283959

0 commit comments

Comments
 (0)