From 66da662d737851fe8bbf3932ff407c3ae8200e0a Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Thu, 23 May 2024 15:51:01 -0700 Subject: [PATCH 1/8] Adding dragons.... --- src/darwin/Framework/CHIP/MTRDevice.mm | 41 ++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 7cb816708aac49..6959579bc87907 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -118,8 +118,8 @@ - (id)strongObject UnsolicitedMessageFromPublisherHandler unsolicitedMessageFromPublisherHandler, ReportBeginHandler reportBeginHandler, ReportEndHandler reportEndHandler) : MTRBaseSubscriptionCallback(attributeReportCallback, eventReportCallback, errorCallback, resubscriptionCallback, - subscriptionEstablishedHandler, onDoneHandler, unsolicitedMessageFromPublisherHandler, reportBeginHandler, - reportEndHandler) + subscriptionEstablishedHandler, onDoneHandler, unsolicitedMessageFromPublisherHandler, reportBeginHandler, + reportEndHandler) { } @@ -936,6 +936,14 @@ - (void)_changeInternalState:(MTRInternalDeviceState)state _internalDeviceState = state; if (lastState != state) { MTR_LOG("%@ internal state change %lu => %lu", self, static_cast(lastState), static_cast(state)); + + /* BEGIN DRAGONS: This is a huge hack for a specific use case, do not rename, remove or modify behavior here */ + if ([delegate respondsToSelector:@selector(_deviceInternalStateChanged:)]) { + dispatch_async(_delegateQueue, ^{ + [(id) delegate _deviceInternalStateChanged:self]; + }); + } + /* END DRAGONS */ } } @@ -3268,6 +3276,35 @@ - (void)removeClientDataForKey:(NSString *)key endpointID:(NSNumber *)endpointID @end +/* BEGIN DRAGONS: Note methods here cannot be renamed, and are used by private callers, do not rename, remove or modify behavior here */ + +@interface NSObject (MatterPrivateForInternalDragonsDoNotFeed) +- (void)_deviceInternalStateChanged:(MTRDevice *)device; +@end + +@implementation MTRDevice (MatterPrivateForInternalDragonsDoNotFeed) + +- (BOOL)_deviceHasActiveSubscription +{ + std::lock_guard lock(_lock); + + return HaveSubscriptionEstablishedRightNow(_internalDeviceState); +} + +- (void)_deviceMayBeOnline +{ + assertChipStackLockedByCurrentThread(); + + MTR_LOG("%@ deviceMayBeOnline called", self); + + [self _triggerResubscribeWithReason:"SPI client indicated the device may now be online" + nodeLikelyReachable:YES]; +} + +/* END DRAGONS */ + +@end + @implementation MTRDevice (Deprecated) + (MTRDevice *)deviceWithNodeID:(uint64_t)nodeID deviceController:(MTRDeviceController *)deviceController From f2d9a181d0304deda3b2e640eb7356507a995fed Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 23 May 2024 22:58:16 +0000 Subject: [PATCH 2/8] Restyled by clang-format --- src/darwin/Framework/CHIP/MTRDevice.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 6959579bc87907..8995efb38bfe67 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -118,8 +118,8 @@ - (id)strongObject UnsolicitedMessageFromPublisherHandler unsolicitedMessageFromPublisherHandler, ReportBeginHandler reportBeginHandler, ReportEndHandler reportEndHandler) : MTRBaseSubscriptionCallback(attributeReportCallback, eventReportCallback, errorCallback, resubscriptionCallback, - subscriptionEstablishedHandler, onDoneHandler, unsolicitedMessageFromPublisherHandler, reportBeginHandler, - reportEndHandler) + subscriptionEstablishedHandler, onDoneHandler, unsolicitedMessageFromPublisherHandler, reportBeginHandler, + reportEndHandler) { } From d88540e6a48ca6f9a2e78eec8ee50c6d1e91f2f5 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Thu, 23 May 2024 16:11:34 -0700 Subject: [PATCH 3/8] Fixing build --- src/darwin/Framework/CHIP/MTRDevice.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 8995efb38bfe67..7a7744e2a329f7 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -938,6 +938,7 @@ - (void)_changeInternalState:(MTRInternalDeviceState)state MTR_LOG("%@ internal state change %lu => %lu", self, static_cast(lastState), static_cast(state)); /* BEGIN DRAGONS: This is a huge hack for a specific use case, do not rename, remove or modify behavior here */ + id delegate = _weakDelegate.strongObject; if ([delegate respondsToSelector:@selector(_deviceInternalStateChanged:)]) { dispatch_async(_delegateQueue, ^{ [(id) delegate _deviceInternalStateChanged:self]; From 25f8b778fb87c7360e40dd3e75324c52de93031d Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Thu, 23 May 2024 17:34:23 -0700 Subject: [PATCH 4/8] Renaming --- src/darwin/Framework/CHIP/MTRDevice.mm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 7a7744e2a329f7..0c0d702cd38b6e 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -118,8 +118,8 @@ - (id)strongObject UnsolicitedMessageFromPublisherHandler unsolicitedMessageFromPublisherHandler, ReportBeginHandler reportBeginHandler, ReportEndHandler reportEndHandler) : MTRBaseSubscriptionCallback(attributeReportCallback, eventReportCallback, errorCallback, resubscriptionCallback, - subscriptionEstablishedHandler, onDoneHandler, unsolicitedMessageFromPublisherHandler, reportBeginHandler, - reportEndHandler) + subscriptionEstablishedHandler, onDoneHandler, unsolicitedMessageFromPublisherHandler, reportBeginHandler, + reportEndHandler) { } @@ -3292,11 +3292,11 @@ - (BOOL)_deviceHasActiveSubscription return HaveSubscriptionEstablishedRightNow(_internalDeviceState); } -- (void)_deviceMayBeOnline +- (void)_deviceMayBeReachable { assertChipStackLockedByCurrentThread(); - MTR_LOG("%@ deviceMayBeOnline called", self); + MTR_LOG("%@ _deviceMayBeReachable called", self); [self _triggerResubscribeWithReason:"SPI client indicated the device may now be online" nodeLikelyReachable:YES]; From f69f1bf7657e85e9d00df75fe470929a546da2f0 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 24 May 2024 00:35:05 +0000 Subject: [PATCH 5/8] Restyled by clang-format --- src/darwin/Framework/CHIP/MTRDevice.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 0c0d702cd38b6e..0bc58143352c4b 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -118,8 +118,8 @@ - (id)strongObject UnsolicitedMessageFromPublisherHandler unsolicitedMessageFromPublisherHandler, ReportBeginHandler reportBeginHandler, ReportEndHandler reportEndHandler) : MTRBaseSubscriptionCallback(attributeReportCallback, eventReportCallback, errorCallback, resubscriptionCallback, - subscriptionEstablishedHandler, onDoneHandler, unsolicitedMessageFromPublisherHandler, reportBeginHandler, - reportEndHandler) + subscriptionEstablishedHandler, onDoneHandler, unsolicitedMessageFromPublisherHandler, reportBeginHandler, + reportEndHandler) { } From dad3b170c5d37b30df3def01e0a4f7f36379a3f4 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Thu, 23 May 2024 17:54:11 -0700 Subject: [PATCH 6/8] Fixing missing interface --- src/darwin/Framework/CHIP/MTRDevice.mm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 0bc58143352c4b..660be9354469d1 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -101,6 +101,14 @@ - (id)strongObject return aNumber; } +/* BEGIN DRAGONS: Note methods here cannot be renamed, and are used by private callers, do not rename, remove or modify behavior here */ + +@interface NSObject (MatterPrivateForInternalDragonsDoNotFeed) +- (void)_deviceInternalStateChanged:(MTRDevice *)device; +@end + +/* END DRAGONS */ + #pragma mark - SubscriptionCallback class declaration using namespace chip; using namespace chip::app; @@ -118,8 +126,8 @@ - (id)strongObject UnsolicitedMessageFromPublisherHandler unsolicitedMessageFromPublisherHandler, ReportBeginHandler reportBeginHandler, ReportEndHandler reportEndHandler) : MTRBaseSubscriptionCallback(attributeReportCallback, eventReportCallback, errorCallback, resubscriptionCallback, - subscriptionEstablishedHandler, onDoneHandler, unsolicitedMessageFromPublisherHandler, reportBeginHandler, - reportEndHandler) + subscriptionEstablishedHandler, onDoneHandler, unsolicitedMessageFromPublisherHandler, reportBeginHandler, + reportEndHandler) { } @@ -3279,10 +3287,6 @@ - (void)removeClientDataForKey:(NSString *)key endpointID:(NSNumber *)endpointID /* BEGIN DRAGONS: Note methods here cannot be renamed, and are used by private callers, do not rename, remove or modify behavior here */ -@interface NSObject (MatterPrivateForInternalDragonsDoNotFeed) -- (void)_deviceInternalStateChanged:(MTRDevice *)device; -@end - @implementation MTRDevice (MatterPrivateForInternalDragonsDoNotFeed) - (BOOL)_deviceHasActiveSubscription From f46feaec4ad62b30d3d6250d628d94913526ac95 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 24 May 2024 00:54:33 +0000 Subject: [PATCH 7/8] Restyled by clang-format --- src/darwin/Framework/CHIP/MTRDevice.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 660be9354469d1..3c11d2327136d8 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -126,8 +126,8 @@ - (void)_deviceInternalStateChanged:(MTRDevice *)device; UnsolicitedMessageFromPublisherHandler unsolicitedMessageFromPublisherHandler, ReportBeginHandler reportBeginHandler, ReportEndHandler reportEndHandler) : MTRBaseSubscriptionCallback(attributeReportCallback, eventReportCallback, errorCallback, resubscriptionCallback, - subscriptionEstablishedHandler, onDoneHandler, unsolicitedMessageFromPublisherHandler, reportBeginHandler, - reportEndHandler) + subscriptionEstablishedHandler, onDoneHandler, unsolicitedMessageFromPublisherHandler, reportBeginHandler, + reportEndHandler) { } From 79228bc831914810783097bcbe02f912c6b31e99 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Thu, 23 May 2024 19:22:14 -0700 Subject: [PATCH 8/8] Update src/darwin/Framework/CHIP/MTRDevice.mm Co-authored-by: Boris Zbarsky --- src/darwin/Framework/CHIP/MTRDevice.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 3c11d2327136d8..b25757672680ec 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -3302,7 +3302,7 @@ - (void)_deviceMayBeReachable MTR_LOG("%@ _deviceMayBeReachable called", self); - [self _triggerResubscribeWithReason:"SPI client indicated the device may now be online" + [self _triggerResubscribeWithReason:"SPI client indicated the device may now be reachable" nodeLikelyReachable:YES]; }