Skip to content

Commit

Permalink
Initialize MTRDevice_XPC and MTRDevice_Concrete with the correspondin…
Browse files Browse the repository at this point in the history
…g controller types.

Removes the unreached/unused initWithNodeID:controller: on MTRDevice.

unitTestSetMostRecentReportTimes is only used on MTRDevice_Concrete instances,
and is already implemented there, so can be removed from MTRDevice.
  • Loading branch information
bzbarsky-apple committed Sep 25, 2024
1 parent 6f93ec2 commit 320d6f1
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 64 deletions.
59 changes: 0 additions & 59 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
Expand Down Expand Up @@ -727,16 +687,6 @@ - (void)_persistClusterDataAsNeeded
_clusterDataPersistenceFirstScheduledTime = nil;
}

#ifdef DEBUG
- (void)unitTestSetMostRecentReportTimes:(NSMutableArray<NSDate *> *)mostRecentReportTimes
{
_mostRecentReportTimes = mostRecentReportTimes;

std::lock_guard lock(_descriptionLock);
_mostRecentReportTimeForDescription = [mostRecentReportTimes lastObject];
}
#endif

- (void)_scheduleClusterDataPersistence
{
os_unfair_lock_assert_owner(&self->_lock);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -858,10 +803,6 @@ - (void)_resetStorageBehaviorState

_clusterDataPersistenceFirstScheduledTime = nil;
_mostRecentReportTimes = nil;
{
std::lock_guard lock(_descriptionLock);
_mostRecentReportTimeForDescription = nil;
}
_deviceReportingExcessivelyStartTime = nil;
_reportToPersistenceDelayCurrentMultiplier = 1;

Expand Down
4 changes: 4 additions & 0 deletions src/darwin/Framework/CHIP/MTRDevice_Concrete.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
#import <Foundation/Foundation.h>
#import <Matter/MTRDevice.h>

#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
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRDevice_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
1 change: 0 additions & 1 deletion src/darwin/Framework/CHIP/MTRDevice_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/darwin/Framework/CHIP/MTRDevice_XPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@

#import <Matter/Matter.h>

#import "MTRDeviceController_XPC.h"

NS_ASSUME_NONNULL_BEGIN

@interface MTRDevice_XPC : MTRDevice <MTRXPCClientProtocol_MTRDevice>

- (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController_XPC *)controller;

@end

NS_ASSUME_NONNULL_END
4 changes: 1 addition & 3 deletions src/darwin/Framework/CHIP/MTRDevice_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down

0 comments on commit 320d6f1

Please sign in to comment.