settings: Generic function to call set handler

This commit implements generic function to decide
witch functions to call for selected value name with given
loading parameters.

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
This commit is contained in:
Radoslaw Koppel 2019-09-18 16:07:01 +02:00 committed by Ioannis Glaropoulos
commit c68ff8b99c
9 changed files with 128 additions and 106 deletions

View file

@ -342,7 +342,6 @@ int settings_commit_subtree(const char *subtree);
struct settings_store_itf;
/**
* @struct settings_store
* Backend handler node for storage handling.
*/
struct settings_store {
@ -354,23 +353,43 @@ struct settings_store {
};
/**
* @struct settings_store_itf
* Arguments for data loading.
* Holds all parameters that changes the way data should be loaded from backend.
*/
struct settings_load_arg {
/**
* @brief Name of the subtree to be loaded
*
* If NULL, all values would be loaded.
*/
const char *subtree;
/**
* @brief Pointer to the callback function.
*
* If NULL then matching registered function would be used.
*/
settings_load_direct_cb cb;
/**
* @brief Parameter for callback function
*
* Parameter to be passed to the callback function.
*/
void *param;
};
/**
* 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 {
int (*csi_load)(struct settings_store *cs, const char *subtree,
settings_load_direct_cb cb, void *param);
int (*csi_load)(struct settings_store *cs,
const struct settings_load_arg *arg);
/**< Loads values from storage limited to subtree defined by subtree.
*
* Parameters:
* - cs - Corresponding backend handler node
* - subtree - subtree name of the subtree to be loaded,
* if NULL loads all values.
* - cb - pointer to the callback function,
* if NULL then matching registered function would be used.
* - param - parameter to be passed when callback function is called.
* - cs - Corresponding backend handler node,
* - arg - Structure that holds additional data for data loading.
*/
int (*csi_save_start)(struct settings_store *cs);
@ -429,9 +448,26 @@ void settings_dst_register(struct settings_store *cs);
* @return settings_handler_static on success, NULL on failure.
*/
struct settings_handler_static *settings_parse_and_lookup(const char *name,
const char **next);
const char **next);
/**
* Calls settings handler.
*
* @param[in] name The name of the data found in the backend.
* @param[in] len The size of the data found in the backend.
* @param[in] read_cb Function provided to read the data from
* the backend.
* @param[in,out] read_cb_arg Arguments for the read function provided by
* the backend.
* @param[in,out] load_arg Arguments for data loading.
*
* @return 0 or negative error code
*/
int settings_call_set_handler(const char *name,
size_t len,
settings_read_cb read_cb,
void *read_cb_arg,
const struct settings_load_arg *load_arg);
/*
* API for const name processing
*/