]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
timer: user_instance: report error for unattached timer instance
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sat, 14 Nov 2020 08:28:09 +0000 (17:28 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sat, 14 Nov 2020 08:28:09 +0000 (17:28 +0900)
When querying or starting the user instance, the instance should be
attached to any timer device or the other instances. Else, applications
receives EBADFD error.

This commit handles it and report local error.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/timer/alsatimer-enum-types.h
src/timer/user-instance.c
tests/alsatimer-enums

index 8fdb55aae0ef919e973d9e35c4319dc818421c86..8a6a1bfc5542345fbc095c746f633df13197f151 100644 (file)
@@ -126,12 +126,15 @@ typedef enum {
  * ALSATimerUserInstanceError:
  * @ALSATIMER_USER_INSTANCE_ERROR_FAILED:           The system call failed.
  * @ALSATIMER_USER_INSTANCE_ERROR_TIMER_NOT_FOUND:  The timer instance is not found.
+ * @ALSATIMER_USER_INSTANCE_ERROR_NOT_ATTACHED:     The timer instance is not attached to any timer
+ *                                                  device or the other instance.
  *
  * A set of error code for GError with domain which equals to #alsatimer_user_instance_error_quark()
  */
 typedef enum {
     ALSATIMER_USER_INSTANCE_ERROR_FAILED,
     ALSATIMER_USER_INSTANCE_ERROR_TIMER_NOT_FOUND,
+    ALSATIMER_USER_INSTANCE_ERROR_NOT_ATTACHED,
 } ALSATimerUserInstanceError;
 
 #endif
index 311a03acb059f601a3e922fa4c9973fb50df528d..ed245b47385915048c608089af9320bd2bd94dd9 100644 (file)
@@ -41,6 +41,7 @@ G_DEFINE_QUARK(alsatimer-user-instance-error-quark, alsatimer_user_instance_erro
 
 static const char *const err_msgs[] = {
     [ALSATIMER_USER_INSTANCE_ERROR_TIMER_NOT_FOUND] = "The timer instance is not found",
+    [ALSATIMER_USER_INSTANCE_ERROR_NOT_ATTACHED] = "The timer instance is not attached to any timer device or the other instance",
 };
 
 #define generate_local_error(exception, code) \
@@ -351,7 +352,10 @@ void alsatimer_user_instance_get_info(ALSATimerUserInstance *self,
     timer_instance_info_refer_private(*instance_info, &info);
 
     if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_INFO, info) < 0) {
-        generate_syscall_error(error, errno, "ioctl(%s)", "INFO");
+        if (errno == EBADFD)
+            generate_local_error(error, ALSATIMER_USER_INSTANCE_ERROR_NOT_ATTACHED);
+        else
+            generate_syscall_error(error, errno, "ioctl(%s)", "INFO");
         g_object_unref(*instance_info);
     }
 }
@@ -382,8 +386,12 @@ void alsatimer_user_instance_set_params(ALSATimerUserInstance *self,
 
     timer_instance_params_refer_private(*instance_params, &params);
 
-    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_PARAMS, params) < 0)
-        generate_syscall_error(error, errno, "ioctl(%s)", "PARAMS");
+    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_PARAMS, params) < 0) {
+        if (errno == EBADFD)
+            generate_local_error(error, ALSATIMER_USER_INSTANCE_ERROR_NOT_ATTACHED);
+        else
+            generate_syscall_error(error, errno, "ioctl(%s)", "PARAMS");
+    }
 }
 
 /**
@@ -413,8 +421,12 @@ void alsatimer_user_instance_get_status(ALSATimerUserInstance *self,
     g_return_if_fail(ALSATIMER_IS_INSTANCE_STATUS(*instance_status));
     timer_instance_status_refer_private(*instance_status, &status);
 
-    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_STATUS, status) < 0)
-        generate_syscall_error(error, errno, "ioctl(%s)", "STATUS");
+    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_STATUS, status) < 0) {
+        if (errno == EBADFD)
+            generate_local_error(error, ALSATIMER_USER_INSTANCE_ERROR_NOT_ATTACHED);
+        else
+            generate_syscall_error(error, errno, "ioctl(%s)", "STATUS");
+    }
 }
 
 static gboolean timer_user_instance_check_src(GSource *gsrc)
@@ -559,8 +571,12 @@ void alsatimer_user_instance_start(ALSATimerUserInstance *self, GError **error)
 
     g_return_if_fail(error == NULL || *error == NULL);
 
-    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_START) < 0)
-        generate_syscall_error(error, errno, "ioctl(%s)", "START");
+    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_START) < 0) {
+        if (errno == EBADFD)
+            generate_local_error(error, ALSATIMER_USER_INSTANCE_ERROR_NOT_ATTACHED);
+        else
+            generate_syscall_error(error, errno, "ioctl(%s)", "START");
+    }
 }
 
 /**
@@ -582,8 +598,12 @@ void alsatimer_user_instance_stop(ALSATimerUserInstance *self, GError **error)
 
     g_return_if_fail(error == NULL || *error == NULL);
 
-    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_STOP) < 0)
-        generate_syscall_error(error, errno, "ioctl(%s)", "STOP");
+    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_STOP) < 0) {
+        if (errno == EBADFD)
+            generate_local_error(error, ALSATIMER_USER_INSTANCE_ERROR_NOT_ATTACHED);
+        else
+            generate_syscall_error(error, errno, "ioctl(%s)", "STOP");
+    }
 }
 
 /**
@@ -605,8 +625,12 @@ void alsatimer_user_instance_pause(ALSATimerUserInstance *self, GError **error)
 
     g_return_if_fail(error == NULL || *error == NULL);
 
-    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_PAUSE) < 0)
-        generate_syscall_error(error, errno, "ioctl(%s)", "PAUSE");
+    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_PAUSE) < 0) {
+        if (errno == EBADFD)
+            generate_local_error(error, ALSATIMER_USER_INSTANCE_ERROR_NOT_ATTACHED);
+        else
+            generate_syscall_error(error, errno, "ioctl(%s)", "PAUSE");
+    }
 }
 
 /**
@@ -629,6 +653,10 @@ void alsatimer_user_instance_continue(ALSATimerUserInstance *self,
 
     g_return_if_fail(error == NULL || *error == NULL);
 
-    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_CONTINUE) < 0)
-        generate_syscall_error(error, errno, "ioctl(%s)", "CONTINUE");
+    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_CONTINUE) < 0) {
+        if (errno == EBADFD)
+            generate_local_error(error, ALSATIMER_USER_INSTANCE_ERROR_NOT_ATTACHED);
+        else
+            generate_syscall_error(error, errno, "ioctl(%s)", "CONTINUE");
+    }
 }
index cdb9bb9c6af7b3f57043f61d4704e3298d1d60cf..69721df3e00dbdf0529fb993620d224c2e5080e7 100644 (file)
@@ -59,6 +59,7 @@ event_data_types = (
 user_instance_error_types = (
     'FAILED',
     'TIMER_NOT_FOUND',
+    'NOT_ATTACHED',
 )
 
 types = {