You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by vi...@apache.org on 2019/03/06 21:25:55 UTC

[mynewt-core] branch master updated: sys/config: Add API for conf_load_one() (#1674)

This is an automated email from the ASF dual-hosted git repository.

vipulrahane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 34d0765  sys/config: Add API for conf_load_one() (#1674)
34d0765 is described below

commit 34d0765d323f6fbdc1dbf6ffb628c989364b718a
Author: Vipul Rahane <vr...@gmail.com>
AuthorDate: Wed Mar 6 13:25:50 2019 -0800

    sys/config: Add API for conf_load_one() (#1674)
    
    sys/config: Add API for conf_load_one()
    - Earlier we would load all configuration values together, this gives a
    way to load just one value.
    - conf_load() still loads everything the way it used to
---
 sys/config/include/config/config.h | 10 ++++++++++
 sys/config/src/config_store.c      | 32 +++++++++++++++++++++++++++++++-
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/sys/config/include/config/config.h b/sys/config/include/config/config.h
index 124737c..a64a3a7 100644
--- a/sys/config/include/config/config.h
+++ b/sys/config/include/config/config.h
@@ -189,6 +189,16 @@ int conf_register(struct conf_handler *cf);
 int conf_load(void);
 
 /**
+ * Load configuration from a specific registered persistence source.
+ * Handlers will be called for configuration subtree for
+ * encountered values.
+ *
+ * @param name of the configuration subtree.
+ * @return 0 on success, non-zero on failure.
+ */
+int conf_load_one(char *name);
+
+/**
  * @brief Loads the configuration if it hasn't been loaded since reboot.
  *
  * @return 0 on success, non-zero on failure.
diff --git a/sys/config/src/config_store.c b/sys/config/src/config_store.c
index 64a39b7..16438a3 100644
--- a/sys/config/src/config_store.c
+++ b/sys/config/src/config_store.c
@@ -67,7 +67,37 @@ conf_dst_register(struct conf_store *cs)
 static void
 conf_load_cb(char *name, char *val, void *cb_arg)
 {
-    conf_set_value(name, val);
+    if (!cb_arg || !strcmp((char*)cb_arg, name)) {
+        /* If cb_arg is set, set specific conf value
+         * If cb_arg is not set, just set the value
+         * anyways
+         */
+        conf_set_value(name, val);
+    }
+}
+
+int
+conf_load_one(char *name)
+{
+    struct conf_store *cs;
+
+    /*
+     * for this specific config store
+     *    load config
+     *    apply config
+     *    commit all
+     */
+    conf_lock();
+    conf_loading = true;
+    SLIST_FOREACH(cs, &conf_load_srcs, cs_next) {
+        cs->cs_itf->csi_load(cs, conf_load_cb, name);
+        if (SLIST_NEXT(cs, cs_next)) {
+            conf_commit(name);
+        }
+    }
+    conf_loading = false;
+    conf_unlock();
+    return conf_commit(name);
 }
 
 int