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/01/14 23:51:28 UTC
incubator-mynewt-larva git commit: Move util/log -> sys/log.
util/stats -> sys/stats, util/config -> sys/config.
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/master 5187f4aa8 -> 4ab72bbad
Move util/log -> sys/log. util/stats -> sys/stats, util/config -> sys/config.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/4ab72bba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/4ab72bba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/4ab72bba
Branch: refs/heads/master
Commit: 4ab72bbad937994c652757db67b2f3fb294408b9
Parents: 5187f4a
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Jan 14 14:50:31 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Jan 14 14:50:31 2016 -0800
----------------------------------------------------------------------
libs/sys/config/egg.yml | 10 +
libs/sys/config/include/config/config.h | 71 +++++++
libs/sys/config/src/config.c | 113 +++++++++++
libs/sys/config/src/config_cli.c | 160 ++++++++++++++++
libs/sys/config/src/test/conf_test.c | 229 ++++++++++++++++++++++
libs/sys/log/egg.yml | 11 ++
libs/sys/log/include/log/log.h | 61 ++++++
libs/sys/log/src/log.c | 274 +++++++++++++++++++++++++++
libs/sys/stats/egg.yml | 11 ++
libs/sys/stats/include/stats/stats.h | 108 +++++++++++
libs/sys/stats/src/stats.c | 221 +++++++++++++++++++++
libs/util/include/util/config.h | 71 -------
libs/util/include/util/log.h | 61 ------
libs/util/include/util/stats.h | 108 -----------
libs/util/src/config.c | 113 -----------
libs/util/src/config_cli.c | 160 ----------------
libs/util/src/log.c | 274 ---------------------------
libs/util/src/stats.c | 221 ---------------------
libs/util/src/test/conf_test.c | 229 ----------------------
libs/util/src/test/util_test.c | 1 -
libs/util/src/test/util_test_priv.h | 1 -
project/blinky/blinky.yml | 4 +-
project/blinky/egg.yml | 3 +
project/blinky/src/main.c | 6 +-
project/slinky/egg.yml | 3 +
project/slinky/slinky.yml | 3 +
project/slinky/src/main.c | 6 +-
27 files changed, 1287 insertions(+), 1246 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/sys/config/egg.yml
----------------------------------------------------------------------
diff --git a/libs/sys/config/egg.yml b/libs/sys/config/egg.yml
new file mode 100644
index 0000000..744124f
--- /dev/null
+++ b/libs/sys/config/egg.yml
@@ -0,0 +1,10 @@
+egg.name: libs/sys/config
+egg.vers: 0.1
+egg.deps:
+ - libs/util
+ - libs/testutil
+egg.deps.SHELL:
+ - libs/shell
+egg.req_caps.SHELL:
+ - console
+egg.cflags.SHELL: -DSHELL_PRESENT
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/sys/config/include/config/config.h
----------------------------------------------------------------------
diff --git a/libs/sys/config/include/config/config.h b/libs/sys/config/include/config/config.h
new file mode 100644
index 0000000..a90e5c9
--- /dev/null
+++ b/libs/sys/config/include/config/config.h
@@ -0,0 +1,71 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __UTIL_CONFIG_H_
+#define __UTIL_CONFIG_H_
+
+#include <os/queue.h>
+#include <stdint.h>
+
+#define CONF_MAX_DIR_DEPTH 8 /* max depth of config tree */
+#define CONF_NAME_SEPARATOR "/"
+
+enum conf_type {
+ CONF_NONE = 0,
+ CONF_DIR,
+ CONF_INT8,
+ CONF_INT16,
+ CONF_INT32,
+ CONF_INT64,
+ CONF_STRING,
+ CONF_BYTES,
+ CONF_FLOAT,
+ CONF_DOUBLE
+} __attribute__((__packed__));
+
+struct conf_entry {
+ const char *c_name;
+ enum conf_type c_type;
+ union {
+ struct { /* INT8, INT16, INT32, INT64, FLOAT, DOUBLE */
+ void *val;
+ } single;
+ struct { /* STRING, BYTES */
+ uint16_t maxlen;
+ uint16_t len;
+ void *val;
+ } array;
+ } c_val;
+};
+
+struct conf_entry_dir {
+ const char *c_name;
+ enum conf_type c_type; /* DIR */
+};
+
+struct conf_node {
+ SLIST_ENTRY(conf_node) cn_next;
+ SLIST_HEAD(, conf_node) cn_children;
+ struct conf_entry *cn_array;
+ int cn_cnt;
+};
+
+int conf_module_init(void);
+int conf_register(struct conf_node *parent, struct conf_node *child);
+struct conf_entry *conf_lookup(int argc, char **argv);
+
+int conf_parse_name(char *name, int *name_argc, char *name_argv[]);
+
+#endif /* __UTIL_CONFIG_H_ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/sys/config/src/config.c
----------------------------------------------------------------------
diff --git a/libs/sys/config/src/config.c b/libs/sys/config/src/config.c
new file mode 100644
index 0000000..85dc9ba
--- /dev/null
+++ b/libs/sys/config/src/config.c
@@ -0,0 +1,113 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string.h>
+
+#include "config/config.h"
+
+#ifdef SHELL_PRESENT
+#include <shell/shell.h>
+#include <console/console.h>
+#endif
+
+static struct conf_node g_conf_root;
+
+static struct conf_entry *
+conf_node_match(struct conf_node *cn, const char *name)
+{
+ int i;
+
+ for (i = 0; i < cn->cn_cnt; i++) {
+ if (!strcmp(name, cn->cn_array[i].c_name)) {
+ return &cn->cn_array[i];
+ }
+ }
+ return NULL;
+}
+
+/*
+ * Register config node to a specific spot in the tree.
+ */
+int
+conf_register(struct conf_node *parent, struct conf_node *child)
+{
+ struct conf_node *cn;
+ int i;
+
+ if (!parent) {
+ parent = &g_conf_root;
+ }
+
+ for (i = 0; i < child->cn_cnt; i++) {
+ SLIST_FOREACH(cn, &parent->cn_children, cn_next) {
+ if (conf_node_match(cn, child->cn_array[i].c_name)) {
+ return -1;
+ }
+ }
+ }
+ SLIST_INSERT_HEAD(&parent->cn_children, child, cn_next);
+ return 0;
+}
+
+/*
+ * Lookup conf_entry based on name.
+ */
+struct conf_entry *
+conf_lookup(int argc, char **argv)
+{
+ int i;
+ struct conf_node *parent = &g_conf_root;
+ struct conf_entry *ret = NULL;
+ struct conf_node *cn;
+
+ for (i = 0; i < argc; i++) {
+ ret = NULL;
+ SLIST_FOREACH(cn, &parent->cn_children, cn_next) {
+ ret = conf_node_match(cn, argv[i]);
+ if (ret) {
+ break;
+ }
+ }
+ parent = cn;
+ if (!parent) {
+ return NULL;
+ }
+ }
+ return ret;
+}
+
+/*
+ * Separate string into argv array.
+ */
+int
+conf_parse_name(char *name, int *name_argc, char *name_argv[])
+{
+ char *tok;
+ char *tok_ptr;
+ int i;
+
+ tok_ptr = NULL;
+ tok = strtok_r(name, CONF_NAME_SEPARATOR, &tok_ptr);
+
+ i = 0;
+ while (tok) {
+ name_argv[i++] = tok;
+ tok = strtok_r(NULL, CONF_NAME_SEPARATOR, &tok_ptr);
+ }
+ *name_argc = i;
+
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/sys/config/src/config_cli.c
----------------------------------------------------------------------
diff --git a/libs/sys/config/src/config_cli.c b/libs/sys/config/src/config_cli.c
new file mode 100644
index 0000000..935ea17
--- /dev/null
+++ b/libs/sys/config/src/config_cli.c
@@ -0,0 +1,160 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stddef.h>
+
+#include "config/config.h"
+
+#ifdef SHELL_PRESENT
+#include <string.h>
+
+#include <shell/shell.h>
+#include <console/console.h>
+
+static struct shell_cmd shell_conf_cmd;
+
+static void
+shell_conf_display(struct conf_entry *ce)
+{
+ int32_t val;
+
+ if (ce->c_type == CONF_STRING) {
+ console_printf("%s\n", (char *)ce->c_val.array.val);
+ return;
+ }
+ switch (ce->c_type) {
+ case CONF_INT8:
+ case CONF_INT16:
+ case CONF_INT32:
+ if (ce->c_type == CONF_INT8) {
+ val = *(int8_t *)ce->c_val.single.val;
+ } else if (ce->c_type == CONF_INT16) {
+ val = *(int16_t *)ce->c_val.single.val;
+ } else {
+ val = *(int32_t *)ce->c_val.single.val;
+ }
+ console_printf("%ld (0x%lx)\n", (long)val, (long)val);
+ break;
+ default:
+ console_printf("Can't print type %d\n", ce->c_type);
+ return;
+ }
+}
+
+static int
+shell_conf_set(struct conf_entry *ce, char *val_str)
+{
+ int32_t val;
+ char *eptr;
+
+ switch (ce->c_type) {
+ case CONF_INT8:
+ case CONF_INT16:
+ case CONF_INT32:
+ val = strtol(val_str, &eptr, 0);
+ if (*eptr != '\0') {
+ goto err;
+ }
+ if (ce->c_type == CONF_INT8) {
+ if (val < INT8_MIN || val > UINT8_MAX) {
+ goto err;
+ }
+ *(int8_t *)ce->c_val.single.val = val;
+ } else if (ce->c_type == CONF_INT16) {
+ if (val < INT16_MIN || val > UINT16_MAX) {
+ goto err;
+ }
+ *(int16_t *)ce->c_val.single.val = val;
+ } else if (ce->c_type == CONF_INT32) {
+ *(int32_t *)ce->c_val.single.val = val;
+ }
+ break;
+ case CONF_STRING:
+ val = strlen(val_str);
+ if (val + 1 > ce->c_val.array.maxlen) {
+ goto err;
+ }
+ strcpy(ce->c_val.array.val, val_str);
+ ce->c_val.array.len = val;
+ break;
+ default:
+ console_printf("Can't parse type %d\n", ce->c_type);
+ break;
+ }
+ return 0;
+err:
+ return -1;
+}
+
+static int
+shell_conf_command(int argc, char **argv)
+{
+ char *name = NULL;
+ char *val = NULL;
+ char *name_argv[CONF_MAX_DIR_DEPTH];
+ int name_argc;
+ int rc;
+ struct conf_entry *ce;
+
+ switch (argc) {
+ case 1:
+ break;
+ case 2:
+ name = argv[1];
+ break;
+ case 3:
+ name = argv[1];
+ val = argv[2];
+ break;
+ default:
+ goto err;
+ }
+
+ rc = conf_parse_name(name, &name_argc, name_argv);
+ if (rc) {
+ goto err;
+ }
+
+ ce = conf_lookup(name_argc, name_argv);
+ if (!ce) {
+ console_printf("No such config variable\n");
+ goto err;
+ }
+
+ if (!val) {
+ shell_conf_display(ce);
+ } else {
+ rc = shell_conf_set(ce, val);
+ if (rc) {
+ console_printf("Failed to set\n");
+ goto err;
+ }
+ }
+ return 0;
+err:
+ console_printf("Invalid args\n");
+ return 0;
+}
+#endif
+
+int conf_module_init(void)
+{
+#ifdef SHELL_PRESENT
+ shell_cmd_register(&shell_conf_cmd, "config", shell_conf_command);
+#endif
+ return 0;
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/sys/config/src/test/conf_test.c
----------------------------------------------------------------------
diff --git a/libs/sys/config/src/test/conf_test.c b/libs/sys/config/src/test/conf_test.c
new file mode 100644
index 0000000..8aa3712
--- /dev/null
+++ b/libs/sys/config/src/test/conf_test.c
@@ -0,0 +1,229 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdio.h>
+#include <string.h>
+
+#include "os/os.h"
+#include "testutil/testutil.h"
+#include "util/config.h"
+
+uint8_t val8;
+
+static struct conf_entry ce1 = {
+ .c_name = "ce1",
+ .c_type = CONF_INT8,
+ .c_val.single.val = &val8
+};
+
+static struct conf_node cn1 = {
+ .cn_cnt = 1,
+ .cn_array = &ce1
+};
+
+static struct conf_entry ce2 = {
+ .c_name = "ce2",
+ .c_type = CONF_INT8,
+ .c_val.single.val = &val8
+};
+
+static struct conf_node cn2 = {
+ .cn_cnt = 1,
+ .cn_array = &ce2
+};
+
+static struct conf_entry ce_arr1[2] = {
+ [0] = {
+ .c_name = "cea1",
+ .c_type = CONF_INT8,
+ .c_val.single.val = &val8
+ },
+ [1] = {
+ .c_name = "cea2",
+ .c_type = CONF_INT8,
+ .c_val.single.val = &val8
+ }
+};
+
+static struct conf_node cn_arr1 = {
+ .cn_cnt = 2,
+ .cn_array = ce_arr1
+};
+
+static struct conf_entry ce_arr2[2] = {
+ [0] = {
+ .c_name = "ce21",
+ .c_type = CONF_INT8,
+ .c_val.single.val = &val8
+ },
+ [1] = {
+ .c_name = "cea2",
+ .c_type = CONF_INT8,
+ .c_val.single.val = &val8
+ }
+};
+
+static struct conf_node cn_arr2 = {
+ .cn_cnt = 2,
+ .cn_array = ce_arr2
+};
+
+static struct conf_entry_dir ce_dir = {
+ .c_name = "foo",
+ .c_type = CONF_DIR
+};
+
+static struct conf_node cn_dir = {
+ .cn_cnt = 1,
+ .cn_array = (struct conf_entry *)&ce_dir
+};
+
+static struct conf_entry ce_foo_arr1[2] = {
+ [0] = {
+ .c_name = "foo1",
+ .c_type = CONF_INT8,
+ .c_val.single.val = &val8
+ },
+ [1] = {
+ .c_name = "foo2",
+ .c_type = CONF_INT8,
+ .c_val.single.val = &val8
+ }
+};
+
+static struct conf_node cn_foo_arr1 = {
+ .cn_cnt = 2,
+ .cn_array = ce_foo_arr1
+};
+
+TEST_CASE(config_empty_lookups)
+{
+ struct conf_entry *ce;
+ char *names1[] = { "foo", "bar" };
+
+ ce = conf_lookup(0, NULL);
+ TEST_ASSERT(ce == NULL);
+
+ ce = conf_lookup(1, names1);
+ TEST_ASSERT(ce == NULL);
+
+ ce = conf_lookup(2, names1);
+ TEST_ASSERT(ce == NULL);
+}
+
+TEST_CASE(config_test_insert)
+{
+ int rc;
+
+ /*
+ * Add 2 new ones
+ */
+ rc = conf_register(NULL, &cn1);
+ TEST_ASSERT(rc == 0);
+ rc = conf_register(NULL, &cn2);
+ TEST_ASSERT(rc == 0);
+
+ /*
+ * Fail adding same ones again
+ */
+ rc = conf_register(NULL, &cn1);
+ TEST_ASSERT(rc != 0);
+ rc = conf_register(NULL, &cn2);
+ TEST_ASSERT(rc != 0);
+
+ /*
+ * Add with multiple conf_entries
+ */
+ rc = conf_register(NULL, &cn_arr1);
+ TEST_ASSERT(rc == 0);
+
+ /*
+ * Cannot add it again
+ */
+ rc = conf_register(NULL, &cn_arr1);
+ TEST_ASSERT(rc != 0);
+
+ /*
+ * Should fail right away
+ */
+ rc = conf_register(NULL, &cn_arr2);
+ TEST_ASSERT(rc != 0);
+
+}
+
+TEST_CASE(config_test_lookup)
+{
+ struct conf_entry *ce;
+ char *names1[] = { "foo", "bar" };
+ char *names2[] = { "ce1" };
+ char *names3[] = { "cea2" };
+
+ ce = conf_lookup(0, NULL);
+ TEST_ASSERT(ce == NULL);
+
+ ce = conf_lookup(1, names1);
+ TEST_ASSERT(ce == NULL);
+
+ ce = conf_lookup(2, names1);
+ TEST_ASSERT(ce == NULL);
+
+ ce = conf_lookup(1, names2);
+ TEST_ASSERT(ce != NULL);
+ TEST_ASSERT(!strcmp(ce->c_name, names2[0]));
+
+ ce = conf_lookup(1, names3);
+ TEST_ASSERT(ce != NULL);
+ TEST_ASSERT(!strcmp(ce->c_name, names3[0]));
+}
+
+TEST_CASE(config_test_dir)
+{
+ int rc;
+ struct conf_entry *ce;
+ char *names1[] = { "foo", "foo1" };
+ char *names2[] = { "foo", "foo2" };
+ char *names3[] = { "foo", "foo3" };
+
+ /*
+ * Add directory node, and node under.
+ */
+ rc = conf_register(NULL, &cn_dir);
+ TEST_ASSERT(rc == 0);
+ rc = conf_register(&cn_dir, &cn_foo_arr1);
+ TEST_ASSERT(rc == 0);
+
+ ce = conf_lookup(1, names1);
+ TEST_ASSERT(ce != NULL);
+ TEST_ASSERT(ce->c_type == CONF_DIR);
+
+ ce = conf_lookup(2, names1);
+ TEST_ASSERT(ce != NULL);
+ TEST_ASSERT(!strcmp(ce->c_name, names1[1]));
+
+ ce = conf_lookup(2, names2);
+ TEST_ASSERT(ce != NULL);
+ TEST_ASSERT(!strcmp(ce->c_name, names2[1]));
+
+ ce = conf_lookup(2, names3);
+ TEST_ASSERT(ce == NULL);
+}
+
+TEST_SUITE(config_test_suite)
+{
+ config_empty_lookups();
+ config_test_insert();
+ config_test_lookup();
+ config_test_dir();
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/sys/log/egg.yml
----------------------------------------------------------------------
diff --git a/libs/sys/log/egg.yml b/libs/sys/log/egg.yml
new file mode 100644
index 0000000..2be9f65
--- /dev/null
+++ b/libs/sys/log/egg.yml
@@ -0,0 +1,11 @@
+egg.name: libs/sys/log
+egg.vers: 0.1
+egg.deps:
+ - libs/os
+ - libs/util
+ - libs/testutil
+egg.deps.SHELL:
+ - libs/shell
+egg.req_caps.SHELL:
+ - console
+egg.cflags.SHELL: -DSHELL_PRESENT
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/sys/log/include/log/log.h
----------------------------------------------------------------------
diff --git a/libs/sys/log/include/log/log.h b/libs/sys/log/include/log/log.h
new file mode 100644
index 0000000..b1b64d7
--- /dev/null
+++ b/libs/sys/log/include/log/log.h
@@ -0,0 +1,61 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __UTIL_LOG_H__
+#define __UTIL_LOG_H__
+
+#include "util/cbmem.h"
+#include <os/queue.h>
+
+struct util_log;
+
+typedef int (*util_log_walk_func_t)(struct util_log *, void *arg, void *offset,
+ uint16_t len);
+
+typedef int (*ulh_read_func_t)(struct util_log *, void *dptr, void *buf,
+ uint16_t offset, uint16_t len);
+typedef int (*ulh_append_func_t)(struct util_log *, void *buf, int len);
+typedef int (*ulh_walk_func_t)(struct util_log *,
+ util_log_walk_func_t walk_func, void *arg);
+typedef int (*ulh_flush_func_t)(struct util_log *);
+
+struct ul_handler {
+ ulh_read_func_t ulh_read;
+ ulh_append_func_t ulh_append;
+ ulh_walk_func_t ulh_walk;
+ ulh_flush_func_t ulh_flush;
+ void *ulh_arg;
+};
+
+struct ul_entry_hdr {
+ int64_t ue_ts;
+};
+
+struct util_log {
+ char *ul_name;
+ struct ul_handler *ul_ulh;
+ STAILQ_ENTRY(util_log) ul_next;
+};
+
+int util_log_cbmem_handler_init(struct ul_handler *, struct cbmem *);
+int util_log_register(char *name, struct util_log *log, struct ul_handler *);
+int util_log_append(struct util_log *log, uint8_t *data, uint16_t len);
+int util_log_read(struct util_log *log, void *dptr, void *buf, uint16_t off,
+ uint16_t len);
+int util_log_walk(struct util_log *log, util_log_walk_func_t walk_func,
+ void *arg);
+int util_log_flush(struct util_log *log);
+
+#endif /* __UTIL_LOG_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/sys/log/src/log.c
----------------------------------------------------------------------
diff --git a/libs/sys/log/src/log.c b/libs/sys/log/src/log.c
new file mode 100644
index 0000000..a6ebfa7
--- /dev/null
+++ b/libs/sys/log/src/log.c
@@ -0,0 +1,274 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <os/os.h>
+
+#include <string.h>
+
+#include "log/log.h"
+#include <util/cbmem.h>
+
+#include <stdio.h>
+
+#ifdef SHELL_PRESENT
+
+#include <shell/shell.h>
+#include <console/console.h>
+
+struct shell_cmd shell_log_cmd;
+uint8_t shell_registered;
+
+#endif
+
+static STAILQ_HEAD(, util_log) g_util_log_list =
+ STAILQ_HEAD_INITIALIZER(g_util_log_list);
+
+
+#ifdef SHELL_PRESENT
+
+static int
+shell_log_dump_entry(struct util_log *log, void *arg, void *dptr, uint16_t len)
+{
+ struct ul_entry_hdr ueh;
+ char data[128];
+ int dlen;
+ int rc;
+
+ rc = util_log_read(log, dptr, &ueh, 0, sizeof(ueh));
+ if (rc != sizeof(ueh)) {
+ goto err;
+ }
+
+ dlen = min(len-sizeof(ueh), 128);
+
+ rc = util_log_read(log, dptr, data, sizeof(ueh), dlen);
+ if (rc < 0) {
+ goto err;
+ }
+ data[rc] = 0;
+
+ /* XXX: This is evil. newlib printf does not like 64-bit
+ * values, and this causes memory to be overwritten. Cast to a
+ * unsigned 32-bit value for now.
+ */
+ console_printf("[%lu] %s\n", (unsigned long) ueh.ue_ts, data);
+
+ return (0);
+err:
+ return (rc);
+}
+
+static int
+shell_log_dump_all(int argc, char **argv)
+{
+ struct util_log *log;
+ int rc;
+
+ STAILQ_FOREACH(log, &g_util_log_list, ul_next) {
+ rc = util_log_walk(log, shell_log_dump_entry, NULL);
+ if (rc != 0) {
+ goto err;
+ }
+ }
+
+ return (0);
+err:
+ return (rc);
+}
+
+#endif
+
+static int
+ulh_cbmem_append(struct util_log *log, void *buf, int len)
+{
+ struct cbmem *cbmem;
+ int rc;
+
+ cbmem = (struct cbmem *) log->ul_ulh->ulh_arg;
+
+ rc = cbmem_append(cbmem, buf, len);
+ if (rc != 0) {
+ goto err;
+ }
+
+ return (0);
+err:
+ return (rc);
+}
+
+static int
+ulh_cbmem_read(struct util_log *log, void *dptr, void *buf, uint16_t offset,
+ uint16_t len)
+{
+ struct cbmem *cbmem;
+ struct cbmem_entry_hdr *hdr;
+ int rc;
+
+ cbmem = (struct cbmem *) log->ul_ulh->ulh_arg;
+ hdr = (struct cbmem_entry_hdr *) dptr;
+
+ rc = cbmem_read(cbmem, hdr, buf, offset, len);
+
+ return (rc);
+}
+
+static int
+ulh_cbmem_walk(struct util_log *log, util_log_walk_func_t walk_func, void *arg)
+{
+ struct cbmem *cbmem;
+ struct cbmem_entry_hdr *hdr;
+ struct cbmem_iter iter;
+ int rc;
+
+ cbmem = (struct cbmem *) log->ul_ulh->ulh_arg;
+
+ rc = cbmem_lock_acquire(cbmem);
+ if (rc != 0) {
+ goto err;
+ }
+
+ cbmem_iter_start(cbmem, &iter);
+ while (1) {
+ hdr = cbmem_iter_next(cbmem, &iter);
+ if (!hdr) {
+ break;
+ }
+
+ rc = walk_func(log, arg, (void *) hdr, hdr->ceh_len);
+ if (rc == 1) {
+ break;
+ }
+ }
+
+ rc = cbmem_lock_release(cbmem);
+ if (rc != 0) {
+ goto err;
+ }
+
+ return (0);
+err:
+ return (rc);
+}
+
+static int
+ulh_cbmem_flush(struct util_log *log)
+{
+ struct cbmem *cbmem;
+ int rc;
+
+ cbmem = (struct cbmem *) log->ul_ulh->ulh_arg;
+
+ rc = cbmem_flush(cbmem);
+ if (rc != 0) {
+ goto err;
+ }
+
+ return (0);
+err:
+ return (rc);
+}
+
+int
+util_log_cbmem_handler_init(struct ul_handler *handler, struct cbmem *cbmem)
+{
+ handler->ulh_read = ulh_cbmem_read;
+ handler->ulh_append = ulh_cbmem_append;
+ handler->ulh_walk = ulh_cbmem_walk;
+ handler->ulh_flush = ulh_cbmem_flush;
+ handler->ulh_arg = (void *) cbmem;
+
+ return (0);
+}
+
+int
+util_log_register(char *name, struct util_log *log, struct ul_handler *ulh)
+{
+#ifdef SHELL_PRESENT
+ if (!shell_registered) {
+ /* register the shell */
+
+ shell_registered = 1;
+ shell_cmd_register(&shell_log_cmd, "log", shell_log_dump_all);
+ }
+#endif
+
+ log->ul_name = name;
+ log->ul_ulh = ulh;
+
+ STAILQ_INSERT_TAIL(&g_util_log_list, log, ul_next);
+
+ return (0);
+}
+
+int
+util_log_append(struct util_log *log, uint8_t *data, uint16_t len)
+{
+ struct ul_entry_hdr *ue;
+ int rc;
+
+ ue = (struct ul_entry_hdr *) data;
+ ue->ue_ts = (int64_t) os_time_get();
+
+ rc = log->ul_ulh->ulh_append(log, data, len + sizeof(*ue));
+ if (rc != 0) {
+ goto err;
+ }
+
+ return (0);
+err:
+ return (rc);
+}
+
+int
+util_log_walk(struct util_log *log, util_log_walk_func_t walk_func, void *arg)
+{
+ int rc;
+
+ rc = log->ul_ulh->ulh_walk(log, walk_func, arg);
+ if (rc != 0) {
+ goto err;
+ }
+
+ return (0);
+err:
+ return (rc);
+}
+
+int
+util_log_read(struct util_log *log, void *dptr, void *buf, uint16_t off,
+ uint16_t len)
+{
+ int rc;
+
+ rc = log->ul_ulh->ulh_read(log, dptr, buf, off, len);
+
+ return (rc);
+}
+
+int
+util_log_flush(struct util_log *log)
+{
+ int rc;
+
+ rc = log->ul_ulh->ulh_flush(log);
+ if (rc != 0) {
+ goto err;
+ }
+
+ return (0);
+err:
+ return (rc);
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/sys/stats/egg.yml
----------------------------------------------------------------------
diff --git a/libs/sys/stats/egg.yml b/libs/sys/stats/egg.yml
new file mode 100644
index 0000000..ee5dfea
--- /dev/null
+++ b/libs/sys/stats/egg.yml
@@ -0,0 +1,11 @@
+egg.name: libs/sys/stats
+egg.vers: 0.1
+egg.deps:
+ - libs/os
+ - libs/util
+ - libs/testutil
+egg.deps.SHELL:
+ - libs/shell
+egg.req_caps.SHELL:
+ - console
+egg.cflags.SHELL: -DSHELL_PRESENT
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/sys/stats/include/stats/stats.h
----------------------------------------------------------------------
diff --git a/libs/sys/stats/include/stats/stats.h b/libs/sys/stats/include/stats/stats.h
new file mode 100644
index 0000000..f35e0c0
--- /dev/null
+++ b/libs/sys/stats/include/stats/stats.h
@@ -0,0 +1,108 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __UTIL_STATS_H__
+#define __UTIL_STATS_H__
+
+#include <os/queue.h>
+#include <stdint.h>
+
+struct stats_name_map {
+ void *snm_off;
+ char *snm_name;
+};
+
+struct stats_hdr {
+ char *s_name;
+ uint8_t s_size;
+ uint8_t s_cnt;
+ uint16_t s_pad1;
+#ifdef STATS_NAME_ENABLE
+ struct stats_name_map *s_map;
+ int s_map_cnt;
+#endif
+ STAILQ_ENTRY(stats_hdr) s_next;
+};
+
+
+#define STATS_SECT_START(__name) \
+struct stats_ ## __name { \
+ struct stats_hdr s_hdr;
+
+
+#define STATS_SECT_END(__name) \
+} g_stats_ ## __name;
+
+#define STATS_SECT_NAME(__name) \
+ g_stats_ ## __name
+
+#define STATS_HDR(__name) ((struct stats_hdr *) &STATS_SECT_NAME(__name))
+
+#define STATS_SECT_VAR(__var) \
+ s##__var
+
+#define STATS_SIZE_16 (sizeof(uint16_t))
+#define STATS_SIZE_32 (sizeof(uint32_t))
+#define STATS_SIZE_64 (sizeof(uint64_t))
+
+#define STATS_SECT_ENTRY(__var) uint32_t STATS_SECT_VAR(__var);
+#define STATS_SECT_ENTRY16(__var) uint16_t STATS_SECT_VAR(__var);
+#define STATS_SECT_ENTRY32(__var) uint32_t STATS_SECT_VAR(__var);
+#define STATS_SECT_ENTRY64(__var) uint64_t STATS_SECT_VAR(__var);
+
+#define STATS_SIZE_INIT_PARMS(__name, __size) \
+ __size, \
+ ((sizeof(STATS_SECT_NAME(__name)) - sizeof(struct stats_hdr)) / __size)
+
+
+#define STATS_INC(__name, __var) \
+ (STATS_SECT_NAME(__name).STATS_SECT_VAR(__var)++)
+
+#define STATS_INCN(__name, __var, __n) \
+ (STATS_SECT_NAME(__name).STATS_SECT_VAR(__var) += (__n))
+
+#ifdef STATS_NAME_ENABLE
+
+#define STATS_NAME_MAP_NAME(__name) g_stats_map_ ## __name
+
+#define STATS_NAME_START(__name) \
+struct stats_name_map STATS_NAME_MAP_NAME(__name)[] = {
+
+#define STATS_NAME(__name, __entry) \
+ { &STATS_SECT_NAME(__name).STATS_SECT_VAR(__entry), #__entry },
+
+#define STATS_NAME_END(__name) \
+};
+
+#define STATS_NAME_INIT_PARMS(__name) \
+ &(STATS_NAME_MAP_NAME(__name)[0]), \
+ (sizeof(STATS_NAME_MAP_NAME(__name)) / sizeof(struct stats_name_map))
+
+#else /* STATS_NAME_ENABLE */
+
+#define STATS_NAME_START(__name)
+#define STATS_NAME(__name, __entry)
+#define STATS_NAME_END(__name)
+#define STATS_NAME_INIT_PARMS(__name) NULL, 0
+
+#endif /* STATS_NAME_ENABLE */
+
+int stats_module_init(void);
+int stats_init(struct stats_hdr *shdr, uint8_t size, uint8_t cnt,
+ struct stats_name_map *map, uint8_t map_cnt);
+int stats_register(char *name, struct stats_hdr *shdr);
+struct stats_hdr *stats_find(char *name);
+
+#endif /* __UTIL_STATS_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/sys/stats/src/stats.c
----------------------------------------------------------------------
diff --git a/libs/sys/stats/src/stats.c b/libs/sys/stats/src/stats.c
new file mode 100644
index 0000000..07e60d1
--- /dev/null
+++ b/libs/sys/stats/src/stats.c
@@ -0,0 +1,221 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <os/os.h>
+
+#include <string.h>
+
+#include "stats/stats.h"
+
+#ifdef SHELL_PRESENT
+#include <shell/shell.h>
+#include <console/console.h>
+#endif
+
+#include <stdio.h>
+
+STATS_SECT_START(stats)
+ STATS_SECT_ENTRY(num_registered)
+STATS_SECT_END(stats)
+
+STATS_NAME_START(stats)
+ STATS_NAME(stats, num_registered)
+STATS_NAME_END(stats)
+
+STAILQ_HEAD(, stats_hdr) g_stats_registry =
+ STAILQ_HEAD_INITIALIZER(g_stats_registry);
+
+#ifdef SHELL_PRESENT
+uint8_t stats_shell_registered;
+struct shell_cmd shell_stats_cmd;
+#endif
+
+
+#ifdef SHELL_PRESENT
+
+static void
+shell_stats_display_entry(struct stats_hdr *hdr, uint8_t *ptr)
+{
+ char *name;
+ char buf[12];
+ int ent_n;
+ int len;
+#ifdef STATS_NAME_ENABLE
+ int i;
+#endif
+
+ name = NULL;
+
+#ifdef STATS_NAME_ENABLE
+ for (i = 0; i < hdr->s_map_cnt; i++) {
+ if (hdr->s_map[i].snm_off == ptr) {
+ name = hdr->s_map[i].snm_name;
+ break;
+ }
+ }
+#endif
+
+ if (name == NULL) {
+ ent_n = (ptr - ((uint8_t *) hdr + sizeof(*hdr))) / hdr->s_size;
+
+ len = snprintf(buf, sizeof(buf), "s%d", ent_n);
+ buf[len] = 0;
+ name = buf;
+ }
+
+ switch (hdr->s_size) {
+ case sizeof(uint16_t):
+ console_printf("%s: %u\n", name, *(uint16_t *) ptr);
+ break;
+ case sizeof(uint32_t):
+ console_printf("%s: %lu\n", name, *(unsigned long *) ptr);
+ break;
+ case sizeof(uint64_t):
+ console_printf("%s: %llu\n", name, *(uint64_t *) ptr);
+ break;
+ default:
+ console_printf("Unknown stat size for %s %u\n", name,
+ hdr->s_size);
+ break;
+ }
+}
+
+static int
+shell_stats_display(int argc, char **argv)
+{
+ struct stats_hdr *hdr;
+ char *name;
+ uint8_t *cur;
+ uint8_t *end;
+
+ name = argv[1];
+ if (name == NULL || !strcmp(name, "")) {
+ console_printf("Must specify a statistic name to dump, "
+ "possible names are:\n");
+ STAILQ_FOREACH(hdr, &g_stats_registry, s_next) {
+ console_printf("\t%s\n", hdr->s_name);
+ }
+ goto done;
+ }
+
+
+ hdr = stats_find(name);
+ if (!hdr) {
+ console_printf("Could not find statistic %s\n", name);
+ goto done;
+ }
+
+ cur = (uint8_t *) hdr + sizeof(*hdr);
+ end = (uint8_t *) hdr + sizeof(*hdr) + (hdr->s_size * hdr->s_cnt);
+ while (cur < end) {
+ shell_stats_display_entry(hdr, (uint8_t *) cur);
+ cur += hdr->s_size;
+ }
+
+done:
+ return (0);
+}
+
+#endif
+
+
+int
+stats_module_init(void)
+{
+ int rc;
+#ifdef SHELL_PRESENT
+ if (!stats_shell_registered) {
+ stats_shell_registered = 1;
+ shell_cmd_register(&shell_stats_cmd, "stat", shell_stats_display);
+ }
+#endif
+
+
+ rc = stats_init(STATS_HDR(stats), STATS_SIZE_INIT_PARMS(stats, STATS_SIZE_32),
+ STATS_NAME_INIT_PARMS(stats));
+ if (rc != 0) {
+ goto err;
+ }
+
+ rc = stats_register("stat", STATS_HDR(stats));
+ if (rc != 0) {
+ goto err;
+ }
+
+ return (0);
+err:
+ return (rc);
+}
+
+
+int
+stats_init(struct stats_hdr *shdr, uint8_t size, uint8_t cnt,
+ struct stats_name_map *map, uint8_t map_cnt)
+{
+ memset((uint8_t *) shdr, 0, sizeof(*shdr) + (size * cnt));
+
+ shdr->s_size = size;
+ shdr->s_cnt = cnt;
+#ifdef STATS_NAME_ENABLE
+ shdr->s_map = map;
+ shdr->s_map_cnt = map_cnt;
+#endif
+
+ return (0);
+}
+
+int
+stats_register(char *name, struct stats_hdr *shdr)
+{
+ struct stats_hdr *cur;
+ int rc;
+
+ /* Don't allow duplicate entries, return an error if this stat
+ * is already registered.
+ */
+ STAILQ_FOREACH(cur, &g_stats_registry, s_next) {
+ if (!strcmp(cur->s_name, name)) {
+ rc = -1;
+ goto err;
+ }
+ }
+
+ shdr->s_name = name;
+
+ STAILQ_INSERT_TAIL(&g_stats_registry, shdr, s_next);
+
+ STATS_INC(stats, num_registered);
+
+ return (0);
+err:
+ return (rc);
+}
+
+struct stats_hdr *
+stats_find(char *name)
+{
+ struct stats_hdr *cur;
+
+ cur = NULL;
+ STAILQ_FOREACH(cur, &g_stats_registry, s_next) {
+ if (!strcmp(cur->s_name, name)) {
+ break;
+ }
+ }
+
+ return (cur);
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/util/include/util/config.h
----------------------------------------------------------------------
diff --git a/libs/util/include/util/config.h b/libs/util/include/util/config.h
deleted file mode 100644
index a90e5c9..0000000
--- a/libs/util/include/util/config.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __UTIL_CONFIG_H_
-#define __UTIL_CONFIG_H_
-
-#include <os/queue.h>
-#include <stdint.h>
-
-#define CONF_MAX_DIR_DEPTH 8 /* max depth of config tree */
-#define CONF_NAME_SEPARATOR "/"
-
-enum conf_type {
- CONF_NONE = 0,
- CONF_DIR,
- CONF_INT8,
- CONF_INT16,
- CONF_INT32,
- CONF_INT64,
- CONF_STRING,
- CONF_BYTES,
- CONF_FLOAT,
- CONF_DOUBLE
-} __attribute__((__packed__));
-
-struct conf_entry {
- const char *c_name;
- enum conf_type c_type;
- union {
- struct { /* INT8, INT16, INT32, INT64, FLOAT, DOUBLE */
- void *val;
- } single;
- struct { /* STRING, BYTES */
- uint16_t maxlen;
- uint16_t len;
- void *val;
- } array;
- } c_val;
-};
-
-struct conf_entry_dir {
- const char *c_name;
- enum conf_type c_type; /* DIR */
-};
-
-struct conf_node {
- SLIST_ENTRY(conf_node) cn_next;
- SLIST_HEAD(, conf_node) cn_children;
- struct conf_entry *cn_array;
- int cn_cnt;
-};
-
-int conf_module_init(void);
-int conf_register(struct conf_node *parent, struct conf_node *child);
-struct conf_entry *conf_lookup(int argc, char **argv);
-
-int conf_parse_name(char *name, int *name_argc, char *name_argv[]);
-
-#endif /* __UTIL_CONFIG_H_ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/util/include/util/log.h
----------------------------------------------------------------------
diff --git a/libs/util/include/util/log.h b/libs/util/include/util/log.h
deleted file mode 100644
index b1b64d7..0000000
--- a/libs/util/include/util/log.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __UTIL_LOG_H__
-#define __UTIL_LOG_H__
-
-#include "util/cbmem.h"
-#include <os/queue.h>
-
-struct util_log;
-
-typedef int (*util_log_walk_func_t)(struct util_log *, void *arg, void *offset,
- uint16_t len);
-
-typedef int (*ulh_read_func_t)(struct util_log *, void *dptr, void *buf,
- uint16_t offset, uint16_t len);
-typedef int (*ulh_append_func_t)(struct util_log *, void *buf, int len);
-typedef int (*ulh_walk_func_t)(struct util_log *,
- util_log_walk_func_t walk_func, void *arg);
-typedef int (*ulh_flush_func_t)(struct util_log *);
-
-struct ul_handler {
- ulh_read_func_t ulh_read;
- ulh_append_func_t ulh_append;
- ulh_walk_func_t ulh_walk;
- ulh_flush_func_t ulh_flush;
- void *ulh_arg;
-};
-
-struct ul_entry_hdr {
- int64_t ue_ts;
-};
-
-struct util_log {
- char *ul_name;
- struct ul_handler *ul_ulh;
- STAILQ_ENTRY(util_log) ul_next;
-};
-
-int util_log_cbmem_handler_init(struct ul_handler *, struct cbmem *);
-int util_log_register(char *name, struct util_log *log, struct ul_handler *);
-int util_log_append(struct util_log *log, uint8_t *data, uint16_t len);
-int util_log_read(struct util_log *log, void *dptr, void *buf, uint16_t off,
- uint16_t len);
-int util_log_walk(struct util_log *log, util_log_walk_func_t walk_func,
- void *arg);
-int util_log_flush(struct util_log *log);
-
-#endif /* __UTIL_LOG_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/util/include/util/stats.h
----------------------------------------------------------------------
diff --git a/libs/util/include/util/stats.h b/libs/util/include/util/stats.h
deleted file mode 100644
index f35e0c0..0000000
--- a/libs/util/include/util/stats.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __UTIL_STATS_H__
-#define __UTIL_STATS_H__
-
-#include <os/queue.h>
-#include <stdint.h>
-
-struct stats_name_map {
- void *snm_off;
- char *snm_name;
-};
-
-struct stats_hdr {
- char *s_name;
- uint8_t s_size;
- uint8_t s_cnt;
- uint16_t s_pad1;
-#ifdef STATS_NAME_ENABLE
- struct stats_name_map *s_map;
- int s_map_cnt;
-#endif
- STAILQ_ENTRY(stats_hdr) s_next;
-};
-
-
-#define STATS_SECT_START(__name) \
-struct stats_ ## __name { \
- struct stats_hdr s_hdr;
-
-
-#define STATS_SECT_END(__name) \
-} g_stats_ ## __name;
-
-#define STATS_SECT_NAME(__name) \
- g_stats_ ## __name
-
-#define STATS_HDR(__name) ((struct stats_hdr *) &STATS_SECT_NAME(__name))
-
-#define STATS_SECT_VAR(__var) \
- s##__var
-
-#define STATS_SIZE_16 (sizeof(uint16_t))
-#define STATS_SIZE_32 (sizeof(uint32_t))
-#define STATS_SIZE_64 (sizeof(uint64_t))
-
-#define STATS_SECT_ENTRY(__var) uint32_t STATS_SECT_VAR(__var);
-#define STATS_SECT_ENTRY16(__var) uint16_t STATS_SECT_VAR(__var);
-#define STATS_SECT_ENTRY32(__var) uint32_t STATS_SECT_VAR(__var);
-#define STATS_SECT_ENTRY64(__var) uint64_t STATS_SECT_VAR(__var);
-
-#define STATS_SIZE_INIT_PARMS(__name, __size) \
- __size, \
- ((sizeof(STATS_SECT_NAME(__name)) - sizeof(struct stats_hdr)) / __size)
-
-
-#define STATS_INC(__name, __var) \
- (STATS_SECT_NAME(__name).STATS_SECT_VAR(__var)++)
-
-#define STATS_INCN(__name, __var, __n) \
- (STATS_SECT_NAME(__name).STATS_SECT_VAR(__var) += (__n))
-
-#ifdef STATS_NAME_ENABLE
-
-#define STATS_NAME_MAP_NAME(__name) g_stats_map_ ## __name
-
-#define STATS_NAME_START(__name) \
-struct stats_name_map STATS_NAME_MAP_NAME(__name)[] = {
-
-#define STATS_NAME(__name, __entry) \
- { &STATS_SECT_NAME(__name).STATS_SECT_VAR(__entry), #__entry },
-
-#define STATS_NAME_END(__name) \
-};
-
-#define STATS_NAME_INIT_PARMS(__name) \
- &(STATS_NAME_MAP_NAME(__name)[0]), \
- (sizeof(STATS_NAME_MAP_NAME(__name)) / sizeof(struct stats_name_map))
-
-#else /* STATS_NAME_ENABLE */
-
-#define STATS_NAME_START(__name)
-#define STATS_NAME(__name, __entry)
-#define STATS_NAME_END(__name)
-#define STATS_NAME_INIT_PARMS(__name) NULL, 0
-
-#endif /* STATS_NAME_ENABLE */
-
-int stats_module_init(void);
-int stats_init(struct stats_hdr *shdr, uint8_t size, uint8_t cnt,
- struct stats_name_map *map, uint8_t map_cnt);
-int stats_register(char *name, struct stats_hdr *shdr);
-struct stats_hdr *stats_find(char *name);
-
-#endif /* __UTIL_STATS_H__ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/util/src/config.c
----------------------------------------------------------------------
diff --git a/libs/util/src/config.c b/libs/util/src/config.c
deleted file mode 100644
index ccc4d69..0000000
--- a/libs/util/src/config.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string.h>
-
-#include "util/config.h"
-
-#ifdef SHELL_PRESENT
-#include <shell/shell.h>
-#include <console/console.h>
-#endif
-
-static struct conf_node g_conf_root;
-
-static struct conf_entry *
-conf_node_match(struct conf_node *cn, const char *name)
-{
- int i;
-
- for (i = 0; i < cn->cn_cnt; i++) {
- if (!strcmp(name, cn->cn_array[i].c_name)) {
- return &cn->cn_array[i];
- }
- }
- return NULL;
-}
-
-/*
- * Register config node to a specific spot in the tree.
- */
-int
-conf_register(struct conf_node *parent, struct conf_node *child)
-{
- struct conf_node *cn;
- int i;
-
- if (!parent) {
- parent = &g_conf_root;
- }
-
- for (i = 0; i < child->cn_cnt; i++) {
- SLIST_FOREACH(cn, &parent->cn_children, cn_next) {
- if (conf_node_match(cn, child->cn_array[i].c_name)) {
- return -1;
- }
- }
- }
- SLIST_INSERT_HEAD(&parent->cn_children, child, cn_next);
- return 0;
-}
-
-/*
- * Lookup conf_entry based on name.
- */
-struct conf_entry *
-conf_lookup(int argc, char **argv)
-{
- int i;
- struct conf_node *parent = &g_conf_root;
- struct conf_entry *ret = NULL;
- struct conf_node *cn;
-
- for (i = 0; i < argc; i++) {
- ret = NULL;
- SLIST_FOREACH(cn, &parent->cn_children, cn_next) {
- ret = conf_node_match(cn, argv[i]);
- if (ret) {
- break;
- }
- }
- parent = cn;
- if (!parent) {
- return NULL;
- }
- }
- return ret;
-}
-
-/*
- * Separate string into argv array.
- */
-int
-conf_parse_name(char *name, int *name_argc, char *name_argv[])
-{
- char *tok;
- char *tok_ptr;
- int i;
-
- tok_ptr = NULL;
- tok = strtok_r(name, CONF_NAME_SEPARATOR, &tok_ptr);
-
- i = 0;
- while (tok) {
- name_argv[i++] = tok;
- tok = strtok_r(NULL, CONF_NAME_SEPARATOR, &tok_ptr);
- }
- *name_argc = i;
-
- return 0;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/util/src/config_cli.c
----------------------------------------------------------------------
diff --git a/libs/util/src/config_cli.c b/libs/util/src/config_cli.c
deleted file mode 100644
index 2cc6a96..0000000
--- a/libs/util/src/config_cli.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stddef.h>
-
-#include "util/config.h"
-
-#ifdef SHELL_PRESENT
-#include <string.h>
-
-#include <shell/shell.h>
-#include <console/console.h>
-
-static struct shell_cmd shell_conf_cmd;
-
-static void
-shell_conf_display(struct conf_entry *ce)
-{
- int32_t val;
-
- if (ce->c_type == CONF_STRING) {
- console_printf("%s\n", (char *)ce->c_val.array.val);
- return;
- }
- switch (ce->c_type) {
- case CONF_INT8:
- case CONF_INT16:
- case CONF_INT32:
- if (ce->c_type == CONF_INT8) {
- val = *(int8_t *)ce->c_val.single.val;
- } else if (ce->c_type == CONF_INT16) {
- val = *(int16_t *)ce->c_val.single.val;
- } else {
- val = *(int32_t *)ce->c_val.single.val;
- }
- console_printf("%ld (0x%lx)\n", (long)val, (long)val);
- break;
- default:
- console_printf("Can't print type %d\n", ce->c_type);
- return;
- }
-}
-
-static int
-shell_conf_set(struct conf_entry *ce, char *val_str)
-{
- int32_t val;
- char *eptr;
-
- switch (ce->c_type) {
- case CONF_INT8:
- case CONF_INT16:
- case CONF_INT32:
- val = strtol(val_str, &eptr, 0);
- if (*eptr != '\0') {
- goto err;
- }
- if (ce->c_type == CONF_INT8) {
- if (val < INT8_MIN || val > UINT8_MAX) {
- goto err;
- }
- *(int8_t *)ce->c_val.single.val = val;
- } else if (ce->c_type == CONF_INT16) {
- if (val < INT16_MIN || val > UINT16_MAX) {
- goto err;
- }
- *(int16_t *)ce->c_val.single.val = val;
- } else if (ce->c_type == CONF_INT32) {
- *(int32_t *)ce->c_val.single.val = val;
- }
- break;
- case CONF_STRING:
- val = strlen(val_str);
- if (val + 1 > ce->c_val.array.maxlen) {
- goto err;
- }
- strcpy(ce->c_val.array.val, val_str);
- ce->c_val.array.len = val;
- break;
- default:
- console_printf("Can't parse type %d\n", ce->c_type);
- break;
- }
- return 0;
-err:
- return -1;
-}
-
-static int
-shell_conf_command(int argc, char **argv)
-{
- char *name = NULL;
- char *val = NULL;
- char *name_argv[CONF_MAX_DIR_DEPTH];
- int name_argc;
- int rc;
- struct conf_entry *ce;
-
- switch (argc) {
- case 1:
- break;
- case 2:
- name = argv[1];
- break;
- case 3:
- name = argv[1];
- val = argv[2];
- break;
- default:
- goto err;
- }
-
- rc = conf_parse_name(name, &name_argc, name_argv);
- if (rc) {
- goto err;
- }
-
- ce = conf_lookup(name_argc, name_argv);
- if (!ce) {
- console_printf("No such config variable\n");
- goto err;
- }
-
- if (!val) {
- shell_conf_display(ce);
- } else {
- rc = shell_conf_set(ce, val);
- if (rc) {
- console_printf("Failed to set\n");
- goto err;
- }
- }
- return 0;
-err:
- console_printf("Invalid args\n");
- return 0;
-}
-#endif
-
-int conf_module_init(void)
-{
-#ifdef SHELL_PRESENT
- shell_cmd_register(&shell_conf_cmd, "config", shell_conf_command);
-#endif
- return 0;
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/util/src/log.c
----------------------------------------------------------------------
diff --git a/libs/util/src/log.c b/libs/util/src/log.c
deleted file mode 100644
index f837a88..0000000
--- a/libs/util/src/log.c
+++ /dev/null
@@ -1,274 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <os/os.h>
-
-#include <string.h>
-
-#include "util/log.h"
-#include "util/cbmem.h"
-
-#include <stdio.h>
-
-#ifdef SHELL_PRESENT
-
-#include <shell/shell.h>
-#include <console/console.h>
-
-struct shell_cmd shell_log_cmd;
-uint8_t shell_registered;
-
-#endif
-
-static STAILQ_HEAD(, util_log) g_util_log_list =
- STAILQ_HEAD_INITIALIZER(g_util_log_list);
-
-
-#ifdef SHELL_PRESENT
-
-static int
-shell_log_dump_entry(struct util_log *log, void *arg, void *dptr, uint16_t len)
-{
- struct ul_entry_hdr ueh;
- char data[128];
- int dlen;
- int rc;
-
- rc = util_log_read(log, dptr, &ueh, 0, sizeof(ueh));
- if (rc != sizeof(ueh)) {
- goto err;
- }
-
- dlen = min(len-sizeof(ueh), 128);
-
- rc = util_log_read(log, dptr, data, sizeof(ueh), dlen);
- if (rc < 0) {
- goto err;
- }
- data[rc] = 0;
-
- /* XXX: This is evil. newlib printf does not like 64-bit
- * values, and this causes memory to be overwritten. Cast to a
- * unsigned 32-bit value for now.
- */
- console_printf("[%lu] %s\n", (unsigned long) ueh.ue_ts, data);
-
- return (0);
-err:
- return (rc);
-}
-
-static int
-shell_log_dump_all(int argc, char **argv)
-{
- struct util_log *log;
- int rc;
-
- STAILQ_FOREACH(log, &g_util_log_list, ul_next) {
- rc = util_log_walk(log, shell_log_dump_entry, NULL);
- if (rc != 0) {
- goto err;
- }
- }
-
- return (0);
-err:
- return (rc);
-}
-
-#endif
-
-static int
-ulh_cbmem_append(struct util_log *log, void *buf, int len)
-{
- struct cbmem *cbmem;
- int rc;
-
- cbmem = (struct cbmem *) log->ul_ulh->ulh_arg;
-
- rc = cbmem_append(cbmem, buf, len);
- if (rc != 0) {
- goto err;
- }
-
- return (0);
-err:
- return (rc);
-}
-
-static int
-ulh_cbmem_read(struct util_log *log, void *dptr, void *buf, uint16_t offset,
- uint16_t len)
-{
- struct cbmem *cbmem;
- struct cbmem_entry_hdr *hdr;
- int rc;
-
- cbmem = (struct cbmem *) log->ul_ulh->ulh_arg;
- hdr = (struct cbmem_entry_hdr *) dptr;
-
- rc = cbmem_read(cbmem, hdr, buf, offset, len);
-
- return (rc);
-}
-
-static int
-ulh_cbmem_walk(struct util_log *log, util_log_walk_func_t walk_func, void *arg)
-{
- struct cbmem *cbmem;
- struct cbmem_entry_hdr *hdr;
- struct cbmem_iter iter;
- int rc;
-
- cbmem = (struct cbmem *) log->ul_ulh->ulh_arg;
-
- rc = cbmem_lock_acquire(cbmem);
- if (rc != 0) {
- goto err;
- }
-
- cbmem_iter_start(cbmem, &iter);
- while (1) {
- hdr = cbmem_iter_next(cbmem, &iter);
- if (!hdr) {
- break;
- }
-
- rc = walk_func(log, arg, (void *) hdr, hdr->ceh_len);
- if (rc == 1) {
- break;
- }
- }
-
- rc = cbmem_lock_release(cbmem);
- if (rc != 0) {
- goto err;
- }
-
- return (0);
-err:
- return (rc);
-}
-
-static int
-ulh_cbmem_flush(struct util_log *log)
-{
- struct cbmem *cbmem;
- int rc;
-
- cbmem = (struct cbmem *) log->ul_ulh->ulh_arg;
-
- rc = cbmem_flush(cbmem);
- if (rc != 0) {
- goto err;
- }
-
- return (0);
-err:
- return (rc);
-}
-
-int
-util_log_cbmem_handler_init(struct ul_handler *handler, struct cbmem *cbmem)
-{
- handler->ulh_read = ulh_cbmem_read;
- handler->ulh_append = ulh_cbmem_append;
- handler->ulh_walk = ulh_cbmem_walk;
- handler->ulh_flush = ulh_cbmem_flush;
- handler->ulh_arg = (void *) cbmem;
-
- return (0);
-}
-
-int
-util_log_register(char *name, struct util_log *log, struct ul_handler *ulh)
-{
-#ifdef SHELL_PRESENT
- if (!shell_registered) {
- /* register the shell */
-
- shell_registered = 1;
- shell_cmd_register(&shell_log_cmd, "log", shell_log_dump_all);
- }
-#endif
-
- log->ul_name = name;
- log->ul_ulh = ulh;
-
- STAILQ_INSERT_TAIL(&g_util_log_list, log, ul_next);
-
- return (0);
-}
-
-int
-util_log_append(struct util_log *log, uint8_t *data, uint16_t len)
-{
- struct ul_entry_hdr *ue;
- int rc;
-
- ue = (struct ul_entry_hdr *) data;
- ue->ue_ts = (int64_t) os_time_get();
-
- rc = log->ul_ulh->ulh_append(log, data, len + sizeof(*ue));
- if (rc != 0) {
- goto err;
- }
-
- return (0);
-err:
- return (rc);
-}
-
-int
-util_log_walk(struct util_log *log, util_log_walk_func_t walk_func, void *arg)
-{
- int rc;
-
- rc = log->ul_ulh->ulh_walk(log, walk_func, arg);
- if (rc != 0) {
- goto err;
- }
-
- return (0);
-err:
- return (rc);
-}
-
-int
-util_log_read(struct util_log *log, void *dptr, void *buf, uint16_t off,
- uint16_t len)
-{
- int rc;
-
- rc = log->ul_ulh->ulh_read(log, dptr, buf, off, len);
-
- return (rc);
-}
-
-int
-util_log_flush(struct util_log *log)
-{
- int rc;
-
- rc = log->ul_ulh->ulh_flush(log);
- if (rc != 0) {
- goto err;
- }
-
- return (0);
-err:
- return (rc);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/util/src/stats.c
----------------------------------------------------------------------
diff --git a/libs/util/src/stats.c b/libs/util/src/stats.c
deleted file mode 100644
index e3bf0c4..0000000
--- a/libs/util/src/stats.c
+++ /dev/null
@@ -1,221 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <os/os.h>
-
-#include <string.h>
-
-#include "util/stats.h"
-
-#ifdef SHELL_PRESENT
-#include "shell/shell.h"
-#include "console/console.h"
-#endif
-
-#include <stdio.h>
-
-STATS_SECT_START(stats)
- STATS_SECT_ENTRY(num_registered)
-STATS_SECT_END(stats)
-
-STATS_NAME_START(stats)
- STATS_NAME(stats, num_registered)
-STATS_NAME_END(stats)
-
-STAILQ_HEAD(, stats_hdr) g_stats_registry =
- STAILQ_HEAD_INITIALIZER(g_stats_registry);
-
-#ifdef SHELL_PRESENT
-uint8_t stats_shell_registered;
-struct shell_cmd shell_stats_cmd;
-#endif
-
-
-#ifdef SHELL_PRESENT
-
-static void
-shell_stats_display_entry(struct stats_hdr *hdr, uint8_t *ptr)
-{
- char *name;
- char buf[12];
- int ent_n;
- int len;
-#ifdef STATS_NAME_ENABLE
- int i;
-#endif
-
- name = NULL;
-
-#ifdef STATS_NAME_ENABLE
- for (i = 0; i < hdr->s_map_cnt; i++) {
- if (hdr->s_map[i].snm_off == ptr) {
- name = hdr->s_map[i].snm_name;
- break;
- }
- }
-#endif
-
- if (name == NULL) {
- ent_n = (ptr - ((uint8_t *) hdr + sizeof(*hdr))) / hdr->s_size;
-
- len = snprintf(buf, sizeof(buf), "s%d", ent_n);
- buf[len] = 0;
- name = buf;
- }
-
- switch (hdr->s_size) {
- case sizeof(uint16_t):
- console_printf("%s: %u\n", name, *(uint16_t *) ptr);
- break;
- case sizeof(uint32_t):
- console_printf("%s: %lu\n", name, *(unsigned long *) ptr);
- break;
- case sizeof(uint64_t):
- console_printf("%s: %llu\n", name, *(uint64_t *) ptr);
- break;
- default:
- console_printf("Unknown stat size for %s %u\n", name,
- hdr->s_size);
- break;
- }
-}
-
-static int
-shell_stats_display(int argc, char **argv)
-{
- struct stats_hdr *hdr;
- char *name;
- uint8_t *cur;
- uint8_t *end;
-
- name = argv[1];
- if (name == NULL || !strcmp(name, "")) {
- console_printf("Must specify a statistic name to dump, "
- "possible names are:\n");
- STAILQ_FOREACH(hdr, &g_stats_registry, s_next) {
- console_printf("\t%s\n", hdr->s_name);
- }
- goto done;
- }
-
-
- hdr = stats_find(name);
- if (!hdr) {
- console_printf("Could not find statistic %s\n", name);
- goto done;
- }
-
- cur = (uint8_t *) hdr + sizeof(*hdr);
- end = (uint8_t *) hdr + sizeof(*hdr) + (hdr->s_size * hdr->s_cnt);
- while (cur < end) {
- shell_stats_display_entry(hdr, (uint8_t *) cur);
- cur += hdr->s_size;
- }
-
-done:
- return (0);
-}
-
-#endif
-
-
-int
-stats_module_init(void)
-{
- int rc;
-#ifdef SHELL_PRESENT
- if (!stats_shell_registered) {
- stats_shell_registered = 1;
- shell_cmd_register(&shell_stats_cmd, "stat", shell_stats_display);
- }
-#endif
-
-
- rc = stats_init(STATS_HDR(stats), STATS_SIZE_INIT_PARMS(stats, STATS_SIZE_32),
- STATS_NAME_INIT_PARMS(stats));
- if (rc != 0) {
- goto err;
- }
-
- rc = stats_register("stat", STATS_HDR(stats));
- if (rc != 0) {
- goto err;
- }
-
- return (0);
-err:
- return (rc);
-}
-
-
-int
-stats_init(struct stats_hdr *shdr, uint8_t size, uint8_t cnt,
- struct stats_name_map *map, uint8_t map_cnt)
-{
- memset((uint8_t *) shdr, 0, sizeof(*shdr) + (size * cnt));
-
- shdr->s_size = size;
- shdr->s_cnt = cnt;
-#ifdef STATS_NAME_ENABLE
- shdr->s_map = map;
- shdr->s_map_cnt = map_cnt;
-#endif
-
- return (0);
-}
-
-int
-stats_register(char *name, struct stats_hdr *shdr)
-{
- struct stats_hdr *cur;
- int rc;
-
- /* Don't allow duplicate entries, return an error if this stat
- * is already registered.
- */
- STAILQ_FOREACH(cur, &g_stats_registry, s_next) {
- if (!strcmp(cur->s_name, name)) {
- rc = -1;
- goto err;
- }
- }
-
- shdr->s_name = name;
-
- STAILQ_INSERT_TAIL(&g_stats_registry, shdr, s_next);
-
- STATS_INC(stats, num_registered);
-
- return (0);
-err:
- return (rc);
-}
-
-struct stats_hdr *
-stats_find(char *name)
-{
- struct stats_hdr *cur;
-
- cur = NULL;
- STAILQ_FOREACH(cur, &g_stats_registry, s_next) {
- if (!strcmp(cur->s_name, name)) {
- break;
- }
- }
-
- return (cur);
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/util/src/test/conf_test.c
----------------------------------------------------------------------
diff --git a/libs/util/src/test/conf_test.c b/libs/util/src/test/conf_test.c
deleted file mode 100644
index 8aa3712..0000000
--- a/libs/util/src/test/conf_test.c
+++ /dev/null
@@ -1,229 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <stdio.h>
-#include <string.h>
-
-#include "os/os.h"
-#include "testutil/testutil.h"
-#include "util/config.h"
-
-uint8_t val8;
-
-static struct conf_entry ce1 = {
- .c_name = "ce1",
- .c_type = CONF_INT8,
- .c_val.single.val = &val8
-};
-
-static struct conf_node cn1 = {
- .cn_cnt = 1,
- .cn_array = &ce1
-};
-
-static struct conf_entry ce2 = {
- .c_name = "ce2",
- .c_type = CONF_INT8,
- .c_val.single.val = &val8
-};
-
-static struct conf_node cn2 = {
- .cn_cnt = 1,
- .cn_array = &ce2
-};
-
-static struct conf_entry ce_arr1[2] = {
- [0] = {
- .c_name = "cea1",
- .c_type = CONF_INT8,
- .c_val.single.val = &val8
- },
- [1] = {
- .c_name = "cea2",
- .c_type = CONF_INT8,
- .c_val.single.val = &val8
- }
-};
-
-static struct conf_node cn_arr1 = {
- .cn_cnt = 2,
- .cn_array = ce_arr1
-};
-
-static struct conf_entry ce_arr2[2] = {
- [0] = {
- .c_name = "ce21",
- .c_type = CONF_INT8,
- .c_val.single.val = &val8
- },
- [1] = {
- .c_name = "cea2",
- .c_type = CONF_INT8,
- .c_val.single.val = &val8
- }
-};
-
-static struct conf_node cn_arr2 = {
- .cn_cnt = 2,
- .cn_array = ce_arr2
-};
-
-static struct conf_entry_dir ce_dir = {
- .c_name = "foo",
- .c_type = CONF_DIR
-};
-
-static struct conf_node cn_dir = {
- .cn_cnt = 1,
- .cn_array = (struct conf_entry *)&ce_dir
-};
-
-static struct conf_entry ce_foo_arr1[2] = {
- [0] = {
- .c_name = "foo1",
- .c_type = CONF_INT8,
- .c_val.single.val = &val8
- },
- [1] = {
- .c_name = "foo2",
- .c_type = CONF_INT8,
- .c_val.single.val = &val8
- }
-};
-
-static struct conf_node cn_foo_arr1 = {
- .cn_cnt = 2,
- .cn_array = ce_foo_arr1
-};
-
-TEST_CASE(config_empty_lookups)
-{
- struct conf_entry *ce;
- char *names1[] = { "foo", "bar" };
-
- ce = conf_lookup(0, NULL);
- TEST_ASSERT(ce == NULL);
-
- ce = conf_lookup(1, names1);
- TEST_ASSERT(ce == NULL);
-
- ce = conf_lookup(2, names1);
- TEST_ASSERT(ce == NULL);
-}
-
-TEST_CASE(config_test_insert)
-{
- int rc;
-
- /*
- * Add 2 new ones
- */
- rc = conf_register(NULL, &cn1);
- TEST_ASSERT(rc == 0);
- rc = conf_register(NULL, &cn2);
- TEST_ASSERT(rc == 0);
-
- /*
- * Fail adding same ones again
- */
- rc = conf_register(NULL, &cn1);
- TEST_ASSERT(rc != 0);
- rc = conf_register(NULL, &cn2);
- TEST_ASSERT(rc != 0);
-
- /*
- * Add with multiple conf_entries
- */
- rc = conf_register(NULL, &cn_arr1);
- TEST_ASSERT(rc == 0);
-
- /*
- * Cannot add it again
- */
- rc = conf_register(NULL, &cn_arr1);
- TEST_ASSERT(rc != 0);
-
- /*
- * Should fail right away
- */
- rc = conf_register(NULL, &cn_arr2);
- TEST_ASSERT(rc != 0);
-
-}
-
-TEST_CASE(config_test_lookup)
-{
- struct conf_entry *ce;
- char *names1[] = { "foo", "bar" };
- char *names2[] = { "ce1" };
- char *names3[] = { "cea2" };
-
- ce = conf_lookup(0, NULL);
- TEST_ASSERT(ce == NULL);
-
- ce = conf_lookup(1, names1);
- TEST_ASSERT(ce == NULL);
-
- ce = conf_lookup(2, names1);
- TEST_ASSERT(ce == NULL);
-
- ce = conf_lookup(1, names2);
- TEST_ASSERT(ce != NULL);
- TEST_ASSERT(!strcmp(ce->c_name, names2[0]));
-
- ce = conf_lookup(1, names3);
- TEST_ASSERT(ce != NULL);
- TEST_ASSERT(!strcmp(ce->c_name, names3[0]));
-}
-
-TEST_CASE(config_test_dir)
-{
- int rc;
- struct conf_entry *ce;
- char *names1[] = { "foo", "foo1" };
- char *names2[] = { "foo", "foo2" };
- char *names3[] = { "foo", "foo3" };
-
- /*
- * Add directory node, and node under.
- */
- rc = conf_register(NULL, &cn_dir);
- TEST_ASSERT(rc == 0);
- rc = conf_register(&cn_dir, &cn_foo_arr1);
- TEST_ASSERT(rc == 0);
-
- ce = conf_lookup(1, names1);
- TEST_ASSERT(ce != NULL);
- TEST_ASSERT(ce->c_type == CONF_DIR);
-
- ce = conf_lookup(2, names1);
- TEST_ASSERT(ce != NULL);
- TEST_ASSERT(!strcmp(ce->c_name, names1[1]));
-
- ce = conf_lookup(2, names2);
- TEST_ASSERT(ce != NULL);
- TEST_ASSERT(!strcmp(ce->c_name, names2[1]));
-
- ce = conf_lookup(2, names3);
- TEST_ASSERT(ce == NULL);
-}
-
-TEST_SUITE(config_test_suite)
-{
- config_empty_lookups();
- config_test_insert();
- config_test_lookup();
- config_test_dir();
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/util/src/test/util_test.c
----------------------------------------------------------------------
diff --git a/libs/util/src/test/util_test.c b/libs/util/src/test/util_test.c
index bbedf9d..9998fa7 100644
--- a/libs/util/src/test/util_test.c
+++ b/libs/util/src/test/util_test.c
@@ -24,7 +24,6 @@ util_test_all(void)
{
cbmem_test_suite();
flash_map_test_suite();
- config_test_suite();
return tu_case_failed;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/libs/util/src/test/util_test_priv.h
----------------------------------------------------------------------
diff --git a/libs/util/src/test/util_test_priv.h b/libs/util/src/test/util_test_priv.h
index 5132bbe..d6f8da4 100644
--- a/libs/util/src/test/util_test_priv.h
+++ b/libs/util/src/test/util_test_priv.h
@@ -19,6 +19,5 @@
int cbmem_test_suite(void);
int flash_map_test_suite(void);
-int config_test_suite(void);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/project/blinky/blinky.yml
----------------------------------------------------------------------
diff --git a/project/blinky/blinky.yml b/project/blinky/blinky.yml
index 5bd9134..cdfd369 100644
--- a/project/blinky/blinky.yml
+++ b/project/blinky/blinky.yml
@@ -2,5 +2,7 @@ project.name: blinky
project.eggs:
- libs/console/full
- libs/shell
- - libs/util
- libs/os
+ - libs/sys/config
+ - libs/sys/log
+ - libs/sys/stats
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/project/blinky/egg.yml
----------------------------------------------------------------------
diff --git a/project/blinky/egg.yml b/project/blinky/egg.yml
index 34612a0..05a7a3c 100644
--- a/project/blinky/egg.yml
+++ b/project/blinky/egg.yml
@@ -5,4 +5,7 @@ egg.deps:
- libs/console/full
- libs/shell
- libs/newtmgr
+ - libs/sys/config
+ - libs/sys/log
+ - libs/sys/stats
- hw/hal
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/project/blinky/src/main.c
----------------------------------------------------------------------
diff --git a/project/blinky/src/main.c b/project/blinky/src/main.c
index 0e3c289..43b985e 100755
--- a/project/blinky/src/main.c
+++ b/project/blinky/src/main.c
@@ -18,9 +18,9 @@
#include "hal/hal_gpio.h"
#include "console/console.h"
#include "shell/shell.h"
-#include "util/log.h"
-#include "util/stats.h"
-#include "util/config.h"
+#include "log/log.h"
+#include "stats/stats.h"
+#include "config/config.h"
#include <assert.h>
#include <string.h>
#ifdef ARCH_sim
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/project/slinky/egg.yml
----------------------------------------------------------------------
diff --git a/project/slinky/egg.yml b/project/slinky/egg.yml
index fa27082..cd465b1 100644
--- a/project/slinky/egg.yml
+++ b/project/slinky/egg.yml
@@ -6,4 +6,7 @@ egg.deps:
- libs/shell
- libs/newtmgr
- libs/imgmgr
+ - libs/sys/config
+ - libs/sys/log
+ - libs/sys/stats
- hw/hal
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/project/slinky/slinky.yml
----------------------------------------------------------------------
diff --git a/project/slinky/slinky.yml b/project/slinky/slinky.yml
index 9f9b029..ed9db1a 100644
--- a/project/slinky/slinky.yml
+++ b/project/slinky/slinky.yml
@@ -5,4 +5,7 @@ project.eggs:
- libs/imgmgr
- libs/shell
- libs/util
+ - libs/sys/config
+ - libs/sys/log
+ - libs/sys/stats
- libs/os
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/4ab72bba/project/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/project/slinky/src/main.c b/project/slinky/src/main.c
index 98cd4b1..1d2e330 100755
--- a/project/slinky/src/main.c
+++ b/project/slinky/src/main.c
@@ -19,9 +19,9 @@
#include <hal/hal_flash.h>
#include <console/console.h>
#include <shell/shell.h>
-#include <util/log.h>
-#include <util/stats.h>
-#include <util/config.h>
+#include <log/log.h>
+#include <stats/stats.h>
+#include <config/config.h>
#include <util/flash_map.h>
#include <fs/fs.h>
#include <nffs/nffs.h>