]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
rawmidi: stream_pair: report error about write-only file descriptor
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 16 Nov 2020 02:45:41 +0000 (11:45 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 16 Nov 2020 02:45:41 +0000 (11:45 +0900)
In design of ALSA rawmidi interface, one character device can handle
operations for both capture and playback. Applications can indicate
usage of both or either by flags of open system call.

The libalsarawmidi library checks the flag by fcntl(2) system call to
create GSource for capture. When the file descriptor is not configured
for read, the call returns error.

This commit handles the error for local error reporting.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/rawmidi/alsarawmidi-enum-types.h
src/rawmidi/stream-pair.c

index 6da9cb20a9958a77f8f7dba85bad587acc41a0a8..7c385b1c6161e4d163aa37e7951613c341f37bdd 100644 (file)
@@ -35,12 +35,14 @@ typedef enum /*< flags >*/
  * ALSARawmidiStreamPairError:
  * @ALSARAWMIDI_STREAM_PAIR_ERROR_FAILED:       The system call failed.
  * @ALSARAWMIDI_STREAM_PAIR_ERROR_DISCONNECTED: The card associated to the instance is in disconnect state.
+ * @ALSARAWMIDI_STREAM_PAIR_ERROR_UNREADABLE:   The instance is not for read operation.
  *
  * A set of error code for GError with domain which equals to #alsarawmidi_stream_pair_error_quark()
  */
 typedef enum {
     ALSARAWMIDI_STREAM_PAIR_ERROR_FAILED,
     ALSARAWMIDI_STREAM_PAIR_ERROR_DISCONNECTED,
+    ALSARAWMIDI_STREAM_PAIR_ERROR_UNREADABLE,
 } ALSARawmidiStreamPairError;
 
 #endif
index 9c4b03474cadba6047f14bec9e0ce73c07f6a466..3e62dc185916044378cf51e66012988b120c7357 100644 (file)
@@ -52,6 +52,7 @@ G_DEFINE_QUARK(alsarawmidi-stream-pair-error-quark, alsarawmidi_stream_pair_erro
 
 static const char *const err_msgs[] = {
         [ALSARAWMIDI_STREAM_PAIR_ERROR_DISCONNECTED] = "The card is in disconnect state",
+        [ALSARAWMIDI_STREAM_PAIR_ERROR_UNREADABLE] = "The instance is not for read operation",
 };
 
 #define generate_local_error(error, code) \
@@ -662,7 +663,7 @@ void alsarawmidi_stream_pair_create_source(ALSARawmidiStreamPair *self,
     }
 
     if (!(access_modes & O_RDWR) && !(access_modes & O_WRONLY)) {
-        generate_error(error, ENOTSUP);
+        generate_local_error(error, ALSARAWMIDI_STREAM_PAIR_ERROR_UNREADABLE);
         return;
     }