Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make descriptions for MTRDevice clearly say whether it's the XPC version. #35112

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 2 additions & 73 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,6 @@ bool HaveSubscriptionEstablishedRightNow(MTRInternalDeviceState state)
return state == MTRInternalDeviceStateInitialSubscriptionEstablished || state == MTRInternalDeviceStateLaterSubscriptionEstablished;
}

NSString * InternalDeviceStateString(MTRInternalDeviceState state)
{
switch (state) {
case MTRInternalDeviceStateUnsubscribed:
return @"Unsubscribed";
case MTRInternalDeviceStateSubscribing:
return @"Subscribing";
case MTRInternalDeviceStateInitialSubscriptionEstablished:
return @"InitialSubscriptionEstablished";
case MTRInternalDeviceStateResubscribing:
return @"Resubscribing";
case MTRInternalDeviceStateLaterSubscriptionEstablished:
return @"LaterSubscriptionEstablished";
default:
return @"Unknown";
}
}
} // anonymous namespace

typedef NS_ENUM(NSUInteger, MTRDeviceExpectedValueFieldIndex) {
Expand Down Expand Up @@ -491,6 +474,8 @@ - (instancetype)initForSubclassesWithNodeID:(NSNumber *)nodeID controller:(MTRDe
if (self = [super init]) {
_lock = OS_UNFAIR_LOCK_INIT;
_delegates = [NSMutableSet set];
_deviceController = controller;
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
_nodeID = nodeID;
}

return self;
Expand Down Expand Up @@ -546,62 +531,6 @@ - (void)dealloc
MTR_LOG("MTRDevice dealloc: %p", self);
}

- (NSString *)description
{
id _Nullable vid;
id _Nullable pid;
NSNumber * _Nullable networkFeatures;
MTRInternalDeviceState internalDeviceState;
uint32_t lastSubscriptionAttemptWait;
NSDate * _Nullable mostRecentReportTime;
NSDate * _Nullable lastSubscriptionFailureTime;
{
std::lock_guard lock(_descriptionLock);
vid = _vid;
pid = _pid;
networkFeatures = _allNetworkFeatures;
internalDeviceState = _internalDeviceStateForDescription;
lastSubscriptionAttemptWait = _lastSubscriptionAttemptWaitForDescription;
mostRecentReportTime = _mostRecentReportTimeForDescription;
lastSubscriptionFailureTime = _lastSubscriptionFailureTimeForDescription;
}

if (vid == nil) {
vid = @"Unknown";
}

if (pid == nil) {
pid = @"Unknown";
}

NSString * wifi;
NSString * thread;
if (networkFeatures == nil) {
wifi = @"NO";
thread = @"NO";
} else {
wifi = YES_NO(networkFeatures.unsignedLongLongValue & MTRNetworkCommissioningFeatureWiFiNetworkInterface);
thread = YES_NO(networkFeatures.unsignedLongLongValue & MTRNetworkCommissioningFeatureThreadNetworkInterface);
}

NSString * reportAge;
if (mostRecentReportTime) {
reportAge = [NSString stringWithFormat:@" (%.0lfs ago)", -[mostRecentReportTime timeIntervalSinceNow]];
} else {
reportAge = @"";
}

NSString * subscriptionFailureAge;
if (lastSubscriptionFailureTime) {
subscriptionFailureAge = [NSString stringWithFormat:@" (%.0lfs ago)", -[lastSubscriptionFailureTime timeIntervalSinceNow]];
} else {
subscriptionFailureAge = @"";
}

return [NSString
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];
}

+ (MTRDevice *)deviceWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller
{
return [controller deviceForNodeID:nodeID];
Expand Down
8 changes: 1 addition & 7 deletions src/darwin/Framework/CHIP/MTRDevice_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
// allow readwrite access to superclass properties
@interface MTRDevice_Concrete ()

@property (nonatomic, readwrite, copy) NSNumber * nodeID;
@property (nonatomic, readwrite, nullable) MTRDeviceController * deviceController;
@property (nonatomic, readwrite) MTRAsyncWorkQueue<MTRDevice *> * asyncWorkQueue;
@property (nonatomic, readwrite) MTRDeviceState state;
@property (nonatomic, readwrite, nullable) NSDate * estimatedStartTime;
Expand Down Expand Up @@ -356,8 +354,6 @@ @implementation MTRDevice_Concrete {
}

// synthesize superclass property readwrite accessors
@synthesize nodeID = _nodeID;
@synthesize deviceController = _deviceController;
@synthesize queue = _queue;
@synthesize asyncWorkQueue = _asyncWorkQueue;
@synthesize state = _state;
Expand All @@ -372,9 +368,7 @@ - (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceControlle
if (self = [super initForSubclassesWithNodeID:nodeID controller:controller]) {
_timeSyncLock = OS_UNFAIR_LOCK_INIT;
_descriptionLock = OS_UNFAIR_LOCK_INIT;
_nodeID = [nodeID copy];
_fabricIndex = controller.fabricIndex;
_deviceController = controller;
_queue
= dispatch_queue_create("org.csa-iot.matter.framework.device.workqueue", DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL);
_expectedValueCache = [NSMutableDictionary dictionary];
Expand Down Expand Up @@ -467,7 +461,7 @@ - (NSString *)description
}

return [NSString
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];
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];
}

+ (MTRDevice *)deviceWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller
Expand Down
8 changes: 8 additions & 0 deletions src/darwin/Framework/CHIP/MTRDevice_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ MTR_DIRECT_MEMBERS
// Lock that protects overall device state, including delegate storage.
os_unfair_lock _lock;
NSMutableSet<MTRDeviceDelegateInfo *> * _delegates;

// Our node ID, with the ivar declared explicitly so it's accessible to
// subclasses.
NSNumber * _nodeID;

// Our controller. Declared nullable because our property is, though in
// practice it does not look like we ever set it to nil.
MTRDeviceController * _Nullable _deviceController;
}

- (instancetype)initForSubclassesWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller;
Expand Down
10 changes: 10 additions & 0 deletions src/darwin/Framework/CHIP/MTRDevice_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ - (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceControlle
return self;
}

- (NSString *)description
{
// TODO: Figure out whether, and if so how, to log: VID, PID, WiFi, Thread,
// internalDeviceState (do we even have such a thing here?), last
// subscription attempt wait (does that apply to us?) queued work (do we
// have any?), last report, last subscription failure (does that apply to us?).
return [NSString
stringWithFormat:@"<MTRDevice: %p, XPC: YES, node: %016llX-%016llX (%llu), controller: %@>", self, _deviceController.compressedFabricID.unsignedLongLongValue, _nodeID.unsignedLongLongValue, _nodeID.unsignedLongLongValue, _deviceController.uniqueIdentifier];
}

#pragma mark - Client Callbacks (MTRDeviceDelegate)

// required methods for MTRDeviceDelegates
Expand Down
Loading