[asterisk-commits] kmoore: branch kmoore/stasis-http_sounds r387790 - in /team/kmoore/stasis-htt...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon May 6 17:09:01 CDT 2013


Author: kmoore
Date: Mon May  6 17:09:00 2013
New Revision: 387790

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387790
Log:
More clean up and documentation

Modified:
    team/kmoore/stasis-http_sounds/include/asterisk/sounds.h
    team/kmoore/stasis-http_sounds/main/file.c
    team/kmoore/stasis-http_sounds/res/res_sounds.c
    team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c

Modified: team/kmoore/stasis-http_sounds/include/asterisk/sounds.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/include/asterisk/sounds.h?view=diff&rev=387790&r1=387789&r2=387790
==============================================================================
--- team/kmoore/stasis-http_sounds/include/asterisk/sounds.h (original)
+++ team/kmoore/stasis-http_sounds/include/asterisk/sounds.h Mon May  6 17:09:00 2013
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2013, Digium, Inc.
  *
- * Kinsey Moore <markster at digium.com>
+ * Kinsey Moore <kmoore at digium.com>
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk project. Please do not directly contact
@@ -31,52 +31,19 @@
 
 /*! \brief Interface for sound indexers to use when registering themselves */
 struct ast_sounds_indexer {
-	/*!
-	 * \brief Get the description for a sound
-	 *
-	 * \param filename Name of the file for which to get the description
-	 * \param lang Language for which to get the description
-	 *
-	 * \retval NULL if not found
-	 * \return a copy of the description (must be ast_freed)
-	 */
+	/*! \brief Function pointer called by ast_sounds_get_description */
 	char *(*get_description)(const char *filename, const char *lang);
 
-	/*!
-	 * \brief Get the ast_format_cap for a sound
-	 *
-	 * \param filename Name of the file for which to get the description
-	 * \param lang Language for which to get the description
-	 *
-	 * \retval NULL if not found
-	 * \return a copy of the format capabilities (must be destroyed)
-	 */
+	/*! \brief Function pointer called by ast_sounds_get_format_cap */
 	struct ast_format_cap *(*get_format_cap)(const char *filename, const char *lang);
 
-	/*!
-	 * \brief Get the languages in which a sound is available
-	 *
-	 * \param filename Name of the file for which to get available languages
-	 *
-	 * \retval NULL on error
-	 * \return an ast_str_container filled with language strings
-	 */
+	/*! \brief Function pointer called by ast_sounds_get_languages */
 	struct ao2_container *(*get_languages)(const char *filename);
 
-	/*!
-	 * \brief Get the a container of all sounds available on the system
-	 *
-	 * \retval NULL on error
-	 * \return an ast_str_container filled with sound file name strings
-	 */
+	/*! \brief Function pointer called by ast_sounds_get_sounds */
 	struct ao2_container *(*get_sounds)(void);
 
-	/*!
-	 * \brief Reload the sounds index
-	 *
-	 * \retval zero on success
-	 * \retval non-zero on failure
-	 */
+	/*! \brief Function pointer called by ast_sounds_reindex */
 	int (*reindex)(void);
 };
 

Modified: team/kmoore/stasis-http_sounds/main/file.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/main/file.c?view=diff&rev=387790&r1=387789&r2=387790
==============================================================================
--- team/kmoore/stasis-http_sounds/main/file.c (original)
+++ team/kmoore/stasis-http_sounds/main/file.c Mon May  6 17:09:00 2013
@@ -1686,7 +1686,7 @@
 }
 
 static struct ast_cli_entry cli_file[] = {
-	AST_CLI_DEFINE(handle_cli_core_show_file_formats, "Displays file formats"),
+	AST_CLI_DEFINE(handle_cli_core_show_file_formats, "Displays file formats")
 };
 
 static void file_shutdown(void)

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=387790&r1=387789&r2=387790
==============================================================================
--- team/kmoore/stasis-http_sounds/res/res_sounds.c (original)
+++ team/kmoore/stasis-http_sounds/res/res_sounds.c Mon May  6 17:09:00 2013
@@ -35,10 +35,10 @@
 	<support_level>core</support_level>
  ***/
 
-#define SOUND_VARIANT_BUCKETS 7
-
-#define LANGUAGE_DIR_BUCKETS 7
-
+/*! \brief The number of buckets to be used for storing language-keyed objects */
+#define LANGUAGE_BUCKETS 7
+
+/*! \brief The number of buckets to be used for storing sound filename-keyed objects */
 #define SOUNDS_BUCKETS 157
 
 static struct ao2_container *sounds_index;
@@ -117,7 +117,7 @@
 		return NULL;
 	}
 
-	info->variant_list = ao2_container_alloc(SOUND_VARIANT_BUCKETS, sound_variant_hash, sound_variant_cmp);
+	info->variant_list = ao2_container_alloc(LANGUAGE_BUCKETS, sound_variant_hash, sound_variant_cmp);
 	if (!info->variant_list) {
 		return NULL;
 	}
@@ -141,7 +141,7 @@
 	return strcasecmp(opt1->name, name) ? 0 : CMP_MATCH | CMP_STOP;
 }
 
-/*! \brief Get the languages that sound files are available in */
+/*! \brief Get the languages in which sound files are available */
 static struct ao2_container *get_languages(void)
 {
 	RAII_VAR(struct ao2_container *, lang_dirs, NULL, ao2_cleanup);
@@ -149,7 +149,7 @@
 	DIR* srcdir;
 	RAII_VAR(struct ast_str *, sounds_dir, ast_str_create(64), ast_free);
 
-	lang_dirs = ast_str_container_alloc(LANGUAGE_DIR_BUCKETS);
+	lang_dirs = ast_str_container_alloc(LANGUAGE_BUCKETS);
 	if (!sounds_dir || !lang_dirs) {
 		return NULL;
 	}
@@ -185,7 +185,7 @@
 	return lang_dirs;
 }
 
