Skip to content

Commit

Permalink
doc/reference/storage/settings: fix misleading examples
Browse files Browse the repository at this point in the history
Code snippets show misleading example of read_callback usage
in h_set handlers.

This patch aligns snippets to implemented behavior.

fixes zephyrproject-rtos#15451

Signed-off-by: Andrzej Puzdrowski <[email protected]>
  • Loading branch information
nvlsianpu authored and ioannisg committed Aug 9, 2019
1 parent 513244a commit 413f1be
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions doc/reference/storage/settings/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ export functionality, for example, writing to the shell console).

.. code-block:: c
static int8 foo_val;
#define DEFAULT_FOO_VAL_VALUE 1
static int8 foo_val = DEFAULT_FOO_VAL_VALUE;
struct settings_handler my_conf = {
.name = "foo",
Expand All @@ -141,9 +143,25 @@ export functionality, for example, writing to the shell console).
static int foo_settings_set(int argc, char **argv, settings_read_cb read_cb,
void *cb_arg)
{
int rc;
if (argc == 1) {
if (!strcmp(argv[0], "bar")) {
return read_cb(cb_arg, &foo_val, sizeof(foo_val));
rc = read_cb(cb_arg, &foo_val, sizeof(foo_val));
if (rc >= 0) {
/* key-value pair was properly read.
* rc contains value length.
* key-value is deleted if length equals 0.
* Let's return success.
*/
if (rc == 0) {
/* set the default value as its key is deleted */
foo_val = DEFAULT_FOO_VAL_VALUE;
}
return 0;
}
/* read-out error */
return rc;
}
}
Expand Down Expand Up @@ -181,9 +199,16 @@ up from where it was before restart.
static int foo_settings_set(int argc, char **argv, settings_read_cb read_cb,
void *cb_arg)
{
int rc;
if (argc == 1) {
if (!strcmp(argv[0], "bar")) {
return read_cb(cb_arg, &foo_val, sizeof(foo_val));
rc = read_cb(cb_arg, &foo_val, sizeof(foo_val));
if (rc >= 0) {
return 0;
}
return rc;
}
}
Expand Down

0 comments on commit 413f1be

Please sign in to comment.