You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/04/08 17:27:32 UTC

[1/3] incubator-mynewt-core git commit: config; add conf_save_one() to persist individual setting.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop f4fd3ba40 -> 35b4f2339


config; add conf_save_one() to persist individual setting.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/35b4f233
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/35b4f233
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/35b4f233

Branch: refs/heads/develop
Commit: 35b4f2339df2d2b5f2ec819b87e3b8e40b840d1a
Parents: d3f4915
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Apr 8 08:24:57 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Apr 8 08:25:50 2016 -0700

----------------------------------------------------------------------
 sys/config/include/config/config.h |  2 +
 sys/config/src/config_file.c       | 23 +++++++--
 sys/config/src/config_store.c      | 21 ++++++--
 sys/config/src/test/conf_test.c    | 85 +++++++++++++++++++++++++++++++++
 4 files changed, 124 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/35b4f233/sys/config/include/config/config.h
----------------------------------------------------------------------
diff --git a/sys/config/include/config/config.h b/sys/config/include/config/config.h
index c90fbba..729d13b 100644
--- a/sys/config/include/config/config.h
+++ b/sys/config/include/config/config.h
@@ -57,6 +57,8 @@ int conf_register(struct conf_handler *);
 int conf_load(void);
 
 int conf_save(void);
+int conf_save_one(struct conf_handler *, char *name, char *var);
+
 /*
   XXXX for later
   int conf_save_lib(char *name);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/35b4f233/sys/config/src/config_file.c
----------------------------------------------------------------------
diff --git a/sys/config/src/config_file.c b/sys/config/src/config_file.c
index f1bb6aa..ff627d0 100644
--- a/sys/config/src/config_file.c
+++ b/sys/config/src/config_file.c
@@ -182,8 +182,10 @@ conf_file_save(struct conf_store *cs, struct conf_handler *ch,
   char *name, char *value)
 {
     struct conf_file *cf = (struct conf_file *)cs;
+    struct fs_file *file;
     char buf[CONF_MAX_NAME_LEN + CONF_MAX_VAL_LEN + 32];
     int len;
+    int rc;
 
     if (!name) {
         return OS_INVALID_PARM;
@@ -195,10 +197,25 @@ conf_file_save(struct conf_store *cs, struct conf_handler *ch,
     }
     buf[len++] = '\n';
 
-    if (fs_write(cf->cf_save_fp, buf, len)) {
-        return OS_EINVAL;
+    if (cf->cf_save_fp) {
+        file = cf->cf_save_fp;
+    } else {
+        /*
+         * Open the file to add this one value.
+         */
+        if (fs_open(cf->cf_name, FS_ACCESS_WRITE | FS_ACCESS_APPEND, &file)) {
+            return OS_EINVAL;
+        }
     }
-    return OS_OK;
+    if (fs_write(file, buf, len)) {
+        rc = OS_EINVAL;
+    } else {
+        rc = 0;
+    }
+    if (!cf->cf_save_fp) {
+        fs_close(file);
+    }
+    return rc;
 }
 
 static int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/35b4f233/sys/config/src/config_store.c
----------------------------------------------------------------------
diff --git a/sys/config/src/config_store.c b/sys/config/src/config_store.c
index bee16de..887dfaa 100644
--- a/sys/config/src/config_store.c
+++ b/sys/config/src/config_store.c
@@ -74,16 +74,29 @@ conf_load(void)
     return conf_commit(NULL);
 }
 
-static void
-conf_store_one(struct conf_handler *ch, char *name, char *value)
+/*
+ * Append a sigle value to persisted config.
+ */
+int
+conf_save_one(struct conf_handler *ch, char *name, char *value)
 {
     struct conf_store *cs;
 
     cs = conf_save_dst;
     if (!cs) {
-        return;
+        return OS_ENOENT;
     }
-    cs->cs_itf->csi_save(cs, ch, name, value);
+    return cs->cs_itf->csi_save(cs, ch, name, value);
+}
+
+/*
+ * Walk through all registered subsystems, and ask them to export their
+ * config variables. Persist these settings.
+ */
+static void
+conf_store_one(struct conf_handler *ch, char *name, char *value)
+{
+    conf_save_one(ch, name, value);
 }
 
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/35b4f233/sys/config/src/test/conf_test.c
----------------------------------------------------------------------
diff --git a/sys/config/src/test/conf_test.c b/sys/config/src/test/conf_test.c
index 0065683..6fa263c 100644
--- a/sys/config/src/test/conf_test.c
+++ b/sys/config/src/test/conf_test.c
@@ -557,6 +557,40 @@ TEST_CASE(config_test_save_in_file)
     TEST_ASSERT(rc == 0);
 }
 
