From 8fae3f1f127d111f3fc0e4f4c5dd581976b4229a Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Tue, 31 May 2022 10:41:31 +0900 Subject: [PATCH] ctl: query: 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 --- samples/ctl | 2 +- samples/hwdep | 3 ++- samples/rawmidi | 3 ++- src/ctl/alsactl.map | 14 +++++++---- src/ctl/query.c | 59 +++++++++++++++++++++++++++++++-------------- src/ctl/query.h | 8 +++--- 6 files changed, 59 insertions(+), 30 deletions(-) diff --git a/samples/ctl b/samples/ctl index 2976cbb..4b4eed2 100755 --- a/samples/ctl +++ b/samples/ctl @@ -8,7 +8,7 @@ from gi.repository import GLib, ALSACtl from signal import SIGINT # Retrieve the list of available sound cards. -card_id_list = ALSACtl.get_card_id_list() +_, card_id_list = ALSACtl.get_card_id_list() # Open ALSA control character device. card = ALSACtl.Card.new() diff --git a/samples/hwdep b/samples/hwdep index 5752ed9..f0c1f1f 100755 --- a/samples/hwdep +++ b/samples/hwdep @@ -5,7 +5,8 @@ gi.require_version('ALSACtl', '0.0') gi.require_version('ALSAHwdep', '0.0') from gi.repository import ALSACtl, ALSAHwdep -for card_id in ALSACtl.get_card_id_list(): +_, card_id_list = ALSACtl.get_card_id_list() +for card_id in card_id_list: print('Card {}:'.format(card_id)) for device_id in ALSAHwdep.get_device_id_list(card_id): print(' Device {}:'.format(device_id)) diff --git a/samples/rawmidi b/samples/rawmidi index 53c6bfe..8b5da22 100755 --- a/samples/rawmidi +++ b/samples/rawmidi @@ -11,7 +11,8 @@ from signal import SIGINT # Open ALSA Rawmidi chracter device in which a pair of input/output substreams # is available in the same subdevice ID. -for card_id in ALSACtl.get_card_id_list(): +_, card_id_list = ALSACtl.get_card_id_list() +for card_id in card_id_list: for device_id in ALSARawmidi.get_device_id_list(card_id): outputs = ALSARawmidi.get_subdevice_id_list(card_id, device_id, ALSARawmidi.StreamDirection.OUTPUT) diff --git a/src/ctl/alsactl.map b/src/ctl/alsactl.map index 20ca7ea..72848b0 100644 --- a/src/ctl/alsactl.map +++ b/src/ctl/alsactl.map @@ -6,11 +6,6 @@ ALSA_GOBJECT_0_0_0 { "alsactl_event_type_get_type"; "alsactl_elem_event_mask_get_type"; - "alsactl_get_card_id_list"; - "alsactl_get_card_sysname"; - "alsactl_get_control_sysname"; - "alsactl_get_control_devnode"; - "alsactl_card_get_type"; "alsactl_card_new"; "alsactl_card_open"; @@ -70,9 +65,18 @@ ALSA_GOBJECT_0_0_0 { }; ALSA_GOBJECT_0_2_0 { + global: "alsactl_card_error_get_type"; "alsactl_card_error_quark"; "alsactl_card_write_elem_tlv"; "alsactl_card_read_elem_tlv"; "alsactl_card_command_elem_tlv"; } ALSA_GOBJECT_0_0_0; + +ALSA_GOBJECT_0_3_0 { + global: + "alsactl_get_card_id_list"; + "alsactl_get_card_sysname"; + "alsactl_get_control_sysname"; + "alsactl_get_control_devnode"; +} ALSA_GOBJECT_0_2_0; diff --git a/src/ctl/query.c b/src/ctl/query.c index 1602e55..722c088 100644 --- a/src/ctl/query.c +++ b/src/ctl/query.c @@ -12,19 +12,24 @@ * Get the list of numeric ID for available sound cards. * * Nodes under sound subsystem in sysfs are used to gather the information. + * + * Returns: %TRUE when the overall operation finishes successfully, else %FALSE. */ -void alsactl_get_card_id_list(guint **entries, gsize *entry_count, - GError **error) +gboolean alsactl_get_card_id_list(guint **entries, gsize *entry_count, GError **error) { int err; - 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); err = generate_card_sysnum_list(entries, entry_count); - if (err < 0) + if (err < 0) { generate_file_error(error, -err, "Fail to generate list of card sysnum"); + return FALSE; + } + + return TRUE; } /** @@ -36,17 +41,23 @@ void alsactl_get_card_id_list(guint **entries, gsize *entry_count, * Allocate sysname for the sound card and return it when it exists. * * Nodes under sound subsystem in sysfs are used to gather the information. + * + * Returns: %TRUE when the overall operation finishes successfully, else %FALSE. */ -void alsactl_get_card_sysname(guint card_id, char **sysname, GError **error) +gboolean alsactl_get_card_sysname(guint card_id, char **sysname, GError **error) { int err; - g_return_if_fail(sysname != NULL); - g_return_if_fail(error == NULL || *error == NULL); + g_return_val_if_fail(sysname != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); err = lookup_and_allocate_card_sysname(sysname, card_id); - if (err < 0) + if (err < 0) { generate_file_error(error, -err, "Fail to generate card sysname"); + return FALSE; + } + + return TRUE; } /** @@ -58,17 +69,23 @@ void alsactl_get_card_sysname(guint card_id, char **sysname, GError **error) * Allocate sysname of control device for the sound card and return it if exists. * * Nodes under sound subsystem in sysfs are used to gather the information. + * + * Returns: %TRUE when the overall operation finishes successfully, else %FALSE. */ -void alsactl_get_control_sysname(guint card_id, char **sysname, GError **error) +gboolean alsactl_get_control_sysname(guint card_id, char **sysname, GError **error) { int err; - g_return_if_fail(sysname != NULL); - g_return_if_fail(error == NULL || *error == NULL); + g_return_val_if_fail(sysname != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); err = lookup_and_allocate_control_sysname(sysname, card_id); - if (err < 0) + if (err < 0) { generate_file_error(error, -err, "Fail to generate control sysname"); + return FALSE; + } + + return TRUE; } /** @@ -80,15 +97,21 @@ void alsactl_get_control_sysname(guint card_id, char **sysname, GError **error) * Allocate string of devnode for control device of the sound card and return it if exists. * * Nodes under sound subsystem in sysfs are used to gather the information. + * + * Returns: %TRUE when the overall operation finishes successfully, else %FALSE. */ -void alsactl_get_control_devnode(guint card_id, char **devnode, GError **error) +gboolean alsactl_get_control_devnode(guint card_id, char **devnode, GError **error) { int err; - g_return_if_fail(devnode != NULL); - g_return_if_fail(error == NULL || *error == NULL); + g_return_val_if_fail(devnode != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); err = lookup_and_allocate_control_devname(devnode, card_id); - if (err < 0) + if (err < 0) { generate_file_error(error, -err, "Fail to generate control devname"); + return FALSE; + } + + return TRUE; } diff --git a/src/ctl/query.h b/src/ctl/query.h index b48576a..5275d82 100644 --- a/src/ctl/query.h +++ b/src/ctl/query.h @@ -6,14 +6,14 @@ G_BEGIN_DECLS -void alsactl_get_card_id_list(guint **entries, gsize *entry_count, +gboolean alsactl_get_card_id_list(guint **entries, gsize *entry_count, GError **error); -void alsactl_get_card_sysname(guint card_id, char **sysname, GError **error); +gboolean alsactl_get_card_sysname(guint card_id, char **sysname, GError **error); -void alsactl_get_control_sysname(guint card_id, char **sysname, GError **error); +gboolean alsactl_get_control_sysname(guint card_id, char **sysname, GError **error); -void alsactl_get_control_devnode(guint card_id, char **devnode, GError **error); +gboolean alsactl_get_control_devnode(guint card_id, char **devnode, GError **error); G_END_DECLS -- 2.47.3