Skip to content

Commit a95c3d5

Browse files
authored
Darwin changes for logging (#32053)
1 parent 67f2ae5 commit a95c3d5

9 files changed

+65
-53
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

+23-16
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ - (void)invalidate
284284

285285
os_unfair_lock_lock(&self->_lock);
286286

287+
_state = MTRDeviceStateUnknown;
288+
287289
_weakDelegate = nil;
288290

289291
// Make sure we don't try to resubscribe if we have a pending resubscribe
@@ -343,20 +345,23 @@ - (void)_changeState:(MTRDeviceState)state
343345
_state = state;
344346
if (lastState != state) {
345347
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),
347349
static_cast<unsigned long>(state));
348350
_estimatedStartTime = nil;
349351
_estimatedStartTimeFromGeneralDiagnosticsUpTime = nil;
350352
} else {
351353
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));
353355
}
354356
id<MTRDeviceDelegate> delegate = _weakDelegate.strongObject;
355357
if (delegate) {
356358
dispatch_async(_delegateQueue, ^{
357359
[delegate device:self stateChanged:state];
358360
});
359361
}
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));
360365
}
361366
}
362367

@@ -592,14 +597,14 @@ - (void)_handleEventReport:(NSArray<NSDictionary<NSString *, id> *> *)eventRepor
592597
// If event time is of MTREventTimeTypeSystemUpTime type, then update estimated start time as needed
593598
NSNumber * eventTimeTypeNumber = eventDict[MTREventTimeTypeKey];
594599
if (!eventTimeTypeNumber) {
595-
MTR_LOG_ERROR("Event %@ missing event time type", eventDict);
600+
MTR_LOG_ERROR("%@ Event %@ missing event time type", self, eventDict);
596601
continue;
597602
}
598603
MTREventTimeType eventTimeType = (MTREventTimeType) eventTimeTypeNumber.unsignedIntegerValue;
599604
if (eventTimeType == MTREventTimeTypeSystemUpTime) {
600605
NSNumber * eventTimeValueNumber = eventDict[MTREventSystemUpTimeKey];
601606
if (!eventTimeValueNumber) {
602-
MTR_LOG_ERROR("Event %@ missing event time value", eventDict);
607+
MTR_LOG_ERROR("%@ Event %@ missing event time value", self, eventDict);
603608
continue;
604609
}
605610
NSTimeInterval eventTimeValue = eventTimeValueNumber.doubleValue;
@@ -792,7 +797,7 @@ - (void)_setupSubscription
792797
CHIP_ERROR err = readClient->SendAutoResubscribeRequest(std::move(readParams));
793798

794799
if (err != CHIP_NO_ERROR) {
795-
NSError * error = [MTRError errorForCHIPErrorCode:err];
800+
NSError * error = [MTRError errorForCHIPErrorCode:err logContext:self];
796801
MTR_LOG_ERROR("%@ SendAutoResubscribeRequest error %@", self, error);
797802
dispatch_async(self.queue, ^{
798803
[self _handleSubscriptionError:error];
@@ -982,6 +987,8 @@ static BOOL AttributeHasChangesOmittedQuality(MTRAttributePath * attributePath)
982987
// Create work item, set ready handler to perform task, then enqueue the work
983988
MTRAsyncWorkItem * workItem = [[MTRAsyncWorkItem alloc] initWithQueue:self.queue];
984989
uint64_t workItemID = workItem.uniqueID; // capture only the ID, not the work item
990+
NSNumber * nodeID = [self nodeID];
991+
985992
[workItem setBatchingID:MTRDeviceWorkItemBatchingReadID data:readRequests handler:^(id opaqueDataCurrent, id opaqueDataNext) {
986993
mtr_hide(self); // don't capture self accidentally
987994
NSMutableArray<NSArray *> * readRequestsCurrent = opaqueDataCurrent;
@@ -991,23 +998,23 @@ static BOOL AttributeHasChangesOmittedQuality(MTRAttributePath * attributePath)
991998
while (readRequestsNext.count) {
992999
// Can only read up to 9 paths at a time, per spec
9931000
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);
9951002
return outcome;
9961003
}
9971004

9981005
// if params don't match then they cannot be merged
9991006
if (![readRequestsNext[0][MTRDeviceReadRequestFieldParamsIndex]
10001007
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);
10021009
return outcome;
10031010
}
10041011

10051012
// merge the next item's first request into the current item's list
10061013
auto readItem = readRequestsNext.firstObject;
10071014
[readRequestsNext removeObjectAtIndex:0];
10081015
[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);
10111018
outcome = MTRBatchedPartially;
10121019
}
10131020
NSCAssert(readRequestsNext.count == 0, @"should have batched everything or returned early");
@@ -1017,7 +1024,7 @@ static BOOL AttributeHasChangesOmittedQuality(MTRAttributePath * attributePath)
10171024
mtr_hide(self); // don't capture self accidentally
10181025
for (NSArray * readItem in readRequests) {
10191026
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);
10211028
*isDuplicate = YES;
10221029
*stop = YES;
10231030
return;
@@ -1053,23 +1060,23 @@ static BOOL AttributeHasChangesOmittedQuality(MTRAttributePath * attributePath)
10531060
if (values) {
10541061
// Since the format is the same data-value dictionary, this looks like an
10551062
// 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);
10571064
[self _handleAttributeReport:values];
10581065
}
10591066

10601067
// TODO: better retry logic
10611068
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);
10631070
completion(MTRAsyncWorkNeedsRetry);
10641071
} else {
10651072
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);
10671074
}
10681075
completion(MTRAsyncWorkComplete);
10691076
}
10701077
}];
10711078
}];
1072-
[_asyncWorkQueue enqueueWorkItem:workItem descriptionWithFormat:@"read %@ %@ %@", endpointID, clusterID, attributeID];
1079+
[_asyncWorkQueue enqueueWorkItem:workItem descriptionWithFormat:@"read %@ %@ %@ %@", self.nodeID, endpointID, clusterID, attributeID];
10731080
}
10741081

