Skip to content

Commit

Permalink
Fix, for now, weird subclassing of MTRDevice and MTRDeviceController. (
Browse files Browse the repository at this point in the history
…#35833)

Some of our API consumers are apparently relying on implementation details.
Stop breaking them for now, until they can fix that.
  • Loading branch information
bzbarsky-apple committed Sep 28, 2024
1 parent e754c22 commit 241cec1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@ - (instancetype)initForSubclassesWithNodeID:(NSNumber *)nodeID controller:(MTRDe
return self;
}

// For now, implement an initWithNodeID in case some sub-class outside the
// framework called it (by manually declaring it, even though it's not public
// API). Ideally we would not have this thing, since its signature does not
// match the initWithNodeID signatures of our subclasses.
- (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller
{
return [self initForSubclassesWithNodeID:nodeID controller:controller];
}

- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:_systemTimeChangeObserverToken];
Expand Down
6 changes: 5 additions & 1 deletion src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,11 @@ - (MTRBaseDevice *)baseDeviceForNodeID:(NSNumber *)nodeID
- (MTRDevice *)_setupDeviceForNodeID:(NSNumber *)nodeID prefetchedClusterData:(NSDictionary<MTRClusterPath *, MTRDeviceClusterData *> *)prefetchedClusterData
{
MTR_ABSTRACT_METHOD();
return nil;
// We promise to not return nil from this API... return an MTRDevice
// instance, which will largely not be able to do anything useful. This
// only matters when someone subclasses MTRDeviceController in a weird way,
// then tries to create an MTRDevice from their subclass.
return [[MTRDevice alloc] initForSubclassesWithNodeID:nodeID controller:self];
}

- (MTRDevice *)deviceForNodeID:(NSNumber *)nodeID
Expand Down

0 comments on commit 241cec1

Please sign in to comment.