diff --git a/src/platform/Darwin/BUILD.gn b/src/platform/Darwin/BUILD.gn index 24bfc62f000e1f..9dbb8460ae0566 100644 --- a/src/platform/Darwin/BUILD.gn +++ b/src/platform/Darwin/BUILD.gn @@ -76,8 +76,8 @@ static_library("Darwin") { "PosixConfig.h", "SystemPlatformConfig.h", "SystemTimeSupport.cpp", - "UserDefaultUtils.h", - "UserDefaultUtils.mm", + "UserDefaults.h", + "UserDefaults.mm", ] if (chip_enable_wifi) { diff --git a/src/platform/Darwin/DnssdImpl.cpp b/src/platform/Darwin/DnssdImpl.cpp index bc935ed671a202..4c7932367784ec 100644 --- a/src/platform/Darwin/DnssdImpl.cpp +++ b/src/platform/Darwin/DnssdImpl.cpp @@ -17,7 +17,7 @@ #include "DnssdImpl.h" #include "DnssdType.h" #include "MdnsError.h" -#include "UserDefaultUtils.h" +#include "UserDefaults.h" #include @@ -30,7 +30,7 @@ using namespace chip::Dnssd; using namespace chip::Dnssd::Internal; -using namespace chip::DeviceLayer::Utils; +using namespace chip::DeviceLayer; namespace { @@ -79,12 +79,12 @@ void LogOnFailure(const char * name, DNSServiceErrorType err) CHIP_ERROR StartSRPTimer(uint16_t timeoutInMSecs, ResolveContext * ctx) { // Check to see if an user default value exists for the SRP timeout. If it does, override the timeoutInMSecs with user default - // value. To override the timeout value, use ` defaults write org.csa-iot.matter.darwindefaults SRPTimeoutOverride - // ` See UserDefaultUtils.mm for details - uint16_t userDefaultSRPTimeout = getUserDefaultDnssdSRPTimeout(); - if (userDefaultSRPTimeout) + // value. To override the timeout value, use ` defaults write org.csa-iot.matter.darwin SRPTimeoutInMSecsOverride + // ` See UserDefaults.mm for details + uint16_t userDefaultSRPTimeoutInMsecs = static_cast(getUserDefaultDnssdSRPTimeoutInMSecs()); + if (userDefaultSRPTimeoutInMsecs) { - timeoutInMSecs = userDefaultSRPTimeout; + timeoutInMSecs = userDefaultSRPTimeoutInMsecs; } VerifyOrReturnValue(ctx != nullptr, CHIP_ERROR_INCORRECT_STATE); ChipLogProgress(Discovery, "Starting timer to wait for %d milliseconds for possible SRP resolve results for %s", timeoutInMSecs, diff --git a/src/platform/Darwin/UserDefaultUtils.h b/src/platform/Darwin/UserDefaults.h similarity index 90% rename from src/platform/Darwin/UserDefaultUtils.h rename to src/platform/Darwin/UserDefaults.h index 4129ff97b0cfc4..1252f9d2534b48 100644 --- a/src/platform/Darwin/UserDefaultUtils.h +++ b/src/platform/Darwin/UserDefaults.h @@ -15,12 +15,12 @@ * limitations under the License. */ +#pragma once + namespace chip { namespace DeviceLayer { -namespace Utils { -uint16_t getUserDefaultDnssdSRPTimeout(); +uint16_t getUserDefaultDnssdSRPTimeoutInMSecs(); -} // namespace Utils } // namespace DeviceLayer } // namespace chip diff --git a/src/platform/Darwin/UserDefaultUtils.mm b/src/platform/Darwin/UserDefaults.mm similarity index 60% rename from src/platform/Darwin/UserDefaultUtils.mm rename to src/platform/Darwin/UserDefaults.mm index be04c29eb94f13..ca5b54812032b9 100644 --- a/src/platform/Darwin/UserDefaultUtils.mm +++ b/src/platform/Darwin/UserDefaults.mm @@ -15,26 +15,20 @@ * limitations under the License. */ -/** - * @file - * Implementation for an utility to set configurable parametes via user defaults. - */ -#import "UserDefaultUtils.h" #import -static NSString * const kUserDefaultDomain = @"org.csa-iot.matter.darwindefaults"; -static NSString * const kSRPTimeoutUserDefaultKey = @"SRPTimeoutOverride"; +static NSString * const kUserDefaultDomain = @"org.csa-iot.matter.darwin"; +static NSString * const kSRPTimeoutInMsecsUserDefaultKey = @"SRPTimeoutInMSecsOverride"; namespace chip { namespace DeviceLayer { - namespace Utils { - uint16_t getUserDefaultDnssdSRPTimeout() - { - NSUserDefaults * defaults = [[NSUserDefaults alloc] initWithSuiteName:kUserDefaultDomain]; - return static_cast([defaults integerForKey:kSRPTimeoutUserDefaultKey]); - } +uint16_t getUserDefaultDnssdSRPTimeoutInMSecs() +{ + NSUserDefaults * defaults = [[NSUserDefaults alloc] initWithSuiteName:kUserDefaultDomain]; + NSInteger srpTimeoutValue = [defaults integerForKey:kSRPTimeoutInMsecsUserDefaultKey]; + return (srpTimeoutValue < UINT16_MAX) ? static_cast(srpTimeoutValue) : 0; +} - } // namespace Utils } // namespace DeviceLayer } // namespace chip