From 5aacb6a82d4cf625774fa1ea39ca193a3be73b35 Mon Sep 17 00:00:00 2001 From: kpfleming Date: Mon, 18 Sep 2006 19:54:18 +0000 Subject: merge qwell's CLI verbification work git-svn-id: http://svn.digium.com/svn/asterisk/trunk@43212 f38db490-d61c-443f-a65b-d21fe96a405b --- main/translate.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 5 deletions(-) (limited to 'main/translate.c') diff --git a/main/translate.c b/main/translate.c index 45b0292bd..77feabbac 100644 --- a/main/translate.c +++ b/main/translate.c @@ -475,7 +475,7 @@ static void rebuild_matrix(int samples) } /*! \brief CLI "show translation" command handler */ -static int show_translation(int fd, int argc, char *argv[]) +static int show_translation_deprecated(int fd, int argc, char *argv[]) { #define SHOW_TRANS 12 int x, y, z; @@ -544,16 +544,92 @@ static int show_translation(int fd, int argc, char *argv[]) return RESULT_SUCCESS; } +static int show_translation(int fd, int argc, char *argv[]) +{ +#define SHOW_TRANS 12 + int x, y, z; + int curlen = 0, longest = 0; + + if (argc > 5) + return RESULT_SHOWUSAGE; + + AST_LIST_LOCK(&translators); + + if (argv[3] && !strcasecmp(argv[3], "recalc")) { + z = argv[4] ? atoi(argv[4]) : 1; + + if (z <= 0) { + ast_cli(fd, " C'mon let's be serious here... defaulting to 1.\n"); + z = 1; + } + + if (z > MAX_RECALC) { + ast_cli(fd, " Maximum limit of recalc exceeded by %d, truncating value to %d\n", z - MAX_RECALC, MAX_RECALC); + z = MAX_RECALC; + } + ast_cli(fd, " Recalculating Codec Translation (number of sample seconds: %d)\n\n", z); + rebuild_matrix(z); + } + + ast_cli(fd, " Translation times between formats (in milliseconds) for one second of data\n"); + ast_cli(fd, " Source Format (Rows) Destination Format (Columns)\n\n"); + /* Get the length of the longest (usable?) codec name, so we know how wide the left side should be */ + for (x = 0; x < SHOW_TRANS; x++) { + curlen = strlen(ast_getformatname(1 << (x + 1))); + if (curlen > longest) + longest = curlen; + } + for (x = -1; x < SHOW_TRANS; x++) { + char line[80]; + char *buf = line; + size_t left = sizeof(line) - 1; /* one initial space */ + /* next 2 lines run faster than using ast_build_string() */ + *buf++ = ' '; + *buf = '\0'; + for (y = -1; y < SHOW_TRANS; y++) { + curlen = strlen(ast_getformatname(1 << (y))); + + if (x >= 0 && y >= 0 && tr_matrix[x][y].step) { + /* XXX 999 is a little hackish + We don't want this number being larger than the shortest (or current) codec + For now, that is "gsm" */ + ast_build_string(&buf, &left, "%*d", curlen + 1, tr_matrix[x][y].cost > 999 ? 0 : tr_matrix[x][y].cost); + } else if (x == -1 && y >= 0) { + /* Top row - use a dynamic size */ + ast_build_string(&buf, &left, "%*s", curlen + 1, ast_getformatname(1 << (x + y + 1)) ); + } else if (y == -1 && x >= 0) { + /* Left column - use a static size. */ + ast_build_string(&buf, &left, "%*s", longest, ast_getformatname(1 << (x + y + 1)) ); + } else if (x >= 0 && y >= 0) { + ast_build_string(&buf, &left, "%*s", curlen + 1, "-"); + } else { + ast_build_string(&buf, &left, "%*s", longest, ""); + } + } + ast_build_string(&buf, &left, "\n"); + ast_cli(fd, line); + } + AST_LIST_UNLOCK(&translators); + return RESULT_SUCCESS; +} static char show_trans_usage[] = -"Usage: show translation [recalc] []\n" +"Usage: core show translation [recalc] []\n" " Displays known codec translators and the cost associated\n" "with each conversion. If the argument 'recalc' is supplied along\n" "with optional number of seconds to test a new test will be performed\n" "as the chart is being displayed.\n"; -static struct ast_cli_entry show_trans = -{ { "show", "translation", NULL }, show_translation, "Display translation matrix", show_trans_usage }; +static struct ast_cli_entry cli_show_translation_deprecated = { + { "show", "translation", NULL }, + show_translation_deprecated, NULL, + NULL }; + +static struct ast_cli_entry cli_translate[] = { + { { "core", "show", "translation", NULL }, + show_translation, "Display translation matrix", + show_trans_usage, NULL, &cli_show_translation_deprecated }, +}; /*! \brief register codec translator */ int __ast_register_translator(struct ast_translator *t, struct ast_module *mod) @@ -613,7 +689,7 @@ int __ast_register_translator(struct ast_translator *t, struct ast_module *mod) } AST_LIST_LOCK(&translators); if (!added_cli) { - ast_cli_register(&show_trans); + ast_cli_register_multiple(cli_translate, sizeof(cli_translate) / sizeof(struct ast_cli_entry)); added_cli++; } AST_LIST_INSERT_HEAD(&translators, t, list); -- cgit v1.2.3