[asterisk-commits] kmoore: branch kmoore/stasis-http_sounds r389243 - /team/kmoore/stasis-http_s...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon May 20 12:34:03 CDT 2013


Author: kmoore
Date: Mon May 20 12:33:59 2013
New Revision: 389243

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389243
Log:
Remove the 'sounds reload' CLI command since it is unnecessary and add a 'sounds show' command for querying information

Modified:
    team/kmoore/stasis-http_sounds/res/res_sounds.c

Modified: team/kmoore/stasis-http_sounds/res/res_sounds.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/res/res_sounds.c?view=diff&rev=389243&r1=389242&r2=389243
==============================================================================
--- team/kmoore/stasis-http_sounds/res/res_sounds.c (original)
+++ team/kmoore/stasis-http_sounds/res/res_sounds.c Mon May 20 12:33:59 2013
@@ -591,36 +591,88 @@
 	return 0;
 }
 
+static int show_sounds_cb(void *obj, void *arg, int flags)
+{
+	struct sound_info *info = obj;
+	struct ast_cli_args *a = arg;
+	ast_cli(a->fd, "%s\n", info->name);
+	return 0;
+}
+
+static int show_sound_info_cb(void *obj, void *arg, int flags)
+{
+	struct sound_variant *variant = obj;
+	struct ast_cli_args *a = arg;
+        struct ast_format format;
+
+	ast_cli(a->fd, "  Language %s:\n", variant->language);
+	ast_cli(a->fd, "    Description: %s\n", variant->description);
+
+        ast_format_cap_iter_start(variant->formats);
+        while (!ast_format_cap_iter_next(variant->formats, &format)) {
+		ast_cli(a->fd, "    Format: %s\n", ast_getformatname(&format));
+        }
+        ast_format_cap_iter_end(variant->formats);
+
+	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)
+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 = "sounds show";
 		e->usage =
-			"Usage: sounds reload\n"
-			"       Reloads the index of sound files and their descriptions.\n";
+			"Usage: sounds show[ soundid]\n"
+			"       Shows a listing of sound files or information about the specified sound.\n";
 		return NULL;
 	case CLI_GENERATE:
-		return NULL;
-	}
-
-	if (a->argc != 2) {
-		return CLI_SHOWUSAGE;
-	}
-
-	if (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;
+	{
+                int length = strlen(a->word);
+                int which = 0;
+                struct ao2_iterator it_sounds;
+		char *match = NULL;
+		struct sound_info *info;
+
+		it_sounds = ao2_iterator_init(sounds_index, 0);
+                while ((info = ao2_iterator_next(&it_sounds))) {
+                        if (!strncasecmp(a->word, info->name, length) && ++which > a->n) {
+                                match = ast_strdup(info->name);
+                                ao2_ref(info, -1);
+                                break;
+                        }
+                        ao2_ref(info, -1);
+                }
+                ao2_iterator_destroy(&it_sounds);
+                return match;
+	}
+	}
+
+	if (a->argc == 2) {
+		ast_cli(a->fd, "Available audio files:\n");
+		ao2_callback(sounds_index, OBJ_MULTIPLE | OBJ_NODATA, show_sounds_cb, a);
+		return CLI_SUCCESS;
+	}
+
+	if (a->argc == 3) {
+		RAII_VAR(struct sound_info *, info, ao2_find(sounds_index, a->argv[2], OBJ_KEY), ao2_cleanup);
+		if (!info) {
+			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", info->name);
+		ao2_callback(info->variant_list, OBJ_MULTIPLE | OBJ_NODATA, show_sound_info_cb, a);
+		return CLI_SUCCESS;
+	}
+
+	return CLI_SHOWUSAGE;
 }
 
 /*! \brief Struct for registering CLI commands */
 static struct ast_cli_entry cli_sounds[] = {
-	AST_CLI_DEFINE(handle_cli_sounds_reload, "Reloads sounds index"),
+	AST_CLI_DEFINE(handle_cli_sounds_show, "Shows available sounds"),
 };
 
 /*! \brief Struct for registering this sound indexer's function calls */




More information about the asterisk-commits mailing list