Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nivi-apple committed Apr 19, 2024
1 parent 58cbfc8 commit 372414a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/platform/Darwin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions src/platform/Darwin/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "DnssdImpl.h"
#include "DnssdType.h"
#include "MdnsError.h"
#include "UserDefaultUtils.h"
#include "UserDefaults.h"

#include <cstdio>

Expand All @@ -30,7 +30,7 @@

using namespace chip::Dnssd;
using namespace chip::Dnssd::Internal;
using namespace chip::DeviceLayer::Utils;
using namespace chip::DeviceLayer;

namespace {

Expand Down Expand Up @@ -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
// <timeoutinMsecs>` 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
// <timeoutinMsecs>` See UserDefaults.mm for details
uint16_t userDefaultSRPTimeoutInMsecs = static_cast<uint16_t>(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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,20 @@
* limitations under the License.
*/

/**
* @file
* Implementation for an utility to set configurable parametes via user defaults.
*/
#import "UserDefaultUtils.h"
#import <Foundation/Foundation.h>

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<uint16_t>([defaults integerForKey:kSRPTimeoutUserDefaultKey]);
}
uint16_t getUserDefaultDnssdSRPTimeoutInMSecs()
{
NSUserDefaults * defaults = [[NSUserDefaults alloc] initWithSuiteName:kUserDefaultDomain];
NSInteger srpTimeoutValue = [defaults integerForKey:kSRPTimeoutInMsecsUserDefaultKey];
return (srpTimeoutValue < UINT16_MAX) ? static_cast<uint16_t>(srpTimeoutValue) : 0;
}

} // namespace Utils
} // namespace DeviceLayer
} // namespace chip

0 comments on commit 372414a

Please sign in to comment.