Skip to content

Commit f3bba7d

Browse files
bzbarsky-applePeterC1965
authored andcommitted
Make descriptions for MTRDevice clearly say whether it's the XPC version. (project-chip#35112)
This requires hoisting _nodeID and _deviceController ivars clearly into the MTRDevice superclass, so they can be accessed from subclasses. The XPC version does not have a bunch of the state the non-XPC one does, so for now it does not try to log that
1 parent 9fda39a commit f3bba7d

File tree

4 files changed

+19
-80
lines changed

4 files changed

+19
-80
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

-73
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,6 @@ bool HaveSubscriptionEstablishedRightNow(MTRInternalDeviceState state)
173173
return state == MTRInternalDeviceStateInitialSubscriptionEstablished || state == MTRInternalDeviceStateLaterSubscriptionEstablished;
174174
}
175175

176-
NSString * InternalDeviceStateString(MTRInternalDeviceState state)
177-
{
178-
switch (state) {
179-
case MTRInternalDeviceStateUnsubscribed:
180-
return @"Unsubscribed";
181-
case MTRInternalDeviceStateSubscribing:
182-
return @"Subscribing";
183-
case MTRInternalDeviceStateInitialSubscriptionEstablished:
184-
return @"InitialSubscriptionEstablished";
185-
case MTRInternalDeviceStateResubscribing:
186-
return @"Resubscribing";
187-
case MTRInternalDeviceStateLaterSubscriptionEstablished:
188-
return @"LaterSubscriptionEstablished";
189-
default:
190-
return @"Unknown";
191-
}
192-
}
193176
} // anonymous namespace
194177

195178
typedef NS_ENUM(NSUInteger, MTRDeviceExpectedValueFieldIndex) {
@@ -548,62 +531,6 @@ - (void)dealloc
548531
MTR_LOG("MTRDevice dealloc: %p", self);
549532
}
550533

