From 159f47660fb6adb0c3a9519b882a4f46df66f96f Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Wed, 10 Jun 2020 10:37:42 +0900 Subject: [PATCH] timer: event_data_timestamp: become boxed object Signed-off-by: Takashi Sakamoto --- src/timer/alsatimer.map | 1 - src/timer/event-data-timestamp.c | 101 ++------------------------- src/timer/event-data-timestamp.h | 43 ++---------- src/timer/event.h | 3 +- src/timer/privates.h | 4 -- tests/alsatimer-event-data-timestamp | 23 ------ tests/meson.build | 1 - 7 files changed, 13 insertions(+), 163 deletions(-) delete mode 100644 tests/alsatimer-event-data-timestamp diff --git a/src/timer/alsatimer.map b/src/timer/alsatimer.map index 3fac32e..c584257 100644 --- a/src/timer/alsatimer.map +++ b/src/timer/alsatimer.map @@ -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: diff --git a/src/timer/event-data-timestamp.c b/src/timer/event-data-timestamp.c index 0f72774..78f7162 100644 --- a/src/timer/event-data-timestamp.c +++ b/src/timer/event-data-timestamp.c @@ -5,104 +5,17 @@ /** * 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) diff --git a/src/timer/event-data-timestamp.h b/src/timer/event-data-timestamp.h index 3cb3d7b..01a0ef8 100644 --- a/src/timer/event-data-timestamp.h +++ b/src/timer/event-data-timestamp.h @@ -5,50 +5,15 @@ #include #include -#include +#include 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 diff --git a/src/timer/event.h b/src/timer/event.h index d550987..6277d3c 100644 --- a/src/timer/event.h +++ b/src/timer/event.h @@ -6,6 +6,7 @@ #include #include +#include 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; diff --git a/src/timer/privates.h b/src/timer/privates.h index 0c03e72..87d3dcc 100644 --- a/src/timer/privates.h +++ b/src/timer/privates.h @@ -8,7 +8,6 @@ #include "instance-info.h" #include "instance-params.h" #include "instance-status.h" -#include "event-data-timestamp.h" #include @@ -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 index b9c4971..0000000 --- a/tests/alsatimer-event-data-timestamp +++ /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) diff --git a/tests/meson.build b/tests/meson.build index 2540603..3c3142e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -25,7 +25,6 @@ tests = { 'alsatimer-instance-params', 'alsatimer-instance-status', 'alsatimer-event-data', - 'alsatimer-event-data-timestamp', ], 'seq': [ 'alsaseq-enums', -- 2.47.3