From: Takashi Sakamoto Date: Wed, 1 Apr 2020 09:13:28 +0000 (+0900) Subject: seq: add global method to get information of client for ALSA Sequencer X-Git-Tag: v0.1.0~301 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=fd8fbfb342e53e2436c0d1cb855b3335fbe7d7ff;p=alsa-gobject.git seq: add global method to get information of client for ALSA Sequencer Signed-off-by: Takashi Sakamoto --- diff --git a/src/seq/alsaseq.map b/src/seq/alsaseq.map index 27cc717..2c444a7 100644 --- a/src/seq/alsaseq.map +++ b/src/seq/alsaseq.map @@ -20,6 +20,7 @@ ALSA_GOBJECT_0_0_0 { "alsaseq_get_seq_devnode"; "alsaseq_get_system_info"; "alsaseq_get_client_id_list"; + "alsaseq_get_client_info"; "alsaseq_system_info_get_type"; diff --git a/src/seq/client-info.c b/src/seq/client-info.c index f49359a..fa8d281 100644 --- a/src/seq/client-info.c +++ b/src/seq/client-info.c @@ -1,5 +1,4 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -#include "client-info.h" #include "privates.h" #include @@ -166,7 +165,7 @@ static void alsaseq_client_info_class_init(ALSASeqClientInfoClass *klass) seq_client_info_props[SEQ_CLIENT_INFO_PROP_PROCESS_ID] = g_param_spec_long("process-id", "process-id", - "The process ID for uset client, otherwise -1.", + "The process ID for user client, otherwise -1.", G_MINLONG, G_MAXLONG, -1, G_PARAM_READABLE); @@ -290,3 +289,12 @@ void alsaseq_client_info_get_event_filter(ALSASeqClientInfo *self, } } } + +void seq_client_info_refer_private(ALSASeqClientInfo *self, + struct snd_seq_client_info **info) +{ + ALSASeqClientInfoPrivate *priv = + alsaseq_client_info_get_instance_private(self); + + *info = &priv->info; +} diff --git a/src/seq/privates.h b/src/seq/privates.h index 68316f9..fe693b9 100644 --- a/src/seq/privates.h +++ b/src/seq/privates.h @@ -8,6 +8,7 @@ #include #include "system-info.h" +#include "client-info.h" #include @@ -22,6 +23,9 @@ GQuark alsaseq_error_quark(void); void seq_system_info_refer_private(ALSASeqSystemInfo *self, struct snd_seq_system_info **info); +void seq_client_info_refer_private(ALSASeqClientInfo *self, + struct snd_seq_client_info **info); + G_END_DECLS #endif diff --git a/src/seq/query.c b/src/seq/query.c index ce0ca13..0c5a35d 100644 --- a/src/seq/query.c +++ b/src/seq/query.c @@ -225,3 +225,46 @@ void alsaseq_get_client_id_list(guint **entries, gsize *entry_count, *entries = list; *entry_count = count; } + +/** + * alsaseq_get_client_info: + * @client_id: The numerical ID of client to query. One of + * ALSASeqSpecificClientId is available as well as any numerical + * value. + * @client_info: (out): A #ALSASeqClientInfo for the client. + * @error: A #GError. + * + * Get the information of client according to the numerical ID. + */ +void alsaseq_get_client_info(guint client_id, ALSASeqClientInfo **client_info, + GError **error) +{ + char *devnode; + struct snd_seq_client_info *info; + int fd; + + alsaseq_get_seq_devnode(&devnode, error); + if (*error != NULL) + return; + + *client_info = g_object_new(ALSASEQ_TYPE_CLIENT_INFO, NULL); + seq_client_info_refer_private(*client_info, &info); + + fd = open(devnode, O_RDONLY); + g_free(devnode); + if (fd < 0) { + generate_error(error, errno); + g_object_unref(*client_info); + *client_info = NULL; + return; + } + + info->client = client_id; + if (ioctl(fd, SNDRV_SEQ_IOCTL_GET_CLIENT_INFO, info) < 0) + generate_error(error, errno); + close(fd); + if (*error != NULL) { + g_object_unref(*client_info); + *client_info = NULL; + } +} diff --git a/src/seq/query.h b/src/seq/query.h index 7a07f49..49a01b2 100644 --- a/src/seq/query.h +++ b/src/seq/query.h @@ -6,6 +6,7 @@ #include #include +#include G_BEGIN_DECLS @@ -18,6 +19,9 @@ void alsaseq_get_system_info(ALSASeqSystemInfo **system_info, GError **error); void alsaseq_get_client_id_list(guint **entries, gsize *entry_count, GError **error); +void alsaseq_get_client_info(guint client_id, ALSASeqClientInfo **client_info, + GError **error); + G_END_DECLS #endif