From: Takashi Sakamoto Date: Sun, 21 Jun 2020 12:35:14 +0000 (+0900) Subject: seq: add an API to retrieve current version of protocol in sequencer interface X-Git-Tag: v0.1.0~5 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=2eb591115d9748324ff0d4b017639f1ac1ece16f;p=alsa-gobject.git seq: add an API to retrieve current version of protocol in sequencer interface Signed-off-by: Takashi Sakamoto --- diff --git a/src/seq/alsaseq.map b/src/seq/alsaseq.map index c07d13c..22ed438 100644 --- a/src/seq/alsaseq.map +++ b/src/seq/alsaseq.map @@ -42,6 +42,7 @@ ALSA_GOBJECT_0_0_0 { "alsaseq_user_client_get_type"; "alsaseq_user_client_new"; "alsaseq_user_client_open"; + "alsaseq_user_client_get_protocol_version"; "alsaseq_user_client_set_info"; "alsaseq_user_client_get_info"; "alsaseq_user_client_create_port"; diff --git a/src/seq/user-client.c b/src/seq/user-client.c index 32ba0d5..1337cd5 100644 --- a/src/seq/user-client.c +++ b/src/seq/user-client.c @@ -29,6 +29,7 @@ struct _ALSASeqUserClientPrivate { int fd; int client_id; + guint16 proto_ver_triplet[3]; }; G_DEFINE_TYPE_WITH_PRIVATE(ALSASeqUserClient, alsaseq_user_client, G_TYPE_OBJECT) @@ -155,6 +156,7 @@ void alsaseq_user_client_open(ALSASeqUserClient *self, gint open_flag, { ALSASeqUserClientPrivate *priv; char *devnode; + int proto_ver; g_return_if_fail(ALSASEQ_IS_USER_CLIENT(self)); priv = alsaseq_user_client_get_instance_private(self); @@ -176,6 +178,47 @@ void alsaseq_user_client_open(ALSASeqUserClient *self, gint open_flag, close(priv->fd); priv->fd = -1; } + + // Remember the version of protocol currently used. + if (ioctl(priv->fd, SNDRV_SEQ_IOCTL_PVERSION, &proto_ver) < 0) { + generate_error(error, errno); + close(priv->fd); + priv->fd = -1; + return; + } + + priv->proto_ver_triplet[0] = SNDRV_PROTOCOL_MAJOR(proto_ver); + priv->proto_ver_triplet[1] = SNDRV_PROTOCOL_MINOR(proto_ver); + priv->proto_ver_triplet[2] = SNDRV_PROTOCOL_MICRO(proto_ver); +} + +/** + * alsaseq_user_client_get_protocol_version: + * @self: A #ALSASeqUserClient. + * @proto_ver_triplet: (array fixed-size=3)(out)(transfer none): The version of + * protocol currently used. + * @error: A #GError. + * + * Get the version of sequencer protocol currently used. The version is + * represented as the array with three elements; major, minor, and micro version + * in the order. The length of major version is 16 bit, the length of minor + * and micro version is 8 bit each. + */ +void alsaseq_user_client_get_protocol_version(ALSASeqUserClient *self, + const guint16 *proto_ver_triplet[3], + GError **error) +{ + ALSASeqUserClientPrivate *priv; + + g_return_if_fail(ALSASEQ_IS_USER_CLIENT(self)); + priv = alsaseq_user_client_get_instance_private(self); + + if (priv->fd < 0) { + generate_error(error, ENXIO); + return; + } + + *proto_ver_triplet = (const guint16 *)priv->proto_ver_triplet; } /** diff --git a/src/seq/user-client.h b/src/seq/user-client.h index 160e03b..0a98fdc 100644 --- a/src/seq/user-client.h +++ b/src/seq/user-client.h @@ -74,6 +74,10 @@ ALSASeqUserClient *alsaseq_user_client_new(); void alsaseq_user_client_open(ALSASeqUserClient *self, gint open_flag, GError **error); +void alsaseq_user_client_get_protocol_version(ALSASeqUserClient *self, + const guint16 *proto_ver_triplet[3], + GError **error); + void alsaseq_user_client_set_info(ALSASeqUserClient *self, ALSASeqClientInfo *client_info, GError **error); diff --git a/tests/alsaseq-user-client b/tests/alsaseq-user-client index dbe508c..896c370 100644 --- a/tests/alsaseq-user-client +++ b/tests/alsaseq-user-client @@ -16,6 +16,7 @@ props = ( methods = ( 'new', 'open', + 'get_protocol_version', 'set_info', 'get_info', 'create_port',