[settings] simplify and enhance Settings (#6683)

This commit updates the `Settings` implementation. It adds template
versions of methods `Read<EntryType>()`, `Save<EntryType>()`, and
`Delete<EntryType>()` which make it easier for other modules to use,
while ensuing to share a common underlying implementation for all
entry types.

The settings entry types (e.g., `NetworkInfo`, `ParentInfo`, etc.) are
changed in this commit to provide a constant `kKey` specifying the
associated setting key with the entry. For simple entries, a related
class is added to define the `kKey` constant and the associated value
type (e.g., `OmrPrefix` defines `Ip6::Prefix` as its `ValueType`).
This model makes it easier to add new setting keys and entries in
future.

This commit also simplifies the logging in `Settings`. The entry types
now provide `Log()` method to log their data and a common
`Settings::Log()` method is added which handles all logging (on
success or in case of an error).

Finally, this commit moves the `SettingsDriver` definition to its own
`common/settings_driver.hpp` header file and and ensures that its
methods are defined as inline.
This commit is contained in:
Abtin Keshavarzian
2021-05-27 15:57:06 -07:00
committed by GitHub
parent 0869422c2c
commit a24b67ef30
11 changed files with 795 additions and 872 deletions
+2 -2
View File
@@ -213,7 +213,7 @@ void DuaManager::Restore(void)
{
Settings::DadInfo dadInfo;
SuccessOrExit(Get<Settings>().ReadDadInfo(dadInfo));
SuccessOrExit(Get<Settings>().Read(dadInfo));
mDadCounter = dadInfo.GetDadCounter();
exit:
@@ -225,7 +225,7 @@ Error DuaManager::Store(void)
Settings::DadInfo dadInfo;
dadInfo.SetDadCounter(mDadCounter);
return Get<Settings>().SaveDadInfo(dadInfo);
return Get<Settings>().Save(dadInfo);
}
void DuaManager::AddDomainUnicastAddress(void)