From: Takashi Sakamoto Date: Wed, 1 Apr 2020 09:13:28 +0000 (+0900) Subject: seq: user_client: add APIs to create/delete port for client X-Git-Tag: v0.1.0~290 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=10106b80df24b3e7118a8ed887979d356a708411;p=alsa-gobject.git seq: user_client: add APIs to create/delete port for client Signed-off-by: Takashi Sakamoto --- diff --git a/src/seq/alsaseq.map b/src/seq/alsaseq.map index afef3a6..3e4ee36 100644 --- a/src/seq/alsaseq.map +++ b/src/seq/alsaseq.map @@ -36,6 +36,9 @@ ALSA_GOBJECT_0_0_0 { "alsaseq_user_client_open"; "alsaseq_user_client_set_info"; "alsaseq_user_client_get_info"; + "alsaseq_user_client_create_port"; + "alsaseq_user_client_update_port"; + "alsaseq_user_client_delete_port"; "alsaseq_addr_get_type"; "alsaseq_addr_new"; diff --git a/src/seq/user-client.c b/src/seq/user-client.c index 96955eb..d33bd44 100644 --- a/src/seq/user-client.c +++ b/src/seq/user-client.c @@ -174,3 +174,90 @@ void alsaseq_user_client_get_info(ALSASeqUserClient *self, if (ioctl(priv->fd, SNDRV_SEQ_IOCTL_GET_CLIENT_INFO, info) < 0) generate_error(error, errno); } + +/** + * alsaseq_user_client_create_port: + * @self: A #ALSASeqUserClient. + * @port_info: A #ALSASeqPortInfo. + * @port_id: (nullable): The numerical ID of port if specified. + * @error: A #GError. + * + * Create a port into the client. + */ +void alsaseq_user_client_create_port(ALSASeqUserClient *self, + ALSASeqPortInfo *port_info, + guint8 *port_id, GError **error) +{ + ALSASeqUserClientPrivate *priv; + struct snd_seq_port_info *info; + + g_return_if_fail(ALSASEQ_IS_USER_CLIENT(self)); + g_return_if_fail(ALSASEQ_IS_PORT_INFO(port_info)); + priv = alsaseq_user_client_get_instance_private(self); + + seq_port_info_refer_private(port_info, &info); + + info->addr.client = priv->client_id; + if (port_id != NULL) { + info->addr.port = *port_id; + info->flags |= SNDRV_SEQ_PORT_FLG_GIVEN_PORT; + } + if (ioctl(priv->fd, SNDRV_SEQ_IOCTL_CREATE_PORT, info) < 0) + generate_error(error, errno); +} + +/** + * alsaseq_user_client_update_port: + * @self: A #ALSASeqUserClient. + * @port_info: A #ALSASeqPortInfo. + * @port_id: The numerical ID of port. + * @error: A #GError. + * + */ +void alsaseq_user_client_update_port(ALSASeqUserClient *self, + ALSASeqPortInfo *port_info, + guint8 port_id, GError **error) +{ + ALSASeqUserClientPrivate *priv; + struct snd_seq_port_info *info; + + g_return_if_fail(ALSASEQ_IS_USER_CLIENT(self)); + g_return_if_fail(ALSASEQ_IS_PORT_INFO(port_info)); + priv = alsaseq_user_client_get_instance_private(self); + + seq_port_info_refer_private(port_info, &info); + + info->addr.client = priv->client_id; + info->addr.port = port_id; + + if (ioctl(priv->fd, SNDRV_SEQ_IOCTL_SET_PORT_INFO, info) < 0) + generate_error(error, errno); +} + +/** + * alsaseq_user_client_delete_port: + * @self: A #ALSASeqUserClient. + * @port_info: A #ALSASeqPortInfo. + * @port_id: The numerical ID of port. + * @error: A #GError. + * + * Delete a port from the client. + */ +void alsaseq_user_client_delete_port(ALSASeqUserClient *self, + ALSASeqPortInfo *port_info, + guint8 port_id, GError **error) +{ + ALSASeqUserClientPrivate *priv; + struct snd_seq_port_info *info; + + g_return_if_fail(ALSASEQ_IS_USER_CLIENT(self)); + g_return_if_fail(ALSASEQ_IS_PORT_INFO(port_info)); + priv = alsaseq_user_client_get_instance_private(self); + + seq_port_info_refer_private(port_info, &info); + + info->addr.client = priv->client_id; + info->addr.port = port_id; + if (ioctl(priv->fd, SNDRV_SEQ_IOCTL_DELETE_PORT, info) < 0) + generate_error(error, errno); +} diff --git a/src/seq/user-client.h b/src/seq/user-client.h index df3013f..1bbe191 100644 --- a/src/seq/user-client.h +++ b/src/seq/user-client.h @@ -6,6 +6,7 @@ #include #include +#include G_BEGIN_DECLS @@ -59,6 +60,18 @@ void alsaseq_user_client_get_info(ALSASeqUserClient *self, ALSASeqClientInfo *const *client_info, GError **error); +void alsaseq_user_client_create_port(ALSASeqUserClient *self, + ALSASeqPortInfo *port_info, + guint8 *port_id, GError **error); + +void alsaseq_user_client_update_port(ALSASeqUserClient *self, + ALSASeqPortInfo *port_info, + guint8 port_id, GError **error); + +void alsaseq_user_client_delete_port(ALSASeqUserClient *self, + ALSASeqPortInfo *port_info, + guint8 port_id, GError **error); + G_END_DECLS #endif diff --git a/tests/alsaseq-user-client b/tests/alsaseq-user-client index c21e4a5..72d7900 100644 --- a/tests/alsaseq-user-client +++ b/tests/alsaseq-user-client @@ -18,6 +18,9 @@ methods = ( 'open', 'set_info', 'get_info', + 'create_port', + 'update_port', + 'delete_port', ) signals = ()