[asterisk-commits] kmoore: branch kmoore/stasis-http_sounds r389656 - /team/kmoore/stasis-http_s...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu May 23 17:52:32 CDT 2013
Author: kmoore
Date: Thu May 23 17:52:29 2013
New Revision: 389656
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389656
Log:
Some post-refactor cleanup
Modified:
team/kmoore/stasis-http_sounds/main/media_index.c
team/kmoore/stasis-http_sounds/main/sounds_index.c
Modified: team/kmoore/stasis-http_sounds/main/media_index.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/main/media_index.c?view=diff&rev=389656&r1=389655&r2=389656
==============================================================================
--- team/kmoore/stasis-http_sounds/main/media_index.c (original)
+++ team/kmoore/stasis-http_sounds/main/media_index.c Thu May 23 17:52:29 2013
@@ -36,7 +36,7 @@
<support_level>core</support_level>
***/
-/*! \brief The number of buckets to be used for storing language-keyed objects */
+/*! \brief The number of buckets to be used for storing variant-keyed objects */
#define VARIANT_BUCKETS 7
/*! \brief The number of buckets to be used for storing media filename-keyed objects */
@@ -80,15 +80,15 @@
static int media_variant_hash(const void *obj, const int flags)
{
- const char *language = (flags & OBJ_KEY) ? obj : ((struct media_variant*) obj)->variant;
- return ast_str_case_hash(language);
+ const char *variant = (flags & OBJ_KEY) ? obj : ((struct media_variant*) obj)->variant;
+ return ast_str_case_hash(variant);
}
static int media_variant_cmp(void *obj, void *arg, int flags)
{
struct media_variant *opt1 = obj, *opt2 = arg;
- const char *language = (flags & OBJ_KEY) ? arg : opt2->variant;
- return strcasecmp(opt1->variant, language) ? 0 : CMP_MATCH | CMP_STOP;
+ const char *variant = (flags & OBJ_KEY) ? arg : opt2->variant;
+ return strcasecmp(opt1->variant, variant) ? 0 : CMP_MATCH | CMP_STOP;
}
/*! \brief Structure to hold information about a media file */
@@ -96,7 +96,7 @@
AST_DECLARE_STRING_FIELDS(
AST_STRING_FIELD(name); /*!< The file name of the media */
);
- struct ao2_container *variant_list; /*!< The variants for which this media is available */
+ struct ao2_container *variants; /*!< The variants for which this media is available */
};
static void media_info_destroy(void *obj)
@@ -104,8 +104,8 @@
struct media_info *info = obj;
ast_string_field_free_memory(info);
- ao2_cleanup(info->variant_list);
- info->variant_list = NULL;
+ ao2_cleanup(info->variants);
+ info->variants = NULL;
}
static struct media_info *media_info_alloc(const char *name)
@@ -116,8 +116,8 @@
return NULL;
}
- info->variant_list = ao2_container_alloc(VARIANT_BUCKETS, media_variant_hash, media_variant_cmp);
- if (!info->variant_list) {
+ info->variants = ao2_container_alloc(VARIANT_BUCKETS, media_variant_hash, media_variant_cmp);
+ if (!info->variants) {
return NULL;
}
@@ -167,7 +167,7 @@
return index;
}
-static struct media_variant *find_variant(struct ast_media_index *index, const char *filename, const char *lang)
+static struct media_variant *find_variant(struct ast_media_index *index, const char *filename, const char *variant)
{
RAII_VAR(struct media_info *, info, NULL, ao2_cleanup);
@@ -176,7 +176,7 @@
return NULL;
}
- return ao2_find(info->variant_list, lang, OBJ_KEY);
+ return ao2_find(info->variants, variant, OBJ_KEY);
}
/*! \brief create the appropriate media_variant and any necessary structures */
@@ -197,16 +197,16 @@
ao2_link(index->index, info);
}
- variant = ao2_find(info->variant_list, variant_str, OBJ_KEY);
+ variant = ao2_find(info->variants, variant_str, OBJ_KEY);
if (!variant) {
- /* This is the first time the index has seen this language for
+ /* This is the first time the index has seen this variant for
* this filename, allocate and link */
variant = media_variant_alloc(variant_str);
if (!variant) {
return NULL;
}
- ao2_link(info->variant_list, variant);
+ ao2_link(info->variants, variant);
}
ao2_ref(variant, +1);
@@ -243,12 +243,12 @@
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)
+/*! \brief Add the variant to the list of variants requested */
+static int add_variant_cb(void *obj, void *arg, int flags)
{
struct media_variant *variant = obj;
- struct ao2_container *languages = arg;
- ast_str_container_add(languages, variant->variant);
+ struct ao2_container *variants= arg;
+ ast_str_container_add(variants, variant->variant);
return 0;
}
@@ -270,7 +270,7 @@
return NULL;
}
- ao2_callback(info->variant_list, OBJ_NODATA, add_language_cb, variants);
+ ao2_callback(info->variants, OBJ_NODATA, add_variant_cb, variants);
ao2_ref(variants, +1);
return variants;
@@ -307,12 +307,12 @@
return index->media_list_cache;
}
-/*! \brief Update an index with new format/language information */
-static int update_file_format_info(struct ast_media_index *index, const char *filename, const char *lang, const struct ast_format *file_format)
-{
- RAII_VAR(struct media_variant *, variant, find_variant(index, filename, lang), ao2_cleanup);
+/*! \brief Update an index with new format/variant information */
+static int update_file_format_info(struct ast_media_index *index, const char *filename, const char *variant_str, const struct ast_format *file_format)
+{
+ RAII_VAR(struct media_variant *, variant, find_variant(index, filename, variant_str), ao2_cleanup);
if (!variant) {
- variant = alloc_variant(index, filename, lang);
+ variant = alloc_variant(index, filename, variant_str);
if (!variant) {
return -1;
}
Modified: team/kmoore/stasis-http_sounds/main/sounds_index.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/main/sounds_index.c?view=diff&rev=389656&r1=389655&r2=389656
==============================================================================
--- team/kmoore/stasis-http_sounds/main/sounds_index.c (original)
+++ team/kmoore/stasis-http_sounds/main/sounds_index.c Thu May 23 17:52:29 2013
@@ -93,6 +93,7 @@
static int update_index_cb(void *obj, void *arg, int flags)
{
char *lang = obj;
+ struct ast_media_index *index = arg;
RAII_VAR(struct ast_str *, sounds_lang_dir, ast_str_create(64), ast_free);
if (!sounds_lang_dir) {
@@ -101,44 +102,29 @@
ast_str_set(&sounds_lang_dir, 0, "%s/sounds", ast_config_AST_DATA_DIR);
- if (ast_media_index_update(sounds_index, ast_str_buffer(sounds_lang_dir), lang)) {
+ if (ast_media_index_update(index, ast_str_buffer(sounds_lang_dir), lang)) {
return CMP_STOP;
}
return 0;
}
-/*! \brief Index sounds and sound descriptions */
-static int index_sounds(void)
+int ast_sounds_reindex(void)
{
RAII_VAR(struct ao2_container *, languages, get_languages(), ao2_cleanup);
-
- if (sounds_index || !languages) {
+ struct ast_media_index *new_index, *old_index = sounds_index;
+
+ if (!languages) {
return -1;
}
- sounds_index = ast_media_index_create();
- if (!sounds_index) {
+ new_index = ast_media_index_create();
+ if (!new_index) {
return -1;
}
- ao2_callback(languages, OBJ_NODATA, update_index_cb, NULL);
- return 0;
-}
-
-/*! \brief Free the current sounds index */
-static void drop_sound_index(void)
-{
- ao2_cleanup(sounds_index);
- sounds_index = NULL;
-}
-
-/*! \brief Drop and then reindex available sounds */
-int ast_sounds_reindex(void)
-{
- drop_sound_index();
- if (index_sounds()) {
- return -1;
- }
+ ao2_callback(languages, OBJ_NODATA, update_index_cb, new_index);
+ sounds_index = new_index;
+ ao2_cleanup(old_index);
return 0;
}
@@ -271,14 +257,14 @@
static void sounds_cleanup(void)
{
ast_cli_unregister_multiple(cli_sounds, ARRAY_LEN(cli_sounds));
- drop_sound_index();
-}
-
-int ast_sounds_index_init(void)
-{
ao2_cleanup(sounds_index);
sounds_index = NULL;
- if (index_sounds()) {
+}
+
+int ast_sounds_index_init(void)
+{
+ sounds_index = NULL;
+ if (ast_sounds_reindex()) {
return -1;
}
ast_cli_register_multiple(cli_sounds, ARRAY_LEN(cli_sounds));
More information about the asterisk-commits
mailing list