From: Takashi Sakamoto Date: Wed, 1 Apr 2020 09:13:28 +0000 (+0900) Subject: seq: add global method to get the list of port ID of client X-Git-Tag: v0.1.0~296 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=a22565c85f97abce194016457ab78abd8d38fd2a;p=alsa-gobject.git seq: add global method to get the list of port ID of client Signed-off-by: Takashi Sakamoto --- diff --git a/src/seq/alsaseq.map b/src/seq/alsaseq.map index aad47fe..bbd7bdc 100644 --- a/src/seq/alsaseq.map +++ b/src/seq/alsaseq.map @@ -21,6 +21,7 @@ ALSA_GOBJECT_0_0_0 { "alsaseq_get_system_info"; "alsaseq_get_client_id_list"; "alsaseq_get_client_info"; + "alsaseq_get_port_id_list"; "alsaseq_system_info_get_type"; diff --git a/src/seq/query.c b/src/seq/query.c index 0c5a35d..93a5e29 100644 --- a/src/seq/query.c +++ b/src/seq/query.c @@ -268,3 +268,76 @@ void alsaseq_get_client_info(guint client_id, ALSASeqClientInfo **client_info, *client_info = NULL; } } + +/** + * alsaseq_get_port_id_list: + * @client_id: The numerical ID of client to query. One of + * ALSASeqSpecificClientId is available as well as any numerical + * value. + * @entries: (array length=entry_count)(out): The array with elements for + * numerical ID of port. One of ALSASeqSpecificPortId is available as + * well as any numerical value. + * @entry_count: The number of entries in the array. + * @error: A #GError. + * + * Get the list of numerical IDs for port added by the client. + */ +void alsaseq_get_port_id_list(guint client_id, guint **entries, + gsize *entry_count, GError **error) +{ + char *devnode; + struct snd_seq_client_info client_info = {0}; + unsigned int count; + guint *list; + unsigned int index; + struct snd_seq_port_info port_info = {0}; + int fd; + + 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; + } + + client_info.client = client_id; + if (ioctl(fd, SNDRV_SEQ_IOCTL_GET_CLIENT_INFO, &client_info) < 0) { + generate_error(error, errno); + close(fd); + return; + } + + count = client_info.num_ports; + list = g_try_malloc0_n(count, sizeof(*list)); + if (list == NULL) { + generate_error(error, ENOMEM); + close(fd); + return; + } + index = 0; + + port_info.addr.client = client_id; + port_info.addr.port = -1; + while (index < count) { + if (ioctl(fd, SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT, &port_info) < 0) { + break; + } + + list[index] = port_info.addr.port; + ++index; + } + 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 49a01b2..b063142 100644 --- a/src/seq/query.h +++ b/src/seq/query.h @@ -22,6 +22,9 @@ void alsaseq_get_client_id_list(guint **entries, gsize *entry_count, void alsaseq_get_client_info(guint client_id, ALSASeqClientInfo **client_info, GError **error); +void alsaseq_get_port_id_list(guint client_id, guint **entries, + gsize *entry_count, GError **error); + G_END_DECLS #endif