]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
seq: add global method to get the list of port ID of client
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 aad47fea98b1ef3b03f32963ac0f522f11cf4494..bbd7bdc30694d064b3012502877a63c2fd1108b1 100644 (file)
@@ -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";
 
index 0c5a35d99df4af4931957b33dfbd8695a670073b..93a5e29fd25c96f59cf1aeb1dc2a9b23727af025 100644 (file)
@@ -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;
+}
index 49a01b2c7baffa3c9667253dd6acc11da93c3c54..b063142620a85bc6d92eabd294c90b555bf3e25e 100644 (file)
@@ -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