You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/06/06 00:03:31 UTC
[GitHub] ccollins476ad closed pull request #1075: sys/config: Automatically
restore on startup
ccollins476ad closed pull request #1075: sys/config: Automatically restore on startup
URL: https://github.com/apache/mynewt-core/pull/1075
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index 61547ad79e..29296cc2d9 100644
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -331,8 +331,6 @@ main(void)
phy_init();
#endif
- conf_load();
-
/* If this app is acting as the loader in a split image setup, jump into
* the second stage application instead of starting the OS.
*/
diff --git a/apps/blesplit/src/main.c b/apps/blesplit/src/main.c
index 2cd7c25ac6..eda8352a4d 100644
--- a/apps/blesplit/src/main.c
+++ b/apps/blesplit/src/main.c
@@ -309,8 +309,6 @@ main(void)
rc = ble_svc_gap_device_name_set("nimble-blesplit");
assert(rc == 0);
- conf_load();
-
/*
* As the last thing, process events from default event queue.
*/
diff --git a/apps/bsnprph/src/main.c b/apps/bsnprph/src/main.c
index 02bb43e9c3..a47722b6e7 100644
--- a/apps/bsnprph/src/main.c
+++ b/apps/bsnprph/src/main.c
@@ -351,8 +351,6 @@ main(void)
rc = ble_svc_gap_device_name_set(MYNEWT_VAL(BSNPRPH_BLE_NAME));
assert(rc == 0);
- conf_load();
-
/* If this app is acting as the loader in a split image setup, jump into
* the second stage application instead of starting the OS.
*/
diff --git a/apps/iptest/src/main.c b/apps/iptest/src/main.c
index 7407db9376..3210b496ef 100644
--- a/apps/iptest/src/main.c
+++ b/apps/iptest/src/main.c
@@ -424,8 +424,6 @@ main(int argc, char **argv)
cbmem_init(&cbmem, cbmem_buf, MAX_CBMEM_BUF);
log_register("log", &my_log, &log_cbmem_handler, &cbmem, LOG_SYSLEVEL);
- conf_load();
-
shell_cmd_register(&net_test_cmd);
/*
diff --git a/apps/sensors_test/src/main.c b/apps/sensors_test/src/main.c
index 0f270bda94..8bd8072ced 100644
--- a/apps/sensors_test/src/main.c
+++ b/apps/sensors_test/src/main.c
@@ -511,9 +511,6 @@ main(int argc, char **argv)
/* Initialize BLE and OIC logs */
ble_oic_log_init();
- /* Load config */
- conf_load();
-
/* Initialize tasks */
init_tasks();
diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
index 5e8d18baf6..a33cafc560 100644
--- a/apps/slinky/src/main.c
+++ b/apps/slinky/src/main.c
@@ -260,8 +260,6 @@ main(int argc, char **argv)
stats_register("gpio_toggle", STATS_HDR(g_stats_gpio_toggle));
- conf_load();
-
reboot_start(hal_reset_cause());
init_tasks();
diff --git a/apps/slinky_oic/src/main.c b/apps/slinky_oic/src/main.c
index e02f4b2b0d..c5854a1569 100644
--- a/apps/slinky_oic/src/main.c
+++ b/apps/slinky_oic/src/main.c
@@ -277,8 +277,6 @@ main(int argc, char **argv)
stats_register("gpio_toggle", STATS_HDR(g_stats_gpio_toggle));
- conf_load();
-
reboot_start(hal_reset_cause());
#if MYNEWT_VAL(SPLIT_LOADER)
diff --git a/apps/splitty/src/main.c b/apps/splitty/src/main.c
index 485f168fa9..674787b613 100644
--- a/apps/splitty/src/main.c
+++ b/apps/splitty/src/main.c
@@ -193,8 +193,6 @@ main(int argc, char **argv)
stats_register("gpio_toggle", STATS_HDR(g_stats_gpio_toggle));
- conf_load();
-
reboot_start(hal_reset_cause());
init_tasks();
diff --git a/apps/testbench/src/testbench.c b/apps/testbench/src/testbench.c
index 1f0e7ca79a..a040844224 100644
--- a/apps/testbench/src/testbench.c
+++ b/apps/testbench/src/testbench.c
@@ -399,8 +399,6 @@ main(int argc, char **argv)
oc_ble_coap_gatt_srv_init();
#endif
- conf_load();
-
reboot_start(hal_reset_cause());
/*
diff --git a/sys/config/src/config.c b/sys/config/src/config.c
index 0793dc464a..d23533b265 100644
--- a/sys/config/src/config.c
+++ b/sys/config/src/config.c
@@ -28,7 +28,12 @@
struct conf_handler_head conf_handlers;
-static uint8_t conf_cmd_inited;
+static os_event_fn conf_ev_fn_load;
+
+/* OS event - causes persisted config values to be loaded at startup. */
+static struct os_event conf_ev_load = {
+ .ev_cb = conf_ev_fn_load,
+};
void
conf_init(void)
@@ -38,10 +43,6 @@ conf_init(void)
SLIST_INIT(&conf_handlers);
conf_store_init();
- if (conf_cmd_inited) {
- return;
- }
-
(void)rc;
#if MYNEWT_VAL(CONFIG_CLI)
@@ -53,7 +54,11 @@ conf_init(void)
SYSINIT_PANIC_ASSERT(rc == 0);
#endif
- conf_cmd_inited = 1;
+ /* Delay loading the configuration until the default event queue is
+ * processed. This gives main() a chance to configure the underlying
+ * storage first.
+ */
+ os_eventq_put(os_eventq_dflt_get(), &conf_ev_load);
}
int
@@ -63,6 +68,12 @@ conf_register(struct conf_handler *handler)
return 0;
}
+static void
+conf_ev_fn_load(struct os_event *ev)
+{
+ conf_load();
+}
+
/*
* Find conf_handler based on name.
*/
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services