From 1c4a48b436bfd941042270c67cc4f24771ea05f0 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Tue, 31 May 2022 10:41:31 +0900 Subject: [PATCH] timer: instance-params: rewrite public API to return gboolean according to GNOME convention In GNOME convention, the throw function to report error at GError argument should return gboolean value to report the overall operation finishes successfully or not. This commit rewrite such public APIs with loss of backward compatibility. Signed-off-by: Takashi Sakamoto --- src/timer/instance-params.c | 30 ++++++++++++++++++------------ src/timer/instance-params.h | 4 ++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/timer/instance-params.c b/src/timer/instance-params.c index 3b27cb4..e76ffd1 100644 --- a/src/timer/instance-params.c +++ b/src/timer/instance-params.c @@ -132,8 +132,10 @@ ALSATimerInstanceParams *alsatimer_instance_params_new() * * Set the list of [enum@EventType] to filter events. This parameter is effective only for target * instance with [enum@EventDataType:TIMESTAMP]. + * + * Returns: %TRUE when the overall operation finishes successfully, else %FALSE. */ -void alsatimer_instance_params_set_event_filter(ALSATimerInstanceParams *self, +gboolean alsatimer_instance_params_set_event_filter(ALSATimerInstanceParams *self, const ALSATimerEventType *entries, gsize entry_count, GError **error) { @@ -141,17 +143,17 @@ void alsatimer_instance_params_set_event_filter(ALSATimerInstanceParams *self, unsigned int filter; int i; - g_return_if_fail(ALSATIMER_IS_INSTANCE_PARAMS(self)); + g_return_val_if_fail(ALSATIMER_IS_INSTANCE_PARAMS(self), FALSE); priv = alsatimer_instance_params_get_instance_private(self); - g_return_if_fail(entries != NULL); - g_return_if_fail(error == NULL || *error == NULL); + g_return_val_if_fail(entries != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); priv->params.filter = 0; // Clear the event filter. if (entries == NULL || entry_count == 0) - return; + return TRUE; filter = 0; for (i = 0; i < entry_count; ++i) { @@ -160,12 +162,13 @@ void alsatimer_instance_params_set_event_filter(ALSATimerInstanceParams *self, (val > SNDRV_TIMER_EVENT_RESUME && val < SNDRV_TIMER_EVENT_MSTART) || val > SNDRV_TIMER_EVENT_MRESUME) { - g_return_if_reached(); + g_return_val_if_reached(FALSE); } filter |= (1u << val); } priv->params.filter = filter; + return TRUE; } /** @@ -177,8 +180,10 @@ void alsatimer_instance_params_set_event_filter(ALSATimerInstanceParams *self, * * Get the list of ALSATimerEventType to filter events. This parameter is effective only for target * instance with [enum@EventDataType:TIMESTAMP]. + * + * Returns: %TRUE when the overall operation finishes successfully, else %FALSE. */ -void alsatimer_instance_params_get_event_filter(ALSATimerInstanceParams *self, +gboolean alsatimer_instance_params_get_event_filter(ALSATimerInstanceParams *self, ALSATimerEventType **entries, gsize *entry_count, GError **error) { @@ -189,12 +194,12 @@ void alsatimer_instance_params_get_event_filter(ALSATimerInstanceParams *self, unsigned int index; int i; - g_return_if_fail(ALSATIMER_IS_INSTANCE_PARAMS(self)); + g_return_val_if_fail(ALSATIMER_IS_INSTANCE_PARAMS(self), FALSE); priv = alsatimer_instance_params_get_instance_private(self); - g_return_if_fail(entries != NULL); - g_return_if_fail(entry_count != NULL); - g_return_if_fail(error == NULL || *error == NULL); + g_return_val_if_fail(entries != NULL, FALSE); + g_return_val_if_fail(entry_count != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); count = 0; filter = priv->params.filter; @@ -204,7 +209,7 @@ void alsatimer_instance_params_get_event_filter(ALSATimerInstanceParams *self, } if (count == 0) - return; + return TRUE; list = g_malloc0_n(count, sizeof(*list)); @@ -221,6 +226,7 @@ void alsatimer_instance_params_get_event_filter(ALSATimerInstanceParams *self, *entries = list; *entry_count = count; + return TRUE; } void timer_instance_params_refer_private(ALSATimerInstanceParams *self, diff --git a/src/timer/instance-params.h b/src/timer/instance-params.h index fc4e00d..5ba060a 100644 --- a/src/timer/instance-params.h +++ b/src/timer/instance-params.h @@ -17,11 +17,11 @@ struct _ALSATimerInstanceParamsClass { ALSATimerInstanceParams *alsatimer_instance_params_new(); -void alsatimer_instance_params_set_event_filter(ALSATimerInstanceParams *self, +gboolean alsatimer_instance_params_set_event_filter(ALSATimerInstanceParams *self, const ALSATimerEventType *entries, gsize entry_count, GError **error); -void alsatimer_instance_params_get_event_filter(ALSATimerInstanceParams *self, +gboolean alsatimer_instance_params_get_event_filter(ALSATimerInstanceParams *self, ALSATimerEventType **entries, gsize *entry_count, GError **error); -- 2.47.3