2018-02-02 14:30:56 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Nordic Semiconductor ASA
|
|
|
|
* Copyright (c) 2015 Runtime Inc
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2018-09-14 10:43:44 -07:00
|
|
|
#ifndef ZEPHYR_INCLUDE_SETTINGS_SETTINGS_H_
|
|
|
|
#define ZEPHYR_INCLUDE_SETTINGS_SETTINGS_H_
|
2018-02-02 14:30:56 +01:00
|
|
|
|
2018-05-15 14:25:29 +02:00
|
|
|
#include <sys/types.h>
|
2018-02-02 14:30:56 +01:00
|
|
|
#include <misc/util.h>
|
|
|
|
#include <misc/slist.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2018-03-22 15:06:36 +01:00
|
|
|
* @defgroup settings Settings subsystem
|
2018-12-08 13:53:36 -05:00
|
|
|
* @ingroup file_system_storage
|
2018-02-02 14:30:56 +01:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SETTINGS_MAX_DIR_DEPTH 8 /* max depth of settings tree */
|
|
|
|
#define SETTINGS_MAX_NAME_LEN (8 * SETTINGS_MAX_DIR_DEPTH)
|
|
|
|
#define SETTINGS_MAX_VAL_LEN 256
|
subsys/settings: change processing to const char
The settings module processes the variable name by splitting it up in
a set of variables. This PR removes the splitting up and keeps the
variable name as one string.
It is an alternative to #16609
The possibility is introduced to register handler including a
separator, or to register a handler for each variable.
The ability is introduced to load a subtree from flash or even to load
a single item.
Two ways to operate on variable and settings_handler names are provided:
settings_name_steq(const char *name, const char *key, const char **next)
which checks if name starts with key, returns 1/0 if it does/does not
the remaining part of name is in next.
settings_name_split(const char *name, char *argv, const char **next)
which splits up name in a part before "/"" that is found in argv and
the remaining part that is in next.
A mutex is added to make settings thread-safe
The settings_handlers list is stored in reverse alphabetical order, this
allows registration of e.g. bt and bt/mesh in separate handlers, the bt
handler itself should not contain any handling of bt/mesh.
A settings_deregister() method is added. Settings_handlers can now be
added/removed when required. This saves RAM when settings_handlers are
not needed.
Tests have been updated to reflect changes in the settings api.
Updates after meeting:
1. Removed settings_deregister
2. Changed settings_name_split() in settings_name_next:
int settings_name_next(const char *name, const char **next): returns
the number of characters before the first separator. This can then be
used to read the correct number of characters from name using strncpy
for processing.
3. New functional test added
Update in settings.h: settings_name_next() changed position -> index
Added some comments in settings.h (settings_name_steq())
Updated tests to reflect change to settings_name_next() and pointer
value comparison. The functional test can now also run on qemu_x86.
Corrected some documentation in header.
Changed registration of handlers to be non ordered.
Changed handler lookup to handle non ordered list of handlers, this
improves handler matching in case different length names are compared
and also makes it easier to add rom based handlers as they will not be
ordered.
Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-06-08 21:24:42 +02:00
|
|
|
#define SETTINGS_NAME_SEPARATOR '/'
|
|
|
|
#define SETTINGS_NAME_END '='
|
2018-02-02 14:30:56 +01:00
|
|
|
|
|
|
|
/* pleace for settings additions:
|
|
|
|
* up to 7 separators, '=', '\0'
|
|
|
|
*/
|
|
|
|
#define SETTINGS_EXTRA_LEN ((SETTINGS_MAX_DIR_DEPTH - 1) + 2)
|
|
|
|
|
2019-04-02 11:06:05 +02:00
|
|
|
typedef ssize_t (*settings_read_cb)(void *cb_arg, void *data, size_t len);
|
2018-02-02 14:30:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @struct settings_handler
|
|
|
|
* Config handlers for subtree implement a set of handler functions.
|
2018-05-15 14:25:29 +02:00
|
|
|
* These are registered using a call to @ref settings_register.
|
2018-02-02 14:30:56 +01:00
|
|
|
*/
|
|
|
|
struct settings_handler {
|
2019-06-18 15:16:26 +02:00
|
|
|
|
|
|
|
char *name;
|
|
|
|
/**< Name of subtree. */
|
|
|
|
|
|
|
|
int (*h_get)(const char *key, char *val, int val_len_max);
|
|
|
|
/**< Get values handler of settings items identified by keyword names.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* - key[in] the name with skipped part that was used as name in
|
|
|
|
* handler registration
|
|
|
|
* - val[out] buffer to receive value.
|
|
|
|
* - val_len_max[in] size of that buffer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int (*h_set)(const char *key, size_t len, settings_read_cb read_cb,
|
|
|
|
void *cb_arg);
|
|
|
|
/**< Set value handler of settings items identified by keyword names.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* - key[in] the name with skipped part that was used as name in
|
|
|
|
* handler registration
|
|
|
|
* - len[in] the size of the data found in the backend.
|
|
|
|
* - read_cb[in] function provided to read the data from the backend.
|
|
|
|
* - cb_arg[in] arguments for the read function provided by the
|
|
|
|
* backend.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int (*h_commit)(void);
|
|
|
|
/**< This handler gets called after settings has been loaded in full.
|
|
|
|
* User might use it to apply setting to the application.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int (*h_export)(int (*export_func)(const char *name, const void *val,
|
|
|
|
size_t val_len));
|
|
|
|
/**< This gets called to dump all current settings items.
|
|
|
|
*
|
|
|
|
* This happens when @ref settings_save tries to save the settings.
|
|
|
|
* Parameters:
|
|
|
|
* - export_func: the pointer to the internal function which appends
|
|
|
|
* a single key-value pair to persisted settings. Don't store
|
|
|
|
* duplicated value. The name is subtree/key string, val is the string
|
|
|
|
* with value.
|
|
|
|
*
|
|
|
|
* @remarks The User might limit a implementations of handler to serving
|
|
|
|
* only one keyword at one call - what will impose limit to get/set
|
|
|
|
* values using full subtree/key name.
|
|
|
|
*/
|
|
|
|
|
2018-02-02 14:30:56 +01:00
|
|
|
sys_snode_t node;
|
2018-05-15 14:25:29 +02:00
|
|
|
/**< Linked list node info for module internal usage. */
|
2019-06-18 15:16:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @struct settings_handler_static
|
|
|
|
* Config handlers without the node element, used for static handlers.
|
|
|
|
* These are registered using a call to SETTINGS_REGISTER_STATIC().
|
|
|
|
*/
|
|
|
|
struct settings_handler_static {
|
2018-05-15 14:25:29 +02:00
|
|
|
|
2018-02-02 14:30:56 +01:00
|
|
|
char *name;
|
2018-05-15 14:25:29 +02:00
|
|
|
/**< Name of subtree. */
|
|
|
|
|
subsys/settings: change processing to const char
The settings module processes the variable name by splitting it up in
a set of variables. This PR removes the splitting up and keeps the
variable name as one string.
It is an alternative to #16609
The possibility is introduced to register handler including a
separator, or to register a handler for each variable.
The ability is introduced to load a subtree from flash or even to load
a single item.
Two ways to operate on variable and settings_handler names are provided:
settings_name_steq(const char *name, const char *key, const char **next)
which checks if name starts with key, returns 1/0 if it does/does not
the remaining part of name is in next.
settings_name_split(const char *name, char *argv, const char **next)
which splits up name in a part before "/"" that is found in argv and
the remaining part that is in next.
A mutex is added to make settings thread-safe
The settings_handlers list is stored in reverse alphabetical order, this
allows registration of e.g. bt and bt/mesh in separate handlers, the bt
handler itself should not contain any handling of bt/mesh.
A settings_deregister() method is added. Settings_handlers can now be
added/removed when required. This saves RAM when settings_handlers are
not needed.
Tests have been updated to reflect changes in the settings api.
Updates after meeting:
1. Removed settings_deregister
2. Changed settings_name_split() in settings_name_next:
int settings_name_next(const char *name, const char **next): returns
the number of characters before the first separator. This can then be
used to read the correct number of characters from name using strncpy
for processing.
3. New functional test added
Update in settings.h: settings_name_next() changed position -> index
Added some comments in settings.h (settings_name_steq())
Updated tests to reflect change to settings_name_next() and pointer
value comparison. The functional test can now also run on qemu_x86.
Corrected some documentation in header.
Changed registration of handlers to be non ordered.
Changed handler lookup to handle non ordered list of handlers, this
improves handler matching in case different length names are compared
and also makes it easier to add rom based handlers as they will not be
ordered.
Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-06-08 21:24:42 +02:00
|
|
|
int (*h_get)(const char *key, char *val, int val_len_max);
|
2018-05-15 14:25:29 +02:00
|
|
|
/**< Get values handler of settings items identified by keyword names.
|
|
|
|
*
|
|
|
|
* Parameters:
|
subsys/settings: change processing to const char
The settings module processes the variable name by splitting it up in
a set of variables. This PR removes the splitting up and keeps the
variable name as one string.
It is an alternative to #16609
The possibility is introduced to register handler including a
separator, or to register a handler for each variable.
The ability is introduced to load a subtree from flash or even to load
a single item.
Two ways to operate on variable and settings_handler names are provided:
settings_name_steq(const char *name, const char *key, const char **next)
which checks if name starts with key, returns 1/0 if it does/does not
the remaining part of name is in next.
settings_name_split(const char *name, char *argv, const char **next)
which splits up name in a part before "/"" that is found in argv and
the remaining part that is in next.
A mutex is added to make settings thread-safe
The settings_handlers list is stored in reverse alphabetical order, this
allows registration of e.g. bt and bt/mesh in separate handlers, the bt
handler itself should not contain any handling of bt/mesh.
A settings_deregister() method is added. Settings_handlers can now be
added/removed when required. This saves RAM when settings_handlers are
not needed.
Tests have been updated to reflect changes in the settings api.
Updates after meeting:
1. Removed settings_deregister
2. Changed settings_name_split() in settings_name_next:
int settings_name_next(const char *name, const char **next): returns
the number of characters before the first separator. This can then be
used to read the correct number of characters from name using strncpy
for processing.
3. New functional test added
Update in settings.h: settings_name_next() changed position -> index
Added some comments in settings.h (settings_name_steq())
Updated tests to reflect change to settings_name_next() and pointer
value comparison. The functional test can now also run on qemu_x86.
Corrected some documentation in header.
Changed registration of handlers to be non ordered.
Changed handler lookup to handle non ordered list of handlers, this
improves handler matching in case different length names are compared
and also makes it easier to add rom based handlers as they will not be
ordered.
Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-06-08 21:24:42 +02:00
|
|
|
* - key[in] the name with skipped part that was used as name in
|
|
|
|
* handler registration
|
|
|
|
* - val[out] buffer to receive value.
|
|
|
|
* - val_len_max[in] size of that buffer.
|
2018-05-15 14:25:29 +02:00
|
|
|
*/
|
|
|
|
|
subsys/settings: change processing to const char
The settings module processes the variable name by splitting it up in
a set of variables. This PR removes the splitting up and keeps the
variable name as one string.
It is an alternative to #16609
The possibility is introduced to register handler including a
separator, or to register a handler for each variable.
The ability is introduced to load a subtree from flash or even to load
a single item.
Two ways to operate on variable and settings_handler names are provided:
settings_name_steq(const char *name, const char *key, const char **next)
which checks if name starts with key, returns 1/0 if it does/does not
the remaining part of name is in next.
settings_name_split(const char *name, char *argv, const char **next)
which splits up name in a part before "/"" that is found in argv and
the remaining part that is in next.
A mutex is added to make settings thread-safe
The settings_handlers list is stored in reverse alphabetical order, this
allows registration of e.g. bt and bt/mesh in separate handlers, the bt
handler itself should not contain any handling of bt/mesh.
A settings_deregister() method is added. Settings_handlers can now be
added/removed when required. This saves RAM when settings_handlers are
not needed.
Tests have been updated to reflect changes in the settings api.
Updates after meeting:
1. Removed settings_deregister
2. Changed settings_name_split() in settings_name_next:
int settings_name_next(const char *name, const char **next): returns
the number of characters before the first separator. This can then be
used to read the correct number of characters from name using strncpy
for processing.
3. New functional test added
Update in settings.h: settings_name_next() changed position -> index
Added some comments in settings.h (settings_name_steq())
Updated tests to reflect change to settings_name_next() and pointer
value comparison. The functional test can now also run on qemu_x86.
Corrected some documentation in header.
Changed registration of handlers to be non ordered.
Changed handler lookup to handle non ordered list of handlers, this
improves handler matching in case different length names are compared
and also makes it easier to add rom based handlers as they will not be
ordered.
Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-06-08 21:24:42 +02:00
|
|
|
int (*h_set)(const char *key, size_t len, settings_read_cb read_cb,
|
|
|
|
void *cb_arg);
|
2018-05-15 14:25:29 +02:00
|
|
|
/**< Set value handler of settings items identified by keyword names.
|
|
|
|
*
|
|
|
|
* Parameters:
|
subsys/settings: change processing to const char
The settings module processes the variable name by splitting it up in
a set of variables. This PR removes the splitting up and keeps the
variable name as one string.
It is an alternative to #16609
The possibility is introduced to register handler including a
separator, or to register a handler for each variable.
The ability is introduced to load a subtree from flash or even to load
a single item.
Two ways to operate on variable and settings_handler names are provided:
settings_name_steq(const char *name, const char *key, const char **next)
which checks if name starts with key, returns 1/0 if it does/does not
the remaining part of name is in next.
settings_name_split(const char *name, char *argv, const char **next)
which splits up name in a part before "/"" that is found in argv and
the remaining part that is in next.
A mutex is added to make settings thread-safe
The settings_handlers list is stored in reverse alphabetical order, this
allows registration of e.g. bt and bt/mesh in separate handlers, the bt
handler itself should not contain any handling of bt/mesh.
A settings_deregister() method is added. Settings_handlers can now be
added/removed when required. This saves RAM when settings_handlers are
not needed.
Tests have been updated to reflect changes in the settings api.
Updates after meeting:
1. Removed settings_deregister
2. Changed settings_name_split() in settings_name_next:
int settings_name_next(const char *name, const char **next): returns
the number of characters before the first separator. This can then be
used to read the correct number of characters from name using strncpy
for processing.
3. New functional test added
Update in settings.h: settings_name_next() changed position -> index
Added some comments in settings.h (settings_name_steq())
Updated tests to reflect change to settings_name_next() and pointer
value comparison. The functional test can now also run on qemu_x86.
Corrected some documentation in header.
Changed registration of handlers to be non ordered.
Changed handler lookup to handle non ordered list of handlers, this
improves handler matching in case different length names are compared
and also makes it easier to add rom based handlers as they will not be
ordered.
Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-06-08 21:24:42 +02:00
|
|
|
* - key[in] the name with skipped part that was used as name in
|
|
|
|
* handler registration
|
|
|
|
* - len[in] the size of the data found in the backend.
|
|
|
|
* - read_cb[in] function provided to read the data from the backend.
|
|
|
|
* - cb_arg[in] arguments for the read function provided by the
|
|
|
|
* backend.
|
2018-05-15 14:25:29 +02:00
|
|
|
*/
|
|
|
|
|
2018-02-02 14:30:56 +01:00
|
|
|
int (*h_commit)(void);
|
2018-05-15 14:25:29 +02:00
|
|
|
/**< This handler gets called after settings has been loaded in full.
|
|
|
|
* User might use it to apply setting to the application.
|
|
|
|
*/
|
|
|
|
|
2019-05-29 08:44:37 +02:00
|
|
|
int (*h_export)(int (*export_func)(const char *name, const void *val,
|
2018-05-15 14:25:29 +02:00
|
|
|
size_t val_len));
|
|
|
|
/**< This gets called to dump all current settings items.
|
|
|
|
*
|
|
|
|
* This happens when @ref settings_save tries to save the settings.
|
|
|
|
* Parameters:
|
|
|
|
* - export_func: the pointer to the internal function which appends
|
|
|
|
* a single key-value pair to persisted settings. Don't store
|
|
|
|
* duplicated value. The name is subtree/key string, val is the string
|
|
|
|
* with value.
|
|
|
|
*
|
|
|
|
* @remarks The User might limit a implementations of handler to serving
|
|
|
|
* only one keyword at one call - what will impose limit to get/set
|
|
|
|
* values using full subtree/key name.
|
|
|
|
*/
|
2018-02-02 14:30:56 +01:00
|
|
|
};
|
|
|
|
|
2019-06-18 15:16:26 +02:00
|
|
|
/**
|
2019-06-20 11:52:18 +02:00
|
|
|
* Define a static handler for settings items
|
2019-06-18 15:16:26 +02:00
|
|
|
*
|
2019-06-20 11:52:18 +02:00
|
|
|
* @param _hname handler name
|
|
|
|
* @param _tree subtree name
|
|
|
|
* @param _get get routine (can be NULL)
|
|
|
|
* @param _set set routine (can be NULL)
|
|
|
|
* @param _commit commit routine (can be NULL)
|
|
|
|
* @param _export export routine (can be NULL)
|
|
|
|
*
|
|
|
|
* This createa a variable _hname prepended by settings_handler_.
|
2019-06-18 15:16:26 +02:00
|
|
|
*
|
|
|
|
*/
|
2019-06-20 11:52:18 +02:00
|
|
|
|
|
|
|
#define SETTINGS_STATIC_HANDLER_DEFINE(_hname, _tree, _get, _set, _commit, \
|
|
|
|
_export) \
|
|
|
|
const Z_STRUCT_SECTION_ITERABLE(settings_handler_static, \
|
|
|
|
settings_handler_ ## _hname) = { \
|
|
|
|
.name = _tree, \
|
|
|
|
.h_get = _get, \
|
|
|
|
.h_set = _set, \
|
|
|
|
.h_commit = _commit, \
|
|
|
|
.h_export = _export, \
|
|
|
|
}
|
2019-06-18 15:16:26 +02:00
|
|
|
|
2018-02-02 14:30:56 +01:00
|
|
|
/**
|
|
|
|
* Initialization of settings and backend
|
|
|
|
*
|
|
|
|
* Can be called at application startup.
|
|
|
|
* In case the backend is NFFS Remember to call it after FS was mounted.
|
|
|
|
* For FCB backend it can be called without such a restriction.
|
2018-04-16 12:48:37 +02:00
|
|
|
*
|
|
|
|
* @return 0 on success, non-zero on failure.
|
2018-02-02 14:30:56 +01:00
|
|
|
*/
|
2018-04-16 12:48:37 +02:00
|
|
|
int settings_subsys_init(void);
|
2018-02-02 14:30:56 +01:00
|
|
|
|
|
|
|
/**
|
2019-06-18 15:16:26 +02:00
|
|
|
* Register a handler for settings items stored in RAM.
|
2018-02-02 14:30:56 +01:00
|
|
|
*
|
|
|
|
* @param cf Structure containing registration info.
|
|
|
|
*
|
|
|
|
* @return 0 on success, non-zero on failure.
|
|
|
|
*/
|
|
|
|
int settings_register(struct settings_handler *cf);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load serialized items from registered persistence sources. Handlers for
|
|
|
|
* serialized item subtrees registered earlier will be called for encountered
|
|
|
|
* values.
|
|
|
|
*
|
|
|
|
* @return 0 on success, non-zero on failure.
|
|
|
|
*/
|
|
|
|
int settings_load(void);
|
|
|
|
|
|
|
|
/**
|
subsys/settings: change processing to const char
The settings module processes the variable name by splitting it up in
a set of variables. This PR removes the splitting up and keeps the
variable name as one string.
It is an alternative to #16609
The possibility is introduced to register handler including a
separator, or to register a handler for each variable.
The ability is introduced to load a subtree from flash or even to load
a single item.
Two ways to operate on variable and settings_handler names are provided:
settings_name_steq(const char *name, const char *key, const char **next)
which checks if name starts with key, returns 1/0 if it does/does not
the remaining part of name is in next.
settings_name_split(const char *name, char *argv, const char **next)
which splits up name in a part before "/"" that is found in argv and
the remaining part that is in next.
A mutex is added to make settings thread-safe
The settings_handlers list is stored in reverse alphabetical order, this
allows registration of e.g. bt and bt/mesh in separate handlers, the bt
handler itself should not contain any handling of bt/mesh.
A settings_deregister() method is added. Settings_handlers can now be
added/removed when required. This saves RAM when settings_handlers are
not needed.
Tests have been updated to reflect changes in the settings api.
Updates after meeting:
1. Removed settings_deregister
2. Changed settings_name_split() in settings_name_next:
int settings_name_next(const char *name, const char **next): returns
the number of characters before the first separator. This can then be
used to read the correct number of characters from name using strncpy
for processing.
3. New functional test added
Update in settings.h: settings_name_next() changed position -> index
Added some comments in settings.h (settings_name_steq())
Updated tests to reflect change to settings_name_next() and pointer
value comparison. The functional test can now also run on qemu_x86.
Corrected some documentation in header.
Changed registration of handlers to be non ordered.
Changed handler lookup to handle non ordered list of handlers, this
improves handler matching in case different length names are compared
and also makes it easier to add rom based handlers as they will not be
ordered.
Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-06-08 21:24:42 +02:00
|
|
|
* Load limited set of serialized items from registered persistence sources.
|
|
|
|
* Handlers for serialized item subtrees registered earlier will be called for
|
|
|
|
* encountered values that belong to the subtree.
|
|
|
|
*
|
|
|
|
* @param[in] subtree name of the subtree to be loaded.
|
|
|
|
* @return 0 on success, non-zero on failure.
|
|
|
|
*/
|
|
|
|
int settings_load_subtree(const char *subtree);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save currently running serialized items. All serialized items which are
|
|
|
|
* different from currently persisted values will be saved.
|
2018-02-02 14:30:56 +01:00
|
|
|
*
|
|
|
|
* @return 0 on success, non-zero on failure.
|
|
|
|
*/
|
|
|
|
int settings_save(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a single serialized value to persisted storage (if it has
|
|
|
|
* changed value).
|
|
|
|
*
|
|
|
|
* @param name Name/key of the settings item.
|
2018-05-15 14:25:29 +02:00
|
|
|
* @param value Pointer to the value of the settings item. This value will
|
|
|
|
* be transferred to the @ref settings_handler::h_export handler implementation.
|
|
|
|
* @param val_len Length of the value.
|
2018-02-02 14:30:56 +01:00
|
|
|
*
|
|
|
|
* @return 0 on success, non-zero on failure.
|
|
|
|
*/
|
2019-05-29 08:44:37 +02:00
|
|
|
int settings_save_one(const char *name, const void *value, size_t val_len);
|
2018-02-02 14:30:56 +01:00
|
|
|
|
2018-12-06 15:02:06 +01:00
|
|
|
/**
|
|
|
|
* Delete a single serialized in persisted storage.
|
|
|
|
*
|
|
|
|
* Deleting an existing key-value pair in the settings mean
|
|
|
|
* to set its value to NULL.
|
|
|
|
*
|
|
|
|
* @param name Name/key of the settings item.
|
|
|
|
*
|
|
|
|
* @return 0 on success, non-zero on failure.
|
|
|
|
*/
|
|
|
|
int settings_delete(const char *name);
|
|
|
|
|
2018-02-02 14:30:56 +01:00
|
|
|
/**
|
2019-04-02 11:06:05 +02:00
|
|
|
* Call commit for all settings handler. This should apply all
|
|
|
|
* settings which has been set, but not applied yet.
|
2018-02-02 14:30:56 +01:00
|
|
|
*
|
|
|
|
* @return 0 on success, non-zero on failure.
|
|
|
|
*/
|
2019-04-02 11:06:05 +02:00
|
|
|
int settings_commit(void);
|
2018-02-02 14:30:56 +01:00
|
|
|
|
subsys/settings: change processing to const char
The settings module processes the variable name by splitting it up in
a set of variables. This PR removes the splitting up and keeps the
variable name as one string.
It is an alternative to #16609
The possibility is introduced to register handler including a
separator, or to register a handler for each variable.
The ability is introduced to load a subtree from flash or even to load
a single item.
Two ways to operate on variable and settings_handler names are provided:
settings_name_steq(const char *name, const char *key, const char **next)
which checks if name starts with key, returns 1/0 if it does/does not
the remaining part of name is in next.
settings_name_split(const char *name, char *argv, const char **next)
which splits up name in a part before "/"" that is found in argv and
the remaining part that is in next.
A mutex is added to make settings thread-safe
The settings_handlers list is stored in reverse alphabetical order, this
allows registration of e.g. bt and bt/mesh in separate handlers, the bt
handler itself should not contain any handling of bt/mesh.
A settings_deregister() method is added. Settings_handlers can now be
added/removed when required. This saves RAM when settings_handlers are
not needed.
Tests have been updated to reflect changes in the settings api.
Updates after meeting:
1. Removed settings_deregister
2. Changed settings_name_split() in settings_name_next:
int settings_name_next(const char *name, const char **next): returns
the number of characters before the first separator. This can then be
used to read the correct number of characters from name using strncpy
for processing.
3. New functional test added
Update in settings.h: settings_name_next() changed position -> index
Added some comments in settings.h (settings_name_steq())
Updated tests to reflect change to settings_name_next() and pointer
value comparison. The functional test can now also run on qemu_x86.
Corrected some documentation in header.
Changed registration of handlers to be non ordered.
Changed handler lookup to handle non ordered list of handlers, this
improves handler matching in case different length names are compared
and also makes it easier to add rom based handlers as they will not be
ordered.
Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-06-08 21:24:42 +02:00
|
|
|
/**
|
|
|
|
* Call commit for settings handler that belong to subtree.
|
|
|
|
* This should apply all settings which has been set, but not applied yet.
|
|
|
|
*
|
|
|
|
* @param[in] subtree name of the subtree to be committed.
|
|
|
|
*
|
|
|
|
* @return 0 on success, non-zero on failure.
|
|
|
|
*/
|
|
|
|
int settings_commit_subtree(const char *subtree);
|
|
|
|
|
2018-02-02 14:30:56 +01:00
|
|
|
/**
|
2019-04-02 11:06:05 +02:00
|
|
|
* @} settings
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* API for config storage
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct settings_store_itf;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @struct settings_store
|
|
|
|
* Backend handler node for storage handling.
|
|
|
|
*/
|
|
|
|
struct settings_store {
|
|
|
|
sys_snode_t cs_next;
|
|
|
|
/**< Linked list node info for internal usage. */
|
|
|
|
|
|
|
|
const struct settings_store_itf *cs_itf;
|
|
|
|
/**< Backend handler structure. */
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @struct settings_store_itf
|
|
|
|
* Backend handler functions.
|
|
|
|
* Sources are registered using a call to @ref settings_src_register.
|
|
|
|
* Destinations are registered using a call to @ref settings_dst_register.
|
|
|
|
*/
|
|
|
|
struct settings_store_itf {
|
subsys/settings: change processing to const char
The settings module processes the variable name by splitting it up in
a set of variables. This PR removes the splitting up and keeps the
variable name as one string.
It is an alternative to #16609
The possibility is introduced to register handler including a
separator, or to register a handler for each variable.
The ability is introduced to load a subtree from flash or even to load
a single item.
Two ways to operate on variable and settings_handler names are provided:
settings_name_steq(const char *name, const char *key, const char **next)
which checks if name starts with key, returns 1/0 if it does/does not
the remaining part of name is in next.
settings_name_split(const char *name, char *argv, const char **next)
which splits up name in a part before "/"" that is found in argv and
the remaining part that is in next.
A mutex is added to make settings thread-safe
The settings_handlers list is stored in reverse alphabetical order, this
allows registration of e.g. bt and bt/mesh in separate handlers, the bt
handler itself should not contain any handling of bt/mesh.
A settings_deregister() method is added. Settings_handlers can now be
added/removed when required. This saves RAM when settings_handlers are
not needed.
Tests have been updated to reflect changes in the settings api.
Updates after meeting:
1. Removed settings_deregister
2. Changed settings_name_split() in settings_name_next:
int settings_name_next(const char *name, const char **next): returns
the number of characters before the first separator. This can then be
used to read the correct number of characters from name using strncpy
for processing.
3. New functional test added
Update in settings.h: settings_name_next() changed position -> index
Added some comments in settings.h (settings_name_steq())
Updated tests to reflect change to settings_name_next() and pointer
value comparison. The functional test can now also run on qemu_x86.
Corrected some documentation in header.
Changed registration of handlers to be non ordered.
Changed handler lookup to handle non ordered list of handlers, this
improves handler matching in case different length names are compared
and also makes it easier to add rom based handlers as they will not be
ordered.
Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-06-08 21:24:42 +02:00
|
|
|
int (*csi_load)(struct settings_store *cs, const char *subtree);
|
|
|
|
/**< Loads values from storage limited to subtree defined by subtree. If
|
|
|
|
* subtree = NULL loads all values.
|
2019-04-02 11:06:05 +02:00
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* - cs - Corresponding backend handler node
|
|
|
|
*/
|
|
|
|
|
|
|
|
int (*csi_save_start)(struct settings_store *cs);
|
|
|
|
/**< Handler called before an export operation.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* - cs - Corresponding backend handler node
|
|
|
|
*/
|
|
|
|
|
|
|
|
int (*csi_save)(struct settings_store *cs, const char *name,
|
|
|
|
const char *value, size_t val_len);
|
|
|
|
/**< Save a single key-value pair to storage.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* - cs - Corresponding backend handler node
|
|
|
|
* - name - Key in string format
|
|
|
|
* - value - Binary value
|
|
|
|
* - val_len - Length of value in bytes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int (*csi_save_end)(struct settings_store *cs);
|
|
|
|
/**< Handler called after an export operation.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* - cs - Corresponding backend handler node
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a backend handler acting as source.
|
2018-02-02 14:30:56 +01:00
|
|
|
*
|
2019-04-02 11:06:05 +02:00
|
|
|
* @param cs Backend handler node containing handler information.
|
2018-02-02 14:30:56 +01:00
|
|
|
*
|
2019-04-02 11:06:05 +02:00
|
|
|
*/
|
|
|
|
void settings_src_register(struct settings_store *cs);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a backend handler acting as destination.
|
2018-02-02 14:30:56 +01:00
|
|
|
*
|
2019-04-02 11:06:05 +02:00
|
|
|
* @param cs Backend handler node containing handler information.
|
2018-02-02 14:30:56 +01:00
|
|
|
*
|
|
|
|
*/
|
2019-04-02 11:06:05 +02:00
|
|
|
void settings_dst_register(struct settings_store *cs);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* API for handler lookup
|
|
|
|
*/
|
2018-02-02 14:30:56 +01:00
|
|
|
|
|
|
|
/**
|
2019-04-02 11:06:05 +02:00
|
|
|
* Parses a key to an array of elements and locate corresponding module handler.
|
2018-02-02 14:30:56 +01:00
|
|
|
*
|
subsys/settings: change processing to const char
The settings module processes the variable name by splitting it up in
a set of variables. This PR removes the splitting up and keeps the
variable name as one string.
It is an alternative to #16609
The possibility is introduced to register handler including a
separator, or to register a handler for each variable.
The ability is introduced to load a subtree from flash or even to load
a single item.
Two ways to operate on variable and settings_handler names are provided:
settings_name_steq(const char *name, const char *key, const char **next)
which checks if name starts with key, returns 1/0 if it does/does not
the remaining part of name is in next.
settings_name_split(const char *name, char *argv, const char **next)
which splits up name in a part before "/"" that is found in argv and
the remaining part that is in next.
A mutex is added to make settings thread-safe
The settings_handlers list is stored in reverse alphabetical order, this
allows registration of e.g. bt and bt/mesh in separate handlers, the bt
handler itself should not contain any handling of bt/mesh.
A settings_deregister() method is added. Settings_handlers can now be
added/removed when required. This saves RAM when settings_handlers are
not needed.
Tests have been updated to reflect changes in the settings api.
Updates after meeting:
1. Removed settings_deregister
2. Changed settings_name_split() in settings_name_next:
int settings_name_next(const char *name, const char **next): returns
the number of characters before the first separator. This can then be
used to read the correct number of characters from name using strncpy
for processing.
3. New functional test added
Update in settings.h: settings_name_next() changed position -> index
Added some comments in settings.h (settings_name_steq())
Updated tests to reflect change to settings_name_next() and pointer
value comparison. The functional test can now also run on qemu_x86.
Corrected some documentation in header.
Changed registration of handlers to be non ordered.
Changed handler lookup to handle non ordered list of handlers, this
improves handler matching in case different length names are compared
and also makes it easier to add rom based handlers as they will not be
ordered.
Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-06-08 21:24:42 +02:00
|
|
|
* @param[in] name in string format
|
|
|
|
* @param[out] next remaining of name after matched handler
|
2018-02-02 14:30:56 +01:00
|
|
|
*
|
2019-06-18 15:16:26 +02:00
|
|
|
* @return settings_handler_static on success, NULL on failure.
|
2019-04-02 11:06:05 +02:00
|
|
|
*/
|
2019-06-18 15:16:26 +02:00
|
|
|
struct settings_handler_static *settings_parse_and_lookup(const char *name,
|
|
|
|
const char **next);
|
2019-04-02 11:06:05 +02:00
|
|
|
|
|
|
|
|
subsys/settings: change processing to const char
The settings module processes the variable name by splitting it up in
a set of variables. This PR removes the splitting up and keeps the
variable name as one string.
It is an alternative to #16609
The possibility is introduced to register handler including a
separator, or to register a handler for each variable.
The ability is introduced to load a subtree from flash or even to load
a single item.
Two ways to operate on variable and settings_handler names are provided:
settings_name_steq(const char *name, const char *key, const char **next)
which checks if name starts with key, returns 1/0 if it does/does not
the remaining part of name is in next.
settings_name_split(const char *name, char *argv, const char **next)
which splits up name in a part before "/"" that is found in argv and
the remaining part that is in next.
A mutex is added to make settings thread-safe
The settings_handlers list is stored in reverse alphabetical order, this
allows registration of e.g. bt and bt/mesh in separate handlers, the bt
handler itself should not contain any handling of bt/mesh.
A settings_deregister() method is added. Settings_handlers can now be
added/removed when required. This saves RAM when settings_handlers are
not needed.
Tests have been updated to reflect changes in the settings api.
Updates after meeting:
1. Removed settings_deregister
2. Changed settings_name_split() in settings_name_next:
int settings_name_next(const char *name, const char **next): returns
the number of characters before the first separator. This can then be
used to read the correct number of characters from name using strncpy
for processing.
3. New functional test added
Update in settings.h: settings_name_next() changed position -> index
Added some comments in settings.h (settings_name_steq())
Updated tests to reflect change to settings_name_next() and pointer
value comparison. The functional test can now also run on qemu_x86.
Corrected some documentation in header.
Changed registration of handlers to be non ordered.
Changed handler lookup to handle non ordered list of handlers, this
improves handler matching in case different length names are compared
and also makes it easier to add rom based handlers as they will not be
ordered.
Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-06-08 21:24:42 +02:00
|
|
|
/*
|
|
|
|
* API for const name processing
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares the start of name with a key
|
|
|
|
*
|
|
|
|
* @param[in] name in string format
|
|
|
|
* @param[in] key comparison string
|
|
|
|
* @param[out] next pointer to remaining of name, when the remaining part
|
|
|
|
* starts with a separator the separator is removed from next
|
|
|
|
*
|
|
|
|
* Some examples:
|
|
|
|
* settings_name_steq("bt/btmesh/iv", "b", &next) returns 1, next="t/btmesh/iv"
|
|
|
|
* settings_name_steq("bt/btmesh/iv", "bt", &next) returns 1, next="btmesh/iv"
|
|
|
|
* settings_name_steq("bt/btmesh/iv", "bt/", &next) returns 0, next=NULL
|
|
|
|
* settings_name_steq("bt/btmesh/iv", "bta", &next) returns 0, next=NULL
|
|
|
|
*
|
|
|
|
* REMARK: This routine could be simplified if the settings_handler names
|
|
|
|
* would include a separator at the end.
|
|
|
|
*
|
|
|
|
* @return 0: no match
|
|
|
|
* 1: match, next can be used to check if match is full
|
|
|
|
*/
|
|
|
|
int settings_name_steq(const char *name, const char *key, const char **next);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* determine the number of characters before the first separator
|
|
|
|
*
|
|
|
|
* @param[in] name in string format
|
|
|
|
* @param[out] next pointer to remaining of name (excluding separator)
|
|
|
|
*
|
|
|
|
* @return index of the first separator, in case no separator was found this
|
|
|
|
* is the size of name
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int settings_name_next(const char *name, const char **next);
|
|
|
|
|
2019-04-02 11:06:05 +02:00
|
|
|
/*
|
|
|
|
* API for runtime settings
|
2018-02-02 14:30:56 +01:00
|
|
|
*/
|
2019-04-02 11:06:05 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_SETTINGS_RUNTIME
|
2018-02-02 14:30:56 +01:00
|
|
|
|
|
|
|
/**
|
2019-04-02 11:06:05 +02:00
|
|
|
* Set a value with a specific key to a module handler.
|
2018-02-02 14:30:56 +01:00
|
|
|
*
|
2019-04-02 11:06:05 +02:00
|
|
|
* @param name Key in string format.
|
|
|
|
* @param data Binary value.
|
|
|
|
* @param len Value length in bytes.
|
2018-02-02 14:30:56 +01:00
|
|
|
*
|
2019-04-02 11:06:05 +02:00
|
|
|
* @return 0 on success, non-zero on failure.
|
2018-02-02 14:30:56 +01:00
|
|
|
*/
|
2019-04-02 11:06:05 +02:00
|
|
|
int settings_runtime_set(const char *name, void *data, size_t len);
|
2018-02-02 14:30:56 +01:00
|
|
|
|
2018-11-23 17:03:44 +01:00
|
|
|
/**
|
2019-04-02 11:06:05 +02:00
|
|
|
* Get a value corresponding to a key from a module handler.
|
2018-11-23 17:03:44 +01:00
|
|
|
*
|
2019-04-02 11:06:05 +02:00
|
|
|
* @param name Key in string format.
|
|
|
|
* @param data Returned binary value.
|
|
|
|
* @param len Returned value length in bytes.
|
2018-11-23 17:03:44 +01:00
|
|
|
*
|
2019-04-02 11:06:05 +02:00
|
|
|
* @return 0 on success, non-zero on failure.
|
2018-11-23 17:03:44 +01:00
|
|
|
*/
|
2019-04-02 11:06:05 +02:00
|
|
|
int settings_runtime_get(const char *name, void *data, size_t len);
|
2018-11-23 17:03:44 +01:00
|
|
|
|
2018-02-02 14:30:56 +01:00
|
|
|
/**
|
2019-04-02 11:06:05 +02:00
|
|
|
* Apply settings in a module handler.
|
|
|
|
*
|
|
|
|
* @param name Key in string format.
|
|
|
|
*
|
|
|
|
* @return 0 on success, non-zero on failure.
|
2018-02-02 14:30:56 +01:00
|
|
|
*/
|
2019-04-02 11:06:05 +02:00
|
|
|
int settings_runtime_commit(const char *name);
|
|
|
|
|
|
|
|
#endif /* CONFIG_SETTINGS_RUNTIME */
|
2018-02-02 14:30:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-09-14 10:43:44 -07:00
|
|
|
#endif /* ZEPHYR_INCLUDE_SETTINGS_SETTINGS_H_ */
|