Skip to content

Commit 0dbda0a

Browse files
Move the operationalInstanceAdded/nodeMayBeAdvertisingOperational bits to concrete device/controller.
These are only used in the concrete case.
1 parent f509f67 commit 0dbda0a

8 files changed

+24
-39
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

-7
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,6 @@ - (void)invalidate
432432
[_delegates removeAllObjects];
433433
}
434434

435-
- (void)nodeMayBeAdvertisingOperational
436-
{
437-
assertChipStackLockedByCurrentThread();
438-
439-
MTR_LOG("%@ saw new operational advertisement", self);
440-
}
441-
442435
- (BOOL)_delegateExists
443436
{
444437
os_unfair_lock_assert_owner(&self->_lock);

src/darwin/Framework/CHIP/MTRDeviceController.mm

-16
Original file line numberDiff line numberDiff line change
@@ -675,22 +675,6 @@ - (void)invalidateCASESessionForNode:(chip::NodeId)nodeID;
675675
[self syncRunOnWorkQueue:block error:nil];
676676
}
677677

678-
- (void)operationalInstanceAdded:(chip::NodeId)nodeID
679-
{
680-
// Don't use deviceForNodeID here, because we don't want to create the
681-
// device if it does not already exist.
682-
os_unfair_lock_lock(self.deviceMapLock);
683-
MTRDevice * device = [_nodeIDToDeviceMap objectForKey:@(nodeID)];
684-
os_unfair_lock_unlock(self.deviceMapLock);
685-
686-
if (device == nil) {
687-
return;
688-
}
689-
690-
ChipLogProgress(Controller, "Notifying device about node 0x" ChipLogFormatX64 " advertising", ChipLogValueX64(nodeID));
691-
[device nodeMayBeAdvertisingOperational];
692-
}
693-
694678
- (void)downloadLogFromNodeWithID:(NSNumber *)nodeID
695679
type:(MTRDiagnosticLogType)type
696680
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
@@ -117,6 +117,12 @@ NS_ASSUME_NONNULL_BEGIN
117117
*/
118118
- (void)directlyGetSessionForNode:(chip::NodeId)nodeID completion:(MTRInternalDeviceConnectionCallback)completion;
119119

120+
/**
121+
* Notify the controller that a new operational instance with the given node id
122+
* and a compressed fabric id that matches this controller has been observed.
123+
*/
124+
- (void)operationalInstanceAdded:(NSNumber *)nodeID;
125+
120126
@end
121127

122128
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)