551-
- (NSString *)description
552-
{
553-
id _Nullable vid;
554-
id _Nullable pid;
555-
NSNumber * _Nullable networkFeatures;
556-
MTRInternalDeviceState internalDeviceState;
557-
uint32_t lastSubscriptionAttemptWait;
558-
NSDate * _Nullable mostRecentReportTime;
559-
NSDate * _Nullable lastSubscriptionFailureTime;
560-
{
561-
std::lock_guard lock(_descriptionLock);
562-
vid = _vid;
563-
pid = _pid;
564-
networkFeatures = _allNetworkFeatures;
565-
internalDeviceState = _internalDeviceStateForDescription;
566-
lastSubscriptionAttemptWait = _lastSubscriptionAttemptWaitForDescription;
567-
mostRecentReportTime = _mostRecentReportTimeForDescription;
568-
lastSubscriptionFailureTime = _lastSubscriptionFailureTimeForDescription;
569-
}
570-
571-
if (vid == nil) {
572-
vid = @"Unknown";
573-
}
574-
575-
if (pid == nil) {
576-
pid = @"Unknown";
577-
}
578-
579-
NSString * wifi;
580-
NSString * thread;
581-
if (networkFeatures == nil) {
582-
wifi = @"NO";
583-
thread = @"NO";
584-
} else {
585-
wifi = YES_NO(networkFeatures.unsignedLongLongValue & MTRNetworkCommissioningFeatureWiFiNetworkInterface);
586-
thread = YES_NO(networkFeatures.unsignedLongLongValue & MTRNetworkCommissioningFeatureThreadNetworkInterface);
587-
}
588-
589-
NSString * reportAge;
590-
if (mostRecentReportTime) {
591-
reportAge = [NSString stringWithFormat:@" (%.0lfs ago)", -[mostRecentReportTime timeIntervalSinceNow]];
592-
} else {
593-
reportAge = @"";
594-
}
595-
596-
NSString * subscriptionFailureAge;
597-
if (lastSubscriptionFailureTime) {
598-
subscriptionFailureAge = [NSString stringWithFormat:@" (%.0lfs ago)", -[lastSubscriptionFailureTime timeIntervalSinceNow]];
599-
} else {
600-
subscriptionFailureAge = @"";
601-
}
602-
603-
return [NSString
604-
stringWithFormat:@"<MTRDevice: %p, node: %016llX-%016llX (%llu), VID: %@, PID: %@, WiFi: %@, Thread: %@, state: %@, last subscription attempt wait: %lus, queued work: %lu, last report: %@%@, last subscription failure: %@%@, controller: %@>", self, _deviceController.compressedFabricID.unsignedLongLongValue, _nodeID.unsignedLongLongValue, _nodeID.unsignedLongLongValue, vid, pid, wifi, thread, InternalDeviceStateString(internalDeviceState), static_cast<unsigned long>(lastSubscriptionAttemptWait), static_cast<unsigned long>(_asyncWorkQueue.itemCount), mostRecentReportTime, reportAge, lastSubscriptionFailureTime, subscriptionFailureAge, _deviceController.uniqueIdentifier];
605-
}
606-
607534
+ (MTRDevice *)deviceWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller
608535
{
609536
return [controller deviceForNodeID:nodeID];

src/darwin/Framework/CHIP/MTRDevice_Concrete.mm

+1-7
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@
5858
// allow readwrite access to superclass properties
5959
@interface MTRDevice_Concrete ()
6060

61-
@property (nonatomic, readwrite, copy) NSNumber * nodeID;
62-
@property (nonatomic, readwrite, nullable) MTRDeviceController * deviceController;
6361
@property (nonatomic, readwrite) MTRAsyncWorkQueue<MTRDevice *> * asyncWorkQueue;
6462
@property (nonatomic, readwrite) MTRDeviceState state;
6563
@property (nonatomic, readwrite, nullable) NSDate * estimatedStartTime;
@@ -356,8 +354,6 @@ @implementation MTRDevice_Concrete {
356354
}
357355

358356
// synthesize superclass property readwrite accessors
359-
@synthesize nodeID = _nodeID;
360-
@synthesize deviceController = _deviceController;
361357
@synthesize queue = _queue;
362358
@synthesize asyncWorkQueue = _asyncWorkQueue;
363359
@synthesize state = _state;
@@ -372,9 +368,7 @@ - (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceControlle
372368
if (self = [super initForSubclassesWithNodeID:nodeID controller:controller]) {
373369
_timeSyncLock = OS_UNFAIR_LOCK_INIT;
374370
_descriptionLock = OS_UNFAIR_LOCK_INIT;
375-
_nodeID = [nodeID copy];
376371
_fabricIndex = controller.fabricIndex;
377-
_deviceController = controller;
378372
_queue
379373
= dispatch_queue_create("org.csa-iot.matter.framework.device.workqueue", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL);
380374
_expectedValueCache = [NSMutableDictionary dictionary];
@@ -467,7 +461,7 @@ - (NSString *)description
467461
}
468462

469463
return [NSString
470-
stringWithFormat:@"<MTRDevice: %p, node: %016llX-%016llX (%llu), VID: %@, PID: %@, WiFi: %@, Thread: %@, state: %@, last subscription attempt wait: %lus, queued work: %lu, last report: %@%@, last subscription failure: %@%@, controller: %@>", self, _deviceController.compressedFabricID.unsignedLongLongValue, _nodeID.unsignedLongLongValue, _nodeID.unsignedLongLongValue, vid, pid, wifi, thread, InternalDeviceStateString(internalDeviceState), static_cast<unsigned long>(lastSubscriptionAttemptWait), static_cast<unsigned long>(_asyncWorkQueue.itemCount), mostRecentReportTime, reportAge, lastSubscriptionFailureTime, subscriptionFailureAge, _deviceController.uniqueIdentifier];
464+
stringWithFormat:@"<MTRDevice: %p, XPC: NO, node: %016llX-%016llX (%llu), VID: %@, PID: %@, WiFi: %@, Thread: %@, state: %@, last subscription attempt wait: %lus, queued work: %lu, last report: %@%@, last subscription failure: %@%@, controller: %@>", self, _deviceController.compressedFabricID.unsignedLongLongValue, _nodeID.unsignedLongLongValue, _nodeID.unsignedLongLongValue, vid, pid, wifi, thread, InternalDeviceStateString(internalDeviceState), static_cast<unsigned long>(lastSubscriptionAttemptWait), static_cast<unsigned long>(_asyncWorkQueue.itemCount), mostRecentReportTime, reportAge, lastSubscriptionFailureTime, subscriptionFailureAge, _deviceController.uniqueIdentifier];
471465
}
472466

473467
+ (MTRDevice *)deviceWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller

src/darwin/Framework/CHIP/MTRDevice_Internal.h

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ MTR_DIRECT_MEMBERS
112112
// Lock that protects overall device state, including delegate storage.
113113
os_unfair_lock _lock;
114114
NSMutableSet<MTRDeviceDelegateInfo *> * _delegates;
115+
116+
// Our node ID, with the ivar declared explicitly so it's accessible to
117+
// subclasses.
118+
NSNumber * _nodeID;
119+
120+
// Our controller. Declared nullable because our property is, though in
121+
// practice it does not look like we ever set it to nil.
122+
MTRDeviceController * _Nullable _deviceController;
115123
}
116124

117125
- (instancetype)initForSubclassesWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller;

src/darwin/Framework/CHIP/MTRDevice_XPC.mm

+10
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ - (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceControlle
9393
return self;
9494
}
9595

96+
- (NSString *)description
97+
{
98+
// TODO: Figure out whether, and if so how, to log: VID, PID, WiFi, Thread,
99+
// internalDeviceState (do we even have such a thing here?), last
100+
// subscription attempt wait (does that apply to us?) queued work (do we
101+
// have any?), last report, last subscription failure (does that apply to us?).
102+
return [NSString
103+
stringWithFormat:@"<MTRDevice: %p, XPC: YES, node: %016llX-%016llX (%llu), controller: %@>", self, _deviceController.compressedFabricID.unsignedLongLongValue, _nodeID.unsignedLongLongValue, _nodeID.unsignedLongLongValue, _deviceController.uniqueIdentifier];
104+
}
105+
96106
#pragma mark - Client Callbacks (MTRDeviceDelegate)
97107

98108
// required methods for MTRDeviceDelegates

0 commit comments

Comments
 (0)