mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccoll...@apache.org
Subject [57/70] [abbrv] incubator-mynewt-larva git commit: Change shell_cmd_register arguments to take struct for the command only. Caller has to fill it in.
Date Fri, 04 Mar 2016 00:40:37 GMT
Change shell_cmd_register arguments to take struct for the command
only. Caller has to fill it in.


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/ded5c1fd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/ded5c1fd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/ded5c1fd

Branch: refs/heads/master
Commit: ded5c1fd77b28ff6da019911bde84eeb62f46789
Parents: 57542c8
Author: Marko Kiiskila <marko@runtime.io>
Authored: Tue Mar 1 18:23:42 2016 -0800
Committer: Marko Kiiskila <marko@runtime.io>
Committed: Tue Mar 1 18:23:42 2016 -0800

----------------------------------------------------------------------
 fs/fs/src/fs_cli.c                          | 33 ++++++++++++----
 libs/elua/elua_base/src/lmynewt.c           |  9 ++++-
 libs/flash_test/src/flash_test/flash_test.c |  8 +++-
 libs/shell/include/shell/shell.h            |  8 ++--
 libs/shell/src/shell.c                      | 50 ++++++++++++++----------
 libs/shell/src/shell_os.c                   |  3 +-
 libs/shell/src/shell_priv.h                 | 26 ++++++++++++
 project/bletiny/src/cmd.c                   |  8 +++-
 sys/config/src/config_cli.c                 |  9 ++++-
 sys/log/src/log.c                           |  9 +++--
 sys/stats/src/stats_shell.c                 | 10 +++--
 11 files changed, 124 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ded5c1fd/fs/fs/src/fs_cli.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_cli.c b/fs/fs/src/fs_cli.c
index 5eb43c7..459533e 100644
--- a/fs/fs/src/fs_cli.c
+++ b/fs/fs/src/fs_cli.c
@@ -27,10 +27,27 @@
 
 #include "fs/fs.h"
 
-static struct shell_cmd fs_ls_struct;
-static struct shell_cmd fs_rm_struct;
-static struct shell_cmd fs_mkdir_struct;
-static struct shell_cmd fs_mv_struct;
+static int fs_ls_cmd(int argc, char **argv);
+static int fs_rm_cmd(int argc, char **argv);
+static int fs_mkdir_cmd(int argc, char **argv);
+static int fs_mv_cmd(int argc, char **argv);
+
+static struct shell_cmd fs_ls_struct = {
+    .sc_cmd = "ls",
+    .sc_cmd_func = fs_ls_cmd
+};
+static struct shell_cmd fs_rm_struct = {
+    .sc_cmd = "rm",
+    .sc_cmd_func = fs_rm_cmd
+};
+static struct shell_cmd fs_mkdir_struct = {
+    .sc_cmd = "mkdir",
+    .sc_cmd_func = fs_mkdir_cmd
+};
+static struct shell_cmd fs_mv_struct = {
+    .sc_cmd = "mv",
+    .sc_cmd_func = fs_mv_cmd
+};
 
 static void
 fs_ls_file(const char *name, struct fs_file *file)
@@ -166,9 +183,9 @@ out:
 void
 fs_cli_init(void)
 {
-    shell_cmd_register(&fs_ls_struct, "ls", fs_ls_cmd);
-    shell_cmd_register(&fs_rm_struct, "rm", fs_rm_cmd);
-    shell_cmd_register(&fs_mkdir_struct, "mkdir", fs_mkdir_cmd);
-    shell_cmd_register(&fs_mv_struct, "mv", fs_mv_cmd);
+    shell_cmd_register(&fs_ls_struct);
+    shell_cmd_register(&fs_rm_struct);
+    shell_cmd_register(&fs_mkdir_struct);
+    shell_cmd_register(&fs_mv_struct);
 }
 #endif /* SHELL_PRESENT */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ded5c1fd/libs/elua/elua_base/src/lmynewt.c
----------------------------------------------------------------------
diff --git a/libs/elua/elua_base/src/lmynewt.c b/libs/elua/elua_base/src/lmynewt.c
index 0c4a7d3..e7eda1e 100644
--- a/libs/elua/elua_base/src/lmynewt.c
+++ b/libs/elua/elua_base/src/lmynewt.c
@@ -22,7 +22,12 @@
 #ifdef MYNEWT
 
 #ifdef SHELL_PRESENT
