Skip to content

Commit 485b7dd

Browse files
Move the operationalInstanceAdded/nodeMayBeAdvertisingOperational bits to concrete device/controller. (project-chip#35800)
These are only used in the concrete case.
1 parent 3d43453 commit 485b7dd

8 files changed

+24
-39
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

-7
Original file line numberDiff line numberDiff line change
@@ -452,13 +452,6 @@ - (void)invalidate
452452
[_delegates removeAllObjects];
453453
}
454454

455-
- (void)nodeMayBeAdvertisingOperational
456-
{
457-
assertChipStackLockedByCurrentThread();
458-
459-
MTR_LOG("%@ saw new operational advertisement", self);
460-
}
461-
462455
- (BOOL)_delegateExists
463456
{
464457
os_unfair_lock_assert_owner(&self->_lock);

src/darwin/Framework/CHIP/MTRDeviceController.mm

-16
Original file line numberDiff line numberDiff line change
@@ -679,22 +679,6 @@ - (void)invalidateCASESessionForNode:(chip::NodeId)nodeID;
679679
[self syncRunOnWorkQueue:block error:nil];
680680
}
681681

682-
- (void)operationalInstanceAdded:(chip::NodeId)nodeID
683-
{
684-
// Don't use deviceForNodeID here, because we don't want to create the
685-
// device if it does not already exist.
686-
os_unfair_lock_lock(self.deviceMapLock);
687-
MTRDevice * device = [_nodeIDToDeviceMap objectForKey:@(nodeID)];
688-
os_unfair_lock_unlock(self.deviceMapLock);
689-
690-
if (device == nil) {
691-
return;
692-
}
693-
694-
ChipLogProgress(Controller, "Notifying device about node 0x" ChipLogFormatX64 " advertising", ChipLogValueX64(nodeID));
695-
[device nodeMayBeAdvertisingOperational];
696-
}
697-
698682
- (void)downloadLogFromNodeWithID:(NSNumber *)nodeID
699683
type:(MTRDiagnosticLogType)type
700684
timeout:(NSTimeInterval)timeout

src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ - (void)operationalInstanceAdded:(chip::PeerId &)operationalID
11321132
if (compressedFabricId != nil && compressedFabricId.unsignedLongLongValue == operationalID.GetCompressedFabricId()) {
11331133
ChipLogProgress(Controller, "Notifying controller at fabric index %u about new operational node 0x" ChipLogFormatX64,
11341134
controller.fabricIndex, ChipLogValueX64(operationalID.GetNodeId()));
1135-
[controller operationalInstanceAdded:operationalID.GetNodeId()];
1135+
[controller operationalInstanceAdded:@(operationalID.GetNodeId())];
11361136
}
11371137

11381138
// Keep going: more than one controller might match a given compressed

src/darwin/Framework/CHIP/MTRDeviceController_Concrete.h

+6
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ NS_ASSUME_NONNULL_BEGIN
125125
*/
126126
- (void)directlyGetSessionForNode:(chip::NodeId)nodeID completion:(MTRInternalDeviceConnectionCallback)completion;
127127

128+
/**
129+
* Notify the controller that a new operational instance with the given node id
130+
* and a compressed fabric id that matches this controller has been observed.
131+
*/
132+
- (void)operationalInstanceAdded:(NSNumber *)nodeID;
133+
128134
@end
129135

130136
NS_ASSUME_NONNULL_END

src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm

+12-4
Original file line numberDiff line numberDiff line change
@@ -1633,20 +1633,28 @@ - (void)invalidateCASESessionForNode:(chip::NodeId)nodeID;
16331633
[self syncRunOnWorkQueue:block error:nil];
16341634
}
16351635

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

16441644
if (device == nil) {
16451645
return;
16461646
}
16471647

1648-
ChipLogProgress(Controller, "Notifying device about node 0x" ChipLogFormatX64 " advertising", ChipLogValueX64(nodeID));
1649-
[device nodeMayBeAdvertisingOperational];
1648+
// TODO: Can we not just assume this isKindOfClass test is true? Would be
1649+
// really nice if we had compile-time checking for this somehow...
1650+
if (![device isKindOfClass:MTRDevice_Concrete.class]) {
1651+
MTR_LOG_ERROR("%@ somehow has %@ instead of MTRDevice_Concrete for node ID 0x%016llX (%llu)", self, device, nodeID.unsignedLongLongValue, nodeID.unsignedLongLongValue);
1652+
return;
1653+
}
1654+
1655+
MTR_LOG("%@ Notifying %@ about its node advertising", self, device);
1656+
auto * concreteDevice = static_cast<MTRDevice_Concrete *>(device);
1657+
[concreteDevice nodeMayBeAdvertisingOperational];
16501658
}
16511659

16521660
- (void)downloadLogFromNodeWithID:(NSNumber *)nodeID

src/darwin/Framework/CHIP/MTRDeviceController_Internal.h

-6
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,6 @@ NS_ASSUME_NONNULL_BEGIN
201201
*/
202202
- (MTRBaseDevice *)baseDeviceForNodeID:(NSNumber *)nodeID;
203203

204-
/**
205-
* Notify the controller that a new operational instance with the given node id
206-
* and a compressed fabric id that matches this controller has been observed.
207-
*/
208-
- (void)operationalInstanceAdded:(chip::NodeId)nodeID;
209-
210204
/**
211205
* Download log of the desired type from the device.
212206
*/

src/darwin/Framework/CHIP/MTRDevice_Concrete.h

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ NS_ASSUME_NONNULL_BEGIN
2626

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

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

3136
NS_ASSUME_NONNULL_END

src/darwin/Framework/CHIP/MTRDevice_Internal.h

-5
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,6 @@ MTR_DIRECT_MEMBERS
128128
// called by controller to clean up and shutdown
129129
- (void)invalidate;
130130

131-
// Called by controller when a new operational advertisement for what we think
132-
// is this device's identity has been observed. This could have
133-
// false-positives, for example due to compressed fabric id collisions.
134-
- (void)nodeMayBeAdvertisingOperational;
135-
136131
- (BOOL)_callDelegatesWithBlock:(void (^)(id<MTRDeviceDelegate> delegate))block;
137132

138133
// Called by MTRDevice_XPC to forward delegate callbacks

0 commit comments

Comments
 (0)