Skip to content

Commit

Permalink
Merge 11bbf46 into 334b1d9
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple authored Nov 21, 2024
2 parents 334b1d9 + 11bbf46 commit 2047408
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
9 changes: 8 additions & 1 deletion src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ - (instancetype)initWithDelegate:(id<MTRDeviceControllerDelegate>)delegate queue
}
@end

@interface MTRDeviceController ()
@property (readwrite, nonatomic) NSUUID * uniqueIdentifier;
@end

@implementation MTRDeviceController {
os_unfair_lock _underlyingDeviceMapLock;

Expand All @@ -107,11 +111,14 @@ - (os_unfair_lock_t)deviceMapLock
return &_underlyingDeviceMapLock;
}

- (instancetype)initForSubclasses:(BOOL)startSuspended
- (instancetype)initForSubclasses:(BOOL)startSuspended uniqueIdentifier:(NSUUID *)uniqueIdentifier
{
if (self = [super init]) {
// nothing, as superclass of MTRDeviceController is NSObject
}

self.uniqueIdentifier = uniqueIdentifier;

_underlyingDeviceMapLock = OS_UNFAIR_LOCK_INIT;

_suspended = startSuspended;
Expand Down
3 changes: 1 addition & 2 deletions src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,9 @@ - (nullable instancetype)initWithFactory:(MTRDeviceControllerFactory *)factory
storageBehaviorConfiguration:(MTRDeviceStorageBehaviorConfiguration *)storageBehaviorConfiguration
startSuspended:(BOOL)startSuspended
{
if (self = [super initForSubclasses:startSuspended]) {
if (self = [super initForSubclasses:startSuspended uniqueIdentifier:uniqueIdentifier]) {
// Make sure our storage is all set up to work as early as possible,
// before we start doing anything else with the controller.
self.uniqueIdentifier = uniqueIdentifier;

// Setup assertion variables
_keepRunningAssertionCounter = 0;
Expand Down
5 changes: 1 addition & 4 deletions src/darwin/Framework/CHIP/MTRDeviceController_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) NSMapTable<NSNumber *, MTRDevice *> * nodeIDToDeviceMap;
@property (readonly, assign) os_unfair_lock_t deviceMapLock;

@property (readwrite, nonatomic) NSUUID * uniqueIdentifier;
// (moved here so subclasses can initialize differently)

- (instancetype)initForSubclasses:(BOOL)startSuspended;
- (instancetype)initForSubclasses:(BOOL)startSuspended uniqueIdentifier:(NSUUID *)uniqueIdentifier;

#pragma mark - MTRDeviceControllerFactory methods

Expand Down
11 changes: 5 additions & 6 deletions src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,11 @@ - (nullable instancetype)initWithParameters:(MTRDeviceControllerAbstractParamete
return nil;
}

if (self = [super initForSubclasses:parameters.startSuspended]) {
auto * xpcParameters = static_cast<MTRXPCDeviceControllerParameters *>(parameters);
auto * xpcParameters = static_cast<MTRXPCDeviceControllerParameters *>(parameters);
auto * UUID = xpcParameters.uniqueIdentifier;

if (self = [super initForSubclasses:parameters.startSuspended uniqueIdentifier:UUID]) {
auto connectionBlock = xpcParameters.xpcConnectionBlock;
auto * UUID = xpcParameters.uniqueIdentifier;

MTR_LOG("Setting up XPC Controller for UUID: %@ with connection block: %p", UUID, connectionBlock);

Expand All @@ -304,7 +305,6 @@ - (nullable instancetype)initWithParameters:(MTRDeviceControllerAbstractParamete
return nil;
}

self.uniqueIdentifier = UUID;
self.xpcParameters = xpcParameters;
_workQueue = dispatch_queue_create("MTRDeviceController_XPC_queue", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL);

Expand All @@ -321,10 +321,9 @@ - (id)initWithUniqueIdentifier:(NSUUID *)UUID machServiceName:(NSString *)machSe
{
// TODO: Presumably this should end up doing some sort of
// MTRDeviceControllerAbstractParameters thing eventually?
if (self = [super initForSubclasses:NO]) {
if (self = [super initForSubclasses:NO uniqueIdentifier:UUID]) {
MTR_LOG("Setting up XPC Controller for UUID: %@ with machServiceName: %s options: %d", UUID, machServiceName, options);
self.xpcConnection = [[NSXPCConnection alloc] initWithMachServiceName:machServiceName options:options];
self.uniqueIdentifier = UUID;

MTR_LOG("Set up XPC Connection: %@", self.xpcConnection);
if (self.xpcConnection) {
Expand Down

0 comments on commit 2047408

Please sign in to comment.