]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
ctl: card: report error about element not found
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Fri, 13 Nov 2020 07:26:26 +0000 (16:26 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Fri, 13 Nov 2020 07:30:44 +0000 (16:30 +0900)
Any operation to control element returns ENOENT when sound card doesn't
have the element.

This commit handles the error in local error domain.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/ctl/alsactl-enum-types.h
src/ctl/card.c
tests/alsactl-enums

index e2040905e09cf42d44c9e288ad6021e78e69e6b5..65a792a00ad6cf56790cd2a47ff8f865ea4100f5 100644 (file)
@@ -113,12 +113,14 @@ typedef enum /*< flags >*/
  * ALSACtlCardError:
  * @ALSACTL_CARD_ERROR_FAILED:              The system call failed.
  * @ALSACTL_CARD_ERROR_DISCONNECTED:        The card associated to the instance is in disconnect state.
+ * @ALSACTL_CARD_ERROR_ELEM_NOT_FOUND:      The control element not found in the card.
  *
  * A set of error code for GError with domain which equals to #alsactl_card_error_quark()
  */
 typedef enum {
     ALSACTL_CARD_ERROR_FAILED,
     ALSACTL_CARD_ERROR_DISCONNECTED,
+    ALSACTL_CARD_ERROR_ELEM_NOT_FOUND,
 } ALSACtlCardError;
 
 #endif
index 773f33670cafb5871ad271dd42ef68a01a8f4a3d..43ea83af4d5f20bcb29443245bbd127422eb251c 100644 (file)
@@ -41,6 +41,7 @@ G_DEFINE_QUARK(alsactl-card-error-quark, alsactl_card_error)
 
 static const char *const err_msgs[] = {
     [ALSACTL_CARD_ERROR_DISCONNECTED] = "The card associated to the instance is in disconnect state",
+    [ALSACTL_CARD_ERROR_ELEM_NOT_FOUND] = "The control element not found in the card",
 };
 
 #define generate_local_error(exception, code) \
@@ -445,6 +446,8 @@ void alsactl_card_lock_elem(ALSACtlCard *self, const ALSACtlElemId *elem_id,
     if (ret < 0) {
         if (errno == ENODEV)
             generate_local_error(error, ALSACTL_CARD_ERROR_DISCONNECTED);
+        else if (errno == ENOENT)
+            generate_local_error(error, ALSACTL_CARD_ERROR_ELEM_NOT_FOUND);
         else
             generate_syscall_error(error, errno, "ioctl(%s)", req_name);
     }
@@ -512,6 +515,8 @@ void alsactl_card_get_elem_info(ALSACtlCard *self, const ALSACtlElemId *elem_id,
     if (ioctl(priv->fd, SNDRV_CTL_IOCTL_ELEM_INFO, info)) {
         if (errno == ENODEV)
             generate_local_error(error, ALSACTL_CARD_ERROR_DISCONNECTED);
+        else if (errno == ENOENT)
+            generate_local_error(error, ALSACTL_CARD_ERROR_ELEM_NOT_FOUND);
         else
             generate_syscall_error(error, errno, "ioctl(%s)", "ELEM_INFO");
         return;
@@ -592,6 +597,8 @@ void alsactl_card_write_elem_tlv(ALSACtlCard *self,
     if (ioctl(priv->fd, SNDRV_CTL_IOCTL_TLV_WRITE, packet) < 0) {
         if (errno == ENODEV)
             generate_local_error(error, ALSACTL_CARD_ERROR_DISCONNECTED);
+        else if (errno == ENOENT)
+            generate_local_error(error, ALSACTL_CARD_ERROR_ELEM_NOT_FOUND);
         else
             generate_syscall_error(error, errno, "ioctl(%s)", "TLV_WRITE");
     }
@@ -641,6 +648,8 @@ void alsactl_card_read_elem_tlv(ALSACtlCard *self, const ALSACtlElemId *elem_id,
     if (ioctl(priv->fd, SNDRV_CTL_IOCTL_TLV_READ, packet) < 0) {
         if (errno == ENODEV)
             generate_local_error(error, ALSACTL_CARD_ERROR_DISCONNECTED);
+        else if (errno == ENOENT)
+            generate_local_error(error, ALSACTL_CARD_ERROR_ELEM_NOT_FOUND);
         else
             generate_syscall_error(error, errno, "ioctl(%s)", "TLV_READ");
     }
@@ -695,6 +704,8 @@ void alsactl_card_command_elem_tlv(ALSACtlCard *self,
     if (ioctl(priv->fd, SNDRV_CTL_IOCTL_TLV_COMMAND, packet) < 0) {
         if (errno == ENODEV)
             generate_local_error(error, ALSACTL_CARD_ERROR_DISCONNECTED);
+        else if (errno == ENOENT)
+            generate_local_error(error, ALSACTL_CARD_ERROR_ELEM_NOT_FOUND);
         else
             generate_syscall_error(error, errno, "ioctl(%s)", "TLV_COMMAND");
     }
@@ -785,6 +796,8 @@ static void add_or_replace_elems(int fd, const ALSACtlElemId *elem_id,
     if (ioctl(fd, request, info) < 0) {
         if (errno == ENODEV)
             generate_local_error(error, ALSACTL_CARD_ERROR_DISCONNECTED);
+        else if (errno == ENOENT)
+            generate_local_error(error, ALSACTL_CARD_ERROR_ELEM_NOT_FOUND);
         else
             generate_syscall_error(error, errno, "ioctl(%s)", req_name);
     }
@@ -890,6 +903,8 @@ void alsactl_card_remove_elems(ALSACtlCard *self, const ALSACtlElemId *elem_id,
     if (ioctl(priv->fd, SNDRV_CTL_IOCTL_ELEM_REMOVE, elem_id) < 0) {
         if (errno == ENODEV)
             generate_local_error(error, ALSACTL_CARD_ERROR_DISCONNECTED);
+        else if (errno == ENOENT)
+            generate_local_error(error, ALSACTL_CARD_ERROR_ELEM_NOT_FOUND);
         else
             generate_syscall_error(error, errno, "ioctl(%s)", "ELEM_REMOVE");
     }
@@ -928,6 +943,8 @@ void alsactl_card_write_elem_value(ALSACtlCard *self,
     if (ioctl(priv->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, value) < 0) {
         if (errno == ENODEV)
             generate_local_error(error, ALSACTL_CARD_ERROR_DISCONNECTED);
+        else if (errno == ENOENT)
+            generate_local_error(error, ALSACTL_CARD_ERROR_ELEM_NOT_FOUND);
         else
             generate_syscall_error(error, errno, "ioctl(%s)", "ELEM_WRITE");
     }
@@ -966,6 +983,8 @@ void alsactl_card_read_elem_value(ALSACtlCard *self,
     if (ioctl(priv->fd, SNDRV_CTL_IOCTL_ELEM_READ, value) < 0) {
         if (errno == ENODEV)
             generate_local_error(error, ALSACTL_CARD_ERROR_DISCONNECTED);
+        else if (errno == ENOENT)
+            generate_local_error(error, ALSACTL_CARD_ERROR_ELEM_NOT_FOUND);
         else
             generate_syscall_error(error, errno, "ioctl(%s)", "ELEM_READ");
     }
index fe84dc4d49028f5a52f7597be00dc4be1f33e6ec..9c8e944c3c0e822dfa24220b2165c181400f43b6 100644 (file)
@@ -54,6 +54,7 @@ elem_event_mask_flags = (
 card_error_types = (
     'FAILED',
     'DISCONNECTED',
+    'ELEM_NOT_FOUND',
 )
 
 types = {