]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
seq: add an API to retrieve current version of protocol in sequencer interface
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 21 Jun 2020 12:35:14 +0000 (21:35 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Sun, 21 Jun 2020 15:12:30 +0000 (00:12 +0900)
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/seq/alsaseq.map
src/seq/user-client.c
src/seq/user-client.h
tests/alsaseq-user-client

index c07d13c3dd6635a17caff69a7b156797bc355acc..22ed438f19daa84c7ccafa8d804f4a281c1a3925 100644 (file)
@@ -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";
index 32ba0d544bf3a9ea2042e9dc02ab8a99329c540b..1337cd50640944bedc4f12155c77904658eff8ec 100644 (file)
@@ -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;
 }
 
 /**
index 160e03b7208852c7b9d031155e4cc52b97ce2585..0a98fdca00c033b7a73d0f1146acac2657691cfd 100644 (file)
@@ -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);
index dbe508c56aeb0925b5a5dc07c9164c4ee8913d5a..896c3709dbb0f8743ffca493667998fa52b38b70 100644 (file)
@@ -16,6 +16,7 @@ props = (
 methods = (
     'new',
     'open',
+    'get_protocol_version',
     'set_info',
     'get_info',
     'create_port',