]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
hwdep: query: rewrite public API to return gboolean according to GNOME convention
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Tue, 31 May 2022 01:41:31 +0000 (10:41 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Tue, 31 May 2022 02:31:59 +0000 (11:31 +0900)
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 <o-takashi@sakamocchi.jp>
samples/hwdep
src/hwdep/alsahwdep.map
src/hwdep/query.c
src/hwdep/query.h

index f0c1f1fa3e061cd96103415a5bc66d7f6015201c..9eb71f90a57279c7748b94f793f450b408568215 100755 (executable)
@@ -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))
index 979c10941b585d409beddec6c96c2d6ef03c77b8..973ed80a21118b0bf196c32eaf4431443a9ad7eb 100644 (file)
@@ -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;
index f421de80323cb1908bd040a894282fdf97c139f5..7e41d8722d1af5ef65180a3a8db21bce8832e959 100644 (file)
  * 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;
 }
index dc0ec8bff7893c95723ea0584ecec47d31274b81..4687187ceceae3dacd2c07c3cee631433bb40ddb 100644 (file)
@@ -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