]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
rawmidi: add an API to retrieve current version of protocol in rawmidi interface
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 21 Jun 2020 12:45:52 +0000 (21:45 +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/rawmidi/alsarawmidi.map
src/rawmidi/stream-pair.c
src/rawmidi/stream-pair.h
tests/alsarawmidi-stream-pair

index dc74eb6ec50b7f4298ffd9640e1de83f466e6088..103a40734e50b30eedea35ae8ccb8b3f9622ccb3 100644 (file)
@@ -14,6 +14,7 @@ ALSA_GOBJECT_0_0_0 {
     "alsarawmidi_stream_pair_get_type";
     "alsarawmidi_stream_pair_new";
     "alsarawmidi_stream_pair_open";
+    "alsarawmidi_stream_pair_get_protocol_version";
     "alsarawmidi_stream_pair_get_substream_info";
     "alsarawmidi_stream_pair_set_substream_params";
     "alsarawmidi_stream_pair_get_substream_status";
index 584b24ea340b1d4be977a7b6cd4fd6de4512e836..61408e053a599345661d786f5b865376cf591cfe 100644 (file)
@@ -37,6 +37,7 @@
 struct _ALSARawmidiStreamPairPrivate {
     int fd;
     char *devnode;
+    guint16 proto_ver_triplet[3];
 };
 G_DEFINE_TYPE_WITH_PRIVATE(ALSARawmidiStreamPair, alsarawmidi_stream_pair, G_TYPE_OBJECT)
 
@@ -182,6 +183,7 @@ void alsarawmidi_stream_pair_open(ALSARawmidiStreamPair *self, guint card_id,
 {
     ALSARawmidiStreamPairPrivate *priv;
     char *devnode;
+    int proto_ver;
 
     g_return_if_fail(ALSARAWMIDI_IS_STREAM_PAIR(self));
     priv = alsarawmidi_stream_pair_get_instance_private(self);
@@ -222,7 +224,47 @@ void alsarawmidi_stream_pair_open(ALSARawmidiStreamPair *self, guint card_id,
         return;
     }
 
+    // Remember the version of protocol currently used.
+    if (ioctl(priv->fd, SNDRV_RAWMIDI_IOCTL_PVERSION, &proto_ver) < 0) {
+        generate_error(error, errno);
+        close(priv->fd);
+        priv->fd = -1;
+        g_free(devnode);
+        return;
+    }
+
     priv->devnode = devnode;
+    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);
+}
+
+/**
+ * alsarawmidi_stream_pair_get_protocol_version:
+ * @self: A #ALSARawmidiStreamPair.
+ * @proto_ver_triplet: (array fixed-size=3)(out)(transfer none): The version of
+ *                     protocol currently used.
+ *
+ * Get the version of rawmidi 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 alsarawmidi_stream_pair_get_protocol_version(ALSARawmidiStreamPair *self,
+                                       const guint16 *proto_ver_triplet[3],
+                                       GError **error)
+{
+    ALSARawmidiStreamPairPrivate *priv;
+
+    g_return_if_fail(ALSARAWMIDI_IS_STREAM_PAIR(self));
+    priv = alsarawmidi_stream_pair_get_instance_private(self);
+
+    if (priv->fd < 0) {
+        generate_error(error, ENXIO);
+        return;
+    }
+
+    *proto_ver_triplet = (const guint16 *)priv->proto_ver_triplet;
 }
 
 /**
index d9931ab7c1f36bfea57ef0b9ad92843b8a19e38a..006a3e28d6796c2b2b51b43a33dbbf1fa1329135 100644 (file)
@@ -76,6 +76,10 @@ void alsarawmidi_stream_pair_open(ALSARawmidiStreamPair *self, guint card_id,
                                   ALSARawmidiStreamPairInfoFlag access_modes,
                                   gint open_flag, GError **error);
 
+void alsarawmidi_stream_pair_get_protocol_version(ALSARawmidiStreamPair *self,
+                                       const guint16 *proto_ver_triplet[3],
+                                       GError **error);
+
 void alsarawmidi_stream_pair_get_substream_info(ALSARawmidiStreamPair *self,
                                 ALSARawmidiStreamDirection direction,
                                 ALSARawmidiSubstreamInfo **substream_info,
index b75d4279cafc9deb61579b197b49550149a17d82..175b50e2dd3636dacde618d8448c5412c76aa2f1 100644 (file)
@@ -16,6 +16,7 @@ props = (
 methods = (
     'new',
     'open',
+    'get_protocol_version',
     'get_substream_info',
     'set_substream_params',
     'get_substream_status',