]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
timer: add global method to get list of available timers
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/alsatimer.map
src/timer/privates.h
src/timer/query.c
src/timer/query.h

index 6d9dcb2821344fa6ae62c510d3146ff4dcae4192..9ae39db6bdb4950c34953cb6c06e2bc782fa06ae 100644 (file)
@@ -9,6 +9,7 @@ ALSA_GOBJECT_0_0_0 {
 
     "alsatimer_get_sysname";
     "alsatimer_get_devnode";
+    "alsatimer_get_device_id_list";
 
     "alsatimer_device_id_get_type";
     "alsatimer_device_id_new";
index 9f5666fe1a1ef53120ca51e621f69aaa1476e439..4efb5fba0ac09d012814be717c700747b2103273 100644 (file)
@@ -2,6 +2,8 @@
 #ifndef __ALSA_GOBJECT_ALSATIMER_PRIVATES__H__
 #define __ALSA_GOBJECT_ALSATIMER_PRIVATES__H__
 
+#include <sound/asound.h>
+
 G_BEGIN_DECLS
 
 GQuark alsatimer_error_quark(void);
index 2a8f58ab0735529bcdaf5c1fb07005e11e8ca28a..61949946d3832eb81e9496f014610e713a2274cd 100644 (file)
@@ -4,6 +4,14 @@
 
 #include <stdbool.h>
 #include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <stdbool.h>
+
+#include <sound/asound.h>
 
 #include <libudev.h>
 
@@ -103,3 +111,46 @@ void alsatimer_get_devnode(char **devnode, GError **error)
     udev_device_unref(dev);
     udev_unref(ctx);
 }
+
+/**
+ * alsatimer_get_device_id_list:
+ * @entries: (element-type ALSATimer.DeviceId)(out): The array with
+ *           entries of ALSATimerId.
+ * @error: A #GError.
+ *
+ */
+void alsatimer_get_device_id_list(GList **entries, GError **error)
+{
+    struct snd_timer_id id = {
+        .dev_class = -1,
+    };
+    char *devnode;
+    int fd;
+
+    g_return_if_fail(entries != 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;
+    }
+
+    while (true) {
+        ALSATimerDeviceId *entry;
+
+        if (ioctl(fd, SNDRV_TIMER_IOCTL_NEXT_DEVICE, &id) < 0)
+            break;
+        if (id.dev_class == SNDRV_TIMER_CLASS_NONE)
+            break;
+
+        entry = g_boxed_copy(ALSATIMER_TYPE_DEVICE_ID, &id);
+        *entries = g_list_append(*entries, entry);
+    }
+
+    close(fd);
+}
index a8ec3a76f0d671a00e208b143c86dd7e1b9b2da1..b8fbc68937b2034a5be74c10d3a4299a4080f723 100644 (file)
@@ -5,12 +5,18 @@
 #include <glib.h>
 #include <glib-object.h>
 
+#include <timer/device-id.h>
+
+#include <timer/alsatimer-enums.h>
+
 G_BEGIN_DECLS
 
 void alsatimer_get_sysname(char **sysname, GError **error);
 
 void alsatimer_get_devnode(char **devnode, GError **error);
 
+void alsatimer_get_device_id_list(GList **entries, GError **error);
+
 G_END_DECLS
 
 #endif