]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
rawmidi: add global method to get devnode string for rawmidi device
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 18 Nov 2019 04:22:44 +0000 (13:22 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Sun, 12 Apr 2020 05:30:33 +0000 (14:30 +0900)
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/rawmidi/alsarawmidi.map
src/rawmidi/query.c
src/rawmidi/query.h

index efe4be47e74dfc4b6c7d919442b26e6d68ed93a3..5b375a2eb5a41c670cbf41e8c1f47d97ca5ce24d 100644 (file)
@@ -5,6 +5,7 @@ ALSA_GOBJECT_0_0_0 {
 
     "alsarawmidi_get_device_id_list";
     "alsarawmidi_get_rawmidi_sysname";
+    "alsarawmidi_get_rawmidi_devnode";
   local:
     *;
 };
index 442a6cb1c1e65b87276c5c4b9b16f72e61752abf..4d035f0e55bce99db2f3bee0138dab771ce736e8 100644 (file)
@@ -241,3 +241,58 @@ void alsarawmidi_get_rawmidi_sysname(guint card_id, guint device_id,
 
     udev_unref(ctx);
 }
+
+/**
+ * alsarawmidi_get_rawmidi_devnode:
+ * @card_id: The numeridcal ID of sound card.
+ * @device_id: The numerical ID of rawmidi device for the sound card.
+ * @devnode: (out): The string for devnode of rawmidi device.
+ * @error: A #GError.
+ *
+ * Allocate devnode string for rawmidi device and return it when exists.
+ */
+void alsarawmidi_get_rawmidi_devnode(guint card_id, guint device_id,
+                                     char **devnode, GError **error)
+{
+    unsigned int length;
+    char *name;
+    struct udev *ctx;
+    struct udev_device *dev;
+    const char *node;
+
+    length = strlen(RAWMIDI_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, RAWMIDI_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);
+    g_free(name);
+    if (dev == NULL) {
+        generate_error(error, ENODEV);
+        udev_unref(ctx);
+        return;
+    }
+
+    node = udev_device_get_devnode(dev);
+    if (node == NULL) {
+        generate_error(error, ENOENT);
+    } else {
+        *devnode = strdup(node);
+        if (*devnode == NULL)
+            generate_error(error, ENOMEM);
+    }
+
+    udev_device_unref(dev);
+    udev_unref(ctx);
+}
index c853226c26aa5e79a06c317bc61dbdd1c9f2af54..eb2b7c6e815c1012c355e21f23be47c1209cba72 100644 (file)
@@ -14,6 +14,9 @@ void alsarawmidi_get_device_id_list(guint card_id,
 void alsarawmidi_get_rawmidi_sysname(guint card_id, guint device_id,
                                      char **sysname, GError **error);
 
+void alsarawmidi_get_rawmidi_devnode(guint card_id, guint device_id,
+                                     char **devnode, GError **error);
+
 G_END_DECLS
 
 #endif