Skip to content

Commit

Permalink
Sort PCM D-Bus paths from the oldest to the newest
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Sep 13, 2024
1 parent 07a4be7 commit e3c3184
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/bluealsactl/cmd-list-pcms.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <dbus/dbus.h>

#include "bluealsactl.h"
#include "shared/dbus-client-pcm.h"

static int ba_pcm_cmp(const void *a, const void *b) {
const struct ba_pcm *pcm_a = a;
const struct ba_pcm *pcm_b = b;
if (pcm_a->sequence == pcm_b->sequence)
return strcmp(pcm_a->pcm_path, pcm_b->pcm_path);
return pcm_a->sequence - pcm_b->sequence;
}

static void usage(const char *command) {
printf("List all BlueALSA PCM paths.\n\n");
bactl_print_usage("%s [OPTION]...", command);
Expand Down Expand Up @@ -64,6 +73,9 @@ static int cmd_list_pcms_func(int argc, char *argv[]) {
return EXIT_FAILURE;
}

/* Sort PCMs from the oldest to the newest (most recently added). */
qsort(pcms, pcms_count, sizeof(*pcms), ba_pcm_cmp);

for (size_t i = 0; i < pcms_count; i++) {
printf("%s\n", pcms[i].pcm_path);
if (config.verbose) {
Expand Down

0 comments on commit e3c3184

Please sign in to comment.