andrzej-kaczmarek commented on a change in pull request #1339: sys/config: Add
API to use FCB as generic key-value storage
URL: https://github.com/apache/mynewt-core/pull/1339#discussion_r211527450
##########
File path: sys/config/src/config_fcb.c
##########
@@ -255,14 +262,84 @@ conf_fcb_append(struct conf_fcb *cf, char *buf, int len)
if (rc) {
return OS_EINVAL;
}
- fcb_append_finish(&cf->cf_fcb, &loc);
+ fcb_append_finish(fcb, &loc);
return OS_OK;
}
static int
conf_fcb_save(struct conf_store *cs, const char *name, const char *value)
{
struct conf_fcb *cf = (struct conf_fcb *)cs;
+
+ return conf_fcb_kv_save(&cf->cf_fcb, name, value);
+}
+
+void
+conf_fcb_compress(struct conf_fcb *cf,
+ int (*copy_or_not)(const char *name, const char *val,
+ void *cn_arg),
+ void *cn_arg)
+{
+ return conf_fcb_compress_internal(&cf->cf_fcb, copy_or_not, cn_arg);
+}
+
+static int
+conf_kv_load_cb(struct fcb_entry *loc, void *arg)
+{
+ struct conf_kv_load_cb_arg *cb_arg = arg;
+ char buf[CONF_MAX_NAME_LEN + CONF_MAX_VAL_LEN + 32];
+ char *name_str;
+ char *val_str;
+ int rc;
+ int len;
+
+ len = loc->fe_data_len;
+ if (len >= sizeof(buf)) {
+ len = sizeof(buf) - 1;
+ }
+
+ rc = flash_area_read(loc->fe_area, loc->fe_data_off, buf, len);
+ if (rc) {
+ return 0;
+ }
+ buf[len] = '\0';
+
+ rc = conf_line_parse(buf, &name_str, &val_str);
+ if (rc) {
+ return 0;
+ }
+
+ if (strcmp(name_str, cb_arg->name)) {
+ return 0;
+ }
+
+ strncpy(cb_arg->value, val_str, cb_arg->len);
+ cb_arg->value[cb_arg->len - 1] = '\0';
+
+ return 0;
+}
+
+int
+conf_fcb_kv_load(struct fcb *fcb, const char *name, char *value, size_t len)
Review comment:
I added doxygen comment for both functions :-)
This one will return last stored value (i.e. internally it obviously walks
FCB and fills output buffer with each value so the last one stored will be
returned).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services