Repository: incubator-mynewt-core Updated Branches: refs/heads/develop 9317ddb1e -> 7dc40e7af
newtmgr; move default handlers to separate package. 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/7dc40e7a Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7dc40e7a Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7dc40e7a Branch: refs/heads/develop Commit: 7dc40e7af58fa27d074198af528f20a653ab8a36 Parents: 9317ddb Author: Marko Kiiskila <ma...@runtime.io> Authored: Mon Sep 19 12:04:30 2016 -0700 Committer: Marko Kiiskila <ma...@runtime.io> Committed: Mon Sep 19 12:05:28 2016 -0700 ---------------------------------------------------------------------- libs/newtmgr/include/newtmgr/newtmgr_priv.h | 24 ++ libs/newtmgr/os/include/nmgr_os/nmgr_os.h | 25 ++ libs/newtmgr/os/pkg.yml | 36 +++ libs/newtmgr/os/src/newtmgr_os.c | 327 +++++++++++++++++++++++ libs/newtmgr/pkg.yml | 1 + libs/newtmgr/src/newtmgr.c | 100 +------ libs/newtmgr/src/newtmgr_os.c | 236 ---------------- libs/newtmgr/src/newtmgr_priv.h | 31 --- 8 files changed, 416 insertions(+), 364 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7dc40e7a/libs/newtmgr/include/newtmgr/newtmgr_priv.h ---------------------------------------------------------------------- diff --git a/libs/newtmgr/include/newtmgr/newtmgr_priv.h b/libs/newtmgr/include/newtmgr/newtmgr_priv.h new file mode 100644 index 0000000..7217711 --- /dev/null +++ b/libs/newtmgr/include/newtmgr/newtmgr_priv.h @@ -0,0 +1,24 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 __NETMGR_PRIV_H_ +#define __NETMGR_PRIV_H_ + +extern struct os_eventq g_nmgr_evq; + +#endif http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7dc40e7a/libs/newtmgr/os/include/nmgr_os/nmgr_os.h ---------------------------------------------------------------------- diff --git a/libs/newtmgr/os/include/nmgr_os/nmgr_os.h b/libs/newtmgr/os/include/nmgr_os/nmgr_os.h new file mode 100644 index 0000000..2c89237 --- /dev/null +++ b/libs/newtmgr/os/include/nmgr_os/nmgr_os.h @@ -0,0 +1,25 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 _NMGR_OS_H_ +#define _NMGR_OS_H_ + +int nmgr_os_groups_register(void); + +#endif /* _NMGR_OS_H_ */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7dc40e7a/libs/newtmgr/os/pkg.yml ---------------------------------------------------------------------- diff --git a/libs/newtmgr/os/pkg.yml b/libs/newtmgr/os/pkg.yml new file mode 100644 index 0000000..4260849 --- /dev/null +++ b/libs/newtmgr/os/pkg.yml @@ -0,0 +1,36 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +pkg.name: libs/newtmgr/os +pkg.description: Default newtmgr command. +pkg.author: "Apache Mynewt <d...@mynewt.incubator.apache.org>" +pkg.homepage: "http://mynewt.apache.org/" +pkg.keywords: + +pkg.deps: + - hw/hal + - libs/os + - libs/json + - libs/util + - libs/testutil + - libs/newtmgr + - sys/reboot + +pkg.reqs: + - console http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7dc40e7a/libs/newtmgr/os/src/newtmgr_os.c ---------------------------------------------------------------------- diff --git a/libs/newtmgr/os/src/newtmgr_os.c b/libs/newtmgr/os/src/newtmgr_os.c new file mode 100644 index 0000000..88b6553 --- /dev/null +++ b/libs/newtmgr/os/src/newtmgr_os.c @@ -0,0 +1,327 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 <os/endian.h> + +#include <assert.h> +#include <string.h> + +#include <hal/hal_system.h> + +#include <newtmgr/newtmgr.h> +#include <newtmgr/newtmgr_priv.h> + +#include <console/console.h> +#include <util/datetime.h> +#include <reboot/log_reboot.h> + +static struct os_callout_func nmgr_reset_callout; + +static int nmgr_def_echo(struct nmgr_jbuf *); +static int nmgr_def_console_echo(struct nmgr_jbuf *); +static int nmgr_def_taskstat_read(struct nmgr_jbuf *njb); +static int nmgr_def_mpstat_read(struct nmgr_jbuf *njb); +static int nmgr_datetime_get(struct nmgr_jbuf *njb); +static int nmgr_datetime_set(struct nmgr_jbuf *njb); +static int nmgr_reset(struct nmgr_jbuf *njb); + +static const struct nmgr_handler nmgr_def_group_handlers[] = { + [NMGR_ID_ECHO] = { + nmgr_def_echo, nmgr_def_echo + }, + [NMGR_ID_CONS_ECHO_CTRL] = { + nmgr_def_console_echo, nmgr_def_console_echo + }, + [NMGR_ID_TASKSTATS] = { + nmgr_def_taskstat_read, NULL + }, + [NMGR_ID_MPSTATS] = { + nmgr_def_mpstat_read, NULL + }, + [NMGR_ID_DATETIME_STR] = { + nmgr_datetime_get, nmgr_datetime_set + }, + [NMGR_ID_RESET] = { + NULL, nmgr_reset + }, +}; + +#define NMGR_DEF_GROUP_SZ \ + (sizeof(nmgr_def_group_handlers) / sizeof(nmgr_def_group_handlers[0])) + +static struct nmgr_group nmgr_def_group = { + .ng_handlers = (struct nmgr_handler *)nmgr_def_group_handlers, + .ng_handlers_count = NMGR_DEF_GROUP_SZ, + .ng_group_id = NMGR_GROUP_ID_DEFAULT +}; + +static int +nmgr_def_echo(struct nmgr_jbuf *njb) +{ + uint8_t echo_buf[128]; + struct json_attr_t attrs[] = { + { "d", t_string, .addr.string = (char *) &echo_buf[0], + .len = sizeof(echo_buf) }, + { NULL }, + }; + struct json_value jv; + int rc; + + rc = json_read_object((struct json_buffer *) njb, attrs); + if (rc != 0) { + goto err; + } + + json_encode_object_start(&njb->njb_enc); + JSON_VALUE_STRINGN(&jv, (char *) echo_buf, strlen((char *) echo_buf)); + json_encode_object_entry(&njb->njb_enc, "r", &jv); + json_encode_object_finish(&njb->njb_enc); + + return (0); +err: + return (rc); +} + +static int +nmgr_def_console_echo(struct nmgr_jbuf *njb) +{ + long long int echo_on = 1; + int rc; + struct json_attr_t attrs[3] = { + [0] = { + .attribute = "echo", + .type = t_integer, + .addr.integer = &echo_on, + .nodefault = 1 + }, + [1] = { + .attribute = NULL + } + }; + + rc = json_read_object(&njb->njb_buf, attrs); + if (rc) { + return OS_EINVAL; + } + + if (echo_on) { + console_echo(1); + } else { + console_echo(0); + } + return (0); +} + +static int +nmgr_def_taskstat_read(struct nmgr_jbuf *njb) +{ + struct os_task *prev_task; + struct os_task_info oti; + struct json_value jv; + + json_encode_object_start(&njb->njb_enc); + JSON_VALUE_INT(&jv, NMGR_ERR_EOK); + json_encode_object_entry(&njb->njb_enc, "rc", &jv); + + json_encode_object_key(&njb->njb_enc, "tasks"); + json_encode_object_start(&njb->njb_enc); + + prev_task = NULL; + while (1) { + prev_task = os_task_info_get_next(prev_task, &oti); + if (prev_task == NULL) { + break; + } + + json_encode_object_key(&njb->njb_enc, oti.oti_name); + + json_encode_object_start(&njb->njb_enc); + JSON_VALUE_UINT(&jv, oti.oti_prio); + json_encode_object_entry(&njb->njb_enc, "prio", &jv); + JSON_VALUE_UINT(&jv, oti.oti_taskid); + json_encode_object_entry(&njb->njb_enc, "tid", &jv); + JSON_VALUE_UINT(&jv, oti.oti_state); + json_encode_object_entry(&njb->njb_enc, "state", &jv); + JSON_VALUE_UINT(&jv, oti.oti_stkusage); + json_encode_object_entry(&njb->njb_enc, "stkuse", &jv); + JSON_VALUE_UINT(&jv, oti.oti_stksize); + json_encode_object_entry(&njb->njb_enc, "stksiz", &jv); + JSON_VALUE_UINT(&jv, oti.oti_cswcnt); + json_encode_object_entry(&njb->njb_enc, "cswcnt", &jv); + JSON_VALUE_UINT(&jv, oti.oti_runtime); + json_encode_object_entry(&njb->njb_enc, "runtime", &jv); + JSON_VALUE_UINT(&jv, oti.oti_last_checkin); + json_encode_object_entry(&njb->njb_enc, "last_checkin", &jv); + JSON_VALUE_UINT(&jv, oti.oti_next_checkin); + json_encode_object_entry(&njb->njb_enc, "next_checkin", &jv); + json_encode_object_finish(&njb->njb_enc); + } + json_encode_object_finish(&njb->njb_enc); + json_encode_object_finish(&njb->njb_enc); + + return (0); +} + +static int +nmgr_def_mpstat_read(struct nmgr_jbuf *njb) +{ + struct os_mempool *prev_mp; + struct os_mempool_info omi; + struct json_value jv; + + json_encode_object_start(&njb->njb_enc); + JSON_VALUE_INT(&jv, NMGR_ERR_EOK); + json_encode_object_entry(&njb->njb_enc, "rc", &jv); + + json_encode_object_key(&njb->njb_enc, "mpools"); + json_encode_object_start(&njb->njb_enc); + + prev_mp = NULL; + while (1) { + prev_mp = os_mempool_info_get_next(prev_mp, &omi); + if (prev_mp == NULL) { + break; + } + + json_encode_object_key(&njb->njb_enc, omi.omi_name); + + json_encode_object_start(&njb->njb_enc); + JSON_VALUE_UINT(&jv, omi.omi_block_size); + json_encode_object_entry(&njb->njb_enc, "blksiz", &jv); + JSON_VALUE_UINT(&jv, omi.omi_num_blocks); + json_encode_object_entry(&njb->njb_enc, "nblks", &jv); + JSON_VALUE_UINT(&jv, omi.omi_num_free); + json_encode_object_entry(&njb->njb_enc, "nfree", &jv); + json_encode_object_finish(&njb->njb_enc); + } + + json_encode_object_finish(&njb->njb_enc); + json_encode_object_finish(&njb->njb_enc); + + return (0); +} + +static int +nmgr_datetime_get(struct nmgr_jbuf *njb) +{ + struct os_timeval tv; + struct os_timezone tz; + char buf[DATETIME_BUFSIZE]; + struct json_value jv; + int rc; + + json_encode_object_start(&njb->njb_enc); + JSON_VALUE_INT(&jv, NMGR_ERR_EOK); + json_encode_object_entry(&njb->njb_enc, "rc", &jv); + + /* Display the current datetime */ + rc = os_gettimeofday(&tv, &tz); + assert(rc == 0); + rc = format_datetime(&tv, &tz, buf, DATETIME_BUFSIZE); + if (rc) { + rc = OS_EINVAL; + goto err; + } + + JSON_VALUE_STRING(&jv, buf) + json_encode_object_entry(&njb->njb_enc, "datetime", &jv); + json_encode_object_finish(&njb->njb_enc); + + return OS_OK; +err: + return (rc); +} + +static int +nmgr_datetime_set(struct nmgr_jbuf *njb) +{ + struct os_timeval tv; + struct os_timezone tz; + struct json_value jv; + char buf[DATETIME_BUFSIZE]; + int rc = OS_OK; + const struct json_attr_t datetime_write_attr[2] = { + [0] = { + .attribute = "datetime", + .type = t_string, + .addr.string = buf, + .len = sizeof(buf), + }, + [1] = { + .attribute = "rc", + .type = t_uinteger, + + } + }; + + rc = json_read_object(&njb->njb_buf, datetime_write_attr); + if (rc) { + rc = OS_EINVAL; + goto out; + } + + /* Set the current datetime */ + rc = parse_datetime(buf, &tv, &tz); + if (!rc) { + rc = os_settimeofday(&tv, &tz); + if (rc) { + rc = OS_EINVAL; + goto out; + } + } else { + rc = OS_EINVAL; + goto out; + } + +out: + json_encode_object_start(&njb->njb_enc); + JSON_VALUE_INT(&jv, rc); + json_encode_object_entry(&njb->njb_enc, "rc", &jv); + json_encode_object_finish(&njb->njb_enc); + return OS_OK; +} + +static void +nmgr_reset_tmo(void *arg) +{ + system_reset(); +} + +static int +nmgr_reset(struct nmgr_jbuf *njb) +{ + if (nmgr_reset_callout.cf_func == NULL) { + os_callout_func_init(&nmgr_reset_callout, &g_nmgr_evq, + nmgr_reset_tmo, NULL); + } + log_reboot(SOFT_REBOOT); + os_callout_reset(&nmgr_reset_callout.cf_c, OS_TICKS_PER_SEC / 4); + + nmgr_jbuf_setoerr(njb, 0); + + return OS_OK; +} + +int +nmgr_os_groups_register(void) +{ + return nmgr_group_register(&nmgr_def_group); +} + http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7dc40e7a/libs/newtmgr/pkg.yml ---------------------------------------------------------------------- diff --git a/libs/newtmgr/pkg.yml b/libs/newtmgr/pkg.yml index a0e75a2..40301b7 100644 --- a/libs/newtmgr/pkg.yml +++ b/libs/newtmgr/pkg.yml @@ -27,6 +27,7 @@ pkg.deps: - hw/hal - libs/os - libs/json + - libs/newtmgr/os - libs/util - libs/testutil - libs/shell http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7dc40e7a/libs/newtmgr/src/newtmgr.c ---------------------------------------------------------------------- diff --git a/libs/newtmgr/src/newtmgr.c b/libs/newtmgr/src/newtmgr.c index d15b4b9..2bd88b4 100644 --- a/libs/newtmgr/src/newtmgr.c +++ b/libs/newtmgr/src/newtmgr.c @@ -24,10 +24,10 @@ #include <string.h> #include <shell/shell.h> -#include <console/console.h> #include <newtmgr/newtmgr.h> +#include <nmgr_os/nmgr_os.h> -#include "newtmgr_priv.h" +#include "newtmgr/newtmgr_priv.h" struct nmgr_transport g_nmgr_shell_transport; @@ -39,83 +39,10 @@ struct os_task g_nmgr_task; STAILQ_HEAD(, nmgr_group) g_nmgr_group_list = STAILQ_HEAD_INITIALIZER(g_nmgr_group_list); -static int nmgr_def_echo(struct nmgr_jbuf *); -static int nmgr_def_console_echo(struct nmgr_jbuf *); - -static struct nmgr_group nmgr_def_group; -/* ORDER MATTERS HERE. - * Each element represents the command ID, referenced from newtmgr. - */ -static const struct nmgr_handler nmgr_def_group_handlers[] = { - [NMGR_ID_ECHO] = {nmgr_def_echo, nmgr_def_echo}, - [NMGR_ID_CONS_ECHO_CTRL] = {nmgr_def_console_echo, nmgr_def_console_echo}, - [NMGR_ID_TASKSTATS] = {nmgr_def_taskstat_read, NULL}, - [NMGR_ID_MPSTATS] = {nmgr_def_mpstat_read, NULL}, - [NMGR_ID_DATETIME_STR] = {nmgr_datetime_get, nmgr_datetime_set}, - [NMGR_ID_RESET] = {NULL, nmgr_reset}, -}; - /* JSON buffer for NMGR task */ struct nmgr_jbuf nmgr_task_jbuf; -static int -nmgr_def_echo(struct nmgr_jbuf *njb) -{ - uint8_t echo_buf[128]; - struct json_attr_t attrs[] = { - { "d", t_string, .addr.string = (char *) &echo_buf[0], - .len = sizeof(echo_buf) }, - { NULL }, - }; - struct json_value jv; - int rc; - - rc = json_read_object((struct json_buffer *) njb, attrs); - if (rc != 0) { - goto err; - } - - json_encode_object_start(&njb->njb_enc); - JSON_VALUE_STRINGN(&jv, (char *) echo_buf, strlen((char *) echo_buf)); - json_encode_object_entry(&njb->njb_enc, "r", &jv); - json_encode_object_finish(&njb->njb_enc); - - return (0); -err: - return (rc); -} - -static int -nmgr_def_console_echo(struct nmgr_jbuf *njb) -{ - long long int echo_on = 1; - int rc; - struct json_attr_t attrs[3] = { - [0] = { - .attribute = "echo", - .type = t_integer, - .addr.integer = &echo_on, - .nodefault = 1 - }, - [1] = { - .attribute = NULL - } - }; - - rc = json_read_object(&njb->njb_buf, attrs); - if (rc) { - return OS_EINVAL; - } - - if (echo_on) { - console_echo(1); - } else { - console_echo(0); - } - return (0); -} - int nmgr_group_list_lock(void) { @@ -601,27 +528,6 @@ err: } -static int -nmgr_default_groups_register(void) -{ - int rc; - - NMGR_GROUP_SET_HANDLERS(&nmgr_def_group, - (struct nmgr_handler *)nmgr_def_group_handlers); - nmgr_def_group.ng_group_id = NMGR_GROUP_ID_DEFAULT; - nmgr_def_group.ng_handlers_count = - sizeof(nmgr_def_group_handlers) / sizeof(nmgr_def_group_handlers[0]); - - rc = nmgr_group_register(&nmgr_def_group); - if (rc != 0) { - goto err; - } - - return (0); -err: - return (rc); -} - int nmgr_task_init(uint8_t prio, os_stack_t *stack_ptr, uint16_t stack_len) { @@ -646,7 +552,7 @@ nmgr_task_init(uint8_t prio, os_stack_t *stack_ptr, uint16_t stack_len) goto err; } - rc = nmgr_default_groups_register(); + rc = nmgr_os_groups_register(); if (rc != 0) { goto err; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7dc40e7a/libs/newtmgr/src/newtmgr_os.c ---------------------------------------------------------------------- diff --git a/libs/newtmgr/src/newtmgr_os.c b/libs/newtmgr/src/newtmgr_os.c deleted file mode 100644 index 8903baa..0000000 --- a/libs/newtmgr/src/newtmgr_os.c +++ /dev/null @@ -1,236 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 <os/endian.h> - -#include <assert.h> -#include <string.h> - -#include <hal/hal_system.h> - -#include <newtmgr/newtmgr.h> -#include <util/datetime.h> -#include <reboot/log_reboot.h> - -#include "newtmgr_priv.h" - -static struct os_callout_func nmgr_reset_callout; - -int -nmgr_def_taskstat_read(struct nmgr_jbuf *njb) -{ - struct os_task *prev_task; - struct os_task_info oti; - struct json_value jv; - - json_encode_object_start(&njb->njb_enc); - JSON_VALUE_INT(&jv, NMGR_ERR_EOK); - json_encode_object_entry(&njb->njb_enc, "rc", &jv); - - json_encode_object_key(&njb->njb_enc, "tasks"); - json_encode_object_start(&njb->njb_enc); - - prev_task = NULL; - while (1) { - prev_task = os_task_info_get_next(prev_task, &oti); - if (prev_task == NULL) { - break; - } - - json_encode_object_key(&njb->njb_enc, oti.oti_name); - - json_encode_object_start(&njb->njb_enc); - JSON_VALUE_UINT(&jv, oti.oti_prio); - json_encode_object_entry(&njb->njb_enc, "prio", &jv); - JSON_VALUE_UINT(&jv, oti.oti_taskid); - json_encode_object_entry(&njb->njb_enc, "tid", &jv); - JSON_VALUE_UINT(&jv, oti.oti_state); - json_encode_object_entry(&njb->njb_enc, "state", &jv); - JSON_VALUE_UINT(&jv, oti.oti_stkusage); - json_encode_object_entry(&njb->njb_enc, "stkuse", &jv); - JSON_VALUE_UINT(&jv, oti.oti_stksize); - json_encode_object_entry(&njb->njb_enc, "stksiz", &jv); - JSON_VALUE_UINT(&jv, oti.oti_cswcnt); - json_encode_object_entry(&njb->njb_enc, "cswcnt", &jv); - JSON_VALUE_UINT(&jv, oti.oti_runtime); - json_encode_object_entry(&njb->njb_enc, "runtime", &jv); - JSON_VALUE_UINT(&jv, oti.oti_last_checkin); - json_encode_object_entry(&njb->njb_enc, "last_checkin", &jv); - JSON_VALUE_UINT(&jv, oti.oti_next_checkin); - json_encode_object_entry(&njb->njb_enc, "next_checkin", &jv); - json_encode_object_finish(&njb->njb_enc); - } - json_encode_object_finish(&njb->njb_enc); - json_encode_object_finish(&njb->njb_enc); - - return (0); -} - -int -nmgr_def_taskstat_write(struct nmgr_jbuf *njb) -{ - return (OS_EINVAL); -} - -int -nmgr_def_mpstat_read(struct nmgr_jbuf *njb) -{ - struct os_mempool *prev_mp; - struct os_mempool_info omi; - struct json_value jv; - - json_encode_object_start(&njb->njb_enc); - JSON_VALUE_INT(&jv, NMGR_ERR_EOK); - json_encode_object_entry(&njb->njb_enc, "rc", &jv); - - json_encode_object_key(&njb->njb_enc, "mpools"); - json_encode_object_start(&njb->njb_enc); - - prev_mp = NULL; - while (1) { - prev_mp = os_mempool_info_get_next(prev_mp, &omi); - if (prev_mp == NULL) { - break; - } - - json_encode_object_key(&njb->njb_enc, omi.omi_name); - - json_encode_object_start(&njb->njb_enc); - JSON_VALUE_UINT(&jv, omi.omi_block_size); - json_encode_object_entry(&njb->njb_enc, "blksiz", &jv); - JSON_VALUE_UINT(&jv, omi.omi_num_blocks); - json_encode_object_entry(&njb->njb_enc, "nblks", &jv); - JSON_VALUE_UINT(&jv, omi.omi_num_free); - json_encode_object_entry(&njb->njb_enc, "nfree", &jv); - json_encode_object_finish(&njb->njb_enc); - } - - json_encode_object_finish(&njb->njb_enc); - json_encode_object_finish(&njb->njb_enc); - - return (0); -} - -int -nmgr_def_mpstat_write(struct nmgr_jbuf *njb) -{ - return (OS_EINVAL); -} - -int -nmgr_datetime_get(struct nmgr_jbuf *njb) -{ - struct os_timeval tv; - struct os_timezone tz; - char buf[DATETIME_BUFSIZE]; - struct json_value jv; - int rc; - - json_encode_object_start(&njb->njb_enc); - JSON_VALUE_INT(&jv, NMGR_ERR_EOK); - json_encode_object_entry(&njb->njb_enc, "rc", &jv); - - /* Display the current datetime */ - rc = os_gettimeofday(&tv, &tz); - assert(rc == 0); - rc = format_datetime(&tv, &tz, buf, DATETIME_BUFSIZE); - if (rc) { - rc = OS_EINVAL; - goto err; - } - - JSON_VALUE_STRING(&jv, buf) - json_encode_object_entry(&njb->njb_enc, "datetime", &jv); - json_encode_object_finish(&njb->njb_enc); - - return OS_OK; -err: - return (rc); -} - -int -nmgr_datetime_set(struct nmgr_jbuf *njb) -{ - struct os_timeval tv; - struct os_timezone tz; - struct json_value jv; - char buf[DATETIME_BUFSIZE]; - int rc = OS_OK; - const struct json_attr_t datetime_write_attr[2] = { - [0] = { - .attribute = "datetime", - .type = t_string, - .addr.string = buf, - .len = sizeof(buf), - }, - [1] = { - .attribute = "rc", - .type = t_uinteger, - - } - }; - - rc = json_read_object(&njb->njb_buf, datetime_write_attr); - if (rc) { - rc = OS_EINVAL; - goto out; - } - - /* Set the current datetime */ - rc = parse_datetime(buf, &tv, &tz); - if (!rc) { - rc = os_settimeofday(&tv, &tz); - if (rc) { - rc = OS_EINVAL; - goto out; - } - } else { - rc = OS_EINVAL; - goto out; - } - -out: - json_encode_object_start(&njb->njb_enc); - JSON_VALUE_INT(&jv, rc); - json_encode_object_entry(&njb->njb_enc, "rc", &jv); - json_encode_object_finish(&njb->njb_enc); - return OS_OK; -} - -static void -nmgr_reset_tmo(void *arg) -{ - system_reset(); -} - -int -nmgr_reset(struct nmgr_jbuf *njb) -{ - if (nmgr_reset_callout.cf_func == NULL) { - os_callout_func_init(&nmgr_reset_callout, &g_nmgr_evq, - nmgr_reset_tmo, NULL); - } - log_reboot(SOFT_REBOOT); - os_callout_reset(&nmgr_reset_callout.cf_c, OS_TICKS_PER_SEC / 4); - - nmgr_jbuf_setoerr(njb, 0); - - return OS_OK; -} http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7dc40e7a/libs/newtmgr/src/newtmgr_priv.h ---------------------------------------------------------------------- diff --git a/libs/newtmgr/src/newtmgr_priv.h b/libs/newtmgr/src/newtmgr_priv.h deleted file mode 100644 index 7afa7f5..0000000 --- a/libs/newtmgr/src/newtmgr_priv.h +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 __NETMGR_PRIV_H_ -#define __NETMGR_PRIV_H_ - -extern struct os_eventq g_nmgr_evq; - -int nmgr_def_taskstat_read(struct nmgr_jbuf *); -int nmgr_def_mpstat_read(struct nmgr_jbuf *); -int nmgr_def_logs_read(struct nmgr_jbuf *); -int nmgr_datetime_get(struct nmgr_jbuf *); -int nmgr_datetime_set(struct nmgr_jbuf *); -int nmgr_reset(struct nmgr_jbuf *); - -#endif