forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utility to get user default values for configurable parameters fo… (
project-chip#33056) * Add utility to get user default values for configurable parameters for darwin - Add support for getting a user default value for the SRP resolve timeout for DNS-SD. If user default value exists, ovveride the timeout. - Update the SRP resolve timeout to 3 secs The default can be set by using `defaults write org.csa-iot.matter.darwindefaults SRPTimeoutOverride <timeoutinMsecs>` * Restyled by whitespace * Restyled by clang-format * Restyled by gn * Address review comments * Restyled by clang-format * Add a check for filtering negative values and returning 0 * Apply suggestions from code review Co-authored-by: Boris Zbarsky <[email protected]> * Return an optional uint16_t value from GetUserDefaultDnssdSRPTimeoutInMSecs * Restyled by clang-format * Move the inclusion of optional header file in UserDefaults.h * Include UserDefaults.h header in UserDefaults.mm file * Include header cstdint from UserDefaults.h --------- Co-authored-by: Restyled.io <[email protected]> Co-authored-by: Boris Zbarsky <[email protected]>
- Loading branch information
1 parent
b008715
commit b4650b9
Showing
5 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <optional> | ||
|
||
namespace chip { | ||
namespace Platform { | ||
|
||
std::optional<uint16_t> GetUserDefaultDnssdSRPTimeoutInMSecs(); | ||
|
||
} // namespace Platform | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "UserDefaults.h" | ||
#include <lib/support/SafeInt.h> | ||
#include <lib/support/logging/CHIPLogging.h> | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
static NSString * const kUserDefaultDomain = @"org.csa-iot.matter.darwin"; | ||
static NSString * const kSRPTimeoutInMsecsUserDefaultKey = @"SRPTimeoutInMSecsOverride"; | ||
|
||
namespace chip { | ||
namespace Platform { | ||
|
||
std::optional<uint16_t> GetUserDefaultDnssdSRPTimeoutInMSecs() | ||
{ | ||
NSUserDefaults * defaults = [[NSUserDefaults alloc] initWithSuiteName:kUserDefaultDomain]; | ||
NSInteger srpTimeoutValue = [defaults integerForKey:kSRPTimeoutInMsecsUserDefaultKey]; | ||
if (CanCastTo<uint16_t>(srpTimeoutValue)) { | ||
uint16_t timeoutinMsecs = static_cast<uint16_t>(srpTimeoutValue); | ||
ChipLogProgress(Discovery, "Got a user default value for Dnssd SRP timeout - %d msecs", timeoutinMsecs); | ||
return std::make_optional(timeoutinMsecs); | ||
} | ||
return std::nullopt; | ||
} | ||
|
||
} // namespace Platform | ||
} // namespace chip |