From: Takashi Sakamoto Date: Wed, 10 Jun 2020 01:31:47 +0000 (+0900) Subject: timer: event_data_tick: become boxed object X-Git-Tag: v0.1.0~90 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=2b60c48252462070bf4762dec717b361acf8becd;p=alsa-gobject.git timer: event_data_tick: become boxed object Signed-off-by: Takashi Sakamoto --- diff --git a/src/timer/event-data-tick.c b/src/timer/event-data-tick.c index 4010119..875aece 100644 --- a/src/timer/event-data-tick.c +++ b/src/timer/event-data-tick.c @@ -5,80 +5,17 @@ /** * SECTION: event-data-tick * @Title: ALSATimerEventDataTick - * @Short_description: A GObject-derived object to represent event of timer with - * tick count + * @Short_description: A boxed object to represent event of timer with tick + * count * - * A #ALSATimerEventDataTick is a GObject-derived object to represent event of - * timer with tick count. The instance of object is passed to handler for - * 'handle-event' GObject signal in ALSATimerUserInstance when it's available. - * The object inherits properties of #ALSATimerEventData. + * A #ALSATimerEventDataTick is a boxed object to represent event of timer with + * tick count. * * The object wraps 'struct snd_timer_read' in UAPI of Linux sound subsystem. */ -struct _ALSATimerEventDataTickPrivate { - struct snd_timer_read event; -}; -G_DEFINE_TYPE_WITH_PRIVATE(ALSATimerEventDataTick, alsatimer_event_data_tick, ALSATIMER_TYPE_EVENT_DATA) - -enum timer_event_data_tick_prop_type{ - TIMER_EVENT_DATA_TICK_PROP_RESOLUTION = 1, - TIMER_EVENT_DATA_TICK_PROP_TICKS, - TIMER_EVENT_DATA_TICK_PROP_COUNT, -}; -static GParamSpec *timer_event_data_tick_props[TIMER_EVENT_DATA_TICK_PROP_COUNT] = { NULL, }; - -static void timer_event_data_tick_get_property(GObject *obj, guint id, GValue *val, GParamSpec *spec) -{ - ALSATimerEventDataTick *self = ALSATIMER_EVENT_DATA_TICK(obj); - ALSATimerEventDataTickPrivate *priv = alsatimer_event_data_tick_get_instance_private(self); - - switch (id) { - case TIMER_EVENT_DATA_TICK_PROP_RESOLUTION: - g_value_set_uint(val, priv->event.resolution); - break; - case TIMER_EVENT_DATA_TICK_PROP_TICKS: - g_value_set_uint(val, priv->event.ticks); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec); - break; - } -} - -static void alsatimer_event_data_tick_class_init(ALSATimerEventDataTickClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->get_property = timer_event_data_tick_get_property; - - timer_event_data_tick_props[TIMER_EVENT_DATA_TICK_PROP_RESOLUTION] = - g_param_spec_uint("resolution", "resolution", - "The resolution of tick.", - 0, G_MAXUINT, - 0, - G_PARAM_READABLE); - - timer_event_data_tick_props[TIMER_EVENT_DATA_TICK_PROP_TICKS] = - g_param_spec_uint("ticks", "ticks", - "The ticks since the latest event.", - 0, G_MAXUINT, - 0, - G_PARAM_READABLE); - - g_object_class_install_properties(gobject_class, TIMER_EVENT_DATA_TICK_PROP_COUNT, - timer_event_data_tick_props); -} - -static void alsatimer_event_data_tick_init(ALSATimerEventDataTick *self) +ALSATimerEventDataTick *timer_event_data_tick_copy(const ALSATimerEventDataTick *self) { - return; + return g_memdup(self, sizeof(*self)); } -void timer_event_data_tick_set_data(ALSATimerEventDataTick *self, - struct snd_timer_read *data) -{ - ALSATimerEventDataTickPrivate *priv = - alsatimer_event_data_tick_get_instance_private(self); - - priv->event = *data; -} +G_DEFINE_BOXED_TYPE(ALSATimerEventDataTick, alsatimer_event_data_tick, timer_event_data_tick_copy, g_free) diff --git a/src/timer/event-data-tick.h b/src/timer/event-data-tick.h index 4ff4a5f..d26c359 100644 --- a/src/timer/event-data-tick.h +++ b/src/timer/event-data-tick.h @@ -5,45 +5,13 @@ #include #include -#include +#include G_BEGIN_DECLS #define ALSATIMER_TYPE_EVENT_DATA_TICK (alsatimer_event_data_tick_get_type()) -#define ALSATIMER_EVENT_DATA_TICK(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - ALSATIMER_TYPE_EVENT_DATA_TICK, \ - ALSATimerEventDataTick)) -#define ALSATIMER_IS_EVENT_DATA_TICK(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ - ALSATIMER_TYPE_EVENT_DATA_TICK)) - -#define ALSATIMER_EVENT_DATA_TICK_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), \ - ALSATIMER_TYPE_EVENT_DATA_TICK, \ - ALSATimerEventDataTickClass)) -#define ALSATIMER_IS_EVENT_DATA_TICK_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), \ - ALSATIMER_TYPE_EVENT_DATA_TICK)) -#define ALSATIMER_EVENT_DATA_TICK_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS((obj), \ - ALSATIMER_TYPE_EVENT_DATA_TICK, \ - ALSATimerEventDataTickkClass)) - -typedef struct _ALSATimerEventDataTick ALSATimerEventDataTick; -typedef struct _ALSATimerEventDataTickClass ALSATimerEventDataTickClass; -typedef struct _ALSATimerEventDataTickPrivate ALSATimerEventDataTickPrivate; - -struct _ALSATimerEventDataTick { - ALSATimerEventData parent_instance; - - ALSATimerEventDataTickPrivate *priv; -}; - -struct _ALSATimerEventDataTickClass { - ALSATimerEventDataClass parent_class; -}; +typedef struct snd_timer_read ALSATimerEventDataTick; GType alsatimer_event_data_tick_get_type() G_GNUC_CONST; diff --git a/src/timer/event.h b/src/timer/event.h index 169db79..d550987 100644 --- a/src/timer/event.h +++ b/src/timer/event.h @@ -5,14 +5,14 @@ #include #include -#include +#include G_BEGIN_DECLS #define ALSATIMER_TYPE_EVENT (alsatimer_event_get_type()) typedef union { - struct snd_timer_read tick; + ALSATimerEventDataTick tick; struct snd_timer_tread timestamp; } ALSATimerEvent; diff --git a/src/timer/privates.h b/src/timer/privates.h index 90c770f..0c03e72 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-tick.h" #include "event-data-timestamp.h" #include @@ -39,9 +38,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_tick_set_data(ALSATimerEventDataTick *self, - struct snd_timer_read *data); - void timer_event_data_timestamp_set_data(ALSATimerEventDataTimestamp *self, struct snd_timer_tread *data); diff --git a/tests/alsatimer-event-data-tick b/tests/alsatimer-event-data-tick deleted file mode 100644 index 1a73f55..0000000 --- a/tests/alsatimer-event-data-tick +++ /dev/null @@ -1,21 +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.EventDataTick() -props = ( - 'resolution', - 'ticks', -) -methods = () -signals = () - -if not test(target, props, methods, signals): - exit(ENXIO) diff --git a/tests/meson.build b/tests/meson.build index c8b5e5b..2540603 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-tick', 'alsatimer-event-data-timestamp', ], 'seq': [