From: Takashi Sakamoto Date: Wed, 20 Nov 2019 07:55:41 +0000 (+0900) Subject: seq: add global method to get list of numerical ID of queue X-Git-Tag: v0.1.0~230 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=940885e0982b61cdcf1aaf1bfcab34a6fe34c6bd;p=alsa-gobject.git seq: add global method to get list of numerical ID of queue Signed-off-by: Takashi Sakamoto --- diff --git a/src/seq/alsaseq.map b/src/seq/alsaseq.map index 86470dc..f4ee99d 100644 --- a/src/seq/alsaseq.map +++ b/src/seq/alsaseq.map @@ -27,6 +27,7 @@ ALSA_GOBJECT_0_0_0 { "alsaseq_get_port_info"; "alsaseq_get_client_pool"; "alsaseq_get_subscription_list"; + "alsaseq_get_queue_id_list"; "alsaseq_system_info_get_type"; diff --git a/src/seq/query.c b/src/seq/query.c index 957d954..2e2a91f 100644 --- a/src/seq/query.c +++ b/src/seq/query.c @@ -515,3 +515,77 @@ void alsaseq_get_subscription_list(const ALSASeqAddr *addr, return; } } + +/** + * alsaseq_get_queue_id_list: + * @entries: (array length=entry_count)(out): The array of elements for + * numerical ID of queue. + * @entry_count: The number of entries. + * @error: A #GError. + * + * Get the list of queue in ALSA Sequencer. + */ +void alsaseq_get_queue_id_list(guint **entries, gsize *entry_count, + GError **error) +{ + char *devnode; + int fd; + struct snd_seq_system_info info = {0}; + unsigned int maximum_count; + unsigned int count; + guint *list; + unsigned int index; + int i; + + alsaseq_get_seq_devnode(&devnode, error); + if (*error != NULL) + return; + + fd = open(devnode, O_RDONLY); + g_free(devnode); + if (fd < 0) { + generate_error(error, errno); + return; + } + + if (ioctl(fd, SNDRV_SEQ_IOCTL_SYSTEM_INFO, &info) < 0) { + generate_error(error, errno); + close(fd); + return; + } + maximum_count = info.queues; + count = info.cur_queues; + + if (count == 0) { + close(fd); + return; + } + + list = g_try_malloc0_n(count, sizeof(*entries)); + if (list == NULL) { + generate_error(error, ENOMEM); + close(fd); + return; + } + + for (i = 0; i < maximum_count; ++i) { + struct snd_seq_queue_info info; + + info.queue = i; + if (ioctl(fd, SNDRV_SEQ_IOCTL_GET_QUEUE_INFO, &info) < 0) + continue; + + list[index] = i; + if (++index >= count) + break; + } + close(fd); + if (index != count) { + generate_error(error, ENXIO); + g_free(list); + return; + } + + *entries = list; + *entry_count = count; +} diff --git a/src/seq/query.h b/src/seq/query.h index 0871542..689327f 100644 --- a/src/seq/query.h +++ b/src/seq/query.h @@ -38,6 +38,9 @@ void alsaseq_get_subscription_list(const ALSASeqAddr *addr, ALSASeqQuerySubscribeType query_type, GList **entries, GError **error); +void alsaseq_get_queue_id_list(guint **entries, gsize *entry_count, + GError **error); + G_END_DECLS #endif