10751082
return attributeValueToReturn;
@@ -1137,7 +1144,7 @@ - (void)writeAttributeWithEndpointID:(NSNumber *)endpointID
11371144
completion(MTRAsyncWorkComplete);
11381145
}];
11391146
}];
1140-
[_asyncWorkQueue enqueueWorkItem:workItem descriptionWithFormat:@"write %@ %@ %@", endpointID, clusterID, attributeID];
1147+
[_asyncWorkQueue enqueueWorkItem:workItem descriptionWithFormat:@"write %@ %@ %@ %@", self.nodeID, endpointID, clusterID, attributeID];
11411148
}
11421149

11431150
- (void)invokeCommandWithEndpointID:(NSNumber *)endpointID
@@ -1739,7 +1746,7 @@ - (void)setExpectedValues:(NSArray<NSDictionary<NSString *, id> *> *)values
17391746
NSDate * expirationTime = [NSDate dateWithTimeIntervalSinceNow:expectedValueInterval.doubleValue / 1000];
17401747

17411748
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]);
17431750

17441751
os_unfair_lock_lock(&self->_lock);
17451752

src/darwin/Framework/CHIP/MTRError.h

+27-25
Original file line numberDiff line numberDiff line change
@@ -104,31 +104,33 @@ typedef NS_ERROR_ENUM(MTRErrorDomain, MTRErrorCode){
104104
typedef NS_ERROR_ENUM(MTRInteractionErrorDomain, MTRInteractionErrorCode){
105105
// These values come from the general status code table in the Matter
106106
// Interaction Model specification.
107-
MTRInteractionErrorCodeFailure = 0x01,
108-
MTRInteractionErrorCodeInvalidSubscription = 0x7d,
109-
MTRInteractionErrorCodeUnsupportedAccess = 0x7e,
110-
MTRInteractionErrorCodeUnsupportedEndpoint = 0x7f,
111-
MTRInteractionErrorCodeInvalidAction = 0x80,
112-
MTRInteractionErrorCodeUnsupportedCommand = 0x81,
113-
MTRInteractionErrorCodeInvalidCommand = 0x85,
114-
MTRInteractionErrorCodeUnsupportedAttribute = 0x86,
115-
MTRInteractionErrorCodeConstraintError = 0x87,
116-
MTRInteractionErrorCodeUnsupportedWrite = 0x88,
117-
MTRInteractionErrorCodeResourceExhausted = 0x89,
118-
MTRInteractionErrorCodeNotFound = 0x8b,
119-
MTRInteractionErrorCodeUnreportableAttribute = 0x8c,
120-
MTRInteractionErrorCodeInvalidDataType = 0x8d,
121-
MTRInteractionErrorCodeUnsupportedRead = 0x8f,
122-
MTRInteractionErrorCodeDataVersionMismatch = 0x92,
123-
MTRInteractionErrorCodeTimeout = 0x94,
124-
MTRInteractionErrorCodeBusy = 0x9c,
125-
MTRInteractionErrorCodeUnsupportedCluster = 0xc3,
126-
MTRInteractionErrorCodeNoUpstreamSubscription = 0xc5,
127-
MTRInteractionErrorCodeNeedsTimedInteraction = 0xc6,
128-
MTRInteractionErrorCodeUnsupportedEvent = 0xc7,
129-
MTRInteractionErrorCodePathsExhausted = 0xc8,
130-
MTRInteractionErrorCodeTimedRequestMismatch = 0xc9,
131-
MTRInteractionErrorCodeFailsafeRequired = 0xca,
107+
MTRInteractionErrorCodeFailure = 0x01,
108+
MTRInteractionErrorCodeInvalidSubscription = 0x7d,
109+
MTRInteractionErrorCodeUnsupportedAccess = 0x7e,
110+
MTRInteractionErrorCodeUnsupportedEndpoint = 0x7f,
111+
MTRInteractionErrorCodeInvalidAction = 0x80,
112+
MTRInteractionErrorCodeUnsupportedCommand = 0x81,
113+
MTRInteractionErrorCodeInvalidCommand = 0x85,
114+
MTRInteractionErrorCodeUnsupportedAttribute = 0x86,
115+
MTRInteractionErrorCodeConstraintError = 0x87,
116+
MTRInteractionErrorCodeUnsupportedWrite = 0x88,
117+
MTRInteractionErrorCodeResourceExhausted = 0x89,
118+
MTRInteractionErrorCodeNotFound = 0x8b,
119+
MTRInteractionErrorCodeUnreportableAttribute = 0x8c,
120+
MTRInteractionErrorCodeInvalidDataType = 0x8d,
121+
MTRInteractionErrorCodeUnsupportedRead = 0x8f,
122+
MTRInteractionErrorCodeDataVersionMismatch = 0x92,
123+
MTRInteractionErrorCodeTimeout = 0x94,
124+
MTRInteractionErrorCodeBusy = 0x9c,
125+
MTRInteractionErrorCodeUnsupportedCluster = 0xc3,
126+
MTRInteractionErrorCodeNoUpstreamSubscription = 0xc5,
127+
MTRInteractionErrorCodeNeedsTimedInteraction = 0xc6,
128+
MTRInteractionErrorCodeUnsupportedEvent = 0xc7,
129+
MTRInteractionErrorCodePathsExhausted = 0xc8,
130+
MTRInteractionErrorCodeTimedRequestMismatch = 0xc9,
131+
MTRInteractionErrorCodeFailsafeRequired = 0xca,
132+
MTRInteractionErrorInvalidInState MTR_NEWLY_AVAILABLE = 0xcb,
133+
MTRInteractionErrorNoCommandResponse MTR_NEWLY_AVAILABLE = 0xcc,
132134
};
133135
// clang-format on
134136

src/darwin/Framework/CHIP/MTRError.mm

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,17 @@ - (instancetype)initWithError:(CHIP_ERROR)error;
4444
@implementation MTRError
4545

4646
+ (NSError *)errorForCHIPErrorCode:(CHIP_ERROR)errorCode
47+
{
48+
return [MTRError errorForCHIPErrorCode:errorCode logContext:nil];
49+
}
50+
51+
+ (NSError *)errorForCHIPErrorCode:(CHIP_ERROR)errorCode logContext:(id)contextToLog
4752
{
4853
if (errorCode == CHIP_NO_ERROR) {
4954
return nil;
5055
}
5156

52-
ChipLogError(Controller, "Creating NSError from %" CHIP_ERROR_FORMAT, errorCode.Format());
57+
ChipLogError(Controller, "Creating NSError from %" CHIP_ERROR_FORMAT " (context: %@)", errorCode.Format(), contextToLog);
5358

5459
if (errorCode.IsIMStatus()) {
5560
chip::app::StatusIB status(errorCode);

src/darwin/Framework/CHIP/MTRError_Internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ NS_ASSUME_NONNULL_BEGIN
2727

2828
@interface MTRError : NSObject
2929
+ (NSError * _Nullable)errorForCHIPErrorCode:(CHIP_ERROR)errorCode;
30+
+ (NSError * _Nullable)errorForCHIPErrorCode:(CHIP_ERROR)errorCode logContext:(id _Nullable)contextToLog;
3031
+ (NSError * _Nullable)errorForIMStatus:(const chip::app::StatusIB &)status;
3132
+ (NSError * _Nullable)errorForIMStatusCode:(chip::Protocols::InteractionModel::Status)status;
3233
+ (CHIP_ERROR)errorToCHIPErrorCode:(NSError * _Nullable)error;

src/darwin/Framework/CHIP/MTRSetupPayload.mm

+4-4
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ + (MTRSetupPayload * _Nullable)setupPayloadWithOnboardingPayload:(NSString *)onb
235235

236236
if (!validPayload) {
237237
if (error) {
238-
*error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INVALID_ARGUMENT];
238+
*error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INVALID_ARGUMENT logContext:onboardingPayload];
239239
}
240240
return nil;
241241
}
@@ -336,23 +336,23 @@ - (NSString * _Nullable)qrCodeString:(NSError * __autoreleasing *)error
336336
if (self.commissioningFlow == MTRCommissioningFlowInvalid) {
337337
// No idea how to map this to the standard codes.
338338
if (error != nil) {
339-
*error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE];
339+
*error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE logContext:@"invalid flow"];
340340
}
341341
return nil;
342342
}
343343

