From 18ea4809517a0d8f5758198d3b1de19260ea86de Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Wed, 1 Apr 2020 18:13:28 +0900 Subject: [PATCH] seq: add global method to get information of port in client Signed-off-by: Takashi Sakamoto --- src/seq/alsaseq.map | 1 + src/seq/port-info.c | 10 +++++++++- src/seq/privates.h | 4 ++++ src/seq/query.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ src/seq/query.h | 4 ++++ 5 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/seq/alsaseq.map b/src/seq/alsaseq.map index 96d1858..afef3a6 100644 --- a/src/seq/alsaseq.map +++ b/src/seq/alsaseq.map @@ -22,6 +22,7 @@ ALSA_GOBJECT_0_0_0 { "alsaseq_get_client_id_list"; "alsaseq_get_client_info"; "alsaseq_get_port_id_list"; + "alsaseq_get_port_info"; "alsaseq_system_info_get_type"; diff --git a/src/seq/port-info.c b/src/seq/port-info.c index 75464ea..35dd698 100644 --- a/src/seq/port-info.c +++ b/src/seq/port-info.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -#include "port-info.h" +#include "privates.h" struct _ALSASeqPortInfoPrivate { struct snd_seq_port_info info; @@ -249,3 +249,11 @@ ALSASeqPortInfo *alsaseq_port_info_new() { return g_object_new(ALSASEQ_TYPE_PORT_INFO, NULL); } + +void seq_port_info_refer_private(ALSASeqPortInfo *self, + struct snd_seq_port_info **info) +{ + ALSASeqPortInfoPrivate *priv = alsaseq_port_info_get_instance_private(self); + + *info = &priv->info; +} diff --git a/src/seq/privates.h b/src/seq/privates.h index fe693b9..0db1e9f 100644 --- a/src/seq/privates.h +++ b/src/seq/privates.h @@ -9,6 +9,7 @@ #include "system-info.h" #include "client-info.h" +#include "port-info.h" #include @@ -26,6 +27,9 @@ void seq_system_info_refer_private(ALSASeqSystemInfo *self, void seq_client_info_refer_private(ALSASeqClientInfo *self, struct snd_seq_client_info **info); +void seq_port_info_refer_private(ALSASeqPortInfo *self, + struct snd_seq_port_info **info); + G_END_DECLS #endif diff --git a/src/seq/query.c b/src/seq/query.c index 93a5e29..402e032 100644 --- a/src/seq/query.c +++ b/src/seq/query.c @@ -341,3 +341,49 @@ void alsaseq_get_port_id_list(guint client_id, guint **entries, *entries = list; *entry_count = count; } + +/** + * alsaseq_get_port_info: + * @client_id: The numerical ID of client to query. One of + * ALSASeqSpecificClientId is available as well as any numerica + * value. + * @port_id: The numerical ID of port in the client. One of + * ALSASeqSpecificPortId is available as well as any numerical value. + * @port_info: (out): A #ALSASeqPortInfo for the port. + * @error: A #GError. + * + * Get the information of port in client. + */ +void alsaseq_get_port_info(guint client_id, guint port_id, + ALSASeqPortInfo **port_info, GError **error) +{ + char *devnode; + struct snd_seq_port_info *info; + int fd; + + alsaseq_get_seq_devnode(&devnode, error); + if (*error != NULL) + return; + + *port_info = g_object_new(ALSASEQ_TYPE_PORT_INFO, NULL); + seq_port_info_refer_private(*port_info, &info); + + fd = open(devnode, O_RDONLY); + g_free(devnode); + if (fd < 0) { + generate_error(error, errno); + g_object_unref(*port_info); + *port_info = NULL; + return; + } + + info->addr.client = client_id; + info->addr.port = port_id; + if (ioctl(fd, SNDRV_SEQ_IOCTL_GET_PORT_INFO, info) < 0) + generate_error(error, errno); + close(fd); + if (*error != NULL) { + g_object_unref(*port_info); + *port_info = NULL; + } +} diff --git a/src/seq/query.h b/src/seq/query.h index b063142..1713306 100644 --- a/src/seq/query.h +++ b/src/seq/query.h @@ -7,6 +7,7 @@ #include #include +#include G_BEGIN_DECLS @@ -25,6 +26,9 @@ void alsaseq_get_client_info(guint client_id, ALSASeqClientInfo **client_info, void alsaseq_get_port_id_list(guint client_id, guint **entries, gsize *entry_count, GError **error); +void alsaseq_get_port_info(guint client_id, guint port_id, + ALSASeqPortInfo **port_info, GError **error); + G_END_DECLS #endif -- 2.47.3