From 9f3186d7b51b95883b7a8b8c8f0b42d695bed6cb Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Wed, 10 Jun 2020 10:24:14 +0900 Subject: [PATCH] timer: user_instance: emit signal with ALSATimerEvent Signed-off-by: Takashi Sakamoto --- src/timer/privates.h | 1 - src/timer/user-instance.c | 84 ++++++++++++--------------------------- src/timer/user-instance.h | 6 +-- 3 files changed, 29 insertions(+), 62 deletions(-) diff --git a/src/timer/privates.h b/src/timer/privates.h index 3e174af..90c770f 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.h" #include "event-data-tick.h" #include "event-data-timestamp.h" diff --git a/src/timer/user-instance.c b/src/timer/user-instance.c index c436a21..78152ad 100644 --- a/src/timer/user-instance.c +++ b/src/timer/user-instance.c @@ -35,7 +35,6 @@ typedef struct { gpointer tag; void *buf; unsigned int buf_len; - ALSATimerEventData *event_data; } TimerUserInstanceSource; enum timer_user_instance_sig_type { @@ -66,7 +65,7 @@ static void alsatimer_user_instance_class_init(ALSATimerUserInstanceClass *klass /** * ALSATimerUserInstance::handle-event: * @self: A #ALSATimerUserInstance. - * @event_data: (transfer none): An object derived from #ALSATimerEventData. + * @event: (transfer none): The instance of #ALSATimerEvent. * * When event occurs for any element, this signal is emit. */ @@ -77,7 +76,7 @@ static void alsatimer_user_instance_class_init(ALSATimerUserInstanceClass *klass G_STRUCT_OFFSET(ALSATimerUserInstanceClass, handle_event), NULL, NULL, g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, ALSATIMER_TYPE_EVENT_DATA); + G_TYPE_NONE, 1, ALSATIMER_TYPE_EVENT); /** * ALSATimerUserInstance::handle-disconnection: @@ -295,40 +294,6 @@ void alsatimer_user_instance_get_status(ALSATimerUserInstance *self, } } -static void handle_tick_events(TimerUserInstanceSource *src, int len) -{ - struct snd_timer_read *ev = src->buf; - - while (len >= sizeof(*ev)) { - ALSATimerEventDataTick *data = ALSATIMER_EVENT_DATA_TICK(src->event_data); - - timer_event_data_tick_set_data(data, ev); - g_signal_emit(src->self, - timer_user_instance_sigs[TIMER_USER_INSTANCE_SIG_HANDLE_EVENT], - 0, src->event_data); - - len -= sizeof(*ev); - ++ev; - } -} - -static void handle_timestamp_events(TimerUserInstanceSource *src, int len) -{ - struct snd_timer_tread *ev = src->buf; - - while (len >= sizeof(*ev)) { - ALSATimerEventDataTimestamp *data = ALSATIMER_EVENT_DATA_TIMESTAMP(src->event_data); - - timer_event_data_timestamp_set_data(data, ev); - g_signal_emit(src->self, - timer_user_instance_sigs[TIMER_USER_INSTANCE_SIG_HANDLE_EVENT], - 0, src->event_data); - - len -= sizeof(*ev); - ++ev; - } -} - static gboolean timer_user_instance_check_src(GSource *gsrc) { TimerUserInstanceSource *src = (TimerUserInstanceSource *)gsrc; @@ -347,7 +312,9 @@ static gboolean timer_user_instance_dispatch_src(GSource *gsrc, GSourceFunc cb, ALSATimerUserInstance *self = src->self; ALSATimerUserInstancePrivate *priv; GIOCondition condition; + size_t event_size; int len; + guint8 *buf; priv = alsatimer_user_instance_get_instance_private(self); if (priv->fd < 0) @@ -369,10 +336,28 @@ static gboolean timer_user_instance_dispatch_src(GSource *gsrc, GSourceFunc cb, return G_SOURCE_REMOVE; } - if (priv->event_data_type == ALSATIMER_EVENT_DATA_TYPE_TICK) - handle_tick_events(src, len); - else - handle_timestamp_events(src, len); + switch (priv->event_data_type) { + case ALSATIMER_EVENT_DATA_TYPE_TICK: + event_size = sizeof(struct snd_timer_read); + break; + case ALSATIMER_EVENT_DATA_TYPE_TIMESTAMP: + event_size = sizeof(struct snd_timer_tread); + break; + default: + return G_SOURCE_CONTINUE; + } + + buf = src->buf; + while (len > 0) { + ALSATimerEvent *ev = (ALSATimerEvent *)buf; + + g_signal_emit(src->self, + timer_user_instance_sigs[TIMER_USER_INSTANCE_SIG_HANDLE_EVENT], + 0, ev); + + buf += event_size; + len -= event_size; + } // Just be sure to continue to process this source. return G_SOURCE_CONTINUE; @@ -383,7 +368,6 @@ static void timer_user_instance_finalize_src(GSource *gsrc) TimerUserInstanceSource *src = (TimerUserInstanceSource *)gsrc; g_free(src->buf); - g_object_unref(src->event_data); g_object_unref(src->self); } @@ -405,7 +389,6 @@ void alsatimer_user_instance_create_source(ALSATimerUserInstance *self, .finalize = timer_user_instance_finalize_src, }; ALSATimerUserInstancePrivate *priv; - GType event_data_class; TimerUserInstanceSource *src; long page_size = sysconf(_SC_PAGESIZE); void *buf; @@ -418,18 +401,6 @@ void alsatimer_user_instance_create_source(ALSATimerUserInstance *self, return; } - switch (priv->event_data_type) { - case ALSATIMER_EVENT_DATA_TYPE_TICK: - event_data_class = ALSATIMER_TYPE_EVENT_DATA_TICK; - break; - case ALSATIMER_EVENT_DATA_TYPE_TIMESTAMP: - event_data_class = ALSATIMER_TYPE_EVENT_DATA_TIMESTAMP; - break; - default: - generate_error(error, EINVAL); - return; - } - buf = g_try_malloc0(page_size); if (buf == NULL) { generate_error(error, ENOMEM); @@ -447,9 +418,6 @@ void alsatimer_user_instance_create_source(ALSATimerUserInstance *self, src->tag = g_source_add_unix_fd(*gsrc, priv->fd, G_IO_IN); src->buf = buf; src->buf_len = page_size; - - src->event_data = g_object_new(event_data_class, - "type", priv->event_data_type, NULL); } /** diff --git a/src/timer/user-instance.h b/src/timer/user-instance.h index 76329ed..dfdce98 100644 --- a/src/timer/user-instance.h +++ b/src/timer/user-instance.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include G_BEGIN_DECLS @@ -51,12 +51,12 @@ struct _ALSATimerUserInstanceClass { /** * ALSATimerUserInstanceClass::handle_event: * @self: A #ALSATimerUserInstance. - * @event_data: (transfer none): An object derived from #ALSATimerEventData. + * @event: (transfer none): An object derived from #ALSATimerEvent. * * When event occurs, this signal is emit. */ void (*handle_event)(ALSATimerUserInstance *self, - const ALSATimerEventData *event_data); + const ALSATimerEvent *event); /** * ALSATimerUserInstanceClass::handle_disconnection: -- 2.47.3