subsys/settings: add a function to save subtree
When running multiple subsystems or applications on a MCU, the usual strategy is to use different settings subtrees. The API provides a way to load or commit a subtree, to avoid adding dependencies between subsystems or applications, but lacks the way to save a subtree only. Fix that by adding a settings_save_subtree() function. Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
This commit is contained in:
parent
37c23f69f2
commit
e94fe44805
2 changed files with 21 additions and 0 deletions
|
|
@ -303,6 +303,16 @@ int settings_load_subtree_direct(
|
|||
*/
|
||||
int settings_save(void);
|
||||
|
||||
/**
|
||||
* Save limited set of currently running serialized items. All serialized items
|
||||
* that belong to subtree and which are different from currently persisted
|
||||
* values will be saved.
|
||||
*
|
||||
* @param[in] subtree name of the subtree to be loaded.
|
||||
* @return 0 on success, non-zero on failure.
|
||||
*/
|
||||
int settings_save_subtree(const char *subtree);
|
||||
|
||||
/**
|
||||
* Write a single serialized value to persisted storage (if it has
|
||||
* changed value).
|
||||
|
|
|
|||
|
|
@ -116,6 +116,11 @@ int settings_delete(const char *name)
|
|||
}
|
||||
|
||||
int settings_save(void)
|
||||
{
|
||||
return settings_save_subtree(NULL);
|
||||
}
|
||||
|
||||
int settings_save_subtree(const char *subtree)
|
||||
{
|
||||
struct settings_store *cs;
|
||||
int rc;
|
||||
|
|
@ -132,6 +137,9 @@ int settings_save(void)
|
|||
rc = 0;
|
||||
|
||||
STRUCT_SECTION_FOREACH(settings_handler_static, ch) {
|
||||
if (subtree && !settings_name_steq(ch->name, subtree, NULL)) {
|
||||
continue;
|
||||
}
|
||||
if (ch->h_export) {
|
||||
rc2 = ch->h_export(settings_save_one);
|
||||
if (!rc) {
|
||||
|
|
@ -143,6 +151,9 @@ int settings_save(void)
|
|||
#if defined(CONFIG_SETTINGS_DYNAMIC_HANDLERS)
|
||||
struct settings_handler *ch;
|
||||
SYS_SLIST_FOR_EACH_CONTAINER(&settings_handlers, ch, node) {
|
||||
if (subtree && !settings_name_steq(ch->name, subtree, NULL)) {
|
||||
continue;
|
||||
}
|
||||
if (ch->h_export) {
|
||||
rc2 = ch->h_export(settings_save_one);
|
||||
if (!rc) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue