From: Takashi Sakamoto Date: Wed, 1 Apr 2020 09:13:28 +0000 (+0900) Subject: seq: add global method to get list of client ID in ALSA Sequencer X-Git-Tag: v0.1.0~304 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=c5b7c598fde46a48d4334ccc529dbc8bc1a3ec80;p=alsa-gobject.git seq: add global method to get list of client ID in ALSA Sequencer Signed-off-by: Takashi Sakamoto --- diff --git a/src/seq/alsaseq.map b/src/seq/alsaseq.map index 1b9fca6..571fc84 100644 --- a/src/seq/alsaseq.map +++ b/src/seq/alsaseq.map @@ -19,6 +19,7 @@ ALSA_GOBJECT_0_0_0 { "alsaseq_get_seq_sysname"; "alsaseq_get_seq_devnode"; "alsaseq_get_system_info"; + "alsaseq_get_client_id_list"; "alsaseq_system_info_get_type"; local: diff --git a/src/seq/query.c b/src/seq/query.c index d81f251..ce0ca13 100644 --- a/src/seq/query.c +++ b/src/seq/query.c @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -141,3 +142,86 @@ void alsaseq_get_system_info(ALSASeqSystemInfo **system_info, GError **error) // Decrement count for the above connection. --info->cur_clients; } + +/** + * alsaseq_get_client_id_list: + * @entries: (array length=entry_count)(out): The array with elements for + * numerical ID of client. One of ALSASeqSpecificClientId can be + * included in result as well as any numerical value. + * @entry_count: The number of entries. + * @error: A #GError. + * + * Get the list of clients as the numerical ID. + */ +void alsaseq_get_client_id_list(guint **entries, gsize *entry_count, + GError **error) +{ + char *devnode; + int my_id; + struct snd_seq_system_info system_info = {0}; + unsigned int count; + guint *list; + unsigned int index; + struct snd_seq_client_info client_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; + } + + if (ioctl(fd, SNDRV_SEQ_IOCTL_CLIENT_ID, &my_id) < 0) { + generate_error(error, errno); + close(fd); + return; + } + + if (ioctl(fd, SNDRV_SEQ_IOCTL_SYSTEM_INFO, &system_info) < 0) { + generate_error(error, errno); + close(fd); + return; + } + + // Exclude myself. + count = system_info.cur_clients - 1; + if (count == 0) { + *entry_count = 0; + close(fd); + return; + } + + list = g_try_malloc0_n(count, sizeof(guint)); + if (list == NULL) { + *entry_count = 0; + close(fd); + return; + } + index = 0; + + client_info.client = -1; + while (index < count) { + if (ioctl(fd, SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT, &client_info) < 0) + break; + + if (client_info.client != my_id) { + list[index] = client_info.client; + ++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 14eb961..7a07f49 100644 --- a/src/seq/query.h +++ b/src/seq/query.h @@ -15,6 +15,9 @@ void alsaseq_get_seq_devnode(gchar **devnode, GError **error); void alsaseq_get_system_info(ALSASeqSystemInfo **system_info, GError **error); +void alsaseq_get_client_id_list(guint **entries, gsize *entry_count, + GError **error); + G_END_DECLS #endif