@@ -284,6 +284,8 @@ - (void)invalidate
284
284
285
285
os_unfair_lock_lock (&self->_lock );
286
286
287
+ _state = MTRDeviceStateUnknown;
288
+
287
289
_weakDelegate = nil ;
288
290
289
291
// Make sure we don't try to resubscribe if we have a pending resubscribe
@@ -343,20 +345,23 @@ - (void)_changeState:(MTRDeviceState)state
343
345
_state = state;
344
346
if (lastState != state) {
345
347
if (state != MTRDeviceStateReachable) {
346
- MTR_LOG_INFO (" %@ State change %lu => %lu, set estimated start time to nil" , self, static_cast <unsigned long >(lastState),
348
+ MTR_LOG_INFO (" %@ reachability state change %lu => %lu, set estimated start time to nil" , self, static_cast <unsigned long >(lastState),
347
349
static_cast <unsigned long >(state));
348
350
_estimatedStartTime = nil ;
349
351
_estimatedStartTimeFromGeneralDiagnosticsUpTime = nil ;
350
352
} else {
351
353
MTR_LOG_INFO (
352
- " %@ State change %lu => %lu" , self, static_cast <unsigned long >(lastState), static_cast <unsigned long >(state));
354
+ " %@ reachability state change %lu => %lu" , self, static_cast <unsigned long >(lastState), static_cast <unsigned long >(state));
353
355
}
354
356
id <MTRDeviceDelegate> delegate = _weakDelegate.strongObject ;
355
357
if (delegate) {
356
358
dispatch_async (_delegateQueue, ^{
357
359
[delegate device: self stateChanged: state];
358
360
});
359
361
}
362
+ } else {
363
+ MTR_LOG_INFO (
364
+ " %@ Not reporting reachability state change, since no change in state %lu => %lu" , self, static_cast <unsigned long >(lastState), static_cast <unsigned long >(state));
360
365
}
361
366
}
362
367
@@ -592,14 +597,14 @@ - (void)_handleEventReport:(NSArray<NSDictionary<NSString *, id> *> *)eventRepor
592
597
// If event time is of MTREventTimeTypeSystemUpTime type, then update estimated start time as needed
593
598
NSNumber * eventTimeTypeNumber = eventDict[MTREventTimeTypeKey];
594
599
if (!eventTimeTypeNumber) {
595
- MTR_LOG_ERROR (" Event %@ missing event time type" , eventDict);
600
+ MTR_LOG_ERROR (" %@ Event %@ missing event time type" , self , eventDict);
596
601
continue ;
597
602
}
598
603
MTREventTimeType eventTimeType = (MTREventTimeType) eventTimeTypeNumber.unsignedIntegerValue ;
599
604
if (eventTimeType == MTREventTimeTypeSystemUpTime) {
600
605
NSNumber * eventTimeValueNumber = eventDict[MTREventSystemUpTimeKey];
601
606
if (!eventTimeValueNumber) {
602
- MTR_LOG_ERROR (" Event %@ missing event time value" , eventDict);
607
+ MTR_LOG_ERROR (" %@ Event %@ missing event time value" , self , eventDict);
603
608
continue ;
604
609
}
605
610
NSTimeInterval eventTimeValue = eventTimeValueNumber.doubleValue ;
@@ -792,7 +797,7 @@ - (void)_setupSubscription
792
797
CHIP_ERROR err = readClient->SendAutoResubscribeRequest (std::move (readParams));
793
798
794
799
if (err != CHIP_NO_ERROR) {
795
- NSError * error = [MTRError errorForCHIPErrorCode: err];
800
+ NSError * error = [MTRError errorForCHIPErrorCode: err logContext: self ];
796
801
MTR_LOG_ERROR (" %@ SendAutoResubscribeRequest error %@" , self, error);
797
802
dispatch_async (self.queue , ^{
798
803
[self _handleSubscriptionError: error];
@@ -982,6 +987,8 @@ static BOOL AttributeHasChangesOmittedQuality(MTRAttributePath * attributePath)
982
987
// Create work item, set ready handler to perform task, then enqueue the work
983
988
MTRAsyncWorkItem * workItem = [[MTRAsyncWorkItem alloc ] initWithQueue: self .queue];
984
989
uint64_t workItemID = workItem.uniqueID ; // capture only the ID, not the work item
990
+ NSNumber * nodeID = [self nodeID ];
991
+
985
992
[workItem setBatchingID: MTRDeviceWorkItemBatchingReadID data: readRequests handler: ^(id opaqueDataCurrent, id opaqueDataNext) {
986
993
mtr_hide (self); // don't capture self accidentally
987
994
NSMutableArray <NSArray *> * readRequestsCurrent = opaqueDataCurrent;
@@ -991,23 +998,23 @@ static BOOL AttributeHasChangesOmittedQuality(MTRAttributePath * attributePath)
991
998
while (readRequestsNext.count ) {
992
999
// Can only read up to 9 paths at a time, per spec
993
1000
if (readRequestsCurrent.count >= 9 ) {
994
- MTR_LOG_INFO (" Batching read attribute work item [%llu]: cannot add more work, item is full" , workItemID);
1001
+ MTR_LOG_INFO (" Batching read attribute work item [%llu]: cannot add more work, item is full [%@:%@:%@:%@] " , workItemID, nodeID, endpointID, clusterID, attributeID );
995
1002
return outcome;
996
1003
}
997
1004
998
1005
// if params don't match then they cannot be merged
999
1006
if (![readRequestsNext[0 ][MTRDeviceReadRequestFieldParamsIndex]
1000
1007
isEqual: readRequestsCurrent[0 ][MTRDeviceReadRequestFieldParamsIndex]]) {
1001
- MTR_LOG_INFO (" Batching read attribute work item [%llu]: cannot add more work, parameter mismatch" , workItemID);
1008
+ MTR_LOG_INFO (" Batching read attribute work item [%llu]: cannot add more work, parameter mismatch [%@:%@:%@:%@] " , workItemID, nodeID, endpointID, clusterID, attributeID );
1002
1009
return outcome;
1003
1010
}
1004
1011
1005
1012
// merge the next item's first request into the current item's list
1006
1013
auto readItem = readRequestsNext.firstObject ;
1007
1014
[readRequestsNext removeObjectAtIndex: 0 ];
1008
1015
[readRequestsCurrent addObject: readItem];
1009
- MTR_LOG_INFO (" Batching read attribute work item [%llu]: added %@ (now %tu requests total)" ,
1010
- workItemID, readItem, readRequestsCurrent.count );
1016
+ MTR_LOG_INFO (" Batching read attribute work item [%llu]: added %@ (now %tu requests total) [%@:%@:%@:%@] " ,
1017
+ workItemID, readItem, readRequestsCurrent.count , nodeID, endpointID, clusterID, attributeID );
1011
1018
outcome = MTRBatchedPartially;
1012
1019
}
1013
1020
NSCAssert (readRequestsNext.count == 0 , @" should have batched everything or returned early" );
@@ -1017,7 +1024,7 @@ static BOOL AttributeHasChangesOmittedQuality(MTRAttributePath * attributePath)
1017
1024
mtr_hide (self); // don't capture self accidentally
1018
1025
for (NSArray * readItem in readRequests) {
1019
1026
if ([readItem isEqual: opaqueItemData]) {
1020
- MTR_LOG_DEFAULT (" Read attribute work item [%llu] report duplicate %@" , workItemID, readItem);
1027
+ MTR_LOG_DEFAULT (" Read attribute work item [%llu] report duplicate %@ [%@:%@:%@:%@] " , workItemID, readItem, nodeID, endpointID, clusterID, attributeID );
1021
1028
*isDuplicate = YES ;
1022
1029
*stop = YES ;
1023
1030
return ;
@@ -1053,23 +1060,23 @@ static BOOL AttributeHasChangesOmittedQuality(MTRAttributePath * attributePath)
1053
1060
if (values) {
1054
1061
// Since the format is the same data-value dictionary, this looks like an
1055
1062
// attribute report
1056
- MTR_LOG_INFO (" Read attribute work item [%llu] result: %@" , workItemID, values);
1063
+ MTR_LOG_INFO (" Read attribute work item [%llu] result: %@ [%@:%@:%@:%@] " , workItemID, values, nodeID, endpointID, clusterID, attributeID );
1057
1064
[self _handleAttributeReport: values];
1058
1065
}
1059
1066
1060
1067
// TODO: better retry logic
1061
1068
if (error && (retryCount < 2 )) {
1062
- MTR_LOG_ERROR (" Read attribute work item [%llu] failed (will retry): %@" , workItemID, error);
1069
+ MTR_LOG_ERROR (" Read attribute work item [%llu] failed (will retry): %@ [%@:%@:%@:%@] " , workItemID, error, nodeID, endpointID, clusterID, attributeID );
1063
1070
completion (MTRAsyncWorkNeedsRetry);
1064
1071
} else {
1065
1072
if (error) {
1066
- MTR_LOG_DEFAULT (" Read attribute work item [%llu] failed (giving up): %@" , workItemID, error);
1073
+ MTR_LOG_DEFAULT (" Read attribute work item [%llu] failed (giving up): %@ [%@:%@:%@:%@] " , workItemID, error, nodeID, endpointID, clusterID, attributeID );
1067
1074
}
1068
1075
completion (MTRAsyncWorkComplete);
1069
1076
}
1070
1077
}];
1071
1078
}];
1072
- [_asyncWorkQueue enqueueWorkItem: workItem descriptionWithFormat: @" read %@ %@ %@ " , endpointID, clusterID, attributeID];
1079
+ [_asyncWorkQueue enqueueWorkItem: workItem descriptionWithFormat: @" read %@ %@ %@ %@ " , self .nodeID , endpointID, clusterID, attributeID];
1073
1080
}
1074
1081
1075
1082
return attributeValueToReturn;
@@ -1137,7 +1144,7 @@ - (void)writeAttributeWithEndpointID:(NSNumber *)endpointID
1137
1144
completion (MTRAsyncWorkComplete);
1138
1145
}];
1139
1146
}];
1140
- [_asyncWorkQueue enqueueWorkItem: workItem descriptionWithFormat: @" write %@ %@ %@ " , endpointID, clusterID, attributeID];
1147
+ [_asyncWorkQueue enqueueWorkItem: workItem descriptionWithFormat: @" write %@ %@ %@ %@ " , self .nodeID , endpointID, clusterID, attributeID];
1141
1148
}
1142
1149
1143
1150
- (void )invokeCommandWithEndpointID : (NSNumber *)endpointID
@@ -1739,7 +1746,7 @@ - (void)setExpectedValues:(NSArray<NSDictionary<NSString *, id> *> *)values
1739
1746
NSDate * expirationTime = [NSDate dateWithTimeIntervalSinceNow: expectedValueInterval.doubleValue / 1000 ];
1740
1747
1741
1748
MTR_LOG_INFO (
1742
- " Setting expected values %@ with expiration time %f seconds from now" , values, [expirationTime timeIntervalSinceNow ]);
1749
+ " %@ Setting expected values %@ with expiration time %f seconds from now" , self , values, [expirationTime timeIntervalSinceNow ]);
1743
1750
1744
1751
os_unfair_lock_lock (&self->_lock );
1745
1752
0 commit comments