]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
timer: user_instance: add an API to attach timer device to user instance
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/user-instance.c
src/timer/user-instance.h
tests/alsatimer-user-instance

index 63be1ebb91c98f312882f7b831b66a970e9d26f8..b00c7d1d07b96d2f0e6f8f5cf7323ecb135da13a 100644 (file)
@@ -30,6 +30,8 @@ ALSA_GOBJECT_0_0_0 {
     "alsatimer_user_instance_get_type";
     "alsatimer_user_instance_new";
     "alsatimer_user_instance_open";
+    "alsatimer_user_instance_attach";
+    "alsatimer_user_instance_attach_as_slave";
   local:
     *;
 };
index f9e0835e0e44f7f7fe7f20661c4ba83b88d38da6..5d2143d57342a85a6ee62efa4afd896efde5946b 100644 (file)
@@ -7,6 +7,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <sys/ioctl.h>
 #include <errno.h>
 
 struct _ALSATimerUserInstancePrivate {
@@ -71,3 +72,27 @@ ALSATimerUserInstance *alsatimer_user_instance_new()
 {
     return g_object_new(ALSATIMER_TYPE_USER_INSTANCE, NULL);
 }
+
+/**
+ * alsatimer_user_instance_attach:
+ * @self: A #ALSATimerUserInstance.
+ * @device_id: A #ALSATimerDeviceId to which the instance is attached.
+ * @error: A #GError.
+ *
+ * Attach the instance to the timer device.
+ */
+void alsatimer_user_instance_attach(ALSATimerUserInstance *self,
+                                    ALSATimerDeviceId *device_id,
+                                    GError **error)
+{
+    ALSATimerUserInstancePrivate *priv;
+    struct snd_timer_select sel = {0};
+
+    g_return_if_fail(ALSATIMER_IS_USER_INSTANCE(self));
+    g_return_if_fail(device_id != NULL);
+    priv = alsatimer_user_instance_get_instance_private(self);
+
+    sel.id = *device_id;
+    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_SELECT, &sel) < 0)
+        generate_error(error, errno);
+}
index 768b8bf3bbd51f4ddbe5f07702eae83be2e491b9..004135082a5f1110e51d878ddc9f5bc7c7252c8d 100644 (file)
@@ -5,6 +5,8 @@
 #include <glib.h>
 #include <glib-object.h>
 
+#include <timer/device-id.h>
+
 G_BEGIN_DECLS
 
 #define ALSATIMER_TYPE_USER_INSTANCE    (alsatimer_user_instance_get_type())
@@ -49,6 +51,10 @@ ALSATimerUserInstance *alsatimer_user_instance_new();
 
 void alsatimer_user_instance_open(ALSATimerUserInstance *self, GError **error);
 
+void alsatimer_user_instance_attach(ALSATimerUserInstance *self,
+                                    ALSATimerDeviceId *device_id,
+                                    GError **error);
+
 G_END_DECLS
 
 #endif
index 33ad6b359b62d36320e37381f69c2bcc6574cd5b..5e7c1a5b08602bfd79dab9f5287309d6c5a5d5db 100644 (file)
@@ -14,6 +14,7 @@ props = ()
 methods = (
     'new',
     'open',
+    'attach',
 )
 signals = ()