From: Takashi Sakamoto Date: Mon, 18 Nov 2019 04:22:44 +0000 (+0900) Subject: rawmidi: stream_pair: add APIs to read/write data for attached substeam X-Git-Tag: v0.1.0~174 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=8d547d0f4cab8659fdc311b829493259f31e9d6e;p=alsa-gobject.git rawmidi: stream_pair: add APIs to read/write data for attached substeam Signed-off-by: Takashi Sakamoto --- diff --git a/src/rawmidi/alsarawmidi.map b/src/rawmidi/alsarawmidi.map index 0a6025b..2994533 100644 --- a/src/rawmidi/alsarawmidi.map +++ b/src/rawmidi/alsarawmidi.map @@ -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"; diff --git a/src/rawmidi/stream-pair.c b/src/rawmidi/stream-pair.c index 6276ca9..0bf91bc 100644 --- a/src/rawmidi/stream-pair.c +++ b/src/rawmidi/stream-pair.c @@ -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; + } +} diff --git a/src/rawmidi/stream-pair.h b/src/rawmidi/stream-pair.h index 22f4652..ffa80e6 100644 --- a/src/rawmidi/stream-pair.h +++ b/src/rawmidi/stream-pair.h @@ -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 diff --git a/tests/alsarawmidi-stream-pair b/tests/alsarawmidi-stream-pair index fb7c33c..433c74d 100644 --- a/tests/alsarawmidi-stream-pair +++ b/tests/alsarawmidi-stream-pair @@ -19,6 +19,8 @@ methods = ( 'get_substream_info', 'set_substream_params', 'get_substream_status', + 'read_from_substream', + 'write_to_substream', ) signals = ()