]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
timer: device_status: add properties
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-status.c
src/timer/device-status.h

index 0cb59281c930c5d0ad0302c4530a6189a20a086f..c27866d66caa451307c68540de544778475e8397 100644 (file)
@@ -1,10 +1,75 @@
 // SPDX-License-Identifier: LGPL-3.0-or-later
 #include "device-status.h"
 
-G_DEFINE_TYPE(ALSATimerDeviceStatus, alsatimer_device_status, G_TYPE_OBJECT)
+#include <sound/asound.h>
+
+struct _ALSATimerDeviceStatusPrivate {
+    struct snd_timer_gstatus status;
+};
+G_DEFINE_TYPE_WITH_PRIVATE(ALSATimerDeviceStatus, alsatimer_device_status, G_TYPE_OBJECT)
+
+enum timer_device_status_prop_type {
+    TIMER_DEVICE_STATUS_PROP_RESOLUTION = 1,
+    TIMER_DEVICE_STATUS_PROP_RESOLUTION_NUM,
+    TIMER_DEVICE_STATUS_PROP_RESOLUTION_DEN,
+    TIMER_DEVICE_STATUS_PROP_COUNT,
+};
+static GParamSpec *timer_device_status_props[TIMER_DEVICE_STATUS_PROP_COUNT] = { NULL, };
+
+
+static void timer_device_status_get_property(GObject *obj, guint id,
+                                             GValue *val, GParamSpec *spec)
+{
+    ALSATimerDeviceStatus *self = ALSATIMER_DEVICE_STATUS(obj);
+    ALSATimerDeviceStatusPrivate *priv =
+                            alsatimer_device_status_get_instance_private(self);
+
+    switch (id) {
+    case TIMER_DEVICE_STATUS_PROP_RESOLUTION:
+        g_value_set_uint64(val, priv->status.resolution);
+        break;
+    case TIMER_DEVICE_STATUS_PROP_RESOLUTION_NUM:
+        g_value_set_uint64(val, priv->status.resolution_num);
+        break;
+    case TIMER_DEVICE_STATUS_PROP_RESOLUTION_DEN:
+        g_value_set_uint64(val, priv->status.resolution_den);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec);
+        break;
+    }
+}
 
 static void alsatimer_device_status_class_init(ALSATimerDeviceStatusClass *klass)
 {
+    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+    gobject_class->get_property = timer_device_status_get_property;
+
+    timer_device_status_props[TIMER_DEVICE_STATUS_PROP_RESOLUTION] =
+        g_param_spec_uint64("resolution", "resolution",
+                            "The current resolution in nano seconds.",
+                            0, G_MAXUINT64,
+                            0,
+                            G_PARAM_READABLE);
+
+    timer_device_status_props[TIMER_DEVICE_STATUS_PROP_RESOLUTION_NUM] =
+        g_param_spec_uint64("resolution-numerator", "resolution-numerator",
+                            "The numerator of current resolution in seconds.",
+                            0, G_MAXUINT64,
+                            0,
+                            G_PARAM_READABLE);
+
+    timer_device_status_props[TIMER_DEVICE_STATUS_PROP_RESOLUTION_DEN] =
+        g_param_spec_uint64("resolution-denominator", "resolution-denominator",
+                            "The denominator of current resolution in seconds.",
+                            0, G_MAXUINT64,
+                            0,
+                            G_PARAM_READABLE);
+
+    g_object_class_install_properties(gobject_class,
+                                      TIMER_DEVICE_STATUS_PROP_COUNT,
+                                      timer_device_status_props);
 }
 
 static void alsatimer_device_status_init(ALSATimerDeviceStatus *self)
index 70b4e095c180872d5034fc76a908212c122ef0ab..97c929631df2bc97e198c64318d66cb9a09f3991 100644 (file)
@@ -31,9 +31,12 @@ G_BEGIN_DECLS
 
 typedef struct _ALSATimerDeviceStatus           ALSATimerDeviceStatus;
 typedef struct _ALSATimerDeviceStatusClass      ALSATimerDeviceStatusClass;
+typedef struct _ALSATimerDeviceStatusPrivate    ALSATimerDeviceStatusPrivate;
 
 struct _ALSATimerDeviceStatus {
     GObject parent_instance;
+
+    ALSATimerDeviceStatusPrivate *priv;
 };
 
 struct _ALSATimerDeviceStatusClass {