-static struct shell_cmd lua_shell_cmd;
+static int lua_cmd(int argc, char **argv);
+
+static struct shell_cmd lua_shell_cmd = {
+    .sc_cmd = "lua",
+    .sc_cmd_func = lua_cmd
+};
 
 static int
 lua_cmd(int argc, char **argv)
@@ -36,7 +41,7 @@ int
 lua_init(void)
 {
 #ifdef SHELL_PRESENT
-    return shell_cmd_register(&lua_shell_cmd, "lua", lua_cmd);
+    return shell_cmd_register(&lua_shell_cmd);
 #else
     return 0;
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ded5c1fd/libs/flash_test/src/flash_test/flash_test.c
----------------------------------------------------------------------
diff --git a/libs/flash_test/src/flash_test/flash_test.c b/libs/flash_test/src/flash_test/flash_test.c
index 9985a70..2db72b5 100644
--- a/libs/flash_test/src/flash_test/flash_test.c
+++ b/libs/flash_test/src/flash_test/flash_test.c
@@ -25,7 +25,11 @@
 #include <shell/shell.h>
 #include <stdio.h>
 
-static struct shell_cmd flash_cmd_struct;
+static int flash_cli_cmd(int argc, char **argv);
+static struct shell_cmd flash_cmd_struct = {
+    .sc_cmd = "flash",
+    .sc_cmd_func = flash_cli_cmd
+};
 
 static int
 flash_cli_cmd(int argc, char **argv)
@@ -144,6 +148,6 @@ err:
 
 int
 flash_test_init(void) {
-    shell_cmd_register(&flash_cmd_struct, "flash", flash_cli_cmd);
+    shell_cmd_register(&flash_cmd_struct);
     return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ded5c1fd/libs/shell/include/shell/shell.h
----------------------------------------------------------------------
diff --git a/libs/shell/include/shell/shell.h b/libs/shell/include/shell/shell.h
index 283d70a..29ff2dc 100644
--- a/libs/shell/include/shell/shell.h
+++ b/libs/shell/include/shell/shell.h
@@ -6,7 +6,7 @@
  * 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,
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-#ifndef __SHELL_H__ 
+#ifndef __SHELL_H__
 #define __SHELL_H__
 
 #include <os/os.h>
@@ -28,9 +28,7 @@ struct shell_cmd {
     STAILQ_ENTRY(shell_cmd) sc_next;
 };
 
-int shell_cmd_register(struct shell_cmd *sc, char *cmd, 
-        shell_cmd_func_t func);
-
+int shell_cmd_register(struct shell_cmd *sc);
 
 #define SHELL_NLIP_PKT_START1 (6)
 #define SHELL_NLIP_PKT_START2 (9)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ded5c1fd/libs/shell/src/shell.c
----------------------------------------------------------------------
diff --git a/libs/shell/src/shell.c b/libs/shell/src/shell.c
index fe5f138..1773eab 100644
--- a/libs/shell/src/shell.c
+++ b/libs/shell/src/shell.c
@@ -6,7 +6,7 @@
  * 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,
@@ -21,7 +21,9 @@
 
 #include <console/console.h>
 
-#include <shell/shell.h>
+#include "shell/shell.h"
+#include "shell_priv.h"
+
 #include <os/endian.h>
 #include <util/base64.h>
 
@@ -39,10 +41,25 @@ static struct os_mqueue g_shell_nlip_mq;
 #define SHELL_HELP_PER_LINE     6
 #define SHELL_MAX_ARGS          20
 
-static struct shell_cmd g_shell_echo_cmd;
-static struct shell_cmd g_shell_help_cmd;
-static struct shell_cmd g_shell_os_tasks_display_cmd;
-static struct shell_cmd g_shell_os_mpool_display_cmd;
+static int shell_echo_cmd(int argc, char **argv);
+static int shell_help_cmd(int argc, char **argv);
+
+static struct shell_cmd g_shell_echo_cmd = {
+    .sc_cmd = "echo",
+    .sc_cmd_func = shell_echo_cmd
+};
+static struct shell_cmd g_shell_help_cmd = {
+    .sc_cmd = "?",
+    .sc_cmd_func = shell_help_cmd
+};
+static struct shell_cmd g_shell_os_tasks_display_cmd = {
+    .sc_cmd = "tasks",
+    .sc_cmd_func = shell_os_tasks_display_cmd
+};
+static struct shell_cmd g_shell_os_mpool_display_cmd = {
+    .sc_cmd = "mempools",
+    .sc_cmd_func = shell_os_mpool_display_cmd
+};
 
 static struct os_task shell_task;
 static struct os_eventq shell_evq;
@@ -62,9 +79,6 @@ static STAILQ_HEAD(, shell_cmd) g_shell_cmd_list =
 static struct os_mbuf *g_nlip_mbuf;
 static uint16_t g_nlip_expected_len;
 
-int shell_os_tasks_display_cmd(int argc, char **argv);
-int shell_os_mpool_display_cmd(int argc, char **argv);
-
 static int 
 shell_cmd_list_lock(void)
 {
@@ -102,15 +116,11 @@ err:
 }
 
 int
-shell_cmd_register(struct shell_cmd *sc, char *cmd, shell_cmd_func_t func)
+shell_cmd_register(struct shell_cmd *sc)
 {
     int rc;
 
-    /* Create the command that is being registered. */
-    sc->sc_cmd = cmd;
-    sc->sc_cmd_func = func;
-    STAILQ_NEXT(sc, sc_next) = NULL;
-
+    /* Add the command that is being registered. */
     rc = shell_cmd_list_lock();
     if (rc != 0) {
         goto err;
@@ -523,24 +533,22 @@ shell_task_init(uint8_t prio, os_stack_t *stack, uint16_t stack_size,
         goto err;
     }
 
-    rc = shell_cmd_register(&g_shell_echo_cmd, "echo", shell_echo_cmd);
+    rc = shell_cmd_register(&g_shell_echo_cmd);
     if (rc != 0) {
         goto err;
     }
 
-    rc = shell_cmd_register(&g_shell_help_cmd, "?", shell_help_cmd);
+    rc = shell_cmd_register(&g_shell_help_cmd);
     if (rc != 0) {
         goto err;
     }
 
-    rc = shell_cmd_register(&g_shell_os_tasks_display_cmd, "tasks", 
-            shell_os_tasks_display_cmd);
+    rc = shell_cmd_register(&g_shell_os_tasks_display_cmd);
     if (rc != 0) {
         goto err;
     }
 
-    rc = shell_cmd_register(&g_shell_os_mpool_display_cmd, "mempools",
-            shell_os_mpool_display_cmd);
+    rc = shell_cmd_register(&g_shell_os_mpool_display_cmd);
     if (rc != 0) {
         goto err;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ded5c1fd/libs/shell/src/shell_os.c
----------------------------------------------------------------------
diff --git a/libs/shell/src/shell_os.c b/libs/shell/src/shell_os.c
index e063862..43ff4dc 100644
--- a/libs/shell/src/shell_os.c
+++ b/libs/shell/src/shell_os.c
@@ -22,7 +22,8 @@
 #include "os/queue.h"
 
 #include "console/console.h"
-#include "shell/shell.h" 
+#include "shell/shell.h"
+#include "shell_priv.h"
 
 #include <string.h>
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ded5c1fd/libs/shell/src/shell_priv.h
----------------------------------------------------------------------
diff --git a/libs/shell/src/shell_priv.h b/libs/shell/src/shell_priv.h
new file mode 100644
index 0000000..67ac47c
--- /dev/null
+++ b/libs/shell/src/shell_priv.h
@@ -0,0 +1,26 @@
+/**
+ * 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 __SHELL_PRIV_H_
+#define __SHELL_PRIV_H_
+
+int shell_os_tasks_display_cmd(int argc, char **argv);
+int shell_os_mpool_display_cmd(int argc, char **argv);
+
+#endif /* __SHELL_PRIV_H_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ded5c1fd/project/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/project/bletiny/src/cmd.c b/project/bletiny/src/cmd.c
index 28e1c7d..ce66a8e 100644
--- a/project/bletiny/src/cmd.c
+++ b/project/bletiny/src/cmd.c
@@ -33,7 +33,11 @@
 
 #define CMD_BUF_SZ      256
 
-static struct shell_cmd cmd_b;
+static int cmd_b_exec(int argc, char **argv);
+static struct shell_cmd cmd_b = {
+    .sc_cmd = "b",
+    .sc_cmd_func = cmd_b_exec
+};
 
 static bssnz_t uint8_t cmd_buf[CMD_BUF_SZ];
 
@@ -1466,7 +1470,7 @@ cmd_init(void)
 {
     int rc;
 
-    rc = shell_cmd_register(&cmd_b, "b", cmd_b_exec);
+    rc = shell_cmd_register(&cmd_b);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ded5c1fd/sys/config/src/config_cli.c
----------------------------------------------------------------------
diff --git a/sys/config/src/config_cli.c b/sys/config/src/config_cli.c
index c2fae73..2090652 100644
--- a/sys/config/src/config_cli.c
+++ b/sys/config/src/config_cli.c
@@ -28,7 +28,12 @@
 #include <shell/shell.h>
 #include <console/console.h>
 
-static struct shell_cmd shell_conf_cmd;
+static int shell_conf_command(int argc, char **argv);
+
+static struct shell_cmd shell_conf_cmd = {
+    .sc_cmd = "config",
+    .sc_cmd_func = shell_conf_command
+};
 
 static int
 shell_conf_command(int argc, char **argv)
@@ -83,7 +88,7 @@ err:
 int
 conf_cli_register(void)
 {
-    return shell_cmd_register(&shell_conf_cmd, "config", shell_conf_command);
+    return shell_cmd_register(&shell_conf_cmd);
 }
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ded5c1fd/sys/log/src/log.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log.c b/sys/log/src/log.c
index 8ecb0be..d957768 100644
--- a/sys/log/src/log.c
+++ b/sys/log/src/log.c
@@ -30,14 +30,17 @@
 
 #ifdef SHELL_PRESENT
 #include <shell/shell.h>
-#endif 
+#endif
 
 static STAILQ_HEAD(, log) g_log_list = STAILQ_HEAD_INITIALIZER(g_log_list);
 static uint8_t log_inited;
 
 #ifdef SHELL_PRESENT
-struct shell_cmd g_shell_log_cmd;
 int shell_log_dump_all_cmd(int, char **);
+struct shell_cmd g_shell_log_cmd = {
+    .sc_cmd = "log",
+    .sc_cmd_func = shell_log_dump_all_cmd
+};
 #endif
 
 int
@@ -53,7 +56,7 @@ log_init(void)
     log_inited = 1;
 
 #ifdef SHELL_PRESENT
-    shell_cmd_register(&g_shell_log_cmd, "log", shell_log_dump_all_cmd);
+    shell_cmd_register(&g_shell_log_cmd);
 #endif
 
 #ifdef NEWTMGR_PRESENT

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/ded5c1fd/sys/stats/src/stats_shell.c
----------------------------------------------------------------------
diff --git a/sys/stats/src/stats_shell.c b/sys/stats/src/stats_shell.c
index 54b0182..ebb5969 100644
--- a/sys/stats/src/stats_shell.c
+++ b/sys/stats/src/stats_shell.c
@@ -31,8 +31,12 @@
 #include <shell/shell.h>
 #include <console/console.h>
 
+static int shell_stats_display(int argc, char **argv);
+static struct shell_cmd shell_stats_cmd = {
+    .sc_cmd = "stat",
+    .sc_cmd_func = shell_stats_display
+};
 uint8_t stats_shell_registered;
-struct shell_cmd shell_stats_cmd;
 
 static int 
 stats_shell_display_entry(struct stats_hdr *hdr, void *arg, char *name,
@@ -67,7 +71,7 @@ stats_shell_display_group(struct stats_hdr *hdr, void *arg)
     return (0);
 }
 
-static int 
+static int
 shell_stats_display(int argc, char **argv)
 {
     struct stats_hdr *hdr;
@@ -106,7 +110,7 @@ stats_shell_register(void)
 {
     if (!stats_shell_registered) {
         stats_shell_registered = 1;
-        shell_cmd_register(&shell_stats_cmd, "stat", shell_stats_display);
+        shell_cmd_register(&shell_stats_cmd);
     }
 
     return (0);


Mime
View raw message