From f8e0c9c94bd6e7aa6423534b590bcd90e23bafb2 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Sun, 9 Feb 2020 12:20:53 +0900 Subject: [PATCH] timer: add global method to set parameters of timer device Signed-off-by: Takashi Sakamoto --- src/timer/device-params.c | 9 +++++++++ src/timer/privates.h | 3 +++ src/timer/query.c | 39 +++++++++++++++++++++++++++++++++++++++ src/timer/query.h | 5 +++++ 4 files changed, 56 insertions(+) diff --git a/src/timer/device-params.c b/src/timer/device-params.c index b7b5406..71682b4 100644 --- a/src/timer/device-params.c +++ b/src/timer/device-params.c @@ -94,3 +94,12 @@ ALSATimerDeviceParams *alsatimer_device_params_new() { return g_object_new(ALSATIMER_TYPE_DEVICE_PARAMS, NULL); } + +void timer_device_params_refer_private(ALSATimerDeviceParams *self, + struct snd_timer_gparams **params) +{ + ALSATimerDeviceParamsPrivate *priv = + alsatimer_device_params_get_instance_private(self); + + *params = &priv->params; +} diff --git a/src/timer/privates.h b/src/timer/privates.h index e29e848..5527914 100644 --- a/src/timer/privates.h +++ b/src/timer/privates.h @@ -22,6 +22,9 @@ void timer_device_info_refer_private(ALSATimerDeviceInfo *self, void timer_device_status_refer_private(ALSATimerDeviceStatus *self, struct snd_timer_gstatus **status); +void timer_device_params_refer_private(ALSATimerDeviceParams *self, + struct snd_timer_gparams **params); + G_END_DECLS #endif diff --git a/src/timer/query.c b/src/timer/query.c index b65a5f3..4a8a8dd 100644 --- a/src/timer/query.c +++ b/src/timer/query.c @@ -232,3 +232,42 @@ void alsatimer_get_device_status(ALSATimerDeviceId *device_id, close(fd); } + +/** + * alsatimer_set_device_params: + * @device_id: A #ALSATimerDeviceId to identify the timer device. + * @device_params: The parameters of timer device. + * @error: A #GError. + * + * Set the given parameters to the timer indicated by the identifier. + */ +void alsatimer_set_device_params(ALSATimerDeviceId *device_id, + const ALSATimerDeviceParams *device_params, + GError **error) +{ + char *devnode; + struct snd_timer_gparams *params; + int fd; + + g_return_if_fail(device_id != NULL); + g_return_if_fail(device_params != NULL); + + alsatimer_get_devnode(&devnode, error); + if (*error != NULL) + return; + + fd = open(devnode, O_RDONLY); + g_free(devnode); + if (fd < 0) { + generate_error(error, errno); + return; + } + + timer_device_params_refer_private((ALSATimerDeviceParams *)device_params, + ¶ms); + params->tid = *device_id; + if (ioctl(fd, SNDRV_TIMER_IOCTL_GPARAMS, params) < 0) + generate_error(error, errno); + + close(fd); +} diff --git a/src/timer/query.h b/src/timer/query.h index d3dc3a7..4707be6 100644 --- a/src/timer/query.h +++ b/src/timer/query.h @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -27,6 +28,10 @@ void alsatimer_get_device_status(ALSATimerDeviceId *device_id, ALSATimerDeviceStatus **device_status, GError **error); +void alsatimer_set_device_params(ALSATimerDeviceId *device_id, + const ALSATimerDeviceParams *device_params, + GError **error); + G_END_DECLS #endif -- 2.47.3