From: Takashi Sakamoto Date: Sat, 14 Nov 2020 08:28:09 +0000 (+0900) Subject: timer: user_instance: report error for timer already attached X-Git-Tag: v0.1.99~56 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=9c8b8f4e2d4bedbe975e0fb0d9749492ae06c63a;p=alsa-gobject.git timer: user_instance: report error for timer already attached 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 --- diff --git a/src/timer/alsatimer-enum-types.h b/src/timer/alsatimer-enum-types.h index 8a6a1bf..b09599d 100644 --- a/src/timer/alsatimer-enum-types.h +++ b/src/timer/alsatimer-enum-types.h @@ -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 diff --git a/src/timer/user-instance.c b/src/timer/user-instance.c index ed245b4..d15bdb7 100644 --- a/src/timer/user-instance.c +++ b/src/timer/user-instance.c @@ -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; + } } /** diff --git a/tests/alsatimer-enums b/tests/alsatimer-enums index 69721df..008a1f8 100644 --- a/tests/alsatimer-enums +++ b/tests/alsatimer-enums @@ -60,6 +60,7 @@ user_instance_error_types = ( 'FAILED', 'TIMER_NOT_FOUND', 'NOT_ATTACHED', + 'ATTACHED', ) types = {