344344
if (self.hasShortDiscriminator) {
345345
// Can't create a QR code with a short discriminator.
346346
if (error != nil) {
347-
*error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE];
347+
*error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE logContext:@"cannot create a QR code with a short descrimintor"];
348348
}
349349
return nil;
350350
}
351351

352352
if (self.discoveryCapabilities == MTRDiscoveryCapabilitiesUnknown) {
353353
// Can't create a QR code if we don't know the discovery capabilities.
354354
if (error != nil) {
355-
*error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE];
355+
*error = [MTRError errorForCHIPErrorCode:CHIP_ERROR_INCORRECT_STATE logContext:@"cannot create a QR code with unknown discovery capabilities"];
356356
}
357357
return nil;
358358
}

src/darwin/Framework/Matter.xcodeproj/project.pbxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@
16481648
isa = PBXProject;
16491649
attributes = {
16501650
BuildIndependentTargetsInParallel = YES;
1651-
LastUpgradeCheck = 1140;
1651+
LastUpgradeCheck = 1500;
16521652
ORGANIZATIONNAME = CHIP;
16531653
TargetAttributes = {
16541654
037C3CA42991A44B00B7EEE2 = {

src/darwin/Framework/Matter.xcodeproj/xcshareddata/xcschemes/Matter Framework Tests.xcscheme

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1200"
3+
LastUpgradeVersion = "1500"
44
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -38,8 +38,6 @@
3838
BlueprintName = "MatterTests"
3939
ReferencedContainer = "container:Matter.xcodeproj">
4040
</BuildableReference>
41-
<SkippedTests>
42-
</SkippedTests>
4341
</TestableReference>
4442
</Testables>
4543
</TestAction>

src/darwin/Framework/Matter.xcodeproj/xcshareddata/xcschemes/Matter Framework.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1200"
3+
LastUpgradeVersion = "1500"
44
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"

src/darwin/Framework/Matter.xcodeproj/xcshareddata/xcschemes/darwin-framework-tool.xcscheme

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1410"
3+
LastUpgradeVersion = "1500"
44
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -38,7 +38,6 @@
3838
useCustomWorkingDirectory = "NO"
3939
ignoresPersistentStateOnLaunch = "NO"
4040
debugDocumentVersioning = "YES"
41-
debugServiceExtension = ""
4241
allowLocationSimulation = "YES"
4342
viewDebuggingEnabled = "No">
4443
<BuildableProductRunnable

0 commit comments

Comments
 (0)