forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove various un-necessary code from MTRDevice. (project-chip#36132)
* Remove various un-necessary code from MTRDevice. The _deviceInternalStateChanged declaration was duplicated in MTRDevice_Concrete and only needed there. MTRDeviceClusterData implementation can move into its own file. setPersistedClusterData: is only used on MTRDevice_Concrete instances, so its declaration can move to MTRDevice_Concrete and the unused implementation in MTRDevice can be removed. setPersistedDeviceData: is only used on MTRDevice_Concrete instances, so its declaration can move to MTRDevice_Concrete and the unused implementation in MTRDevice can be removed. Now _setLastInitialSubscribeLatency and _updateAttributeDependentDescriptionData on MTRDevice are unused and can be removed. At this point, _informationalVendorID, _informationalProductID, _networkFeatures, _vid, _pid, _allNetworkFeatures, and _descriptionLock are all unused on MTRDevice and can be removed. Now _informationalNumberAtAttributePath is unused on MTRDevice and can be removed. _endpointList is also unused on MTRDevice and can be removed. deviceCachePrimed is implemented by both MTRDevice_XPC and MTRDevice_Concrete, so the implementation on MTRDevice can be removed. unitTestGetClusterDataForPath, unitTestGetPersistedClusters, unitTestClusterHasBeenPersisted, unitTestResetSubscription, unitTestAttributesReportedSinceLastCheck, unitTestClearClusterData, unitTestInjectEventReport, unitTestInjectAttributeReport, and unitTestAttributeCount are only used on MTRDevice_Concrete, so the duplicate implementations on MTRDevice can be removed. At this point, _cachedAttributeValueForPath is unused on MTRDevice and can be removed. Now _getCachedDataVersions is unused on MTRDevice and can be removed. deviceUsesThread is only used by MTRDeviceController_Concrete on MTRDevice_Concrete instances and so can move to MTRDevice_Concrete entirely. Then _deviceUsesThread becomes unused on MTRDevice and can be removed. Then _clusterDataForPath is unused on MTRDevice and can be removed. Now _reconcilePersistedClustersWithStorage is unused on MTRDevice and can be removed. Also, _knownClusters is unused on MTRDevice and can be removed. setStorageBehaviorConfiguration is only used from MTRDeviceController_Concrete (which has an MTRDevice_Concrete) and from unit tests (which have an MTRDevice_Concrete, though they don't know it), so it can be removed from MTRDevice. Then _resetStorageBehaviorState also becomes unused and can be removed. At this point, _scheduleClusterDataPersistence is not used on MTRDevice and can be removed. This makes _persistClusterDataAsNeeded and _deviceCachePrimed unused, and they can also be removed. At this point, _persistClusterData, _deviceIsReportingExcessively, _reportToPersistenceDelayTimeAfterMutiplier, _reportToPersistenceDelayTimeMaxAfterMutiplier, _mostRecentReportTimes, and _clusterDataPersistenceFirstScheduledTime are not used on MTRDevice and can be removed. Now _dataStoreExists, _clusterDataToPersistSnapshot, _storageBehaviorConfiguration, _reportToPersistenceDelayCurrentMultiplier, _deviceReportingExcessivelyStartTime, and _persistedClusters are unused on MTRDevice and can be removed. At this point _clusterDataToPersist and _persistedClusterData are unused on MTRDevice and can be removed. _systemTimeChangeObserverToken was never actually used on MTRDevice (it's only used on MTRDevice_Concrete) and can be removed. The MTRDeviceAttributeReportHandler typedef is unused on MTRDevice and can be removed. kSecondsToWaitBeforeMarkingUnreachableAfterSettingUpSubscription and ENABLE_CONNECTIVITY_MONITORING are unused on MTRDevice and can be removed. assertChipStackLockedByCurrentThread is not used in MTRDevice, so the LockTracker.h include can be removed. MTRAsyncWorkQueue, MTRAttributeIsSpecified, MTRCommandNeedsTimedInvoke, MTRDeviceConnectivityMonitor, MTRDeviceControllerOverXPC, MTRDecodeEventPayload, are all unused in MTRDevice, so the imports of the corresponding headers can be removed. arrayOfNumbersFromAttributeValue is now unused on MTRDevice and can be removed. The fabricIndex property is write-only on both MTRDevice and MTRDevice_Concrete and can be removed on both. _dataValueWithoutDataVersion is unused on MTRDevice and can be removed. * Move MTRDeviceClusterData into a separate header/implementation file.
- Loading branch information
1 parent
76e9e14
commit 2574847
Showing
15 changed files
with
261 additions
and
905 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import "MTRDefines_Internal.h" | ||
#import "MTRDeviceDataValueDictionary.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
* Information about a cluster: data version and known attribute values. | ||
*/ | ||
MTR_TESTABLE | ||
@interface MTRDeviceClusterData : NSObject <NSSecureCoding, NSCopying> | ||
@property (nonatomic, nullable) NSNumber * dataVersion; | ||
@property (nonatomic, readonly) NSDictionary<NSNumber *, MTRDeviceDataValueDictionary> * attributes; // attributeID => data-value dictionary | ||
|
||
- (void)storeValue:(MTRDeviceDataValueDictionary _Nullable)value forAttribute:(NSNumber *)attribute; | ||
- (void)removeValueForAttribute:(NSNumber *)attribute; | ||
|
||
- (nullable instancetype)initWithDataVersion:(NSNumber * _Nullable)dataVersion attributes:(NSDictionary<NSNumber *, MTRDeviceDataValueDictionary> * _Nullable)attributes; | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/** | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import "MTRDeviceClusterData.h" | ||
#import "MTRLogging_Internal.h" | ||
#import "MTRUtilities.h" | ||
|
||
static NSString * const sDataVersionKey = @"dataVersion"; | ||
static NSString * const sAttributesKey = @"attributes"; | ||
|
||
@implementation MTRDeviceClusterData { | ||
NSMutableDictionary<NSNumber *, MTRDeviceDataValueDictionary> * _attributes; | ||
} | ||
|
||
- (void)storeValue:(MTRDeviceDataValueDictionary _Nullable)value forAttribute:(NSNumber *)attribute | ||
{ | ||
_attributes[attribute] = value; | ||
} | ||
|
||
- (void)removeValueForAttribute:(NSNumber *)attribute | ||
{ | ||
[_attributes removeObjectForKey:attribute]; | ||
} | ||
|
||
- (NSDictionary<NSNumber *, MTRDeviceDataValueDictionary> *)attributes | ||
{ | ||
return _attributes; | ||
} | ||
|
||
+ (BOOL)supportsSecureCoding | ||
{ | ||
return YES; | ||
} | ||
|
||
- (NSString *)description | ||
{ | ||
return [NSString stringWithFormat:@"<MTRDeviceClusterData: dataVersion %@ attributes count %lu>", _dataVersion, static_cast<unsigned long>(_attributes.count)]; | ||
} | ||
|
||
- (nullable instancetype)init | ||
{ | ||
return [self initWithDataVersion:nil attributes:nil]; | ||
} | ||
|
||
// Attributes dictionary is: attributeID => data-value dictionary | ||
- (nullable instancetype)initWithDataVersion:(NSNumber * _Nullable)dataVersion attributes:(NSDictionary<NSNumber *, MTRDeviceDataValueDictionary> * _Nullable)attributes | ||
{ | ||
self = [super init]; | ||
if (self == nil) { | ||
return nil; | ||
} | ||
|
||
_dataVersion = [dataVersion copy]; | ||
_attributes = [NSMutableDictionary dictionaryWithCapacity:attributes.count]; | ||
[_attributes addEntriesFromDictionary:attributes]; | ||
|
||
return self; | ||
} | ||
|
||
- (nullable instancetype)initWithCoder:(NSCoder *)decoder | ||
{ | ||
self = [super init]; | ||
if (self == nil) { | ||
return nil; | ||
} | ||
|
||
_dataVersion = [decoder decodeObjectOfClass:[NSNumber class] forKey:sDataVersionKey]; | ||
if (_dataVersion != nil && ![_dataVersion isKindOfClass:[NSNumber class]]) { | ||
MTR_LOG_ERROR("MTRDeviceClusterData got %@ for data version, not NSNumber.", _dataVersion); | ||
return nil; | ||
} | ||
|
||
static NSSet * const sAttributeValueClasses = [NSSet setWithObjects:[NSDictionary class], [NSArray class], [NSData class], [NSString class], [NSNumber class], nil]; | ||
_attributes = [decoder decodeObjectOfClasses:sAttributeValueClasses forKey:sAttributesKey]; | ||
if (_attributes != nil && ![_attributes isKindOfClass:[NSDictionary class]]) { | ||
MTR_LOG_ERROR("MTRDeviceClusterData got %@ for attributes, not NSDictionary.", _attributes); | ||
return nil; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)encodeWithCoder:(NSCoder *)coder | ||
{ | ||
[coder encodeObject:self.dataVersion forKey:sDataVersionKey]; | ||
[coder encodeObject:self.attributes forKey:sAttributesKey]; | ||
} | ||
|
||
- (id)copyWithZone:(NSZone *)zone | ||
{ | ||
return [[MTRDeviceClusterData alloc] initWithDataVersion:_dataVersion attributes:_attributes]; | ||
} | ||
|
||
- (BOOL)isEqualToClusterData:(MTRDeviceClusterData *)otherClusterData | ||
{ | ||
return MTREqualObjects(_dataVersion, otherClusterData.dataVersion) | ||
&& MTREqualObjects(_attributes, otherClusterData.attributes); | ||
} | ||
|
||
- (BOOL)isEqual:(id)object | ||
{ | ||
if ([object class] != [self class]) { | ||
return NO; | ||
} | ||
|
||
return [self isEqualToClusterData:object]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
typedef NSDictionary<NSString *, id> * MTRDeviceDataValueDictionary; | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.