From 1160f97b9061de3ec9e383de0f5111663d25fd3a Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Wed, 13 Mar 2024 07:13:03 -0700 Subject: [PATCH] Add a way for a client to know if the device cache is primed in Darwin (#32556) * Initial commit * Restyled by whitespace * Restyled by clang-format * Update src/darwin/Framework/CHIP/MTRDevice.mm Co-authored-by: Anush Nadathur * Update src/darwin/Framework/CHIP/MTRDevice.h Co-authored-by: Karsten Sperling <113487422+ksperling-apple@users.noreply.github.com> * Adding header * Restyled by clang-format --------- Co-authored-by: Restyled.io Co-authored-by: Anush Nadathur Co-authored-by: Karsten Sperling <113487422+ksperling-apple@users.noreply.github.com> --- src/darwin/Framework/CHIP/MTRDevice.h | 8 ++++++++ src/darwin/Framework/CHIP/MTRDevice.mm | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/src/darwin/Framework/CHIP/MTRDevice.h b/src/darwin/Framework/CHIP/MTRDevice.h index 50ca8d41b272fa..d2404c2899836e 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 (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..4c6b4a21e828d9 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -33,6 +33,7 @@ #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" @@ -2017,6 +2018,12 @@ - (void)setAttributeValues:(NSArray *)attributeValues reportChan os_unfair_lock_unlock(&self->_lock); } +- (BOOL)deviceCachePrimed +{ + std::lock_guard lock(_lock); + return [self _isCachePrimedWithInitialConfigurationData]; +} + // If value is non-nil, associate with expectedValueID // If value is nil, remove only if expectedValueID matches // previousValue is an out parameter