Skip to content

Commit 3e87fe8

Browse files
restyled-commitsnivi-apple
authored andcommitted
Restyled by clang-format
1 parent d975eb7 commit 3e87fe8

File tree

3 files changed

+131
-193
lines changed

3 files changed

+131
-193
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

+68-88
Original file line numberDiff line numberDiff line change
@@ -2770,109 +2770,93 @@ - (void)_pruneOrphanedEndpointsAndClusters:(MTRAttributePath *)attributePath
27702770
{
27712771
os_unfair_lock_assert_owner(&self->_lock);
27722772

2773-
if (_persistedClusters == nil || _persistedClusterData == nil || !previousValue.count)
2774-
{
2773+
if (_persistedClusters == nil || _persistedClusterData == nil || !previousValue.count) {
27752774
return;
27762775
}
27772776
// Check if parts list changed or server list changed for the descriptor cluster or the attribute list changed for a cluster.
27782777
// If yes, we might need to prune any deleted endpoints, clusters or attributes from the storage and persisted cluster data.
27792778
if (attributePath.cluster.unsignedLongValue == MTRClusterIDTypeDescriptorID) {
27802779
switch (attributePath.attribute.unsignedLongValue) {
27812780

2782-
// If the parts list changed and one or more endpoints were removed, remove all the clusters in _persistedClusters and _persistedClusterData for all those endpoints.
2783-
// Also remove it from the data store.
2784-
case MTRAttributeIDTypeClusterDescriptorAttributePartsListID:
2785-
{
2786-
NSMutableSet * toBeRemovedEndpoints = [NSMutableSet setWithArray:[self arrayOfNumbersFromAttributeValue:previousValue]];
2787-
NSSet * endpointsOnDevice = [NSSet setWithArray:[self arrayOfNumbersFromAttributeValue:attributeDataValue]];
2788-
[toBeRemovedEndpoints minusSet:endpointsOnDevice];
2789-
2790-
for (NSNumber * endpoint in toBeRemovedEndpoints)
2791-
{
2792-
NSMutableSet<MTRClusterPath *> * clusterPathsToRemove = [[NSMutableSet alloc]init];
2793-
for (MTRClusterPath * path in _persistedClusters)
2794-
{
2795-
if ([path.endpoint isEqualToNumber:endpoint])
2796-
{
2797-
[clusterPathsToRemove addObject:path];
2798-
[_persistedClusterData removeObjectForKey:path];
2799-
[self.deviceController.controllerDataStore clearStoredClusterDataForNodeIDWithEndpointID:self.nodeID endpointID:endpoint];
2800-
}
2781+
// If the parts list changed and one or more endpoints were removed, remove all the clusters in _persistedClusters and _persistedClusterData for all those endpoints.
2782+
// Also remove it from the data store.
2783+
case MTRAttributeIDTypeClusterDescriptorAttributePartsListID: {
2784+
NSMutableSet * toBeRemovedEndpoints = [NSMutableSet setWithArray:[self arrayOfNumbersFromAttributeValue:previousValue]];
2785+
NSSet * endpointsOnDevice = [NSSet setWithArray:[self arrayOfNumbersFromAttributeValue:attributeDataValue]];
2786+
[toBeRemovedEndpoints minusSet:endpointsOnDevice];
2787+
2788+
for (NSNumber * endpoint in toBeRemovedEndpoints) {
2789+
NSMutableSet<MTRClusterPath *> * clusterPathsToRemove = [[NSMutableSet alloc] init];
2790+
for (MTRClusterPath * path in _persistedClusters) {
2791+
if ([path.endpoint isEqualToNumber:endpoint]) {
2792+
[clusterPathsToRemove addObject:path];
2793+
[_persistedClusterData removeObjectForKey:path];
2794+
[self.deviceController.controllerDataStore clearStoredClusterDataForNodeIDWithEndpointID:self.nodeID endpointID:endpoint];
28012795
}
2802-
[_persistedClusters minusSet:clusterPathsToRemove];
28032796
}
2804-
break;
2797+
[_persistedClusters minusSet:clusterPathsToRemove];
28052798
}
2799+
break;
2800+
}
28062801

2807-
// If the server list changed and clusters were removed, remove the clusters from the _persistedClusters and _persistedClusterData for that endpoint
2808-
// Also remove it from the data store.
2809-
case MTRAttributeIDTypeClusterDescriptorAttributeServerListID:
2810-
{
2811-
NSMutableSet * toBeRemovedClusters= [NSMutableSet setWithArray:[self arrayOfNumbersFromAttributeValue:previousValue]];
2812-
NSSet * clustersOnDevice = [NSSet setWithArray:[self arrayOfNumbersFromAttributeValue:attributeDataValue]];
2813-
[toBeRemovedClusters minusSet:clustersOnDevice];
2814-
2815-
NSMutableSet<MTRClusterPath *> * clusterPathsToRemove = [[NSMutableSet alloc]init];
2816-
for (NSNumber * cluster in toBeRemovedClusters)
2817-
{
2818-
for (MTRClusterPath * path in _persistedClusters)
2819-
{
2820-
if ([path.endpoint isEqualToNumber:attributePath.endpoint] && [path.cluster isEqualToNumber:cluster])
2821-
{
2822-
[clusterPathsToRemove addObject:path];
2823-
[_persistedClusterData removeObjectForKey:path];
2824-
2825-
[self.deviceController.controllerDataStore clearStoredClusterDataForNodeIDWithClusterID:self.nodeID endpointID:path.endpoint clusterID:path.cluster];
2826-
}
2802+
// If the server list changed and clusters were removed, remove the clusters from the _persistedClusters and _persistedClusterData for that endpoint
2803+
// Also remove it from the data store.
2804+
case MTRAttributeIDTypeClusterDescriptorAttributeServerListID: {
2805+
NSMutableSet * toBeRemovedClusters = [NSMutableSet setWithArray:[self arrayOfNumbersFromAttributeValue:previousValue]];
2806+
NSSet * clustersOnDevice = [NSSet setWithArray:[self arrayOfNumbersFromAttributeValue:attributeDataValue]];
2807+
[toBeRemovedClusters minusSet:clustersOnDevice];
2808+
2809+
NSMutableSet<MTRClusterPath *> * clusterPathsToRemove = [[NSMutableSet alloc] init];
2810+
for (NSNumber * cluster in toBeRemovedClusters) {
2811+
for (MTRClusterPath * path in _persistedClusters) {
2812+
if ([path.endpoint isEqualToNumber:attributePath.endpoint] && [path.cluster isEqualToNumber:cluster]) {
2813+
[clusterPathsToRemove addObject:path];
2814+
[_persistedClusterData removeObjectForKey:path];
2815+
2816+
[self.deviceController.controllerDataStore clearStoredClusterDataForNodeIDWithClusterID:self.nodeID endpointID:path.endpoint clusterID:path.cluster];
28272817
}
28282818
}
2829-
[_persistedClusters minusSet:clusterPathsToRemove];
2830-
break;
28312819
}
2820+
[_persistedClusters minusSet:clusterPathsToRemove];
2821+
break;
2822+
}
28322823
}
28332824
}
28342825

28352826
switch (attributePath.attribute.unsignedLongValue) {
2836-
// If the attribute list changed and attributes were removed, remove the attributes from the _persistedClusterData for that cluster and endpoint.
2837-
// Also remove it from the data store cluster data.
2838-
case MTRAttributeIDTypeGlobalAttributeAttributeListID:
2839-
{
2840-
NSMutableSet * toBeRemovedAttributes= [NSMutableSet setWithArray:[self arrayOfNumbersFromAttributeValue:[self _cachedAttributeValueForPath:attributePath]]];
2841-
NSSet * attributesOnDevice = [NSSet setWithArray:[self arrayOfNumbersFromAttributeValue:attributeDataValue]];
2842-
2843-
[toBeRemovedAttributes minusSet:attributesOnDevice];
2844-
for (NSNumber * attribute in toBeRemovedAttributes)
2845-
{
2846-
for (MTRClusterPath * path in _persistedClusters)
2847-
{
2848-
if ([path.endpoint isEqualToNumber:attributePath.endpoint] && [path.cluster isEqualToNumber:attributePath.cluster])
2849-
{
2850-
MTRDeviceClusterData * clusterData = [self _clusterDataForPath:path];
2851-
if (clusterData == nil)
2852-
{
2853-
return;
2854-
}
2855-
[clusterData _removeValueForAttribute:attribute];
2856-
[self->_persistedClusterData setObject:clusterData forKey:path];
2857-
2858-
NSDictionary<MTRClusterPath *, MTRDeviceClusterData *> * dataStoreClusterData = [self.deviceController.controllerDataStore getStoredClusterDataForNodeID:self.nodeID];
2859-
NSMutableDictionary<MTRClusterPath *, MTRDeviceClusterData *> * dataStoreClusterDataCopy = [dataStoreClusterData mutableCopy];
2860-
for (MTRClusterPath * dataStorePath in dataStoreClusterData)
2861-
{
2862-
if ([dataStorePath isEqualTo:path])
2863-
{
2864-
[dataStoreClusterDataCopy removeObjectForKey:path];
2865-
[dataStoreClusterDataCopy setObject:clusterData forKey:path];
2866-
[self.deviceController.controllerDataStore storeClusterData:dataStoreClusterDataCopy forNodeID:self.nodeID];
2867-
dataStoreClusterData = [NSMutableDictionary dictionaryWithDictionary:[self.deviceController.controllerDataStore getStoredClusterDataForNodeID:self.nodeID]];
2868-
}
2827+
// If the attribute list changed and attributes were removed, remove the attributes from the _persistedClusterData for that cluster and endpoint.
2828+
// Also remove it from the data store cluster data.
2829+
case MTRAttributeIDTypeGlobalAttributeAttributeListID: {
2830+
NSMutableSet * toBeRemovedAttributes = [NSMutableSet setWithArray:[self arrayOfNumbersFromAttributeValue:[self _cachedAttributeValueForPath:attributePath]]];
2831+
NSSet * attributesOnDevice = [NSSet setWithArray:[self arrayOfNumbersFromAttributeValue:attributeDataValue]];
2832+
2833+
[toBeRemovedAttributes minusSet:attributesOnDevice];
2834+
for (NSNumber * attribute in toBeRemovedAttributes) {
2835+
for (MTRClusterPath * path in _persistedClusters) {
2836+
if ([path.endpoint isEqualToNumber:attributePath.endpoint] && [path.cluster isEqualToNumber:attributePath.cluster]) {
2837+
MTRDeviceClusterData * clusterData = [self _clusterDataForPath:path];
2838+
if (clusterData == nil) {
2839+
return;
2840+
}
2841+
[clusterData _removeValueForAttribute:attribute];
2842+
[self->_persistedClusterData setObject:clusterData forKey:path];
2843+
2844+
NSDictionary<MTRClusterPath *, MTRDeviceClusterData *> * dataStoreClusterData = [self.deviceController.controllerDataStore getStoredClusterDataForNodeID:self.nodeID];
2845+
NSMutableDictionary<MTRClusterPath *, MTRDeviceClusterData *> * dataStoreClusterDataCopy = [dataStoreClusterData mutableCopy];
2846+
for (MTRClusterPath * dataStorePath in dataStoreClusterData) {
2847+
if ([dataStorePath isEqualTo:path]) {
2848+
[dataStoreClusterDataCopy removeObjectForKey:path];
2849+
[dataStoreClusterDataCopy setObject:clusterData forKey:path];
2850+
[self.deviceController.controllerDataStore storeClusterData:dataStoreClusterDataCopy forNodeID:self.nodeID];
2851+
dataStoreClusterData = [NSMutableDictionary dictionaryWithDictionary:[self.deviceController.controllerDataStore getStoredClusterDataForNodeID:self.nodeID]];
28692852
}
2870-
[self _removeCachedAttributeValue:path forPath:attributePath];
28712853
}
2854+
[self _removeCachedAttributeValue:path forPath:attributePath];
28722855
}
28732856
}
2874-
break;
28752857
}
2858+
break;
2859+
}
28762860
}
28772861
}
28782862

@@ -2929,8 +2913,7 @@ - (NSArray *)_getAttributesToReportWithReportedValues:(NSArray<NSDictionary<NSSt
29292913
[self _noteDataVersion:dataVersion forClusterPath:clusterPath];
29302914
}
29312915

2932-
if ([self _needsPruningOfEndpointsAndClusters:attributePath])
2933-
{
2916+
if ([self _needsPruningOfEndpointsAndClusters:attributePath]) {
29342917
previousValue = [self _dataValueWithoutDataVersion:previousValue];
29352918
[self _pruneOrphanedEndpointsAndClusters:attributePath previousValue:previousValue attributeDataValue:attributeDataValue];
29362919
}
@@ -3099,8 +3082,7 @@ - (void)_storePersistedDeviceData
30993082
- (void)_removePersistedClusterDataForPath:(MTRClusterPath *)path
31003083
{
31013084
os_unfair_lock_assert_owner(&self->_lock);
3102-
if (_persistedClusters == nil || _persistedClusterData == nil)
3103-
{
3085+
if (_persistedClusters == nil || _persistedClusterData == nil) {
31043086
return;
31053087
}
31063088

@@ -3119,8 +3101,7 @@ - (MTRDeviceClusterData *)_getPersistedClusterDataForPath:(MTRClusterPath *)path
31193101
{
31203102
std::lock_guard lock(_lock);
31213103

3122-
if ([_persistedClusters containsObject:path])
3123-
{
3104+
if ([_persistedClusters containsObject:path]) {
31243105
return [_persistedClusterData objectForKey:path];
31253106
}
31263107
return nil;
@@ -3130,8 +3111,7 @@ - (BOOL)_persistedClusterContains:(MTRClusterPath *)path
31303111
{
31313112
std::lock_guard lock(_lock);
31323113

3133-
if ([_persistedClusters containsObject:path])
3134-
{
3114+
if ([_persistedClusters containsObject:path]) {
31353115
return YES;
31363116
}
31373117
return NO;

src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm

+1-2
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,7 @@ - (BOOL)_deleteEndpointIndex:(NSNumber *)endpointID forNodeID:(NSNumber *)nodeID
456456
}
457457

458458
NSMutableArray * endpointIndex = [NSMutableArray arrayWithArray:[self _fetchEndpointIndexForNodeID:nodeID]];
459-
if (endpointIndex == nil)
460-
{
459+
if (endpointIndex == nil) {
461460
return NO;
462461
}
463462

0 commit comments

Comments
 (0)