]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
hwdep: add global method to get sysname for hwdep device of sound card
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 27 Nov 2019 06:33:13 +0000 (15:33 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Wed, 8 Apr 2020 01:40:25 +0000 (10:40 +0900)
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/hwdep/alsahwdep.map
src/hwdep/query.c
src/hwdep/query.h

index 779c754e20541bf816589e029e7ec49f056bef27..466d65adef49c87c239af5467ae1ebb51283093a 100644 (file)
@@ -3,6 +3,7 @@ ALSA_GOBJECT_0_0_0 {
     "alsahwdep_iface_type_get_type";
 
     "alsahwdep_get_device_id_list";
+    "alsahwdep_get_hwdep_sysname";
   local:
     *;
 };
index 93357e43c7a55b6372fcbbef1bddd26ba7de54dc..1b0a836f7dccd7de945faa5adbcf9b5c5d1e33cf 100644 (file)
@@ -17,6 +17,7 @@ G_DEFINE_QUARK("alsahwdep-error", alsahwdep_error)
 
 // 'C' is required apart from emulation of Open Sound System.
 #define PREFIX_SYSNAME_TEMPLATE     "hwC%u"
+#define HWDEP_SYSNAME_TEMPLATE      "hwC%uD%u"
 
 static void prepare_udev_enum(struct udev_enumerate **enumerator, GError **error)
 {
@@ -199,3 +200,48 @@ end:
     g_free(prefix);
     release_udev_enum(enumerator);
 }
+
+/**
+ * alsahwdep_get_hwdep_sysname:
+ * @card_id: The numeridcal ID of sound card.
+ * @device_id: The numerical ID of hwdep device for the sound card.
+ * @sysname: (out): The string for sysname of hwdep device.
+ * @error: A #GError.
+ *
+ * Allocate sysname for hwdep device and return it when it exists.
+ */
+void alsahwdep_get_hwdep_sysname(guint card_id, guint device_id,
+                                 char **sysname, GError **error)
+{
+    unsigned int length;
+    char *name;
+    struct udev *ctx;
+    struct udev_device *dev;
+
+    length = strlen(HWDEP_SYSNAME_TEMPLATE) + calculate_digits(card_id) +
+             calculate_digits(device_id) + 1;
+    name = g_try_malloc0(length);
+    if (name == NULL) {
+        generate_error(error, ENOMEM);
+        return;
+    }
+    snprintf(name, length, HWDEP_SYSNAME_TEMPLATE, card_id, device_id);
+
+    ctx = udev_new();
+    if (ctx == NULL) {
+        generate_error(error, errno);
+        g_free(name);
+        return;
+    }
+
+    dev = udev_device_new_from_subsystem_sysname(ctx, "sound", name);
+    if (dev == NULL) {
+        generate_error(error, ENODEV);
+        g_free(name);
+    } else {
+        *sysname = name;
+        udev_device_unref(dev);
+    }
+
+    udev_unref(ctx);
+}
index 4cee162a9af6e078befcc07304ec3926b4b9692b..4eed987d39a74e286aee0963656b47c32931d7a8 100644 (file)
@@ -10,6 +10,9 @@ G_BEGIN_DECLS
 void 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);
+
 G_END_DECLS
 
 #endif