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

index ed05263b1368a6aa25d5df8bb9b574c5a3df0cf0..825418f3e082d4189fef81b460671274c65f6f71 100644 (file)
@@ -11,6 +11,7 @@ ALSA_GOBJECT_0_0_0 {
     "alsatimer_get_devnode";
     "alsatimer_get_device_id_list";
     "alsatimer_get_device_info";
+    "alsatimer_get_device_status";
 
     "alsatimer_device_id_get_type";
     "alsatimer_device_id_new";
index c27866d66caa451307c68540de544778475e8397..233f9d2f5f6ce5d4dc3c2753815bda3872e9a553 100644 (file)
@@ -1,7 +1,5 @@
 // SPDX-License-Identifier: LGPL-3.0-or-later
-#include "device-status.h"
-
-#include <sound/asound.h>
+#include "privates.h"
 
 struct _ALSATimerDeviceStatusPrivate {
     struct snd_timer_gstatus status;
@@ -76,3 +74,12 @@ static void alsatimer_device_status_init(ALSATimerDeviceStatus *self)
 {
     return;
 }
+
+void timer_device_status_refer_private(ALSATimerDeviceStatus *self,
+                                       struct snd_timer_gstatus **status)
+{
+    ALSATimerDeviceStatusPrivate *priv =
+                            alsatimer_device_status_get_instance_private(self);
+
+    *status = &priv->status;
+}
index 5785d461d9d8e90a1ef98a62931fcca611bb6a75..81cb6af27a74de0fcf37b00e64f25c4cd06f4e93 100644 (file)
@@ -3,6 +3,7 @@
 #define __ALSA_GOBJECT_ALSATIMER_PRIVATES__H__
 
 #include "device-info.h"
+#include "device-status.h"
 
 #include <sound/asound.h>
 
@@ -17,6 +18,9 @@ GQuark alsatimer_error_quark(void);
 void timer_device_info_refer_private(ALSATimerDeviceInfo *self,
                                      struct snd_timer_ginfo **info);
 
+void timer_device_status_refer_private(ALSATimerDeviceStatus *self,
+                                       struct snd_timer_gstatus **status);
+
 G_END_DECLS
 
 #endif
index c88a9e50d21e08c09df4b168e6cbb021e009fb59..b65a5f3eb0987f1894e52a8e418b92aff04cf337 100644 (file)
@@ -193,3 +193,42 @@ void alsatimer_get_device_info(ALSATimerDeviceId *device_id,
 
     close(fd);
 }
+
+/**
+ * alsatimer_get_device_status:
+ * @device_id: A #ALSATimerDeviceId to identify the timer device.
+ * @device_status: (out): The status of timer device.
+ * @error: A #GError.
+ */
+void alsatimer_get_device_status(ALSATimerDeviceId *device_id,
+                                 ALSATimerDeviceStatus **device_status,
+                                 GError **error)
+{
+    char *devnode;
+    struct snd_timer_gstatus *status;
+    int fd;
+
+    g_return_if_fail(device_id != 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;
+    }
+
+    *device_status = g_object_new(ALSATIMER_TYPE_DEVICE_STATUS, NULL);
+    timer_device_status_refer_private(*device_status, &status);
+
+    status->tid = *device_id;
+    if (ioctl(fd, SNDRV_TIMER_IOCTL_GSTATUS, status) < 0) {
+        generate_error(error, errno);
+        g_object_unref(*device_status);
+    }
+
+    close(fd);
+}
index facf489df7b1a4e6e631d893d72c3c1c413110e5..d3dc3a7ca9fdadc7cb514e01aa60f0f59c3c0ddf 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <timer/device-id.h>
 #include <timer/device-info.h>
+#include <timer/device-status.h>
 
 #include <timer/alsatimer-enums.h>
 
@@ -21,6 +22,11 @@ void alsatimer_get_device_id_list(GList **entries, GError **error);
 void alsatimer_get_device_info(ALSATimerDeviceId *device_id,
                                ALSATimerDeviceInfo **device_info,
                                GError **error);
+
+void alsatimer_get_device_status(ALSATimerDeviceId *device_id,
+                                 ALSATimerDeviceStatus **device_status,
+                                 GError **error);
+
 G_END_DECLS
 
 #endif