]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
timer: event_data_timestamp: become boxed object
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 10 Jun 2020 01:37:42 +0000 (10:37 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Fri, 12 Jun 2020 00:00:43 +0000 (09:00 +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
src/timer/event.h
src/timer/privates.h
tests/alsatimer-event-data-timestamp [deleted file]
tests/meson.build

index 3fac32ed397842c070799fd2f918f6f057d547b5..c584257eb4116e525a28ed6987063f78786e4fa9 100644 (file)
@@ -60,7 +60,6 @@ ALSA_GOBJECT_0_0_0 {
     "alsatimer_event_data_tick_get_ticks";
 
     "alsatimer_event_data_timestamp_get_type";
-    "alsatimer_event_data_timestamp_get_timestamp";
 
     "alsatimer_event_get_type";
   local:
index 0f72774a06b50d8714c20ffc2a7006105d33410d..78f7162b652106be4f073bcda154bfce358766d4 100644 (file)
 /**
  * SECTION: event-data-timestamp
  * @Title: ALSATimerEventDataTimestamp
- * @Short_description: A GObject-derived object to represent event of timer with
+ * @Short_description: A boxed object to represent event of timer with
  *                     timestamp
  *
- * A #ALSATimerEventDataTimestamp is a GObject-derived object to represent
- * event of timer with timestamp. The instance of object is passed to handler for
- * 'handle-event' GObject signal in ALSATimerUserInstance when it's available.
- * The source of timestamp is decided by 'timer_tstamp_monotonic' option of
- * 'snd-timer' kernel module. The object inherits properties of
- * #ALSATimerEventData.
+ * A #ALSATimerEventDataTimestamp is a boxed object to represent event of timer
+ * with timestamp.
  *
- * The object wraps 'struct snd_timer_read' in UAPI of Linux sound subsystem.
+ * The object wraps 'struct snd_timer_tread' in UAPI of Linux sound subsystem.
  */
-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)
+ALSATimerEventDataTimestamp *timer_event_data_timestamp_copy(const ALSATimerEventDataTimestamp *self)
 {
-    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;
+    return g_memdup(self, sizeof(*self));
 }
 
-void timer_event_data_timestamp_set_data(ALSATimerEventDataTimestamp *self,
-                                         struct snd_timer_tread *data)
-{
-    ALSATimerEventDataTimestampPrivate *priv =
-                    alsatimer_event_data_timestamp_get_instance_private(self);
-
-    priv->event = *data;
-}
+G_DEFINE_BOXED_TYPE(ALSATimerEventDataTimestamp, alsatimer_event_data_timestamp, timer_event_data_timestamp_copy, g_free)
index 3cb3d7bffe50e0896b3ea08ac67d3de099812465..01a0ef81d97050eb8a3acf932aec894919eb830b 100644 (file)
@@ -5,50 +5,15 @@
 #include <glib.h>
 #include <glib-object.h>
 
-#include <timer/event-data.h>
+#include <sound/asound.h>
 
 G_BEGIN_DECLS
 
-#define ALSATIMER_TYPE_EVENT_DATA_TIMESTAMP     (alsatimer_event_data_timestamp_get_type())
-
-#define ALSATIMER_EVENT_DATA_TIMESTAMP(obj)                             \
-    (G_TYPE_CHECK_INSTANCE_CAST((obj),                                  \
-                                ALSATIMER_TYPE_EVENT_DATA_TIMESTAMP,    \
-                                ALSATimerEventDataTimestamp))
-#define ALSATIMER_IS_EVENT_DATA_TIMESTAMP(obj)                          \
-    (G_TYPE_CHECK_INSTANCE_TYPE((obj),                                  \
-                                ALSATIMER_TYPE_EVENT_DATA_TIMESTAMP))
-
-#define ALSATIMER_EVENT_DATA_TIMESTAMP_CLASS(klass)                     \
-    (G_TYPE_CHECK_CLASS_CAST((klass),                                   \
-                             ALSATIMER_TYPE_EVENT_DATA_TIMESTAMP,       \
-                             ALSATimerEventDataTimestampClass))
-#define ALSATIMER_IS_EVENT_DATA_TIMESTAMP_CLASS(klass)                  \
-    (G_TYPE_CHECK_CLASS_TYPE((klass),                                   \
-                             ALSATIMER_TYPE_EVENT_DATA_TIMESTAMP))
-#define ALSATIMER_EVENT_DATA_TIMESTAMP_GET_CLASS(obj)                   \
-    (G_TYPE_INSTANCE_GET_CLASS((obj),                                   \
-                               ALSATIMER_TYPE_EVENT_DATA_TIMESTAMP,     \
-                               ALSATimerEventDataTimestampkClass))
-
-typedef struct _ALSATimerEventDataTimestamp         ALSATimerEventDataTimestamp;
-typedef struct _ALSATimerEventDataTimestampClass    ALSATimerEventDataTimestampClass;
-typedef struct _ALSATimerEventDataTimestampPrivate  ALSATimerEventDataTimestampPrivate;
-
-struct _ALSATimerEventDataTimestamp {
-    ALSATimerEventData parent_instance;
-
-    ALSATimerEventDataTimestampPrivate *priv;
-};
-
-struct _ALSATimerEventDataTimestampClass {
-    ALSATimerEventDataClass parent_class;
-};
+#define ALSATIMER_TYPE_EVENT_DATA_TIMESTAMP (alsatimer_event_data_timestamp_get_type())
 
-GType alsatimer_event_data_timestamp_get_type() G_GNUC_CONST;
+typedef struct snd_timer_tread ALSATimerEventDataTimestamp;
 
-void alsatimer_event_data_timestamp_get_timestamp(ALSATimerEventDataTimestamp *self,
-                                                guint *tv_sec, guint *tv_nsec);
+GType alsatimer_event_data_timestamp_get_type() G_GNUC_CONST;
 
 G_END_DECLS
 
index d550987dcac0909ed2c0cc0212085b07019da6f5..6277d3c01cb2c5f53ee6251268b22f2c781b2124 100644 (file)
@@ -6,6 +6,7 @@
 #include <glib-object.h>
 
 #include <timer/event-data-tick.h>
+#include <timer/event-data-timestamp.h>
 
 G_BEGIN_DECLS
 
@@ -13,7 +14,7 @@ G_BEGIN_DECLS
 
 typedef union {
     ALSATimerEventDataTick tick;
-    struct snd_timer_tread timestamp;
+    ALSATimerEventDataTimestamp timestamp;
 } ALSATimerEvent;
 
 GType alsatimer_event_get_type() G_GNUC_CONST;
index 0c03e7291a67ad91fd44a5f1ff52bb1d4f355d88..87d3dcc749dfca2627d464b62ef9a23edb2a9996 100644 (file)
@@ -8,7 +8,6 @@
 #include "instance-info.h"
 #include "instance-params.h"
 #include "instance-status.h"
-#include "event-data-timestamp.h"
 
 #include <sound/asound.h>
 
@@ -38,9 +37,6 @@ void timer_instance_params_refer_private(ALSATimerInstanceParams *self,
 void timer_instance_status_refer_private(ALSATimerInstanceStatus *self,
                                          struct snd_timer_status **status);
 
-void timer_event_data_timestamp_set_data(ALSATimerEventDataTimestamp *self,
-                                         struct snd_timer_tread *data);
-
 G_END_DECLS
 
 #endif
diff --git a/tests/alsatimer-event-data-timestamp b/tests/alsatimer-event-data-timestamp
deleted file mode 100644 (file)
index b9c4971..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/env python3
-
-from sys import exit
-from errno import ENXIO
-
-from helper import test
-
-import gi
-gi.require_version('ALSATimer', '0.0')
-from gi.repository import ALSATimer
-
-target = ALSATimer.EventDataTimestamp()
-props = (
-    'event',
-    'value',
-)
-methods = (
-    'get_timestamp',
-)
-signals = ()
-
-if not test(target, props, methods, signals):
-    exit(ENXIO)
index 25406036b849c8172af2cf599cfa340c6a95c7be..3c3142e68d2cf1056c64b49c9e60187be8cde1a6 100644 (file)
@@ -25,7 +25,6 @@ tests = {
     'alsatimer-instance-params',
     'alsatimer-instance-status',
     'alsatimer-event-data',
-    'alsatimer-event-data-timestamp',
   ],
   'seq': [
     'alsaseq-enums',