[asterisk-commits] kmoore: branch kmoore/sound_index_cli r396346 - /team/kmoore/sound_index_cli/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 6 16:05:16 CDT 2013


Author: kmoore
Date: Tue Aug  6 16:05:15 2013
New Revision: 396346

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=396346
Log:
Refactor sounds query commands

Modified:
    team/kmoore/sound_index_cli/main/sounds_index.c

Modified: team/kmoore/sound_index_cli/main/sounds_index.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/sound_index_cli/main/sounds_index.c?view=diff&rev=396346&r1=396345&r2=396346
==============================================================================
--- team/kmoore/sound_index_cli/main/sounds_index.c (original)
+++ team/kmoore/sound_index_cli/main/sounds_index.c Tue Aug  6 16:05:15 2013
@@ -162,20 +162,22 @@
 	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");
@@ -211,15 +213,43 @@
 	return CLI_SUCCESS;
 }
 
-/*! \brief Allow for reloading of sounds via the command line */
+/*! \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 show";
+		e->command = "core show sounds";
 		e->usage =
-			"Usage: sounds show [soundid]\n"
-			"       Shows a listing of sound files or information about the specified sound.\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 == 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;
+	}
+
+	return CLI_SHOWUSAGE;
+}
+
+/*! \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 = "core show sound";
+		e->usage =
+			"Usage: core show sound [soundid]\n"
+			"       Shows information about the specified sound.\n";
 		return NULL;
 	case CLI_GENERATE:
 	{
@@ -247,25 +277,14 @@
 	}
 	}
 
-	if (a->argc == 2) {
-		RAII_VAR(struct ao2_container *, sound_files, ast_media_get_media(sounds_index), ao2_cleanup);
-		if (!sound_files) {
+	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[3]);
 			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 (!variants || !ao2_container_count(variants)) {
-			ast_cli(a->fd, "ERROR: File %s not found in index\n", a->argv[2]);
-			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,6 +295,7 @@
 /*! \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_sound_show, "Shows details about a specific sound"),
 	AST_CLI_DEFINE(handle_cli_sounds_reload, "Reload sounds index"),
 };
 




More information about the asterisk-commits mailing list