Commit graph

28 commits

Author SHA1 Message Date
Peter Bigot 0d480e78f8 settings: disallow modifying the content of a subtree name
There may be value in being able to rename a subtree, but there is no
identified need to be able modify the text of an assigned subtree
name.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-07-21 21:54:40 -04:00
Peter Bigot e052c7991c settings: add const qualifier for unmodified data source
Code using this API to set a key to a value that is a string literal
produces errors in C++ because the passed pointer is not const
qualified, allowing the possibility that the callee modifies the
referenced string literal memory.  Add the required const qualifiers
since the set function does not change the passed to it.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-05-07 10:51:49 +02:00
Anas Nashif 428261945b doc: doxygen: add missing groups and categorise
Add various missing groups and categorise modules correctly.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-03-14 13:01:03 -04:00
Andrzej Puzdrowski ead335cb40 settings: Include entire API into doxygen
The Runtime API and the name processing API were omitted in
the documentation as were not included in any doxygen group.

This patch includes them in dedicated settings API doxygen
sub-groups.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2020-02-17 15:34:33 -06:00
Andrzej Puzdrowski 063ee74d4f doc/subsys/settings: improve settings API doc
Corrected improper return value description of
settings_runtime_get().

Added return value description to each of settings handler
description.

Include run-time API into doxygen build.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2020-01-31 07:45:52 -05:00
Andrzej Puzdrowski 68f51f66c6 doc: cleanup after NFFS removal
Patch introduce references to LittleFS instead of NFFS where it
was suitable. In other places NFFS mentions were removed

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2020-01-21 15:32:47 +01:00
David B. Kinder 73896c0bf0 doc: fix misspelling in API doxygen comments
Fix misspellings in API doxygen comments missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-10-29 06:00:14 +01:00
Radoslaw Koppel bb9c453777 settings: doc: Update the backend documentation
This commit updates the settings backend documentation
to clearly state that it cannot provide old entities
before the final one.

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2019-10-14 12:05:42 +02:00
Radoslaw Koppel c68ff8b99c 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>
2019-09-24 14:15:38 +02:00
Radoslaw Koppel 6c2add5445 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>
2019-09-24 14:15:38 +02:00
Andrzej Puzdrowski 1ae2b9eff9 doc/settings: doxygen for settings read callback method
The callback typedef was not documented. This documentation
which explains what behavior is expected from any implementation.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-08-12 15:25:17 +02:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 536dd5a71f cleanup: include/: move misc/slist.h to sys/slist.h
move misc/slist.h to sys/slist.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Laczen JMS 5f19c8160a subsys/settings: Update bluetooth module
Updated the bluetooth module to use static handlers. Removed the
old bt specific static registration.

The routine bt_settings_init() is still calling settings_init() which
IMO is not needed anymore.

Updates:

changed SETTINGS_REGISTER_STATIC() to SETTINGS_STATIC_HANDLER_DEFINE()
changed settings_handler_stat type to settings_handler_static type
removed NULL declarations
renamed bt_handler to bt_settingshandler, as bt_handler already exists.
renamed all bt_XXX_handler to bt_xxx_settingshandler to avoid any
overlap.
changed SETTINGS_STATIC_HANDLER_DEFINE() to create variable names from
_hname by just prepending them with settings_handler_.
updated all bt_xxx_settings_handler to just bt_xxx.

Signed-off-by: Laczen JMS <laczenjms@gmail.com>
2019-06-26 16:31:01 +02:00
Laczen JMS c20ff1150f 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>
2019-06-26 16:31:01 +02:00
Laczen JMS 36edf92ca8 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-18 17:57:08 +02:00
Radoslaw Koppel 974231ee6e subsys/settings: Add const modifier to the value pointer
This commit adds const modifier for value pointer in
settings_save_one function.

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2019-05-29 10:11:12 -04:00
François Delawarde 94451b22fc subsys/settings: Allow to register custom backends in settings subsystem
Major changes are:
- Expose settings backend API to enable custom backend support.
- Add a new CONFIG_SETTINGS_CUSTOM backend to allow registering a custom
backend.
- Change api of the handlers h_set() routines to allow for
backend-specific read callbacks.
- Provide a customizable settings_backend_init() routine for custom
backends.
- Move runtime settings support to be its own backend.

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-04-26 11:24:31 +03:00
David B. Kinder 06d78354ae doc: regular misspelling scan
Fix misspellings in documentation (.rst, Kconfig help text, and .h
doxygen API comments), missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-12-26 13:27:14 -05:00
Andrzej Puzdrowski cb92c95aab settings: add delete key-value pair API
So far to deleting av existing key-value pair it was
required to storing NULL value using setting_save_one().
This patch introduce more intuitive API which takes only
the name key string.


Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-11 11:22:16 +01:00
Andrzej Puzdrowski e5a09ccb3e settings: add API for check value size
Such API is convinient for check the persistent storage
value size or whether the value is NULL.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-11 11:22:16 +01:00
Andrzej Puzdrowski 76f8b97871 subsys/settings: stream-style encoding and decoding to/from storage
This patch reworks routines used to store and read the settings data.
Provide stream-style encoding and decoding to/from flash, so the the
API only requires a pointer to binary data, and the settings
implementation takes care of encoding/decoding to/from base64 and
writing/reading to/from flash on the fly. This would eliminate the
need of a separate base64 value buffer on the application-side, thereby
further contributing to the stack footprint reduction.

Above changes allows to remove:
  256-byte value length limitation.
  removing enum settings_type usage so all settings data are treated
  now as a byte array (i.e. what's previously SETTINGS_BYTES)

Introduced routine settings_val_read_cb for read and decode the
settings data from storage inside h_set handler implementations.
h_set settings handler now provide persistent value's context
used along with read routine instead of immediately value.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-12-11 11:22:16 +01:00
Anas Nashif 05a8537c03 doc: group file system/storage APIs
Group NVS, Filesystems and Settings under "File System and Storage" in
doxygen.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-12-10 20:38:09 -05:00
Flavio Ceolin 67ca176754 headers: Fix headers across the project
Any word started with underscore followed by and uppercase letter or a
second underscore is a reserved word according with C99.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-17 15:49:26 -04:00
Jun Li 7295954399 settings: fix typo in header file
Fixed a typo in the comments of settings.h

Signed-off-by: Jun Li <jun.r.li@intel.com>
2018-06-12 22:49:12 -04:00
Andrzej Puzdrowski 9fe30535d7 susbsys: settings: fix coverity issues
API settings_subsys_init call was changed so that it returns
error (so returns int instead of void).
Prototype of storage helper function export_func for
settings_handler::h_export was changed so that it returns error
(so returns int instead of void).
Fixed few other error handling issues by ignoring return
values.

Tests were aligned to above patches.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-04-25 22:25:32 +05:30
Andrzej Puzdrowski f1275a78f2 doc: subsystem: settings subsystem doc
This patch introduce doc for settings subsystem
with FCB and File System beck-ends.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-04-06 12:46:39 +02:00
Andrzej Puzdrowski 94ff339cbf subsys: Add a new settings subsystem
Adapt the MyNewt non-volatile configuration system to become a settings
system in Zephyr.
The original code was modifed in the following ways:

* Renamed from config to settings
* Use the zephyr FCB, FS API, and base64 subsystems
* lltoa like function was added to sources as it was required but not
  included in Zephyr itself.
* The original code was modified to use Zephyr's slist.h as single
  linked list implementation.
* Reworked code which was using strtok_r, added function
  for decoding a string to a s64_t value.
* Thank to the above the settings subsys doesn't require newlibc anymore.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-03-28 10:44:20 -04:00