[Asterisk-code-review] sounds: Sort 'core show sounds' output (asterisk[master])

George Joseph asteriskteam at digium.com
Wed Feb 6 07:13:08 CST 2019


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/10955 )

Change subject: sounds: Sort 'core show sounds' output
......................................................................

sounds: Sort 'core show sounds' output

Change-Id: Ib39052a745040f75eb635f15a042da15b20e22ab
---
M main/sounds.c
1 file changed, 17 insertions(+), 1 deletion(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/main/sounds.c b/main/sounds.c
index 091a396..c3323da 100644
--- a/main/sounds.c
+++ b/main/sounds.c
@@ -135,6 +135,11 @@
 	return 0;
 }
 
+static int sound_sorter(const void *obj_left, const void *obj_right, int flags)
+{
+	return strcmp(obj_left, obj_right);
+}
+
 /*! \brief Show a list of sounds available on the system */
 static char *handle_cli_sounds_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
@@ -152,6 +157,7 @@
 	if (a->argc == 3) {
 		struct ast_media_index *sounds_index = ast_sounds_get_index();
 		struct ao2_container *sound_files;
+		struct ao2_container *sorted;
 
 		if (!sounds_index) {
 			return CLI_FAILURE;
@@ -163,8 +169,18 @@
 			return CLI_FAILURE;
 		}
 
+		sorted = ao2_container_alloc_rbtree(AO2_ALLOC_OPT_LOCK_NOLOCK, 0,
+			sound_sorter, NULL);
+		if (!sorted
+		   || ao2_container_dup(sorted, sound_files, 0)) {
+			ao2_cleanup(sorted);
+			ao2_cleanup(sound_files);
+			return CLI_FAILURE;
+		}
+
 		ast_cli(a->fd, "Available audio files:\n");
-		ao2_callback(sound_files, OBJ_MULTIPLE | OBJ_NODATA, show_sounds_cb, a);
+		ao2_callback(sorted, OBJ_MULTIPLE | OBJ_NODATA, show_sounds_cb, a);
+		ao2_ref(sorted, -1);
 		ao2_ref(sound_files, -1);
 
 		return CLI_SUCCESS;

-- 
To view, visit https://gerrit.asterisk.org/10955
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib39052a745040f75eb635f15a042da15b20e22ab
Gerrit-Change-Number: 10955
Gerrit-PatchSet: 2
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation (1000185)
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190206/0b83705a/attachment.html>


More information about the asterisk-code-review mailing list