diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 0e079eb10efd8d..552c99c7e873b4 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -280,8 +280,6 @@ @implementation MTRDevice { // _allNetworkFeatures is a bitwise or of the feature maps of all network commissioning clusters // present on the device, or nil if there aren't any. NSNumber * _Nullable _allNetworkFeatures; - // Most recent entry in _mostRecentReportTimes, if any. - NSDate * _Nullable _mostRecentReportTimeForDescription; } - (instancetype)initForSubclassesWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller @@ -297,44 +295,6 @@ - (instancetype)initForSubclassesWithNodeID:(NSNumber *)nodeID controller:(MTRDe return self; } -- (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller -{ - if (self = [super init]) { - _lock = OS_UNFAIR_LOCK_INIT; - _descriptionLock = OS_UNFAIR_LOCK_INIT; - _nodeID = [nodeID copy]; - _fabricIndex = controller.fabricIndex; - _deviceController = controller; - _queue - = dispatch_queue_create("org.csa-iot.matter.framework.device.workqueue", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL); - _asyncWorkQueue = [[MTRAsyncWorkQueue alloc] initWithContext:self]; - _state = MTRDeviceStateUnknown; - if (controller.controllerDataStore) { - _persistedClusterData = [[NSCache alloc] init]; - } else { - _persistedClusterData = nil; - } - _clusterDataToPersist = nil; - _persistedClusters = [NSMutableSet set]; - - // If there is a data store, make sure we have an observer to monitor system clock changes, so - // NSDate-based write coalescing could be reset and not get into a bad state. - if (_persistedClusterData) { - mtr_weakify(self); - _systemTimeChangeObserverToken = [[NSNotificationCenter defaultCenter] addObserverForName:NSSystemClockDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull notification) { - mtr_strongify(self); - std::lock_guard lock(self->_lock); - [self _resetStorageBehaviorState]; - }]; - } - - _delegates = [NSMutableSet set]; - - MTR_LOG_DEBUG("%@ init with hex nodeID 0x%016llX", self, _nodeID.unsignedLongLongValue); - } - return self; -} - - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:_systemTimeChangeObserverToken]; @@ -727,16 +687,6 @@ - (void)_persistClusterDataAsNeeded _clusterDataPersistenceFirstScheduledTime = nil; } -#ifdef DEBUG -- (void)unitTestSetMostRecentReportTimes:(NSMutableArray *)mostRecentReportTimes -{ - _mostRecentReportTimes = mostRecentReportTimes; - - std::lock_guard lock(_descriptionLock); - _mostRecentReportTimeForDescription = [mostRecentReportTimes lastObject]; -} -#endif - - (void)_scheduleClusterDataPersistence { os_unfair_lock_assert_owner(&self->_lock); @@ -788,11 +738,6 @@ - (void)_scheduleClusterDataPersistence } [_mostRecentReportTimes addObject:[NSDate now]]; - { - std::lock_guard lock(_descriptionLock); - _mostRecentReportTimeForDescription = [_mostRecentReportTimes lastObject]; - } - // Calculate running average and update multiplier - need at least 2 items to calculate intervals if (_mostRecentReportTimes.count > 2) { NSTimeInterval cumulativeIntervals = 0; @@ -858,10 +803,6 @@ - (void)_resetStorageBehaviorState _clusterDataPersistenceFirstScheduledTime = nil; _mostRecentReportTimes = nil; - { - std::lock_guard lock(_descriptionLock); - _mostRecentReportTimeForDescription = nil; - } _deviceReportingExcessivelyStartTime = nil; _reportToPersistenceDelayCurrentMultiplier = 1; diff --git a/src/darwin/Framework/CHIP/MTRDevice_Concrete.h b/src/darwin/Framework/CHIP/MTRDevice_Concrete.h index 6466a18c04abf6..74a9a5788c5b8b 100644 --- a/src/darwin/Framework/CHIP/MTRDevice_Concrete.h +++ b/src/darwin/Framework/CHIP/MTRDevice_Concrete.h @@ -18,10 +18,14 @@ #import #import +#import "MTRDeviceController_Concrete.h" + NS_ASSUME_NONNULL_BEGIN @interface MTRDevice_Concrete : MTRDevice +- (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController_Concrete *)controller; + @end NS_ASSUME_NONNULL_END diff --git a/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm b/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm index 0b6b073a57649c..a2dbb2dcbaf35d 100644 --- a/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm +++ b/src/darwin/Framework/CHIP/MTRDevice_Concrete.mm @@ -361,7 +361,7 @@ @implementation MTRDevice_Concrete { //@synthesize lock = _lock; //@synthesize persistedClusterData = _persistedClusterData; -- (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller +- (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController_Concrete *)controller { // `super` was NSObject, is now MTRDevice. MTRDevice hides its `init` if (self = [super initForSubclassesWithNodeID:nodeID controller:controller]) { diff --git a/src/darwin/Framework/CHIP/MTRDevice_Internal.h b/src/darwin/Framework/CHIP/MTRDevice_Internal.h index d0661b2590e9cd..6aea99eeda1ffb 100644 --- a/src/darwin/Framework/CHIP/MTRDevice_Internal.h +++ b/src/darwin/Framework/CHIP/MTRDevice_Internal.h @@ -123,7 +123,6 @@ MTR_DIRECT_MEMBERS } - (instancetype)initForSubclassesWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller; -- (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller; // called by controller to clean up and shutdown - (void)invalidate; diff --git a/src/darwin/Framework/CHIP/MTRDevice_XPC.h b/src/darwin/Framework/CHIP/MTRDevice_XPC.h index a2df4a60446aec..ddde470e7d1a28 100644 --- a/src/darwin/Framework/CHIP/MTRDevice_XPC.h +++ b/src/darwin/Framework/CHIP/MTRDevice_XPC.h @@ -17,10 +17,14 @@ #import +#import "MTRDeviceController_XPC.h" + NS_ASSUME_NONNULL_BEGIN @interface MTRDevice_XPC : MTRDevice +- (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController_XPC *)controller; + @end NS_ASSUME_NONNULL_END diff --git a/src/darwin/Framework/CHIP/MTRDevice_XPC.mm b/src/darwin/Framework/CHIP/MTRDevice_XPC.mm index 0827ee46602449..015736e179c2c4 100644 --- a/src/darwin/Framework/CHIP/MTRDevice_XPC.mm +++ b/src/darwin/Framework/CHIP/MTRDevice_XPC.mm @@ -84,10 +84,8 @@ @implementation MTRDevice_XPC @synthesize _internalState; -- (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller +- (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController_XPC *)controller { - // TODO: Verify that this is a valid MTRDeviceController_XPC? - if (self = [super initForSubclassesWithNodeID:nodeID controller:controller]) { // Nothing else to do, all set. }