]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
timer: add global method to set parameters of timer device
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 9 Feb 2020 03:20:53 +0000 (12:20 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Tue, 11 Feb 2020 04:28:18 +0000 (13:28 +0900)
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/timer/device-params.c
src/timer/privates.h
src/timer/query.c
src/timer/query.h

index b7b5406414a4561978aca39b67b9276f57742fcc..71682b4ea032c860feadae102ef47a1b34ffcb24 100644 (file)
@@ -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;
+}
index e29e8485716afc598b65730ed2393e8dbbafcca4..552791490d1ed862225c49c6bb4c3ebfc826022c 100644 (file)
@@ -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
index b65a5f3eb0987f1894e52a8e418b92aff04cf337..4a8a8dd37298c4a5b12237cc71a33a21ecaa0fab 100644 (file)
@@ -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,
+                                      &params);
+    params->tid = *device_id;
+    if (ioctl(fd, SNDRV_TIMER_IOCTL_GPARAMS, params) < 0)
+        generate_error(error, errno);
+
+    close(fd);
+}
index d3dc3a7ca9fdadc7cb514e01aa60f0f59c3c0ddf..4707be6f025816582f17d14f12d469abd9c024bf 100644 (file)
@@ -8,6 +8,7 @@
 #include <timer/device-id.h>
 #include <timer/device-info.h>
 #include <timer/device-status.h>
+#include <timer/device-params.h>
 
 #include <timer/alsatimer-enums.h>
 
@@ -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