-/*! \brief Find or create the appropriate sound_variant and any necessary structures */
+/*! \brief Find or optionally create the appropriate sound_variant and any necessary structures */
 static struct sound_variant *get_variant(const char *filename, const char *lang, int no_alloc)
 {
 	RAII_VAR(struct sound_info *, info, NULL, ao2_cleanup);
@@ -225,6 +225,7 @@
 	return variant;
 }
 
+/*! \brief Get the description associated with the sound filename for the given language if available */
 static char *sounds_get_description(const char *filename, const char *lang)
 {
 	RAII_VAR(struct sound_variant *, variant, NULL, ao2_cleanup);
@@ -240,6 +241,7 @@
 	return ast_strdup(variant->description);
 }
 
+/*! \brief Get the ast_format_cap associated with the sound filename and language if available */
 static struct ast_format_cap *sounds_get_format_cap(const char *filename, const char *lang)
 {
 	RAII_VAR(struct sound_variant *, variant, NULL, ao2_cleanup);
@@ -255,6 +257,7 @@
 	return ast_format_cap_dup(variant->formats);
 }
 
+/*! \brief Add the variant's language to the list of languages requested */
 static int add_language_cb(void *obj, void *arg, int flags)
 {
 	struct sound_variant *variant = obj;
@@ -263,6 +266,7 @@
 	return 0;
 }
 
+/*! \brief Return the requested container of languages */
 static struct ao2_container *sounds_get_languages(const char *filename)
 {
 	RAII_VAR(struct sound_info *, info, NULL, ao2_cleanup);
@@ -271,7 +275,7 @@
 		return NULL;
 	}
 
-	languages = ast_str_container_alloc(LANGUAGE_DIR_BUCKETS);
+	languages = ast_str_container_alloc(LANGUAGE_BUCKETS);
 	if (!languages) {
 		return NULL;
 	}
@@ -287,6 +291,7 @@
 	return languages;
 }
 
+/*! \brief Add the sound_info's sound filename to the container of filenames requested */
 static int add_sound_cb(void *obj, void *arg, int flags)
 {
 	struct sound_info *info = obj;
@@ -295,6 +300,7 @@
 	return 0;
 }
 
+/*! \brief Return the requested container of sounds */
 static struct ao2_container *sounds_get_sounds(void)
 {
 	RAII_VAR(struct ao2_container *, sounds, NULL, ao2_cleanup);
@@ -356,7 +362,7 @@
  * \brief Process a sounds description text file
  *
  * This currently processes core-sounds-*.txt and extra-sounds-*.txt, but will
- * process others if available.
+ * process others if present.
  */
 static int process_description_file(const char *lang, const char *filename)
 {
@@ -569,6 +575,7 @@
 	sounds_index = NULL;
 }
 
+/*! \brief Drop and then reindex available sounds */
 static int reindex(void)
 {
 	drop_sound_index();
@@ -578,6 +585,7 @@
 	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)
 {
 	switch (cmd) {
@@ -604,10 +612,12 @@
 	return CLI_SUCCESS;
 }
 
+/*! \brief Struct for registering CLI commands */
 static struct ast_cli_entry cli_sounds[] = {
 	AST_CLI_DEFINE(handle_cli_sounds_reload, "Reloads sounds index"),
 };
 
+/*! \brief Struct for registering this sound indexer's function calls */
 static struct ast_sounds_indexer indexer = {
 	.get_description = sounds_get_description,
 	.get_format_cap = sounds_get_format_cap,

Modified: team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c?view=diff&rev=387790&r1=387789&r2=387790
==============================================================================
--- team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c (original)
+++ team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c Mon May  6 17:09:00 2013
@@ -159,9 +159,21 @@
 
 void stasis_http_get_sounds(struct ast_variable *headers, struct ast_get_sounds_args *args, struct stasis_http_response *response)
 {
-	RAII_VAR(struct ao2_container *, sound_files, ast_sounds_get_sounds(), ao2_cleanup);
-	struct ast_json *sounds_blob = ast_json_array_create();
-	if (!sounds_blob || !sound_files) {
+	RAII_VAR(struct ao2_container *, sound_files, NULL, ao2_cleanup);
+	struct ast_json *sounds_blob;
+
+	if (!ast_sounds_indexer_registered()) {
+		stasis_http_response_error(response, 500, "Internal Error", "Sound indexer not available");
+		return;
+	}
+
+	sound_files = ast_sounds_get_sounds();
+	if (!sound_files) {
+		stasis_http_response_error(response, 500, "Internal Error", "Allocation Error");
+	}
+
+	sounds_blob = ast_json_array_create();
+	if (!sounds_blob) {
 		stasis_http_response_error(response, 500, "Internal Error", "Allocation Error");
 	}
 
@@ -177,7 +189,14 @@
 
 void stasis_http_get_stored_sound(struct ast_variable *headers, struct ast_get_stored_sound_args *args, struct stasis_http_response *response)
 {
-	struct ast_json *sound_blob = create_sound_blob(args->sound_id, NULL);
+	struct ast_json *sound_blob;
+
+	if (!ast_sounds_indexer_registered()) {
+		stasis_http_response_error(response, 500, "Internal Error", "Sound indexer not available");
+		return;
+	}
+
+	sound_blob = create_sound_blob(args->sound_id, NULL);
 	if (sound_blob) {
 		stasis_http_response_ok(response, sound_blob);
 		return;




More information about the asterisk-commits mailing list