]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
timer: event_timestamp: add properties and access methods
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/event-data-timestamp.c
src/timer/event-data-timestamp.h
tests/alsatimer-event-data-timestamp

index ce5869f76de6bede2f8b5e40d7fa505e6e4701c2..4dbfe694526b77b63412563eb22f44326ccfc343 100644 (file)
@@ -53,6 +53,7 @@ ALSA_GOBJECT_0_0_0 {
     "alsatimer_event_data_tick_get_type";
 
     "alsatimer_event_data_timestamp_get_type";
+    "alsatimer_event_data_timestamp_get_timestamp";
   local:
     *;
 };
index 3307e2391fab692766b19f78aba4298a6c00dc62..51e7eb2309683296e8a9d825db0c7ca649b5998c 100644 (file)
@@ -1,13 +1,83 @@
 // SPDX-License-Identifier: LGPL-3.0-or-later
 #include "event-data-timestamp.h"
 
-G_DEFINE_TYPE(ALSATimerEventDataTimestamp, alsatimer_event_data_timestamp, ALSATIMER_TYPE_EVENT_DATA)
+struct _ALSATimerEventDataTimestampPrivate {
+    struct snd_timer_tread event;
+};
+G_DEFINE_TYPE_WITH_PRIVATE(ALSATimerEventDataTimestamp, alsatimer_event_data_timestamp, ALSATIMER_TYPE_EVENT_DATA)
+
+enum timer_event_data_timestamp_prop_type{
+    TIMER_EVENT_DATA_TIMESTAMP_PROP_EVENT = 1,
+    TIMER_EVENT_DATA_TIMESTAMP_PROP_VALUE,
+    TIMER_EVENT_DATA_TIMESTAMP_PROP_COUNT,
+};
+static GParamSpec *timer_event_data_timestamp_props[TIMER_EVENT_DATA_TIMESTAMP_PROP_COUNT] = { NULL, };
+
+static void timer_event_data_timestamp_get_property(GObject *obj, guint id, GValue *val, GParamSpec *spec)
+{
+    ALSATimerEventDataTimestamp *self = ALSATIMER_EVENT_DATA_TIMESTAMP(obj);
+    ALSATimerEventDataTimestampPrivate *priv = alsatimer_event_data_timestamp_get_instance_private(self);
+
+    switch (id) {
+    case TIMER_EVENT_DATA_TIMESTAMP_PROP_EVENT:
+        g_value_set_enum(val, priv->event.event);
+        break;
+    case TIMER_EVENT_DATA_TIMESTAMP_PROP_VALUE:
+        g_value_set_uint(val, priv->event.val);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec);
+        break;
+    }
+}
 
 static void alsatimer_event_data_timestamp_class_init(ALSATimerEventDataTimestampClass *klass)
 {
+    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+
+    gobject_class->get_property = timer_event_data_timestamp_get_property;
+
+    timer_event_data_timestamp_props[TIMER_EVENT_DATA_TIMESTAMP_PROP_EVENT] =
+        g_param_spec_enum("event", "event",
+                          "The type of event.",
+                          ALSATIMER_TYPE_EVENT_TYPE,
+                          ALSATIMER_EVENT_TYPE_RESOLUTION,
+                          G_PARAM_READABLE);
+
+    timer_event_data_timestamp_props[TIMER_EVENT_DATA_TIMESTAMP_PROP_VALUE] =
+        g_param_spec_uint("value", "value",
+                          "The value specific to the event.",
+                          0, G_MAXUINT,
+                          0,
+                          G_PARAM_READABLE);
+
+    g_object_class_install_properties(gobject_class, TIMER_EVENT_DATA_TIMESTAMP_PROP_COUNT,
+                                      timer_event_data_timestamp_props);
 }
 
 static void alsatimer_event_data_timestamp_init(ALSATimerEventDataTimestamp *self)
 {
     return;
 }
+
+/**
+ * alsatimer_event_data_timestamp_get_timestamp:
+ * @self: A #ALSATimerEventDataTimestamp.
+ * @tv_sec: (out): The part of timestamp for the field of second.
+ * @tv_nsec: (out): The part of timestamp for the field of nano second.
+ *
+ * Return a pair of fields for timestamp of event.
+ */
+void alsatimer_event_data_timestamp_get_timestamp(ALSATimerEventDataTimestamp *self,
+                                                guint *tv_sec, guint *tv_nsec)
+{
+    ALSATimerEventDataTimestampPrivate *priv;
+
+    g_return_if_fail(ALSATIMER_IS_EVENT_DATA_TIMESTAMP(self));
+    g_return_if_fail(tv_sec != NULL);
+    g_return_if_fail(tv_nsec != NULL);
+    priv = alsatimer_event_data_timestamp_get_instance_private(self);
+
+    *tv_sec = priv->event.tstamp.tv_sec;
+    *tv_nsec = priv->event.tstamp.tv_nsec;
+}
index d10fb087b6726e4e4014c77210fe82ca3f0653c6..3cb3d7bffe50e0896b3ea08ac67d3de099812465 100644 (file)
@@ -33,9 +33,12 @@ G_BEGIN_DECLS
 
 typedef struct _ALSATimerEventDataTimestamp         ALSATimerEventDataTimestamp;
 typedef struct _ALSATimerEventDataTimestampClass    ALSATimerEventDataTimestampClass;
+typedef struct _ALSATimerEventDataTimestampPrivate  ALSATimerEventDataTimestampPrivate;
 
 struct _ALSATimerEventDataTimestamp {
     ALSATimerEventData parent_instance;
+
+    ALSATimerEventDataTimestampPrivate *priv;
 };
 
 struct _ALSATimerEventDataTimestampClass {
@@ -44,6 +47,9 @@ struct _ALSATimerEventDataTimestampClass {
 
 GType alsatimer_event_data_timestamp_get_type() G_GNUC_CONST;
 
+void alsatimer_event_data_timestamp_get_timestamp(ALSATimerEventDataTimestamp *self,
+                                                guint *tv_sec, guint *tv_nsec);
+
 G_END_DECLS
 
 #endif
index 78d1bd29e6d338cfeca978cf2ab635051c2faf01..b9c4971be6613171e28ebcf7ef87688898d13676 100644 (file)
@@ -10,8 +10,13 @@ gi.require_version('ALSATimer', '0.0')
 from gi.repository import ALSATimer
 
 target = ALSATimer.EventDataTimestamp()
-props = ()
-methods = ()
+props = (
+    'event',
+    'value',
+)
+methods = (
+    'get_timestamp',
+)
 signals = ()
 
 if not test(target, props, methods, signals):