Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
settings.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 * Copyright (c) 2015 Runtime Inc
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef ZEPHYR_INCLUDE_SETTINGS_SETTINGS_H_
9#define ZEPHYR_INCLUDE_SETTINGS_SETTINGS_H_
10
11#include <sys/types.h>
12#include <sys/util.h>
13#include <sys/slist.h>
14#include <stdint.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20
33#define SETTINGS_MAX_DIR_DEPTH 8 /* max depth of settings tree */
34#define SETTINGS_MAX_NAME_LEN (8 * SETTINGS_MAX_DIR_DEPTH)
35#define SETTINGS_MAX_VAL_LEN 256
36#define SETTINGS_NAME_SEPARATOR '/'
37#define SETTINGS_NAME_END '='
38
39/* pleace for settings additions:
40 * up to 7 separators, '=', '\0'
41 */
42#define SETTINGS_EXTRA_LEN ((SETTINGS_MAX_DIR_DEPTH - 1) + 2)
43
57typedef ssize_t (*settings_read_cb)(void *cb_arg, void *data, size_t len);
58
65
66 const char *name;
69 int (*h_get)(const char *key, char *val, int val_len_max);
81 int (*h_set)(const char *key, size_t len, settings_read_cb read_cb,
82 void *cb_arg);
96 int (*h_commit)(void);
103 int (*h_export)(int (*export_func)(const char *name, const void *val,
104 size_t val_len));
123};
124
131
132 const char *name;
135 int (*h_get)(const char *key, char *val, int val_len_max);
147 int (*h_set)(const char *key, size_t len, settings_read_cb read_cb,
148 void *cb_arg);
162 int (*h_commit)(void);
167 int (*h_export)(int (*export_func)(const char *name, const void *val,
168 size_t val_len));
184};
185
200#define SETTINGS_STATIC_HANDLER_DEFINE(_hname, _tree, _get, _set, _commit, \
201 _export) \
202 const STRUCT_SECTION_ITERABLE(settings_handler_static, \
203 settings_handler_ ## _hname) = { \
204 .name = _tree, \
205 .h_get = _get, \
206 .h_set = _set, \
207 .h_commit = _commit, \
208 .h_export = _export, \
209 }
210
221
230
239
248int settings_load_subtree(const char *subtree);
249
275 const char *key,
276 size_t len,
277 settings_read_cb read_cb,
278 void *cb_arg,
279 void *param);
280
299 const char *subtree,
301 void *param);
302
310
322int settings_save_one(const char *name, const void *value, size_t val_len);
323
334int settings_delete(const char *name);
335
343
352int settings_commit_subtree(const char *subtree);
353
365/*
366 * API for config storage
367 */
368
369struct settings_store_itf;
370
380};
381
392 const char *subtree;
404 void *param;
405};
406
413 int (*csi_load)(struct settings_store *cs,
414 const struct settings_load_arg *arg);
428 int (*csi_save_start)(struct settings_store *cs);
435 int (*csi_save)(struct settings_store *cs, const char *name,
436 const char *value, size_t val_len);
446 int (*csi_save_end)(struct settings_store *cs);
452};
453
461
469
470
471/*
472 * API for handler lookup
473 */
474
484 const char **next);
485
500 size_t len,
501 settings_read_cb read_cb,
502 void *read_cb_arg,
503 const struct settings_load_arg *load_arg);
535int settings_name_steq(const char *name, const char *key, const char **next);
536
547int settings_name_next(const char *name, const char **next);
552#ifdef CONFIG_SETTINGS_RUNTIME
553
570int settings_runtime_set(const char *name, const void *data, size_t len);
571
581int settings_runtime_get(const char *name, void *data, size_t len);
582
595#endif /* CONFIG_SETTINGS_RUNTIME */
596
597
598#ifdef __cplusplus
599}
600#endif
601
602#endif /* ZEPHYR_INCLUDE_SETTINGS_SETTINGS_H_ */
void
Definition: eswifi_shell.c:15
void settings_dst_register(struct settings_store *cs)
struct settings_handler_static * settings_parse_and_lookup(const char *name, const char **next)
void settings_src_register(struct settings_store *cs)
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)
int settings_name_steq(const char *name, const char *key, const char **next)
int settings_name_next(const char *name, const char **next)
int settings_runtime_get(const char *name, void *data, size_t len)
int settings_runtime_set(const char *name, const void *data, size_t len)
int settings_runtime_commit(const char *name)
int settings_delete(const char *name)
int settings_commit_subtree(const char *subtree)
int settings_load_subtree_direct(const char *subtree, settings_load_direct_cb cb, void *param)
ssize_t(* settings_read_cb)(void *cb_arg, void *data, size_t len)
Definition: settings.h:57
int settings_commit(void)
int(* settings_load_direct_cb)(const char *key, size_t len, settings_read_cb read_cb, void *cb_arg, void *param)
Definition: settings.h:274
int settings_save(void)
int settings_load(void)
int settings_register(struct settings_handler *cf)
int settings_load_subtree(const char *subtree)
int settings_save_one(const char *name, const void *value, size_t val_len)
int settings_subsys_init(void)
__SIZE_TYPE__ ssize_t
Definition: types.h:28
Single-linked list implementation.
struct _snode sys_snode_t
Definition: slist.h:33
static k_spinlock_key_t key
Definition: spinlock_error_case.c:14
Definition: settings.h:130
int(* h_commit)(void)
Definition: settings.h:162
int(* h_set)(const char *key, size_t len, settings_read_cb read_cb, void *cb_arg)
Definition: settings.h:147
const char * name
Definition: settings.h:132
int(* h_export)(int(*export_func)(const char *name, const void *val, size_t val_len))
Definition: settings.h:167
int(* h_get)(const char *key, char *val, int val_len_max)
Definition: settings.h:135
Definition: settings.h:64
int(* h_export)(int(*export_func)(const char *name, const void *val, size_t val_len))
Definition: settings.h:103
sys_snode_t node
Definition: settings.h:121
int(* h_set)(const char *key, size_t len, settings_read_cb read_cb, void *cb_arg)
Definition: settings.h:81
int(* h_get)(const char *key, char *val, int val_len_max)
Definition: settings.h:69
const char * name
Definition: settings.h:66
int(* h_commit)(void)
Definition: settings.h:96
Definition: settings.h:386
const char * subtree
Name of the subtree to be loaded.
Definition: settings.h:392
void * param
Parameter for callback function.
Definition: settings.h:404
settings_load_direct_cb cb
Pointer to the callback function.
Definition: settings.h:398
Definition: settings.h:412
int(* csi_load)(struct settings_store *cs, const struct settings_load_arg *arg)
Definition: settings.h:413
int(* csi_save_end)(struct settings_store *cs)
Definition: settings.h:446
int(* csi_save_start)(struct settings_store *cs)
Definition: settings.h:428
int(* csi_save)(struct settings_store *cs, const char *name, const char *value, size_t val_len)
Definition: settings.h:435
Definition: settings.h:374
sys_snode_t cs_next
Definition: settings.h:375
const struct settings_store_itf * cs_itf
Definition: settings.h:378
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
Misc utilities.