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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat May 4 11:34:23 CDT 2013


Author: kmoore
Date: Sat May  4 11:34:21 2013
New Revision: 387651

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387651
Log:
Get stasis/sounds working

Modified:
    team/kmoore/stasis-http_sounds/include/asterisk/sounds.h
    team/kmoore/stasis-http_sounds/main/sounds.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=387651&r1=387650&r2=387651
==============================================================================
--- team/kmoore/stasis-http_sounds/include/asterisk/sounds.h (original)
+++ team/kmoore/stasis-http_sounds/include/asterisk/sounds.h Sat May  4 11:34:21 2013
@@ -58,10 +58,18 @@
 	 *
 	 * \param filename Name of the file for which to get available languages
 	 *
-	 * \retval NULL if not found
+	 * \retval NULL on error
 	 * \return an ast_str_container filled with language strings
 	 */
 	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
+	 */
+	struct ao2_container *(*get_sounds)(void);
 
 	/*!
 	 * \brief Reload the sounds index
@@ -121,10 +129,18 @@
  *
  * \param filename Name of the file for which to get available languages
  *
- * \retval NULL if not found
+ * \retval NULL on error
  * \return an ast_str_container filled with language strings
  */
 struct ao2_container *ast_sounds_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
+ */
+struct ao2_container *ast_sounds_get_sounds(void);
 
 /*!
  * \brief Reload the sounds index

Modified: team/kmoore/stasis-http_sounds/main/sounds.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/main/sounds.c?view=diff&rev=387651&r1=387650&r2=387651
==============================================================================
--- team/kmoore/stasis-http_sounds/main/sounds.c (original)
+++ team/kmoore/stasis-http_sounds/main/sounds.c Sat May  4 11:34:21 2013
@@ -70,6 +70,15 @@
 	return NULL;
 }
 
+struct ao2_container *ast_sounds_get_sounds(void)
+{
+	if (sounds_indexer && sounds_indexer->get_sounds) {
+		return sounds_indexer->get_sounds();
+	}
+
+	return NULL;
+}
+
 int ast_sounds_reindex(void)
 {
 	if (sounds_indexer && sounds_indexer->reindex) {

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=387651&r1=387650&r2=387651
==============================================================================
--- team/kmoore/stasis-http_sounds/res/res_sounds.c (original)
+++ team/kmoore/stasis-http_sounds/res/res_sounds.c Sat May  4 11:34:21 2013
@@ -39,6 +39,8 @@
 
 #define LANGUAGE_DIR_BUCKETS 7
 
+#define SOUNDS_BUCKETS 157
+
 static struct ao2_container *sounds_index;
 
 /*! \brief Structure to hold a list of the format variations for a sound file in a specific language */
@@ -283,6 +285,29 @@
 
 	ao2_ref(languages, +1);
 	return languages;
+}
+
+static int add_sound_cb(void *obj, void *arg, int flags)
+{
+	struct sound_info *info = obj;
+	struct ao2_container *sounds = arg;
+	ast_str_container_add(sounds, info->name);
+	return 0;
+}
+
+static struct ao2_container *sounds_get_sounds(void)
+{
+	RAII_VAR(struct ao2_container *, sounds, NULL, ao2_cleanup);
+
+	sounds = ast_str_container_alloc(SOUNDS_BUCKETS);
+	if (!sounds) {
+		return NULL;
+	}
+
+	ao2_callback(sounds_index, OBJ_NODATA, add_sound_cb, sounds);
+
+	ao2_ref(sounds, +1);
+	return sounds;
 }
 
 /*! \brief Update an index with new format/language information */
@@ -528,7 +553,7 @@
 		return -1;
 	}
 
-	sounds_index = ao2_container_alloc(SOUND_VARIANT_BUCKETS, sound_info_hash, sound_info_cmp);
+	sounds_index = ao2_container_alloc(SOUNDS_BUCKETS, sound_info_hash, sound_info_cmp);
 	if (!sounds_index) {
 		return -1;
 	}
@@ -587,6 +612,7 @@
 	.get_description = sounds_get_description,
 	.get_format_cap = sounds_get_format_cap,
 	.get_languages = sounds_get_languages,
+	.get_sounds = sounds_get_sounds,
 	.reindex = reindex,
 };
 

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=387651&r1=387650&r2=387651
==============================================================================
--- team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c (original)
+++ team/kmoore/stasis-http_sounds/res/stasis_http/resource_sounds.c Sat May  4 11:34:21 2013
@@ -95,9 +95,30 @@
 	return ast_json_ref(sound);
 }
 
+static int append_sound_cb(void *obj, void *arg, int flags)
+{
+	struct ast_json *sounds_array = arg;
+	char *filename = obj;
+	struct ast_json *sound_blob = create_sound_blob(filename);
+	if (!sound_blob) {
+		return CMP_STOP;
+	}
+
+	ast_json_array_append(sounds_array, sound_blob);
+	return 0;
+}
+
 void stasis_http_get_sounds(struct ast_variable *headers, struct ast_get_sounds_args *args, struct stasis_http_response *response)
 {
-	ast_log(LOG_ERROR, "TODO: stasis_http_get_sounds\n");
+	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) {
+		stasis_http_response_error(response, 500, "Internal Error", "Allocation Error");
+	}
+
+	ao2_callback(sound_files, OBJ_NODATA, append_sound_cb, sounds_blob);
+
+	stasis_http_response_ok(response, sounds_blob);
 }
 
 void stasis_http_get_stored_sound(struct ast_variable *headers, struct ast_get_stored_sound_args *args, struct stasis_http_response *response)




More information about the asterisk-commits mailing list