]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
timer: user_instance: report error for timer already attached
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)
After opening character device, applications can select event type. The
operation should be done before attaching to any timer device or the other
instances, Else it fails and returns EBUSY error to the applications.

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 8a6a1bfc5542345fbc095c746f633df13197f151..b09599d57b37de2bbe5fc02861c0dcb2409f4cb0 100644 (file)
@@ -128,6 +128,8 @@ typedef enum {
  * @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.
+ * @ALSATIMER_USER_INSTANCE_ERROR_ATTACHED:         The timer instance is already attached to timer
+ *                                                  device or the other instance.
  *
  * A set of error code for GError with domain which equals to #alsatimer_user_instance_error_quark()
  */
@@ -135,6 +137,7 @@ typedef enum {
     ALSATIMER_USER_INSTANCE_ERROR_FAILED,
     ALSATIMER_USER_INSTANCE_ERROR_TIMER_NOT_FOUND,
     ALSATIMER_USER_INSTANCE_ERROR_NOT_ATTACHED,
+    ALSATIMER_USER_INSTANCE_ERROR_ATTACHED,
 } ALSATimerUserInstanceError;
 
 #endif
index ed245b47385915048c608089af9320bd2bd94dd9..d15bdb7e6d1e8a65310cd4a11acfb7089f1cafd7 100644 (file)
@@ -42,6 +42,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",
+    [ALSATIMER_USER_INSTANCE_ERROR_ATTACHED] = "The timer instance is already attached to timer device or the other instance",
 };
 
 #define generate_local_error(exception, code) \
@@ -246,10 +247,14 @@ void alsatimer_user_instance_choose_event_data_type(ALSATimerUserInstance *self,
     g_return_if_fail(error == NULL || *error == NULL);
 
     tread = (int)event_data_type;
-    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_TREAD, &tread) < 0)
-        generate_syscall_error(error, errno, "ioctl(%s)", "TREAD");
-    else
+    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_TREAD, &tread) < 0) {
+        if (errno == EBUSY)
+            generate_local_error(error, ALSATIMER_USER_INSTANCE_ERROR_ATTACHED);
+        else
+            generate_syscall_error(error, errno, "ioctl(%s)", "TREAD");
+    } else {
         priv->event_data_type = event_data_type;
+    }
 }
 
 /**
index 69721df3e00dbdf0529fb993620d224c2e5080e7..008a1f824d40f98c388bbd137b44053ddbf032a2 100644 (file)
@@ -60,6 +60,7 @@ user_instance_error_types = (
     'FAILED',
     'TIMER_NOT_FOUND',
     'NOT_ATTACHED',
+    'ATTACHED',
 )
 
 types = {