Skip to content

Commit

Permalink
If an XPC client doesn't care about a nodeID (hasn't made it), don't …
Browse files Browse the repository at this point in the history
…create one (#36586)

* Fixing infinite loop

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
woody-apple and restyled-commits authored Nov 21, 2024
1 parent 334b1d9 commit 709841e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,22 @@ - (MTRDevice *)_setupDeviceForNodeID:(NSNumber *)nodeID prefetchedClusterData:(N
return [[MTRDevice alloc] initForSubclassesWithNodeID:nodeID controller:self];
}

- (MTRDevice *)deviceForNodeID:(NSNumber *)nodeID
- (MTRDevice *)_deviceForNodeID:(NSNumber *)nodeID createIfNeeded:(BOOL)createIfNeeded
{
std::lock_guard lock(*self.deviceMapLock);
MTRDevice * deviceToReturn = [_nodeIDToDeviceMap objectForKey:nodeID];
if (!deviceToReturn) {
if (!deviceToReturn && createIfNeeded) {
deviceToReturn = [self _setupDeviceForNodeID:nodeID prefetchedClusterData:nil];
}

return deviceToReturn;
}

- (MTRDevice *)deviceForNodeID:(NSNumber *)nodeID
{
return [self _deviceForNodeID:nodeID createIfNeeded:YES];
}

- (void)removeDevice:(MTRDevice *)device
{
std::lock_guard lock(*self.deviceMapLock);
Expand Down
1 change: 1 addition & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Device-specific data and SDK access
// DeviceController will act as a central repository for this opaque dictionary that MTRDevice manages
- (MTRDevice *)deviceForNodeID:(NSNumber *)nodeID;
- (MTRDevice *)_deviceForNodeID:(NSNumber *)nodeID createIfNeeded:(BOOL)createIfNeeded;
/**
* _setupDeviceForNodeID is a hook expected to be implemented by subclasses to
* actually allocate a device object of the right type.
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRDeviceController_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ - (oneway void)controller:(NSUUID *)controller controllerConfigurationUpdated:(N
continue;
}

auto * device = static_cast<MTRDevice_XPC *>([self deviceForNodeID:nodeID]);
auto * device = static_cast<MTRDevice_XPC *>([self _deviceForNodeID:nodeID createIfNeeded:NO]);
[device device:nodeID internalStateUpdated:deviceInternalState];
}
}
Expand Down

0 comments on commit 709841e

Please sign in to comment.