diff options
Diffstat (limited to 'apps/systemlib/param')
-rw-r--r-- | apps/systemlib/param/param.c | 58 | ||||
-rw-r--r-- | apps/systemlib/param/param.h | 17 |
2 files changed, 63 insertions, 12 deletions
diff --git a/apps/systemlib/param/param.c b/apps/systemlib/param/param.c index 0ab7c0ea3..9e886ea65 100644 --- a/apps/systemlib/param/param.c +++ b/apps/systemlib/param/param.c @@ -242,6 +242,25 @@ param_name(param_t param) return NULL; } +bool +param_value_is_default(param_t param) +{ + return param_find_changed(param) ? false : true; +} + +bool +param_value_unsaved(param_t param) +{ + static struct param_wbuf_s *s; + + s = param_find_changed(param); + + if (s && s->unsaved) + return true; + + return false; +} + enum param_type_e param_type(param_t param) { @@ -330,8 +349,8 @@ param_get(param_t param, void *val) return result; } -int -param_set(param_t param, const void *val) +static int +param_set_internal(param_t param, const void *val, bool mark_saved) { int result = -1; bool params_changed = false; @@ -394,7 +413,7 @@ param_set(param_t param, const void *val) goto out; } - s->unsaved = true; + s->unsaved = !mark_saved; params_changed = true; result = 0; } @@ -412,6 +431,12 @@ out: return result; } +int +param_set(param_t param, const void *val) +{ + return param_set_internal(param, val, false); +} + void param_reset(param_t param) { @@ -535,6 +560,11 @@ out: return result; } +struct param_import_state +{ + bool mark_saved; +}; + static int param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node) { @@ -542,13 +572,13 @@ param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node) int32_t i; void *v, *tmp = NULL; int result = -1; + struct param_import_state *state = (struct param_import_state *)private; /* * EOO means the end of the parameter object. (Currently not supporting * nested BSON objects). */ if (node->type == BSON_EOO) { - *(bool *)private = true; debug("end of parameters"); return 0; } @@ -621,7 +651,7 @@ param_import_callback(bson_decoder_t decoder, void *private, bson_node_t node) goto out; } - if (param_set(param, v)) { + if (param_set_internal(param, v, state->mark_saved)) { debug("error setting value for '%s'", node->name); goto out; } @@ -642,19 +672,19 @@ out: return result; } -int -param_import(int fd) +static int +param_import_internal(int fd, bool mark_saved) { - bool done; struct bson_decoder_s decoder; int result = -1; + struct param_import_state state; - if (bson_decoder_init(&decoder, fd, param_import_callback, &done)) { + if (bson_decoder_init(&decoder, fd, param_import_callback, &state)) { debug("decoder init failed"); goto out; } - done = false; + state.mark_saved = mark_saved; do { result = bson_decoder_next(&decoder); @@ -669,10 +699,16 @@ out: } int +param_import(int fd) +{ + return param_import_internal(fd, false); +} + +int param_load(int fd) { param_reset_all(); - return param_import(fd); + return param_import_internal(fd, true); } void diff --git a/apps/systemlib/param/param.h b/apps/systemlib/param/param.h index ffce07a4e..41e268db0 100644 --- a/apps/systemlib/param/param.h +++ b/apps/systemlib/param/param.h @@ -122,6 +122,20 @@ __EXPORT int param_get_index(param_t param); __EXPORT const char *param_name(param_t param); /** + * Test whether a parameter's value has changed from the default. + * + * @return If true, the parameter's value has not been changed from the default. + */ +__EXPORT bool param_value_is_default(param_t param); + +/** + * Test whether a parameter's value has been changed but not saved. + * + * @return If true, the parameter's value has not been saved. + */ +__EXPORT bool param_value_unsaved(param_t param); + +/** * Obtain the type of a parameter. * * @param param A handle returned by param_find or passed by param_foreach. @@ -160,7 +174,8 @@ __EXPORT int param_set(param_t param, const void *val); /** * Reset a parameter to its default value. * - * This function frees any storage used by struct parameters, but scalar parameters + * This function frees any storage used by struct parameters, and returns the parameter + * to its default value. * * @param param A handle returned by param_find or passed by param_foreach. */ |