@@ -395,8 +395,8 @@ @implementation MTRDevice {
395
395
NSMutableSet <MTRClusterPath *> * _persistedClusters;
396
396
397
397
// When we last failed to subscribe to the device (either via
398
- // _setupSubscription or via the auto-resubscribe behavior of the
399
- // ReadClient). Nil if we have had no such failures.
398
+ // _setupSubscriptionWithReason or via the auto-resubscribe behavior
399
+ // of the ReadClient). Nil if we have had no such failures.
400
400
NSDate * _Nullable _lastSubscriptionFailureTime;
401
401
MTRDeviceConnectivityMonitor * _connectivityMonitor;
402
402
@@ -745,10 +745,10 @@ - (void)setDelegate:(id<MTRDeviceDelegate>)delegate queue:(dispatch_queue_t)queu
745
745
if ([self _deviceUsesThread ]) {
746
746
[self _scheduleSubscriptionPoolWork: ^{
747
747
std::lock_guard lock (self->_lock );
748
- [self _setupSubscription ];
748
+ [self _setupSubscriptionWithReason: @" delegate is set and subscription is scheduled " ];
749
749
} inNanoseconds: 0 description: @" MTRDevice setDelegate first subscription" ];
750
750
} else {
751
- [self _setupSubscription ];
751
+ [self _setupSubscriptionWithReason: @" delegate is set and subscription is needed " ];
752
752
}
753
753
}
754
754
}
@@ -788,14 +788,14 @@ - (void)nodeMayBeAdvertisingOperational
788
788
789
789
MTR_LOG (" %@ saw new operational advertisement" , self);
790
790
791
- [self _triggerResubscribeWithReason: " operational advertisement seen"
791
+ [self _triggerResubscribeWithReason: @ " operational advertisement seen"
792
792
nodeLikelyReachable: YES ];
793
793
}
794
794
795
795
// Trigger a resubscribe as needed. nodeLikelyReachable should be YES if we
796
796
// have reason to suspect the node is now reachable, NO if we have no idea
797
797
// whether it might be.
798
- - (void )_triggerResubscribeWithReason : (const char *)reason nodeLikelyReachable : (BOOL )nodeLikelyReachable
798
+ - (void )_triggerResubscribeWithReason : (NSString *)reason nodeLikelyReachable : (BOOL )nodeLikelyReachable
799
799
{
800
800
assertChipStackLockedByCurrentThread ();
801
801
@@ -814,7 +814,7 @@ - (void)_triggerResubscribeWithReason:(const char *)reason nodeLikelyReachable:(
814
814
// establish a CASE session. And at that point, our subscription will
815
815
// trigger the state change as needed.
816
816
if (self.reattemptingSubscription ) {
817
- [self _reattemptSubscriptionNowIfNeeded ];
817
+ [self _reattemptSubscriptionNowIfNeededWithReason: reason ];
818
818
} else {
819
819
readClientToResubscribe = self->_currentReadClient ;
820
820
subscriptionCallback = self->_currentSubscriptionCallback ;
@@ -829,7 +829,7 @@ - (void)_triggerResubscribeWithReason:(const char *)reason nodeLikelyReachable:(
829
829
// here (e.g. still booting up), but should try again reasonably quickly.
830
830
subscriptionCallback->ResetResubscriptionBackoff ();
831
831
}
832
- readClientToResubscribe->TriggerResubscribeIfScheduled (reason);
832
+ readClientToResubscribe->TriggerResubscribeIfScheduled (reason. UTF8String );
833
833
}
834
834
}
835
835
@@ -893,7 +893,7 @@ - (void)_readThroughSkipped
893
893
// ReadClient in there. If the dispatch fails, that's fine; it means our
894
894
// controller has shut down, so nothing to be done.
895
895
[_deviceController asyncDispatchToMatterQueue: ^{
896
- [self _triggerResubscribeWithReason: " read-through skipped while not subscribed" nodeLikelyReachable: NO ];
896
+ [self _triggerResubscribeWithReason: @ " read-through skipped while not subscribed" nodeLikelyReachable: NO ];
897
897
}
898
898
errorHandler: nil ];
899
899
}
@@ -1160,7 +1160,7 @@ - (void)_handleResubscriptionNeededWithDelay:(NSNumber *)resubscriptionDelayMs
1160
1160
// this block is run -- if other triggering events had happened, this would become a no-op.
1161
1161
auto resubscriptionBlock = ^{
1162
1162
[self ->_deviceController asyncDispatchToMatterQueue: ^{
1163
- [self _triggerResubscribeWithReason: " ResubscriptionNeeded timer fired" nodeLikelyReachable: NO ];
1163
+ [self _triggerResubscribeWithReason: @ " ResubscriptionNeeded timer fired" nodeLikelyReachable: NO ];
1164
1164
} errorHandler: ^(NSError * _Nonnull error) {
1165
1165
// If controller is not running, clear work item from the subscription queue
1166
1166
MTR_LOG_ERROR (" %@ could not dispatch to matter queue for resubscription - error %@" , self, error);
@@ -1235,25 +1235,25 @@ - (void)_handleSubscriptionReset:(NSNumber * _Nullable)retryDelay
1235
1235
// If we started subscription or session establishment but failed, remove item from the subscription pool so we can re-queue.
1236
1236
[self _clearSubscriptionPoolWork ];
1237
1237
1238
- // Call _reattemptSubscriptionNowIfNeeded when timer fires - if subscription is
1238
+ // Call _reattemptSubscriptionNowIfNeededWithReason when timer fires - if subscription is
1239
1239
// in a better state at that time this will be a no-op.
1240
1240
auto resubscriptionBlock = ^{
1241
1241
os_unfair_lock_lock (&self->_lock );
1242
- [self _reattemptSubscriptionNowIfNeeded ];
1242
+ [self _reattemptSubscriptionNowIfNeededWithReason: @" got subscription reset " ];
1243
1243
os_unfair_lock_unlock (&self->_lock );
1244
1244
};
1245
1245
1246
1246
int64_t resubscriptionDelayNs = static_cast <int64_t >(secondsToWait * NSEC_PER_SEC);
1247
1247
if ([self _deviceUsesThread ]) {
1248
- // For Thread-enabled devices, schedule the _reattemptSubscriptionNowIfNeeded call to run in the subscription pool
1248
+ // For Thread-enabled devices, schedule the _reattemptSubscriptionNowIfNeededWithReason call to run in the subscription pool
1249
1249
[self _scheduleSubscriptionPoolWork: resubscriptionBlock inNanoseconds: resubscriptionDelayNs description: @" MTRDevice resubscription" ];
1250
1250
} else {
1251
1251
// For non-Thread-enabled devices, just call the resubscription block after the specified time
1252
1252
dispatch_after (dispatch_time (DISPATCH_TIME_NOW, resubscriptionDelayNs), self.queue , resubscriptionBlock);
1253
1253
}
1254
1254
}
1255
1255
1256
- - (void )_reattemptSubscriptionNowIfNeeded
1256
+ - (void )_reattemptSubscriptionNowIfNeededWithReason : ( NSString *) reason
1257
1257
{
1258
1258
os_unfair_lock_assert_owner (&self->_lock );
1259
1259
if (!self.reattemptingSubscription ) {
@@ -1262,7 +1262,7 @@ - (void)_reattemptSubscriptionNowIfNeeded
1262
1262
1263
1263
MTR_LOG (" %@ reattempting subscription" , self);
1264
1264
self.reattemptingSubscription = NO ;
1265
- [self _setupSubscription ];
1265
+ [self _setupSubscriptionWithReason: reason ];
1266
1266
}
1267
1267
1268
1268
- (void )_handleUnsolicitedMessageFromPublisher
@@ -1284,8 +1284,8 @@ - (void)_handleUnsolicitedMessageFromPublisher
1284
1284
// reestablishment, this starts the attempt right away
1285
1285
// TODO: This doesn't really make sense. If we _don't_ have a live
1286
1286
// ReadClient how did we get this notification and if we _do_ have an active
1287
- // ReadClient, this call or _setupSubscription would be no-ops.
1288
- [self _reattemptSubscriptionNowIfNeeded ];
1287
+ // ReadClient, this call or _setupSubscriptionWithReason would be no-ops.
1288
+ [self _reattemptSubscriptionNowIfNeededWithReason: @" got unsolicited message from publisher " ];
1289
1289
}
1290
1290
1291
1291
- (void )_markDeviceAsUnreachableIfNeverSubscribed
@@ -1941,7 +1941,7 @@ - (void)_setupConnectivityMonitoring
1941
1941
self->_connectivityMonitor = [[MTRDeviceConnectivityMonitor alloc ] initWithCompressedFabricID: compressedFabricID nodeID: self .nodeID];
1942
1942
[self ->_connectivityMonitor startMonitoringWithHandler: ^{
1943
1943
[self ->_deviceController asyncDispatchToMatterQueue: ^{
1944
- [self _triggerResubscribeWithReason: " device connectivity changed" nodeLikelyReachable: YES ];
1944
+ [self _triggerResubscribeWithReason: @ " device connectivity changed" nodeLikelyReachable: YES ];
1945
1945
}
1946
1946
errorHandler: nil ];
1947
1947
} queue: self .queue];
@@ -1959,12 +1959,12 @@ - (void)_stopConnectivityMonitoring
1959
1959
}
1960
1960
1961
1961
// assume lock is held
1962
- - (void )_setupSubscription
1962
+ - (void )_setupSubscriptionWithReason : ( NSString *) reason
1963
1963
{
1964
1964
os_unfair_lock_assert_owner (&self->_lock );
1965
1965
1966
1966
if (![self _subscriptionsAllowed ]) {
1967
- MTR_LOG (" _setupSubscription: Subscriptions not allowed. Do not set up subscription" );
1967
+ MTR_LOG (" %@ _setupSubscription: Subscriptions not allowed. Do not set up subscription" , self );
1968
1968
return ;
1969
1969
}
1970
1970
@@ -1986,6 +1986,8 @@ - (void)_setupSubscription
1986
1986
1987
1987
[self _changeInternalState: MTRInternalDeviceStateSubscribing];
1988
1988
1989
+ MTR_LOG (" %@ setting up subscription with reason: %@" , self, reason);
1990
+
1989
1991
// Set up a timer to mark as not reachable if it takes too long to set up a subscription
1990
1992
MTRWeakReference<MTRDevice *> * weakSelf = [MTRWeakReference weakReferenceWithObject: self ];
1991
1993
dispatch_after (dispatch_time (DISPATCH_TIME_NOW, static_cast <int64_t >(kSecondsToWaitBeforeMarkingUnreachableAfterSettingUpSubscription ) * static_cast <int64_t >(NSEC_PER_SEC)), self.queue , ^{
@@ -3512,7 +3514,7 @@ - (void)_deviceMayBeReachable
3512
3514
3513
3515
MTR_LOG (" %@ _deviceMayBeReachable called" , self);
3514
3516
3515
- [self _triggerResubscribeWithReason: " SPI client indicated the device may now be reachable"
3517
+ [self _triggerResubscribeWithReason: @ " SPI client indicated the device may now be reachable"
3516
3518
nodeLikelyReachable: YES ];
3517
3519
}
3518
3520
0 commit comments