From 8f30a20d24144470443934d551fc78d0f8e78604 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Tue, 31 May 2022 10:41:31 +0900 Subject: [PATCH] hwdep: 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/hwdep | 5 ++-- src/hwdep/alsahwdep.map | 13 +++++---- src/hwdep/query.c | 64 +++++++++++++++++++++++++++-------------- src/hwdep/query.h | 17 ++++++----- 4 files changed, 62 insertions(+), 37 deletions(-) diff --git a/samples/hwdep b/samples/hwdep index f0c1f1f..9eb71f9 100755 --- a/samples/hwdep +++ b/samples/hwdep @@ -8,9 +8,10 @@ from gi.repository import ALSACtl, ALSAHwdep _, 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): + _, device_id_list = ALSAHwdep.get_device_id_list(card_id) + for device_id in device_id_list: print(' Device {}:'.format(device_id)) - info = ALSAHwdep.get_device_info(card_id, device_id) + _, info = ALSAHwdep.get_device_info(card_id, device_id) for prop in ('device-id', 'card-id', 'id', 'name'): print(' {}: {}'.format(prop, info.get_property(prop))) print(' iface: {}'.format(info.get_property('iface').value_nick)) diff --git a/src/hwdep/alsahwdep.map b/src/hwdep/alsahwdep.map index 979c109..973ed80 100644 --- a/src/hwdep/alsahwdep.map +++ b/src/hwdep/alsahwdep.map @@ -2,12 +2,15 @@ ALSA_GOBJECT_0_0_0 { global: "alsahwdep_iface_type_get_type"; - "alsahwdep_get_device_id_list"; - "alsahwdep_get_hwdep_sysname"; - "alsahwdep_get_hwdep_devnode"; - "alsahwdep_get_device_info"; - "alsahwdep_device_info_get_type"; local: *; }; + +ALSA_GOBJECT_0_3_0 { + global: + "alsahwdep_get_device_id_list"; + "alsahwdep_get_hwdep_sysname"; + "alsahwdep_get_hwdep_devnode"; + "alsahwdep_get_device_info"; +} ALSA_GOBJECT_0_0_0; diff --git a/src/hwdep/query.c b/src/hwdep/query.c index f421de8..7e41d87 100644 --- a/src/hwdep/query.c +++ b/src/hwdep/query.c @@ -15,19 +15,25 @@ * Get the list of numeric ID for available hwdep devices of sound card. * * Nodes under sound subsystem in sysfs are used to gather the information. + * + * Returns: %TRUE when the overall operation finishes successfully, else %FALSE. */ -void alsahwdep_get_device_id_list(guint card_id, guint **entries, - gsize *entry_count, GError **error) +gboolean alsahwdep_get_device_id_list(guint card_id, 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_hwdep_sysnum_list(entries, entry_count, card_id); - if (err < 0) + if (err < 0) { generate_file_error(error, -err, "Fail to generate list of hwdep sysnum"); + return FALSE; + } + + return TRUE; } /** @@ -40,18 +46,24 @@ void alsahwdep_get_device_id_list(guint card_id, guint **entries, * Allocate sysname for hwdep device 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 alsahwdep_get_hwdep_sysname(guint card_id, guint device_id, - char **sysname, GError **error) +gboolean alsahwdep_get_hwdep_sysname(guint card_id, guint device_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_hwdep_sysname(sysname, card_id, device_id); - if (err < 0) + if (err < 0) { generate_file_error(error, -err, "Fail to generate hwdep sysname"); + return FALSE; + } + + return TRUE; } /** @@ -64,18 +76,24 @@ void alsahwdep_get_hwdep_sysname(guint card_id, guint device_id, * Allocate devnode string for hwdep device and return it when exists. * * Nodes under sound subsystem in sysfs are used to gather the information. + * + * Returns: %TRUE when the overall operation finishes successfully, else %FALSE. */ -void alsahwdep_get_hwdep_devnode(guint card_id, guint device_id, - char **devnode, GError **error) +gboolean alsahwdep_get_hwdep_devnode(guint card_id, guint device_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_hwdep_devname(devnode, card_id, device_id); - if (err < 0) + if (err < 0) { generate_file_error(error, -err, "Fail to generate hwdep devname"); + return FALSE; + } + + return TRUE; } /** @@ -89,16 +107,17 @@ void alsahwdep_get_hwdep_devnode(guint card_id, guint device_id, * * The call of function executes `open(2)`, `close(2)`, and `ioctl(2)` system call * with `SNDRV_CTL_IOCTL_HWDEP_INFO` command for ALSA control character device. + * + * Returns: %TRUE when the overall operation finishes successfully, else %FALSE. */ -void alsahwdep_get_device_info(guint card_id, guint device_id, - ALSAHwdepDeviceInfo **device_info, - GError **error) +gboolean alsahwdep_get_device_info(guint card_id, guint device_id, + ALSAHwdepDeviceInfo **device_info, GError **error) { struct snd_hwdep_info *info; int err; - g_return_if_fail(device_info != NULL); - g_return_if_fail(error == NULL || *error == NULL); + g_return_val_if_fail(device_info != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); *device_info = g_object_new(ALSAHWDEP_TYPE_DEVICE_INFO, NULL); hwdep_device_info_refer_private(*device_info, &info); @@ -109,5 +128,8 @@ void alsahwdep_get_device_info(guint card_id, guint device_id, if (err < 0) { generate_file_error(error, -err, "ioctl(HWDEP_INFO)"); g_object_unref(*device_info); + return FALSE; } + + return TRUE; } diff --git a/src/hwdep/query.h b/src/hwdep/query.h index dc0ec8b..4687187 100644 --- a/src/hwdep/query.h +++ b/src/hwdep/query.h @@ -6,18 +6,17 @@ G_BEGIN_DECLS -void alsahwdep_get_device_id_list(guint card_id, guint **entries, - gsize *entry_count, GError **error); +gboolean alsahwdep_get_device_id_list(guint card_id, guint **entries, gsize *entry_count, + GError **error); -void alsahwdep_get_hwdep_sysname(guint card_id, guint device_id, - char **sysname, GError **error); +gboolean alsahwdep_get_hwdep_sysname(guint card_id, guint device_id, char **sysname, + GError **error); -void alsahwdep_get_hwdep_devnode(guint card_id, guint device_id, - char **devnode, GError **error); +gboolean alsahwdep_get_hwdep_devnode(guint card_id, guint device_id, char **devnode, + GError **error); -void alsahwdep_get_device_info(guint card_id, guint device_id, - ALSAHwdepDeviceInfo **device_info, - GError **error); +gboolean alsahwdep_get_device_info(guint card_id, guint device_id, + ALSAHwdepDeviceInfo **device_info, GError **error); G_END_DECLS -- 2.47.3