From 4624120096282a62c7b08355a72b16235f37b5ad Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Tue, 12 Mar 2024 17:05:38 -0700 Subject: [PATCH 1/7] Initial commit --- src/darwin/Framework/CHIP/MTRDevice.h | 8 ++++++++ src/darwin/Framework/CHIP/MTRDevice.mm | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/darwin/Framework/CHIP/MTRDevice.h b/src/darwin/Framework/CHIP/MTRDevice.h index 50ca8d41b272fa..498f66220b9246 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.h +++ b/src/darwin/Framework/CHIP/MTRDevice.h @@ -64,6 +64,14 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) */ @property (nonatomic, readonly) MTRDeviceState state; +/** + * Is the state cache primed for this device? + * + * This verifies that both the MTRDeviceController has a storage delegate, and a subscription has been set up and the resulting state has been cached. If this is true this means most state is ready to cache and will not require a round trip to the accessory. + * + */ +@property (nonatomic, readonly) BOOL deviceCachePrimed; + /** * The estimated device system start time. * diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index f854242dfbeb1f..6dba1a14a66efc 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -2017,6 +2017,18 @@ - (void)setAttributeValues:(NSArray *)attributeValues reportChan os_unfair_lock_unlock(&self->_lock); } +- (BOOL)deviceCachePrimed { + BOOL isPrimed = NO; + + os_unfair_lock_lock(&self->_lock); + + isPrimed = [self _isCachePrimedWithInitialConfigurationData]; + + os_unfair_lock_unlock(&self->_lock); + + return isPrimed; +} + // If value is non-nil, associate with expectedValueID // If value is nil, remove only if expectedValueID matches // previousValue is an out parameter From b8e5b2fc9c28cefa01aa3dd200d55328373c3893 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 13 Mar 2024 00:07:06 +0000 Subject: [PATCH 2/7] Restyled by whitespace --- src/darwin/Framework/CHIP/MTRDevice.h | 2 +- src/darwin/Framework/CHIP/MTRDevice.mm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.h b/src/darwin/Framework/CHIP/MTRDevice.h index 498f66220b9246..c4f7e152cc1825 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.h +++ b/src/darwin/Framework/CHIP/MTRDevice.h @@ -66,7 +66,7 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) /** * Is the state cache primed for this device? - * + * * This verifies that both the MTRDeviceController has a storage delegate, and a subscription has been set up and the resulting state has been cached. If this is true this means most state is ready to cache and will not require a round trip to the accessory. * */ diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 6dba1a14a66efc..f522cc9d51baad 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -2019,7 +2019,7 @@ - (void)setAttributeValues:(NSArray *)attributeValues reportChan - (BOOL)deviceCachePrimed { BOOL isPrimed = NO; - + os_unfair_lock_lock(&self->_lock); isPrimed = [self _isCachePrimedWithInitialConfigurationData]; From 49eb3b9a5c62e39a60d7df65a54e127711f5ec09 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 13 Mar 2024 00:07:08 +0000 Subject: [PATCH 3/7] Restyled by clang-format --- src/darwin/Framework/CHIP/MTRDevice.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index f522cc9d51baad..3612c9fee49763 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -2017,7 +2017,8 @@ - (void)setAttributeValues:(NSArray *)attributeValues reportChan os_unfair_lock_unlock(&self->_lock); } -- (BOOL)deviceCachePrimed { +- (BOOL)deviceCachePrimed +{ BOOL isPrimed = NO; os_unfair_lock_lock(&self->_lock); From 1ec7fc8b6806df9161591083d059b69a1351d464 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Tue, 12 Mar 2024 19:03:04 -0700 Subject: [PATCH 4/7] Update src/darwin/Framework/CHIP/MTRDevice.mm Co-authored-by: Anush Nadathur --- src/darwin/Framework/CHIP/MTRDevice.mm | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 3612c9fee49763..240dcb0dee3f58 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -2019,15 +2019,8 @@ - (void)setAttributeValues:(NSArray *)attributeValues reportChan - (BOOL)deviceCachePrimed { - BOOL isPrimed = NO; - - os_unfair_lock_lock(&self->_lock); - - isPrimed = [self _isCachePrimedWithInitialConfigurationData]; - - os_unfair_lock_unlock(&self->_lock); - - return isPrimed; + std::lock_guard lock(_lock); + return [self _isCachePrimedWithInitialConfigurationData]; } // If value is non-nil, associate with expectedValueID From 122ea0b81816294eb11d8a19feda98dbdd1e0597 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Tue, 12 Mar 2024 19:03:11 -0700 Subject: [PATCH 5/7] Update src/darwin/Framework/CHIP/MTRDevice.h Co-authored-by: Karsten Sperling <113487422+ksperling-apple@users.noreply.github.com> --- src/darwin/Framework/CHIP/MTRDevice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/darwin/Framework/CHIP/MTRDevice.h b/src/darwin/Framework/CHIP/MTRDevice.h index c4f7e152cc1825..d2404c2899836e 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.h +++ b/src/darwin/Framework/CHIP/MTRDevice.h @@ -70,7 +70,7 @@ MTR_AVAILABLE(ios(16.1), macos(13.0), watchos(9.1), tvos(16.1)) * This verifies that both the MTRDeviceController has a storage delegate, and a subscription has been set up and the resulting state has been cached. If this is true this means most state is ready to cache and will not require a round trip to the accessory. * */ -@property (nonatomic, readonly) BOOL deviceCachePrimed; +@property (readonly) BOOL deviceCachePrimed; /** * The estimated device system start time. From 98cc2a823aca3c2ccc6856627091bf571c866e3f Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Tue, 12 Mar 2024 19:10:10 -0700 Subject: [PATCH 6/7] Adding header --- 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 240dcb0dee3f58..45c1efb90884d2 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -28,6 +28,7 @@ #import "MTRCommandTimedCheck.h" #import "MTRConversion.h" #import "MTRDefines_Internal.h" +#import "MTRUnfairLock.h" #import "MTRDeviceController_Internal.h" #import "MTRDevice_Internal.h" #import "MTRError_Internal.h" From 8cebb5ef31f71a5daab70b3af1d2ec24dde9d539 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 13 Mar 2024 02:10:31 +0000 Subject: [PATCH 7/7] Restyled by clang-format --- 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 45c1efb90884d2..4c6b4a21e828d9 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -28,12 +28,12 @@ #import "MTRCommandTimedCheck.h" #import "MTRConversion.h" #import "MTRDefines_Internal.h" -#import "MTRUnfairLock.h" #import "MTRDeviceController_Internal.h" #import "MTRDevice_Internal.h" #import "MTRError_Internal.h" #import "MTREventTLVValueDecoder_Internal.h" #import "MTRLogging_Internal.h" +#import "MTRUnfairLock.h" #import "zap-generated/MTRCommandPayloads_Internal.h" #include "lib/core/CHIPError.h"