Skip to content

Commit

Permalink
Fixing shadow variables, and also fixing registration (project-chip#3…
Browse files Browse the repository at this point in the history
  • Loading branch information
woody-apple authored Sep 8, 2024
1 parent 3e5b149 commit bc19fb0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ @implementation MTRDeviceController {
os_unfair_lock _assertionLock;
}

@synthesize uniqueIdentifier = _uniqueIdentifier;

- (os_unfair_lock_t)deviceMapLock
{
return &_underlyingDeviceMapLock;
Expand Down Expand Up @@ -340,7 +342,7 @@ - (instancetype)initWithFactory:(MTRDeviceControllerFactory *)factory

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p uuid %@>", NSStringFromClass(self.class), self, _uniqueIdentifier];
return [NSString stringWithFormat:@"<%@: %p uuid %@>", NSStringFromClass(self.class), self, self.uniqueIdentifier];
}

- (BOOL)isRunning
Expand Down
5 changes: 0 additions & 5 deletions src/darwin/Framework/CHIP/MTRDeviceController_Concrete.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS
*/
@property (readonly, nonatomic, getter=isRunning) BOOL running;

/**
* The ID assigned to this controller at creation time.
*/
@property (readonly, nonatomic) NSUUID * uniqueIdentifier MTR_AVAILABLE(ios(17.6), macos(14.6), watchos(10.6), tvos(17.6));

/**
* Return the Node ID assigned to the controller. Will return nil if the
* controller is not running (and hence does not know its node id).
Expand Down
15 changes: 5 additions & 10 deletions src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ @interface MTRDeviceController_Concrete ()
@property (nonatomic, readonly) MTRDeviceControllerDelegateBridge * deviceControllerDelegateBridge;
@property (nonatomic, readonly) MTROperationalCredentialsDelegate * operationalCredentialsDelegate;
@property (nonatomic, readonly) MTRDeviceAttestationDelegateBridge * deviceAttestationDelegateBridge;
@property (nonatomic, readwrite) NSUUID * uniqueIdentifier;
@property (nonatomic, readonly) dispatch_queue_t chipWorkQueue;
@property (nonatomic, readonly, nullable) MTRDeviceControllerFactory * factory;
@property (nonatomic, readonly, nullable) id<MTROTAProviderDelegate> otaProviderDelegate;
Expand Down Expand Up @@ -130,9 +129,6 @@ @implementation MTRDeviceController_Concrete {
os_unfair_lock _assertionLock;
}

// TODO: Figure out whether uniqueIdentifier storage should live in the superclass. It
// probably should!
@synthesize uniqueIdentifier = _uniqueIdentifier;
// TODO: Figure out whether the work queue storage lives here or in the superclass
// Right now we seem to have both?
@synthesize chipWorkQueue = _chipWorkQueue;
Expand Down Expand Up @@ -208,7 +204,7 @@ - (instancetype)initWithFactory:(MTRDeviceControllerFactory *)factory
if (self = [super initForSubclasses:startSuspended]) {
// Make sure our storage is all set up to work as early as possible,
// before we start doing anything else with the controller.
_uniqueIdentifier = uniqueIdentifier;
self.uniqueIdentifier = uniqueIdentifier;

// Setup assertion variables
_keepRunningAssertionCounter = 0;
Expand Down Expand Up @@ -340,7 +336,7 @@ - (instancetype)initWithFactory:(MTRDeviceControllerFactory *)factory

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p uuid %@>", NSStringFromClass(self.class), self, _uniqueIdentifier];
return [NSString stringWithFormat:@"<%@: %p uuid %@>", NSStringFromClass(self.class), self, self.uniqueIdentifier];
}

- (BOOL)isRunning
Expand Down Expand Up @@ -744,7 +740,7 @@ - (BOOL)startup:(MTRDeviceControllerStartupParamsInternal *)startupParams
if (_controllerDataStore) {
// If the storage delegate supports the bulk read API, then a dictionary of nodeID => cluster data dictionary would be passed to the handler. Otherwise this would be a no-op, and stored attributes for MTRDevice objects will be loaded lazily in -deviceForNodeID:.
[_controllerDataStore fetchAttributeDataForAllDevices:^(NSDictionary<NSNumber *, NSDictionary<MTRClusterPath *, MTRDeviceClusterData *> *> * _Nonnull clusterDataByNode) {
MTR_LOG("%@ Loaded attribute values for %lu nodes from storage for controller uuid %@", self, static_cast<unsigned long>(clusterDataByNode.count), self->_uniqueIdentifier);
MTR_LOG("%@ Loaded attribute values for %lu nodes from storage for controller uuid %@", self, static_cast<unsigned long>(clusterDataByNode.count), self.uniqueIdentifier);

std::lock_guard lock(*self.deviceMapLock);
NSMutableArray * deviceList = [NSMutableArray array];
Expand Down Expand Up @@ -1290,7 +1286,7 @@ - (BOOL)addServerEndpoint:(MTRServerEndpoint *)endpoint
[self->_serverEndpoints addObject:endpoint];
[endpoint registerMatterEndpoint];
MTR_LOG("%@ Added server endpoint %u to controller %@", self, static_cast<chip::EndpointId>(endpoint.endpointID.unsignedLongLongValue),
self->_uniqueIdentifier);
self.uniqueIdentifier);
}
errorHandler:^(NSError * error) {
MTR_LOG_ERROR("%@ Unexpected failure dispatching to Matter queue on running controller in addServerEndpoint, adding endpoint %u", self,
Expand All @@ -1317,8 +1313,7 @@ - (void)removeServerEndpointInternal:(MTRServerEndpoint *)endpoint queue:(dispat
// tearing it down.
[self asyncDispatchToMatterQueue:^() {
[self removeServerEndpointOnMatterQueue:endpoint];
MTR_LOG("%@ Removed server endpoint %u from controller %@", self, static_cast<chip::EndpointId>(endpoint.endpointID.unsignedLongLongValue),
self->_uniqueIdentifier);
MTR_LOG("%@ Removed server endpoint %u from controller %@", self, static_cast<chip::EndpointId>(endpoint.endpointID.unsignedLongLongValue), self.uniqueIdentifier);
if (queue != nil && completion != nil) {
dispatch_async(queue, completion);
}
Expand Down
2 changes: 2 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) NSMapTable<NSNumber *, MTRDevice *> * nodeIDToDeviceMap;
@property (readonly, assign) os_unfair_lock_t deviceMapLock;

@property (readwrite, nonatomic) NSUUID * uniqueIdentifier;

// queue used to serialize all work performed by the MTRDeviceController
// (moved here so subclasses can initialize differently)
@property (readwrite, retain) dispatch_queue_t chipWorkQueue;
Expand Down
8 changes: 8 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ - (nullable instancetype)initWithParameters:(MTRDeviceControllerAbstractParamete
return nil;
}

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

Expand Down Expand Up @@ -285,6 +286,13 @@ - (MTRDevice *)_setupDeviceForNodeID:(NSNumber *)nodeID prefetchedClusterData:(N
MTRDevice * deviceToReturn = [[MTRDevice_XPC alloc] initWithNodeID:nodeID controller:self];
[self.nodeIDToDeviceMap setObject:deviceToReturn forKey:nodeID];
MTR_LOG("%s: returning XPC device for node id %@", __PRETTY_FUNCTION__, nodeID);

mtr_weakify(self);
[[self.xpcConnection synchronousRemoteObjectProxyWithErrorHandler:^(NSError * _Nonnull error) {
mtr_strongify(self);
MTR_LOG_ERROR("%@ Registration error for device nodeID: %@ : %@", self, nodeID, error);
}] deviceController:self.uniqueIdentifier registerNodeID:nodeID];

return deviceToReturn;
}

Expand Down

0 comments on commit bc19fb0

Please sign in to comment.