]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
rawmidi: stream_pair: add APIs to read/write data for attached substeam
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 18 Nov 2019 04:22:44 +0000 (13:22 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Sun, 12 Apr 2020 05:30:33 +0000 (14:30 +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 0a6025b24539c66473a2257e83d217b4118e73b3..2994533b5157801980b158c3da3f4c5aee27e921 100644 (file)
@@ -17,6 +17,8 @@ ALSA_GOBJECT_0_0_0 {
     "alsarawmidi_stream_pair_get_substream_info";
     "alsarawmidi_stream_pair_set_substream_params";
     "alsarawmidi_stream_pair_get_substream_status";
+    "alsarawmidi_stream_pair_read_from_substream";
+    "alsarawmidi_stream_pair_write_to_substream";
 
     "alsarawmidi_substream_params_get_type";
     "alsarawmidi_substream_params_new";
index 6276ca98563fd02bb47260dc48a974f0d8dde817..0bf91bcd40b3755b2ce8345acf3215871e9820f2 100644 (file)
@@ -240,3 +240,63 @@ void alsarawmidi_stream_pair_get_substream_status(ALSARawmidiStreamPair *self,
     if (ioctl(priv->fd, SNDRV_RAWMIDI_IOCTL_STATUS, status) < 0)
         generate_error(error, errno);
 }
+
+/**
+ * alsarawmidi_stream_pair_read_from_substream:
+ * @self: A #ALSARawmidiStreamPair.
+ * @buf: (array length=buf_size)(inout): The buffer to copy data.
+ * @buf_size: The size of buffer.
+ * @error: A #GError.
+ *
+ * Copy data from intermediate buffer to given buffer for substream attached to
+ * the pair of streams. In a case that the instance is opened without
+ * O_NONBLOCK flag and the intermediate buffer has no data, call of the API
+ * is blocked till any data is available.
+ */
+void alsarawmidi_stream_pair_read_from_substream(ALSARawmidiStreamPair *self,
+                                        guint8 *const *buf, gsize *buf_size,
+                                        GError **error)
+{
+    ALSARawmidiStreamPairPrivate *priv;
+    int len;
+
+    g_return_if_fail(ALSARAWMIDI_IS_STREAM_PAIR(self));
+    priv = alsarawmidi_stream_pair_get_instance_private(self);
+
+    len = read(priv->fd, *buf, *buf_size);
+    if (len < 0) {
+        generate_error(error, errno);
+        return;
+    }
+
+    *buf_size = len;
+}
+
+/**
+ * alsarawmidi_stream_pair_write_to_substream:
+ * @self: A #ALSARawmidiStreamPair.
+ * @buf: (array length=buf_size): The buffer to copy data.
+ * @buf_size: The size of buffer.
+ * @error: A #GError.
+ *
+ * Copy data from given buffer to intermediate buffer for substream attached to
+ * the pair of streams. In a case that the instance is opened without
+ * O_NONBLOCK flag and the intermediate buffer is full, call of the API is
+ * blocked till the buffer has space for the data.
+ */
+void alsarawmidi_stream_pair_write_to_substream(ALSARawmidiStreamPair *self,
+                                        const guint8 *buf, gsize buf_size,
+                                        GError **error)
+{
+    ALSARawmidiStreamPairPrivate *priv;
+    int len;
+
+    g_return_if_fail(ALSARAWMIDI_IS_STREAM_PAIR(self));
+    priv = alsarawmidi_stream_pair_get_instance_private(self);
+
+    len = write(priv->fd, buf, buf_size);
+    if (len < 0) {
+        generate_error(error, errno);
+        return;
+    }
+}
index 22f4652b6dcad1d037376ace680e9c4d4977306e..ffa80e67b3185e9848fa7c8c87ab241a0dcaa70f 100644 (file)
@@ -72,6 +72,13 @@ void alsarawmidi_stream_pair_get_substream_status(ALSARawmidiStreamPair *self,
                             ALSARawmidiSubstreamStatus *const *substream_status,
                             GError **error);
 
+void alsarawmidi_stream_pair_read_from_substream(ALSARawmidiStreamPair *self,
+                                        guint8 *const *buf, gsize *buf_size,
+                                        GError **error);
+void alsarawmidi_stream_pair_write_to_substream(ALSARawmidiStreamPair *self,
+                                        const guint8 *buf, gsize buf_size,
+                                        GError **error);
+
 G_END_DECLS
 
 #endif
index fb7c33c8b6a9dd50753f4643551a21b8b1550e55..433c74d94fa72f6c68578c04a606774c8dea4637 100644 (file)
@@ -19,6 +19,8 @@ methods = (
     'get_substream_info',
     'set_substream_params',
     'get_substream_status',
+    'read_from_substream',
+    'write_to_substream',
 )
 signals = ()