settings: Direct loading functionality

This commit allows loading data from settings permanent storage
directly to the given callback function.

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
This commit is contained in:
Radoslaw Koppel 2019-09-09 16:27:02 +02:00 committed by Ioannis Glaropoulos
commit 6c2add5445
9 changed files with 288 additions and 49 deletions

View file

@ -226,6 +226,59 @@ int settings_load(void);
*/
int settings_load_subtree(const char *subtree);
/**
* Callback function used for direct loading.
* Used by @ref settings_load_subtree_direct function.
*
* @param[in] key the name with skipped part that was used as name in
* handler registration
* @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] cb_arg arguments for the read function provided by the
* backend.
* @param[in,out] param parameter given to the
* @ref settings_load_subtree_direct function.
*
* - 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.
*
* @return When nonzero value is returned, further subtree searching is stopped.
* Use with care as some settings backends would iterate through old
* values, and the current value is returned last.
*/
typedef int (*settings_load_direct_cb)(
const char *key,
size_t len,
settings_read_cb read_cb,
void *cb_arg,
void *param);
/**
* Load limited set of serialized items using given callback.
*
* This function bypasses the normal data workflow in settings module.
* All the settings values that are found are passed to the given callback.
*
* @note
* This function does not call commit function.
* It works as a blocking function, so it is up to the user to call
* any kind of commit function when this operation ends.
*
* @param[in] subtree subtree name of the subtree to be loaded.
* @param[in] cb pointer to the callback function.
* @param[in,out] param parameter to be passed when callback
* function is called.
* @return 0 on success, non-zero on failure.
*/
int settings_load_subtree_direct(
const char *subtree,
settings_load_direct_cb cb,
void *param);
/**
* Save currently running serialized items. All serialized items which are
* different from currently persisted values will be saved.
@ -307,12 +360,17 @@ struct settings_store {
* 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);
/**< Loads values from storage limited to subtree defined by subtree. If
* subtree = NULL loads all values.
int (*csi_load)(struct settings_store *cs, const char *subtree,
settings_load_direct_cb cb, void *param);
/**< 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.
*/
int (*csi_save_start)(struct settings_store *cs);