]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
seq: add global method to get list of client ID in ALSA Sequencer
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 1 Apr 2020 09:13:28 +0000 (18:13 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Fri, 3 Apr 2020 13:06:25 +0000 (22:06 +0900)
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/seq/alsaseq.map
src/seq/query.c
src/seq/query.h

index 1b9fca68eb90e110ae28441f36e69598a420c788..571fc8451d688cf5649d80e8472dcc0f8dc94172 100644 (file)
@@ -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:
index d81f251f4ef4705c91c64d552c21c57771c9a684..ce0ca138e3c6e9518bf096e66cc4ee8a4ed7721b 100644 (file)
@@ -8,6 +8,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
+#include <stdbool.h>
 
 #include <libudev.h>
 
@@ -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;
+}
index 14eb961e597ee8cf80bd0443d114bbcc56d7a167..7a07f49f387ad1bfaa3cf50b299448a5a7a99100 100644 (file)
@@ -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