From: Takashi Sakamoto Date: Sat, 14 Nov 2020 08:28:09 +0000 (+0900) Subject: timer: user_instance: report error for timer instance not found X-Git-Tag: v0.1.99~58 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=e31639d67d1ec18d07d78db917b99f46b2aba0c2;p=alsa-gobject.git timer: user_instance: report error for timer instance not found 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 --- diff --git a/src/timer/alsatimer-enum-types.h b/src/timer/alsatimer-enum-types.h index 02d528b..8fdb55a 100644 --- a/src/timer/alsatimer-enum-types.h +++ b/src/timer/alsatimer-enum-types.h @@ -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 diff --git a/src/timer/user-instance.c b/src/timer/user-instance.c index 580a103..311a03a 100644 --- a/src/timer/user-instance.c +++ b/src/timer/user-instance.c @@ -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"); + } } /** diff --git a/tests/alsatimer-enums b/tests/alsatimer-enums index 4a41296..cdb9bb9 100644 --- a/tests/alsatimer-enums +++ b/tests/alsatimer-enums @@ -58,6 +58,7 @@ event_data_types = ( user_instance_error_types = ( 'FAILED', + 'TIMER_NOT_FOUND', ) types = {