Skip to content

Commit add0bf1

Browse files
Improve some MTRDeviceController logging. (#35609)
More things should include context about which controller is involved.
1 parent 010ad94 commit add0bf1

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

src/darwin/Framework/CHIP/MTRDeviceControllerDelegateBridge.mm

+14-10
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@
6262

6363
void MTRDeviceControllerDelegateBridge::OnStatusUpdate(chip::Controller::DevicePairingDelegate::Status status)
6464
{
65-
MTR_LOG("DeviceControllerDelegate status updated: %d", status);
65+
MTRDeviceController * strongController = mController;
66+
67+
MTR_LOG("%@ DeviceControllerDelegate status updated: %d", strongController, status);
6668

6769
// If pairing failed, PASE failed. However, since OnPairingComplete(failure_code) might not be invoked in all cases, mark
6870
// end of PASE with timeout as assumed failure. If OnPairingComplete is invoked, the right error code will be updated in
@@ -72,7 +74,6 @@
7274
}
7375

7476
id<MTRDeviceControllerDelegate> strongDelegate = mDelegate;
75-
MTRDeviceController * strongController = mController;
7677
if (strongDelegate && mQueue && strongController) {
7778
if ([strongDelegate respondsToSelector:@selector(controller:statusUpdate:)]) {
7879
MTRCommissioningStatus commissioningStatus = MapStatus(status);
@@ -93,15 +94,16 @@
9394

9495
void MTRDeviceControllerDelegateBridge::OnPairingComplete(CHIP_ERROR error)
9596
{
97+
MTRDeviceController * strongController = mController;
98+
9699
if (error == CHIP_NO_ERROR) {
97-
MTR_LOG("MTRDeviceControllerDelegate PASE session establishment succeeded.");
100+
MTR_LOG("%@ MTRDeviceControllerDelegate PASE session establishment succeeded.", strongController);
98101
} else {
99-
MTR_LOG_ERROR("MTRDeviceControllerDelegate PASE session establishment failed: %" CHIP_ERROR_FORMAT, error.Format());
102+
MTR_LOG_ERROR("%@ MTRDeviceControllerDelegate PASE session establishment failed: %" CHIP_ERROR_FORMAT, strongController, error.Format());
100103
}
101104
MATTER_LOG_METRIC_END(kMetricSetupPASESession, error);
102105

103106
id<MTRDeviceControllerDelegate> strongDelegate = mDelegate;
104-
MTRDeviceController * strongController = mController;
105107
if (strongDelegate && mQueue && strongController) {
106108
if ([strongDelegate respondsToSelector:@selector(controller:commissioningSessionEstablishmentDone:)]) {
107109
dispatch_async(mQueue, ^{
@@ -121,13 +123,14 @@
121123

122124
void MTRDeviceControllerDelegateBridge::OnReadCommissioningInfo(const chip::Controller::ReadCommissioningInfo & info)
123125
{
126+
MTRDeviceController * strongController = mController;
127+
124128
chip::VendorId vendorId = info.basic.vendorId;
125129
uint16_t productId = info.basic.productId;
126130

127-
MTR_LOG("DeviceControllerDelegate Read Commissioning Info. VendorId %u ProductId %u", vendorId, productId);
131+
MTR_LOG("%@ DeviceControllerDelegate Read Commissioning Info. VendorId %u ProductId %u", strongController, vendorId, productId);
128132

129133
id<MTRDeviceControllerDelegate> strongDelegate = mDelegate;
130-
MTRDeviceController * strongController = mController;
131134
if (strongDelegate && mQueue && strongController) {
132135
if ([strongDelegate respondsToSelector:@selector(controller:readCommissioningInfo:)]) {
133136
dispatch_async(mQueue, ^{
@@ -140,16 +143,17 @@
140143

141144
void MTRDeviceControllerDelegateBridge::OnCommissioningComplete(chip::NodeId nodeId, CHIP_ERROR error)
142145
{
143-
MTR_LOG("DeviceControllerDelegate Commissioning complete. NodeId %llu Status %s", nodeId, chip::ErrorStr(error));
146+
MTRDeviceController * strongController = mController;
147+
148+
MTR_LOG("%@ DeviceControllerDelegate Commissioning complete. NodeId 0x%016llx Status %s", strongController, nodeId, chip::ErrorStr(error));
144149
MATTER_LOG_METRIC_END(kMetricDeviceCommissioning, error);
145150

146151
id<MTRDeviceControllerDelegate> strongDelegate = mDelegate;
147-
MTRDeviceController * strongController = mController;
148152
if (strongDelegate && mQueue && strongController) {
149153

150154
// Always collect the metrics to avoid unbounded growth of the stats in the collector
151155
MTRMetrics * metrics = [[MTRMetricsCollector sharedInstance] metricSnapshot:TRUE];
152-
MTR_LOG("Device commissioning complete with metrics %@", metrics);
156+
MTR_LOG("%@ Device commissioning complete with metrics %@", strongController, metrics);
153157

154158
if ([strongDelegate respondsToSelector:@selector(controller:commissioningComplete:nodeID:)] ||
155159
[strongDelegate respondsToSelector:@selector(controller:commissioningComplete:nodeID:metrics:)]) {

src/darwin/Framework/CHIP/MTRDeviceController_Concrete.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ - (BOOL)setupCommissioningSessionWithPayload:(MTRSetupPayload *)payload
832832
return NO;
833833
}
834834

835-
MTR_LOG("Setting up commissioning session for device ID 0x%016llX with setup payload %@", newNodeID.unsignedLongLongValue, payload);
835+
MTR_LOG("%@ Setting up commissioning session for device ID 0x%016llX with setup payload %@", self, newNodeID.unsignedLongLongValue, payload);
836836

837837
[[MTRMetricsCollector sharedInstance] resetMetrics];
838838

src/darwin/Framework/CHIP/ServerEndpoint/MTRServerCluster.mm

+2-2
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ - (BOOL)associateWithController:(nullable MTRDeviceController *)controller
346346

347347
_deviceController = controller;
348348

349-
MTR_LOG("Associated %@, attribute count %llu, with controller", [self _descriptionWhileLocked],
350-
static_cast<unsigned long long>(attributeCount));
349+
MTR_LOG("Associated %@, attribute count %llu, with controller %@", [self _descriptionWhileLocked],
350+
static_cast<unsigned long long>(attributeCount), controller);
351351

352352
return YES;
353353
}

src/darwin/Framework/CHIP/ServerEndpoint/MTRServerEndpoint.mm

+2-2
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ - (BOOL)finishAssociationWithController:(nullable MTRDeviceController *)controll
311311

312312
_deviceController = controller;
313313

314-
MTR_LOG("Associated %@, cluster count %llu, with controller",
315-
self, static_cast<unsigned long long>(clusterCount));
314+
MTR_LOG("Associated %@, cluster count %llu, with controller %@",
315+
self, static_cast<unsigned long long>(clusterCount), controller);
316316

317317
return YES;
318318
}

0 commit comments

Comments
 (0)