[svn-commits] file: branch group/stasis_cache_usage r392828 - /team/group/stasis_cache_usag...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jun 25 07:41:20 CDT 2013


Author: file
Date: Tue Jun 25 07:41:18 2013
New Revision: 392828

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392828
Log:
Move ast_complete_channels to using the stasis cache.

Modified:
    team/group/stasis_cache_usage/main/cli.c

Modified: team/group/stasis_cache_usage/main/cli.c
URL: http://svnview.digium.com/svn/asterisk/team/group/stasis_cache_usage/main/cli.c?view=diff&rev=392828&r1=392827&r2=392828
==============================================================================
--- team/group/stasis_cache_usage/main/cli.c (original)
+++ team/group/stasis_cache_usage/main/cli.c Tue Jun 25 07:41:18 2013
@@ -1553,38 +1553,30 @@
 
 char *ast_complete_channels(const char *line, const char *word, int pos, int state, int rpos)
 {
-	struct ast_channel *c = NULL;
-	int which = 0;
-	char notfound = '\0';
-	char *ret = &notfound; /* so NULL can break the loop */
-	struct ast_channel_iterator *iter;
+	int wordlen = strlen(word), which = 0;
+	RAII_VAR(struct ao2_container *, cached_channels, NULL, ao2_cleanup);
+	char *ret = NULL;
+	struct ao2_iterator iter;
+	struct stasis_message *msg;
 
 	if (pos != rpos) {
 		return NULL;
 	}
 
-	if (ast_strlen_zero(word)) {
-		iter = ast_channel_iterator_all_new();
-	} else {
-		iter = ast_channel_iterator_by_name_new(word, strlen(word));
-	}
-
-	if (!iter) {
-		return NULL;
-	}
-
-	while (ret == &notfound && (c = ast_channel_iterator_next(iter))) {
-		if (++which > state) {
-			ast_channel_lock(c);
-			ret = ast_strdup(ast_channel_name(c));
-			ast_channel_unlock(c);
-		}
-		ast_channel_unref(c);
-	}
-
-	ast_channel_iterator_destroy(iter);
-
-	return ret == &notfound ? NULL : ret;
+	cached_channels = stasis_cache_dump(ast_channel_topic_all_cached(), ast_channel_snapshot_type());
+
+	iter = ao2_iterator_init(cached_channels, 0);
+	for (; (msg = ao2_iterator_next(&iter)); ao2_ref(msg, -1)) {
+		struct ast_channel_snapshot *snapshot = stasis_message_data(msg);
+
+		if (!strncasecmp(word, snapshot->name, wordlen) && (++which > state)) {
+			ret = ast_strdup(snapshot->name);
+			break;
+		}
+	}
+	ao2_iterator_destroy(&iter);
+
+	return ret;
 }
 
 static char *group_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)




More information about the svn-commits mailing list