]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
ctl: 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/ctl
samples/hwdep
samples/rawmidi
src/ctl/alsactl.map
src/ctl/query.c
src/ctl/query.h

index 2976cbbcc90e82cec64630446ae4590a368bbd67..4b4eed2030be84fef772288825121d4f7b10510f 100755 (executable)
@@ -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()
index 5752ed9e3be7ad6ca2ed1cc7a3b5987a3e8a3f5c..f0c1f1fa3e061cd96103415a5bc66d7f6015201c 100755 (executable)
@@ -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))
index 53c6bfef7f96332488271456bab33808e04dd683..8b5da227d296f3c6cac6d63ba155639fd5bb7051 100755 (executable)
@@ -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)
index 20ca7ea53f4b2e44fe7e03f521457305fbba33d1..72848b0416b45b3bc89be413497f0f947aa5cecd 100644 (file)
@@ -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;
index 1602e55398c209a391b624a20b53a1e581ca6f05..722c08838a0d4a1e216277d712e1bc99cf572af6 100644 (file)
  * 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;
 }
index b48576a63497cdea3d9a304d941a00cdb5de1017..5275d826fadba5ce29f4b4331a6da8ccfb1feb5d 100644 (file)
@@ -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