+TEST_CASE(config_test_save_one_file)
+{
+    int rc;
+    struct conf_file cf;
+
+    config_wipe_srcs();
+    rc = fs_mkdir("/config");
+    TEST_ASSERT(rc == 0 || rc == FS_EEXIST);
+
+    cf.cf_name = "/config/blah";
+    rc = conf_file_src(&cf);
+    TEST_ASSERT(rc == 0);
+    rc = conf_file_dst(&cf);
+    TEST_ASSERT(rc == 0);
+
+    val8 = 33;
+    rc = conf_save();
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_save_one(&config_test_handler, "mybar", "42");
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_load();
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(val8 == 42);
+
+    rc = conf_save_one(&config_test_handler, "mybar", "44");
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_load();
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(val8 == 44);
+}
+
 struct flash_area fcb_areas[] = {
     [0] = {
         .fa_off = 0x00000000,
@@ -801,16 +835,60 @@ TEST_CASE(config_test_compress_reset)
 
     TEST_ASSERT(fcb_free_sector_cnt(&cf.cf_fcb) == 1);
     TEST_ASSERT(fa == cf.cf_fcb.f_active.fe_area);
+
+    c2_var_count = 0;
+}
+
+TEST_CASE(config_test_save_one_fcb)
+{
+    int rc;
+    struct conf_fcb cf;
+
+    config_wipe_srcs();
+    config_wipe_fcb(fcb_areas, sizeof(fcb_areas) / sizeof(fcb_areas[0]));
+
+    cf.cf_fcb.f_sectors = fcb_areas;
+    cf.cf_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
+
+    rc = conf_fcb_src(&cf);
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_fcb_dst(&cf);
+    TEST_ASSERT(rc == 0);
+
+    val8 = 33;
+    rc = conf_save();
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_save_one(&config_test_handler, "mybar", "42");
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_load();
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(val8 == 42);
+
+    rc = conf_save_one(&config_test_handler, "mybar", "44");
+    TEST_ASSERT(rc == 0);
+
+    rc = conf_load();
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(val8 == 44);
 }
 
 TEST_SUITE(config_test_all)
 {
+    /*
+     * Config tests.
+     */
     config_empty_lookups();
     config_test_insert();
     config_test_getset_unknown();
     config_test_getset_int();
     config_test_commit();
 
+    /*
+     * NFFS as backing storage.
+     */
     config_setup_nffs();
     config_test_empty_file();
     config_test_small_file();
@@ -818,6 +896,11 @@ TEST_SUITE(config_test_all)
 
     config_test_save_in_file();
 
+    config_test_save_one_file();
+
+    /*
+     * FCB as backing storage.
+     */
     config_test_empty_fcb();
     config_test_save_1_fcb();
 
@@ -829,5 +912,7 @@ TEST_SUITE(config_test_all)
     config_test_save_3_fcb();
 
     config_test_compress_reset();
+
+    config_test_save_one_fcb();
 }
 


[2/3] incubator-mynewt-core git commit: FCB; separate return code from fcb_init() if sector magic does not match.

Posted by ma...@apache.org.
FCB; separate return code from fcb_init() if sector magic does not match.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/d3f49151
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d3f49151
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d3f49151

Branch: refs/heads/develop
Commit: d3f4915119bdbdb415aab699642246fbce02ba58
Parents: 3748009
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Apr 8 08:24:02 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Apr 8 08:25:50 2016 -0700

----------------------------------------------------------------------
 sys/fcb/src/fcb.c | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d3f49151/sys/fcb/src/fcb.c
----------------------------------------------------------------------
diff --git a/sys/fcb/src/fcb.c b/sys/fcb/src/fcb.c
index 9c9eb44..60aac43 100644
--- a/sys/fcb/src/fcb.c
+++ b/sys/fcb/src/fcb.c
@@ -193,5 +193,8 @@ fcb_sector_hdr_read(struct fcb *fcb, struct flash_area *fap,
     if (fdap->fd_magic == 0xffffffff) {
         return 0;
     }
+    if (fdap->fd_magic != fcb->f_magic) {
+        return FCB_ERR_MAGIC;
+    }
     return 1;
 }


[3/3] incubator-mynewt-core git commit: FCB; separate return code from fcb_init() if sector magic does not match.

Posted by ma...@apache.org.
FCB; separate return code from fcb_init() if sector magic does not match.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3748009c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3748009c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3748009c

Branch: refs/heads/develop
Commit: 3748009c9b801a7c5938e3ceb84339d4de318ca8
Parents: f4fd3ba
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Apr 8 07:48:09 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Apr 8 08:25:50 2016 -0700

----------------------------------------------------------------------
 sys/fcb/include/fcb/fcb.h | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3748009c/sys/fcb/include/fcb/fcb.h
----------------------------------------------------------------------
diff --git a/sys/fcb/include/fcb/fcb.h b/sys/fcb/include/fcb/fcb.h
index 4adae0e..ca1b272 100644
--- a/sys/fcb/include/fcb/fcb.h
+++ b/sys/fcb/include/fcb/fcb.h
@@ -68,6 +68,7 @@ struct fcb {
 #define FCB_ERR_NOSPACE	-4
 #define FCB_ERR_NOMEM	-5
 #define FCB_ERR_CRC	-6
+#define FCB_ERR_MAGIC   -7
 
 int fcb_init(struct fcb *fcb);