mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 12:16:00 +00:00
Improve sounds indexer CLI commands
This reworks the CLI commands used to access sounds information from "sounds show[ soundid]" to "core show sounds" and "core show sound <soundid>". This also reworks the "sounds reload" CLI command to fall under normal module reloading ("module reload sounds"). Also, make trunk build when DEBUG_MALLOC is not enabled. Review: https://reviewboard.asterisk.org/r/2745/ (closes issue ASTERISK-22141) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396829 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -56,6 +56,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#include "asterisk/heap.h"
|
||||
#include "asterisk/app.h"
|
||||
#include "asterisk/test.h"
|
||||
#include "asterisk/sounds_index.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
@@ -319,6 +320,7 @@ static struct reload_classes {
|
||||
{ "indications", ast_indications_reload },
|
||||
{ "cel", ast_cel_engine_reload },
|
||||
{ "plc", ast_plc_reload },
|
||||
{ "sounds", ast_sounds_reindex },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
@@ -162,20 +162,22 @@ static int show_sound_info_cb(void *obj, void *arg, int flags)
|
||||
int formats_shown = 0;
|
||||
RAII_VAR(struct ast_media_index *, local_index, ast_sounds_get_index(), ao2_cleanup);
|
||||
RAII_VAR(struct ast_format_cap *, cap, NULL, ast_format_cap_destroy);
|
||||
const char *description = ast_media_get_description(local_index, a->argv[2], language);
|
||||
const char *description = ast_media_get_description(local_index, a->argv[3], language);
|
||||
|
||||
ast_cli(a->fd, " Language %s:\n", language);
|
||||
if (!ast_strlen_zero(description)) {
|
||||
ast_cli(a->fd, " Description: %s\n", description);
|
||||
}
|
||||
|
||||
cap = ast_media_get_format_cap(local_index, a->argv[2], language);
|
||||
ast_format_cap_iter_start(cap);
|
||||
while (!ast_format_cap_iter_next(cap, &format)) {
|
||||
ast_cli(a->fd, " Format: %s\n", ast_getformatname(&format));
|
||||
formats_shown = 1;
|
||||
}
|
||||
ast_format_cap_iter_end(cap);
|
||||
cap = ast_media_get_format_cap(local_index, a->argv[3], language);
|
||||
if (cap) {
|
||||
ast_format_cap_iter_start(cap);
|
||||
while (!ast_format_cap_iter_next(cap, &format)) {
|
||||
ast_cli(a->fd, " Format: %s\n", ast_getformatname(&format));
|
||||
formats_shown = 1;
|
||||
}
|
||||
ast_format_cap_iter_end(cap);
|
||||
}
|
||||
|
||||
if (!formats_shown) {
|
||||
ast_cli(a->fd, " No Formats Available\n");
|
||||
@@ -184,42 +186,43 @@ static int show_sound_info_cb(void *obj, void *arg, int flags)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! \brief Allow for reloading of sounds via the command line */
|
||||
static char *handle_cli_sounds_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
||||
/*! \brief Show a list of sounds available on the system */
|
||||
static char *handle_cli_sounds_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
||||
{
|
||||
switch (cmd) {
|
||||
case CLI_INIT:
|
||||
e->command = "sounds reload";
|
||||
e->command = "core show sounds";
|
||||
e->usage =
|
||||
"Usage: sounds reload\n"
|
||||
" Reloads the index of sound files and their descriptions.\n";
|
||||
"Usage: core show sounds\n"
|
||||
" Shows a listing of sound files available on the system.\n";
|
||||
return NULL;
|
||||
case CLI_GENERATE:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (a->argc != 2) {
|
||||
return CLI_SHOWUSAGE;
|
||||
if (a->argc == 3) {
|
||||
RAII_VAR(struct ao2_container *, sound_files, ast_media_get_media(sounds_index), ao2_cleanup);
|
||||
if (!sound_files) {
|
||||
return CLI_FAILURE;
|
||||
}
|
||||
|
||||
ast_cli(a->fd, "Available audio files:\n");
|
||||
ao2_callback(sound_files, OBJ_MULTIPLE | OBJ_NODATA, show_sounds_cb, a);
|
||||
return CLI_SUCCESS;
|
||||
}
|
||||
|
||||
if (ast_sounds_reindex()) {
|
||||
ast_cli(a->fd, "Sound re-indexing failed.\n");
|
||||
return CLI_FAILURE;
|
||||
}
|
||||
|
||||
ast_cli(a->fd, "Sound files re-indexed.\n");
|
||||
return CLI_SUCCESS;
|
||||
return CLI_SHOWUSAGE;
|
||||
}
|
||||
|
||||
/*! \brief Allow for reloading of sounds via the command line */
|
||||
static char *handle_cli_sounds_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
||||
/*! \brief Show details about a sound available in the system */
|
||||
static char *handle_cli_sound_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
||||
{
|
||||
switch (cmd) {
|
||||
case CLI_INIT:
|
||||
e->command = "sounds show";
|
||||
e->command = "core show sound";
|
||||
e->usage =
|
||||
"Usage: sounds show [soundid]\n"
|
||||
" Shows a listing of sound files or information about the specified sound.\n";
|
||||
"Usage: core show sound [soundid]\n"
|
||||
" Shows information about the specified sound.\n";
|
||||
return NULL;
|
||||
case CLI_GENERATE:
|
||||
{
|
||||
@@ -247,25 +250,14 @@ static char *handle_cli_sounds_show(struct ast_cli_entry *e, int cmd, struct ast
|
||||
}
|
||||
}
|
||||
|
||||
if (a->argc == 2) {
|
||||
RAII_VAR(struct ao2_container *, sound_files, ast_media_get_media(sounds_index), ao2_cleanup);
|
||||
if (!sound_files) {
|
||||
return CLI_FAILURE;
|
||||
}
|
||||
|
||||
ast_cli(a->fd, "Available audio files:\n");
|
||||
ao2_callback(sound_files, OBJ_MULTIPLE | OBJ_NODATA, show_sounds_cb, a);
|
||||
return CLI_SUCCESS;
|
||||
}
|
||||
|
||||
if (a->argc == 3) {
|
||||
RAII_VAR(struct ao2_container *, variants, ast_media_get_variants(sounds_index, a->argv[2]), ao2_cleanup);
|
||||
if (a->argc == 4) {
|
||||
RAII_VAR(struct ao2_container *, variants, ast_media_get_variants(sounds_index, a->argv[3]), ao2_cleanup);
|
||||
if (!variants || !ao2_container_count(variants)) {
|
||||
ast_cli(a->fd, "ERROR: File %s not found in index\n", a->argv[2]);
|
||||
ast_cli(a->fd, "ERROR: File %s not found in index\n", a->argv[3]);
|
||||
return CLI_FAILURE;
|
||||
}
|
||||
|
||||
ast_cli(a->fd, "Indexed Information for %s:\n", a->argv[2]);
|
||||
ast_cli(a->fd, "Indexed Information for %s:\n", a->argv[3]);
|
||||
ao2_callback(variants, OBJ_MULTIPLE | OBJ_NODATA, show_sound_info_cb, a);
|
||||
return CLI_SUCCESS;
|
||||
}
|
||||
@@ -276,7 +268,7 @@ static char *handle_cli_sounds_show(struct ast_cli_entry *e, int cmd, struct ast
|
||||
/*! \brief Struct for registering CLI commands */
|
||||
static struct ast_cli_entry cli_sounds[] = {
|
||||
AST_CLI_DEFINE(handle_cli_sounds_show, "Shows available sounds"),
|
||||
AST_CLI_DEFINE(handle_cli_sounds_reload, "Reload sounds index"),
|
||||
AST_CLI_DEFINE(handle_cli_sound_show, "Shows details about a specific sound"),
|
||||
};
|
||||
|
||||
static void sounds_cleanup(void)
|
||||
|
@@ -74,7 +74,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
static char base64[64];
|
||||
static char b2a[256];
|
||||
|
||||
#ifndef __AST_DEBUG_MALLOC
|
||||
void *_ast_mem_backtrace_buffer[_AST_MEM_BACKTRACE_BUFLEN];
|
||||
#endif
|
||||
|
||||
AST_THREADSTORAGE(inet_ntoa_buf);
|
||||
|
||||
|
Reference in New Issue
Block a user