From 5148d3889783b4f5edf163b3fc04b50c31ec6c63 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Sun, 9 Feb 2020 12:20:53 +0900 Subject: [PATCH] timer: user_instance: add GObject signal to handle event Signed-off-by: Takashi Sakamoto --- src/timer/user-instance.c | 22 ++++++++++++++++++++++ src/timer/user-instance.h | 1 + tests/alsatimer-user-instance | 4 +++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/timer/user-instance.c b/src/timer/user-instance.c index daf30f5..0bbc947 100644 --- a/src/timer/user-instance.c +++ b/src/timer/user-instance.c @@ -23,6 +23,12 @@ typedef struct { unsigned int buf_len; } TimerUserInstanceSource; +enum timer_user_instance_sig_type { + TIMER_USER_INSTANCE_SIG_HANDLE_EVENT = 0, + TIMER_USER_INSTANCE_SIG_COUNT, +}; +static guint timer_user_instance_sigs[TIMER_USER_INSTANCE_SIG_COUNT] = { 0 }; + static void timer_user_instance_finalize(GObject *obj) { ALSATimerUserInstance *self = ALSATIMER_USER_INSTANCE(obj); @@ -40,6 +46,22 @@ static void alsatimer_user_instance_class_init(ALSATimerUserInstanceClass *klass GObjectClass *gobject_class = G_OBJECT_CLASS(klass); gobject_class->finalize = timer_user_instance_finalize; + + /** + * ALSATimerUserInstance::handle-event: + * @self: A #ALSATimerUserInstance. + * @event_data: (transfer none): An object derived from #ALSATimerEventData. + * + * When event occurs for any element, this signal is emit. + */ + timer_user_instance_sigs[TIMER_USER_INSTANCE_SIG_HANDLE_EVENT] = + g_signal_new("handle-event", + G_OBJECT_CLASS_TYPE(klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, ALSATIMER_TYPE_EVENT_DATA); } static void alsatimer_user_instance_init(ALSATimerUserInstance *self) diff --git a/src/timer/user-instance.h b/src/timer/user-instance.h index 3a21a0e..a4cc9bf 100644 --- a/src/timer/user-instance.h +++ b/src/timer/user-instance.h @@ -9,6 +9,7 @@ #include #include #include +#include G_BEGIN_DECLS diff --git a/tests/alsatimer-user-instance b/tests/alsatimer-user-instance index 5f189e9..b369f53 100644 --- a/tests/alsatimer-user-instance +++ b/tests/alsatimer-user-instance @@ -21,7 +21,9 @@ methods = ( 'get_status', 'create_source', ) -signals = () +signals = ( + 'handle-event', +) if not test(target, props, methods, signals): exit(ENXIO) -- 2.47.3