Skip to content

Commit

Permalink
Move the operationalInstanceAdded/nodeMayBeAdvertisingOperational bit…
Browse files Browse the repository at this point in the history
…s to concrete device/controller.

These are only used in the concrete case.
  • Loading branch information
bzbarsky-apple committed Sep 26, 2024
1 parent 8323604 commit 1084acb
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 39 deletions.
7 changes: 0 additions & 7 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,6 @@ - (void)invalidate
[_delegates removeAllObjects];
}

- (void)nodeMayBeAdvertisingOperational
{
assertChipStackLockedByCurrentThread();

MTR_LOG("%@ saw new operational advertisement", self);
}

- (BOOL)_delegateExists
{
os_unfair_lock_assert_owner(&self->_lock);
Expand Down
16 changes: 0 additions & 16 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -729,22 +729,6 @@ - (void)invalidateCASESessionForNode:(chip::NodeId)nodeID;
[self syncRunOnWorkQueue:block error:nil];
}

- (void)operationalInstanceAdded:(chip::NodeId)nodeID
{
// Don't use deviceForNodeID here, because we don't want to create the
// device if it does not already exist.
os_unfair_lock_lock(self.deviceMapLock);
MTRDevice * device = [_nodeIDToDeviceMap objectForKey:@(nodeID)];
os_unfair_lock_unlock(self.deviceMapLock);

if (device == nil) {
return;
}

ChipLogProgress(Controller, "Notifying device about node 0x" ChipLogFormatX64 " advertising", ChipLogValueX64(nodeID));
[device nodeMayBeAdvertisingOperational];
}

- (void)downloadLogFromNodeWithID:(NSNumber *)nodeID
type:(MTRDiagnosticLogType)type
timeout:(NSTimeInterval)timeout
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ - (void)operationalInstanceAdded:(chip::PeerId &)operationalID
if (compressedFabricId != nil && compressedFabricId.unsignedLongLongValue == operationalID.GetCompressedFabricId()) {
ChipLogProgress(Controller, "Notifying controller at fabric index %u about new operational node 0x" ChipLogFormatX64,
controller.fabricIndex, ChipLogValueX64(operationalID.GetNodeId()));
[controller operationalInstanceAdded:operationalID.GetNodeId()];
[controller operationalInstanceAdded:@(operationalID.GetNodeId())];
}

// Keep going: more than one controller might match a given compressed
Expand Down
6 changes: 6 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController_Concrete.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)clearPendingShutdown;

/**
* Notify the controller that a new operational instance with the given node id
* and a compressed fabric id that matches this controller has been observed.
*/
- (void)operationalInstanceAdded:(NSNumber *)nodeID;

@end

NS_ASSUME_NONNULL_END
16 changes: 12 additions & 4 deletions src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1633,20 +1633,28 @@ - (void)invalidateCASESessionForNode:(chip::NodeId)nodeID;
[self syncRunOnWorkQueue:block error:nil];
}

- (void)operationalInstanceAdded:(chip::NodeId)nodeID
- (void)operationalInstanceAdded:(NSNumber *)nodeID
{
// Don't use deviceForNodeID here, because we don't want to create the
// device if it does not already exist.
os_unfair_lock_lock(self.deviceMapLock);
MTRDevice * device = [self.nodeIDToDeviceMap objectForKey:@(nodeID)];
MTRDevice * device = [self.nodeIDToDeviceMap objectForKey:nodeID];
os_unfair_lock_unlock(self.deviceMapLock);

if (device == nil) {
return;
}

ChipLogProgress(Controller, "Notifying device about node 0x" ChipLogFormatX64 " advertising", ChipLogValueX64(nodeID));
[device nodeMayBeAdvertisingOperational];
// TODO: Can we not just assume this isKindOfClass test is true? Would be
// really nice if we had compile-time checking for this somehow...
if (![device isKindOfClass:MTRDevice_Concrete.class]) {
MTR_LOG_ERROR("%@ somehow has %@ instead of MTRDevice_Concrete for node ID 0x%016llX (%llu)", self, device, nodeID.unsignedLongLongValue, nodeID.unsignedLongLongValue);
return;
}

MTR_LOG("%@ Notifying %@ about its node advertising", self, device);
auto * concreteDevice = static_cast<MTRDevice_Concrete *>(device);
[concreteDevice nodeMayBeAdvertisingOperational];
}

- (void)downloadLogFromNodeWithID:(NSNumber *)nodeID
Expand Down
6 changes: 0 additions & 6 deletions src/darwin/Framework/CHIP/MTRDeviceController_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (MTRBaseDevice *)baseDeviceForNodeID:(NSNumber *)nodeID;

/**
* Notify the controller that a new operational instance with the given node id
* and a compressed fabric id that matches this controller has been observed.
*/
- (void)operationalInstanceAdded:(chip::NodeId)nodeID;

/**
* Download log of the desired type from the device.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/darwin/Framework/CHIP/MTRDevice_Concrete.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ NS_ASSUME_NONNULL_BEGIN

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

// Called by controller when a new operational advertisement for what we think
// is this device's identity has been observed. This could have
// false-positives, for example due to compressed fabric id collisions.
- (void)nodeMayBeAdvertisingOperational;

@end

NS_ASSUME_NONNULL_END
5 changes: 0 additions & 5 deletions src/darwin/Framework/CHIP/MTRDevice_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ MTR_DIRECT_MEMBERS
// called by controller to clean up and shutdown
- (void)invalidate;

// Called by controller when a new operational advertisement for what we think
// is this device's identity has been observed. This could have
// false-positives, for example due to compressed fabric id collisions.
- (void)nodeMayBeAdvertisingOperational;

- (BOOL)_callDelegatesWithBlock:(void (^)(id<MTRDeviceDelegate> delegate))block;

// Called by MTRDevice_XPC to forward delegate callbacks
Expand Down

0 comments on commit 1084acb

Please sign in to comment.