From: Takashi Sakamoto Date: Wed, 22 Jun 2022 03:05:26 +0000 (+0900) Subject: timer: real-time-event: rename boxed structure X-Git-Tag: v0.3.0~34 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=61b6ea5dceb9941595bfdc98decaddc4fdc2c38b;p=alsa-gobject.git timer: real-time-event: rename boxed structure Signed-off-by: Takashi Sakamoto --- diff --git a/samples/timer b/samples/timer index 808611a..66acae6 100755 --- a/samples/timer +++ b/samples/timer @@ -14,12 +14,12 @@ instance.open(0) # Choose tstamp type of data for event and register event handler. instance.choose_event_type(ALSATimer.EventType.TSTAMP) -def handle_tstamp_event(instance, event): - tstamp = event.get_tstamp([0, 0]) - print('\nEvent at', tstamp) +def handle_real_time_event(instance, event): + real_time = event.get_time([0, 0]) + print('\nEvent at', real_time) print(' ', event.get_event().value_nick) print(' ', event.get_val()) -instance.connect('handle-tstamp-event', handle_tstamp_event) +instance.connect('handle-real-time-event', handle_real_time_event) # Decide ALSA timer device to which the instance is attached. targets = ( diff --git a/src/timer/alsatimer.map b/src/timer/alsatimer.map index 1bff785..39a46d8 100644 --- a/src/timer/alsatimer.map +++ b/src/timer/alsatimer.map @@ -73,8 +73,8 @@ ALSA_GOBJECT_0_3_0 { "alsatimer_tick_time_event_get_resolution"; "alsatimer_tick_time_event_get_count"; - "alsatimer_tstamp_event_get_type"; - "alsatimer_tstamp_event_get_event"; - "alsatimer_tstamp_event_get_tstamp"; - "alsatimer_tstamp_event_get_val"; + "alsatimer_real_time_event_get_type"; + "alsatimer_real_time_event_get_event"; + "alsatimer_real_time_event_get_time"; + "alsatimer_real_time_event_get_val"; } ALSA_GOBJECT_0_2_0; diff --git a/src/timer/real-time-event.c b/src/timer/real-time-event.c index 5970210..179e772 100644 --- a/src/timer/real-time-event.c +++ b/src/timer/real-time-event.c @@ -2,14 +2,14 @@ #include "privates.h" /** - * ALSATimerTstampEvent: - * A boxed object to represent event of timer with tstamp. + * ALSATimerRealTimeEvent: + * A boxed object to express event of timer with real time. * - * A [struct@TstampEvent] is a boxed object to represent event of timer with tstamp. + * A [struct@RealTimeEvent] includes real time at which the event is queued. * * The object wraps `struct snd_timer_tread` in UAPI of Linux sound subsystem. */ -ALSATimerTstampEvent *timer_tstamp_event_copy(const ALSATimerTstampEvent *self) +ALSATimerRealTimeEvent *timer_real_time_event_copy(const ALSATimerRealTimeEvent *self) { #ifdef g_memdup2 return g_memdup2(self, sizeof(*self)); @@ -22,43 +22,44 @@ ALSATimerTstampEvent *timer_tstamp_event_copy(const ALSATimerTstampEvent *self) #endif } -G_DEFINE_BOXED_TYPE(ALSATimerTstampEvent, alsatimer_tstamp_event, timer_tstamp_event_copy, g_free) +G_DEFINE_BOXED_TYPE(ALSATimerRealTimeEvent, alsatimer_real_time_event, timer_real_time_event_copy, g_free) /** - * alsatimer_tstamp_event_get_event: - * @self: A [struct@TstampEvent]. + * alsatimer_real_time_event_get_event: + * @self: A [struct@RealTimeEvent]. * @event: (out): The type of tstamp event, one of [enum@TstampEventType]. * * Get the kind of event for the timestamp event. */ -void alsatimer_tstamp_event_get_event(const ALSATimerTstampEvent *self, - ALSATimerTstampEventType *event) +void alsatimer_real_time_event_get_event(const ALSATimerRealTimeEvent *self, + ALSATimerTstampEventType *event) { *event = (ALSATimerTstampEventType)self->event; } /** - * alsatimer_tstamp_event_get_tstamp: - * @self: A [struct@TstampEvent]. - * @tstamp: (array fixed-size=2) (inout): The array with two elements for the seconds and - * nanoseconds part of timestamp when the instance queues the timestamp event. + * alsatimer_real_time_event_get_time: + * @self: A [struct@RealTimeEvent]. + * @real_time: (array fixed-size=2) (inout): The array with two elements for the seconds and + * nanoseconds part of timestamp when the instance queues the timestamp event. * * Get the seconds and nanoseconds part for the timestamp event. */ -void alsatimer_tstamp_event_get_tstamp(const ALSATimerTstampEvent *self, gint64 *const tstamp[2]) +void alsatimer_real_time_event_get_time(const ALSATimerRealTimeEvent *self, + gint64 *const real_time[2]) { - (*tstamp)[0] = (gint64)self->tstamp.tv_sec; - (*tstamp)[1] = (gint64)self->tstamp.tv_nsec; + (*real_time)[0] = (gint64)self->tstamp.tv_sec; + (*real_time)[1] = (gint64)self->tstamp.tv_nsec; } /** - * alsatimer_tstamp_event_get_val: - * @self: A [struct@TstampEvent]. + * alsatimer_real_time_event_get_val: + * @self: A [struct@RealTimeEvent]. * @val: (out): The value depending on the type of timestamp event. * * Get the value depending on the type of timestamp event. */ -void alsatimer_tstamp_event_get_val(const ALSATimerTstampEvent *self, guint *val) +void alsatimer_real_time_event_get_val(const ALSATimerRealTimeEvent *self, guint *val) { *val = self->val; } diff --git a/src/timer/real-time-event.h b/src/timer/real-time-event.h index 6957fbf..9165dd6 100644 --- a/src/timer/real-time-event.h +++ b/src/timer/real-time-event.h @@ -1,23 +1,24 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -#ifndef __ALSA_GOBJECT_ALSATIMER_TSTAMP_EVENT_H__ -#define __ALSA_GOBJECT_ALSATIMER_TSTAMP_EVENT_H__ +#ifndef __ALSA_GOBJECT_ALSATIMER_REAL_TIME_EVENT_H__ +#define __ALSA_GOBJECT_ALSATIMER_REAL_TIME_EVENT_H__ #include G_BEGIN_DECLS -#define ALSATIMER_TYPE_TSTAMP_EVENT (alsatimer_tstamp_event_get_type()) +#define ALSATIMER_TYPE_REAL_TIME_EVENT (alsatimer_real_time_event_get_type()) -typedef struct snd_timer_tread ALSATimerTstampEvent; +typedef struct snd_timer_tread ALSATimerRealTimeEvent; -GType alsatimer_tstamp_event_get_type() G_GNUC_CONST; +GType alsatimer_real_time_event_get_type() G_GNUC_CONST; -void alsatimer_tstamp_event_get_event(const ALSATimerTstampEvent *self, - ALSATimerTstampEventType *event); +void alsatimer_real_time_event_get_event(const ALSATimerRealTimeEvent *self, + ALSATimerTstampEventType *event); -void alsatimer_tstamp_event_get_tstamp(const ALSATimerTstampEvent *self, gint64 *const tstamp[2]); +void alsatimer_real_time_event_get_time(const ALSATimerRealTimeEvent *self, + gint64 *const real_time[2]); -void alsatimer_tstamp_event_get_val(const ALSATimerTstampEvent *self, guint *val); +void alsatimer_real_time_event_get_val(const ALSATimerRealTimeEvent *self, guint *val); G_END_DECLS diff --git a/src/timer/user-instance.c b/src/timer/user-instance.c index a166d49..26d839b 100644 --- a/src/timer/user-instance.c +++ b/src/timer/user-instance.c @@ -60,7 +60,7 @@ typedef struct { enum timer_user_instance_sig_type { TIMER_USER_INSTANCE_SIG_HANDLE_TICK_TIME_EVENT = 0, - TIMER_USER_INSTANCE_SIG_HANDLE_TSTAMP_EVENT, + TIMER_USER_INSTANCE_SIG_HANDLE_REAL_TIME_EVENT, TIMER_USER_INSTANCE_SIG_HANDLE_DISCONNECTION, TIMER_USER_INSTANCE_SIG_COUNT, }; @@ -101,20 +101,20 @@ static void alsatimer_user_instance_class_init(ALSATimerUserInstanceClass *klass G_TYPE_NONE, 1, ALSATIMER_TYPE_TICK_TIME_EVENT); /** - * ALSATimerUserInstance::handle-tstamp-event: + * ALSATimerUserInstance::handle-real-time-event: * @self: A [class@UserInstance]. - * @event: (transfer none): The instance of [struct@TstampEvent]. + * @event: (transfer none): The instance of [struct@RealTimeEvent]. * * Emitted when timestamp event occurs. */ - timer_user_instance_sigs[TIMER_USER_INSTANCE_SIG_HANDLE_TSTAMP_EVENT] = - g_signal_new("handle-tstamp-event", + timer_user_instance_sigs[TIMER_USER_INSTANCE_SIG_HANDLE_REAL_TIME_EVENT] = + g_signal_new("handle-real-time-event", G_OBJECT_CLASS_TYPE(klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(ALSATimerUserInstanceClass, handle_tstamp_event), + G_STRUCT_OFFSET(ALSATimerUserInstanceClass, handle_real_time_event), NULL, NULL, g_cclosure_marshal_VOID__BOXED, - G_TYPE_NONE, 1, ALSATIMER_TYPE_TSTAMP_EVENT); + G_TYPE_NONE, 1, ALSATIMER_TYPE_REAL_TIME_EVENT); /** * ALSATimerUserInstance::handle-disconnection: @@ -510,14 +510,15 @@ static void dispatch_tick_time_events(ALSATimerUserInstance *self, const guint8 } } -static void dispatch_tstamp_events(ALSATimerUserInstance *self, const guint8 *buf, gsize length) +static void dispatch_real_time_events(ALSATimerUserInstance *self, const guint8 *buf, gsize length) { const struct snd_timer_tread *ev; while (length >= sizeof(*ev)) { const struct snd_timer_tread *ev = (const struct snd_timer_tread *)buf; - g_signal_emit(self, timer_user_instance_sigs[TIMER_USER_INSTANCE_SIG_HANDLE_TSTAMP_EVENT], + g_signal_emit(self, + timer_user_instance_sigs[TIMER_USER_INSTANCE_SIG_HANDLE_REAL_TIME_EVENT], 0, ev); length -= sizeof(*ev); @@ -559,7 +560,7 @@ static gboolean timer_user_instance_dispatch_src(GSource *gsrc, GSourceFunc cb, dispatch_tick_time_events(self, src->buf, (size_t)len); break; case ALSATIMER_EVENT_TYPE_TSTAMP: - dispatch_tstamp_events(self, src->buf, (size_t)len); + dispatch_real_time_events(self, src->buf, (size_t)len); break; default: break; @@ -586,8 +587,8 @@ static void timer_user_instance_finalize_src(GSource *gsrc) * Allocate [struct@GLib.Source] structure to handle events from ALSA timer character device. In * each iteration of [struct@GLib.MainContext], the `read(2)` system call is executed to dispatch * timer event for either [signal@UserInstance::handle-tick-time-event] or - * [signal@UserInstance::handle-tstamp-event] signals, according to the result of `poll(2)` system - * call. + * [signal@UserInstance::handle-real-time-event] signals, according to the result of `poll(2)` + * system call. * * Returns: %TRUE when the overall operation finishes successfully, else %FALSE. */ diff --git a/src/timer/user-instance.h b/src/timer/user-instance.h index 5b49156..5f70c62 100644 --- a/src/timer/user-instance.h +++ b/src/timer/user-instance.h @@ -29,13 +29,13 @@ struct _ALSATimerUserInstanceClass { const ALSATimerTickTimeEvent *event); /** - * ALSATimerUserInstanceClass::handle_tstamp_event: + * ALSATimerUserInstanceClass::handle_real_time_event: * @self: A [class@UserInstance]. - * @event: (transfer none): An object derived from [struct@TstampEvent]. + * @event: (transfer none): An object derived from [struct@RealTimeEvent]. * - * Class closure for the [signal@UserInstance::handle-tstamp-event] signal. + * Class closure for the [signal@UserInstance::handle-real-time-event] signal. */ - void (*handle_tstamp_event)(ALSATimerUserInstance *self, const ALSATimerTstampEvent *event); + void (*handle_real_time_event)(ALSATimerUserInstance *self, const ALSATimerRealTimeEvent *event); /** * ALSATimerUserInstanceClass::handle_disconnection: diff --git a/tests/alsatimer-real-time-event b/tests/alsatimer-real-time-event index 20ad44b..a556817 100644 --- a/tests/alsatimer-real-time-event +++ b/tests/alsatimer-real-time-event @@ -9,10 +9,10 @@ import gi gi.require_version('ALSATimer', '0.0') from gi.repository import ALSATimer -target_type = ALSATimer.TstampEvent +target_type = ALSATimer.RealTimeEvent methods = ( 'get_event', - 'get_tstamp', + 'get_time', 'get_val', ) diff --git a/tests/alsatimer-user-instance b/tests/alsatimer-user-instance index 7d375f0..30b32bb 100644 --- a/tests/alsatimer-user-instance +++ b/tests/alsatimer-user-instance @@ -29,12 +29,12 @@ methods = ( ) vmethods = ( 'do_handle_tick_time_event', - 'do_handle_tstamp_event', + 'do_handle_real_time_event', 'do_handle_disconnection', ) signals = ( 'handle-tick-time-event', - 'handle-tstamp-event', + 'handle-real-time-event', 'handle-disconnection', )