subsys/settings: Enable handler ROM registration
Add the possibility to register handles to ROM using a new macro SETTINGS_REGISTER_STATIC(handler), the handler is of type settings_handler_stat and has to be declared as const: ``` const struct settings_handler_stat test_handler = { .name = "test", /* this can also be "ps/data" .h_get = get, .h_set = set, .h_commit = NULL, /* NULL defines can be ommited */ .h_export = NULL /* NULL defines can be ommited */ }; SETTINGS_REGISTER_STATIC(test_handler); ``` To maintain support for handlers stored in RAM (dynamic handlers) `CONFIG_SETTINGS_DYNAMIC_HANDLERS`must be enabled, which is by default. When registering static handlers there is no check if this handler has been registered earlier, the latest registered static handler will be considered valid for any set/get routine, while the commit and export routines will be executed for both registered handlers. When a dynamic handler is registered a check is done to see if there was an earlier registration of the name as a static or dynamic handler registration will fail. To get to the lowest possible RAM usage it is advised to set `CONFIG_SETTINGS_DYNAMIC_HANDLERS=n`. Updates: a. Changed usage of RAM to DYNAMIC/dynamic, ROM to STATIC/static b. Updated settings.h to remove added #if defined() c. Make static handlers always enabled d. Corrected error introduced in common-rom.ld. e. Changed return value of settings_parse_and_lookup to settings_handler_stat type to reduce stack usage. f. Updated the name generated to store a handler item in ROM. It now uses the name used to register in combination with the line where SETTINGS_REGISTER_STATIC() is called. g. renamed settings_handler_stat type to settings_handler_static h. renamed SETTINGS_REGISTER_STATIC to SETTINGS_STATIC_HANDLER_DEFINE() Signed-off-by: Laczen JMS <laczenjms@gmail.com>
This commit is contained in:
parent
f91d8386a3
commit
c20ff1150f
7 changed files with 175 additions and 33 deletions
|
@ -42,8 +42,64 @@ typedef ssize_t (*settings_read_cb)(void *cb_arg, void *data, size_t len);
|
|||
* These are registered using a call to @ref settings_register.
|
||||
*/
|
||||
struct settings_handler {
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
sys_snode_t node;
|
||||
/**< Linked list node info for module internal usage. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @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 {
|
||||
|
||||
char *name;
|
||||
/**< Name of subtree. */
|
||||
|
@ -93,6 +149,19 @@ struct settings_handler {
|
|||
*/
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a static handler for settings items
|
||||
*
|
||||
* @param _handler Structure containing registration info, this must be const
|
||||
* The handler name in ROM needs to be unique, it is generated from
|
||||
* _handler and the linenumber of SETTINGS_REGISTER_STATIC()
|
||||
*
|
||||
*/
|
||||
#define SETTINGS_STATIC_HANDLER_DEFINE(_handler) \
|
||||
const Z_STRUCT_SECTION_ITERABLE(settings_handler_static, \
|
||||
_CONCAT(_handler, __LINE__))\
|
||||
= _handler
|
||||
|
||||
/**
|
||||
* Initialization of settings and backend
|
||||
*
|
||||
|
@ -105,7 +174,7 @@ struct settings_handler {
|
|||
int settings_subsys_init(void);
|
||||
|
||||
/**
|
||||
* Register a handler for settings items.
|
||||
* Register a handler for settings items stored in RAM.
|
||||
*
|
||||
* @param cf Structure containing registration info.
|
||||
*
|
||||
|
@ -274,10 +343,10 @@ void settings_dst_register(struct settings_store *cs);
|
|||
* @param[in] name in string format
|
||||
* @param[out] next remaining of name after matched handler
|
||||
*
|
||||
* @return settings_handler node on success, NULL on failure.
|
||||
* @return settings_handler_static on success, NULL on failure.
|
||||
*/
|
||||
struct settings_handler *settings_parse_and_lookup(const char *name,
|
||||
const char **next);
|
||||
struct settings_handler_static *settings_parse_and_lookup(const char *name,
|
||||
const char **next);
|
||||
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue