]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
timer: user_instance: report error for timer instance not found
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 instantiation and opening character device, application can attach
any timer device to the instance according to the identifier information.
If ALSA timer system has no substance identified by the information,
application receives ENODEV 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 02d528b3c7c73cf46fcec0fe8f22ee68ac81d802..8fdb55aae0ef919e973d9e35c4319dc818421c86 100644 (file)
@@ -125,11 +125,13 @@ 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.
  *
  * 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,
 } ALSATimerUserInstanceError;
 
 #endif
index 580a1039da184d787f11b145e50b2c3dc8d746ae..311a03acb059f601a3e922fa4c9973fb50df528d 100644 (file)
@@ -39,6 +39,13 @@ G_DEFINE_TYPE_WITH_PRIVATE(ALSATimerUserInstance, alsatimer_user_instance, G_TYP
  */
 G_DEFINE_QUARK(alsatimer-user-instance-error-quark, alsatimer_user_instance_error)
 
+static const char *const err_msgs[] = {
+    [ALSATIMER_USER_INSTANCE_ERROR_TIMER_NOT_FOUND] = "The timer instance is not found",
+};
+
+#define generate_local_error(exception, code) \
+    g_set_error_literal(exception, ALSATIMER_USER_INSTANCE_ERROR, code, err_msgs[code])
+
 #define generate_syscall_error(exception, errno, fmt, arg)                                      \
     g_set_error(exception, ALSATIMER_USER_INSTANCE_ERROR, ALSATIMER_USER_INSTANCE_ERROR_FAILED, \
                 fmt" %d(%s)", arg, errno, strerror(errno))
@@ -270,8 +277,12 @@ void alsatimer_user_instance_attach(ALSATimerUserInstance *self,
     g_return_if_fail(error == NULL || *error == NULL);
 
     sel.id = *device_id;
-    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_SELECT, &sel) < 0)
-        generate_syscall_error(error, errno, "ioctl(%s)", "SELECT");
+    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_SELECT, &sel) < 0) {
+        if (errno == ENODEV)
+            generate_local_error(error, ALSATIMER_USER_INSTANCE_ERROR_TIMER_NOT_FOUND);
+        else
+            generate_syscall_error(error, errno, "ioctl(%s)", "SELECT");
+    }
 }
 
 /**
index 4a412966b599894b1d16e09a885c4252883c1380..cdb9bb9c6af7b3f57043f61d4704e3298d1d60cf 100644 (file)
@@ -58,6 +58,7 @@ event_data_types = (
 
 user_instance_error_types = (
     'FAILED',
+    'TIMER_NOT_FOUND',
 )
 
 types = {