From: Takashi Sakamoto Date: Mon, 18 Nov 2019 04:22:44 +0000 (+0900) Subject: rawmidi; add global method to get sysname for rawmidi device of sound card X-Git-Tag: v0.1.0~190 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=d891dde4e0340b311e047c037780c29fdc7aa321;p=alsa-gobject.git rawmidi; add global method to get sysname for rawmidi device of sound card Signed-off-by: Takashi Sakamoto --- diff --git a/src/rawmidi/alsarawmidi.map b/src/rawmidi/alsarawmidi.map index 589359a..efe4be4 100644 --- a/src/rawmidi/alsarawmidi.map +++ b/src/rawmidi/alsarawmidi.map @@ -4,6 +4,7 @@ ALSA_GOBJECT_0_0_0 { "alsarawmidi_stream_pair_info_flag_get_type"; "alsarawmidi_get_device_id_list"; + "alsarawmidi_get_rawmidi_sysname"; local: *; }; diff --git a/src/rawmidi/query.c b/src/rawmidi/query.c index 1f1371a..442a6cb 100644 --- a/src/rawmidi/query.c +++ b/src/rawmidi/query.c @@ -13,6 +13,7 @@ G_DEFINE_QUARK("alsarawmidi-error", alsarawmidi_error) // 'C' is required apart from emulation of Open Sound System. #define PREFIX_SYSNAME_TEMPLATE "midiC%u" +#define RAWMIDI_SYSNAME_TEMPLATE "midiC%uD%u" static void prepare_udev_enum(struct udev_enumerate **enumerator, GError **error) { @@ -195,3 +196,48 @@ end: g_free(prefix); release_udev_enum(enumerator); } + +/** + * alsarawmidi_get_rawmidi_sysname: + * @card_id: The numeridcal ID of sound card. + * @device_id: The numerical ID of rawmidi device for the sound card. + * @sysname: (out): The string for sysname of rawmidi device. + * @error: A #GError. + * + * Allocate sysname for rawmidi device and return it when it exists. + */ +void alsarawmidi_get_rawmidi_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(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); + if (dev == NULL) { + generate_error(error, ENODEV); + g_free(name); + } else { + *sysname = name; + udev_device_unref(dev); + } + + udev_unref(ctx); +} diff --git a/src/rawmidi/query.h b/src/rawmidi/query.h index bb7e5b2..c853226 100644 --- a/src/rawmidi/query.h +++ b/src/rawmidi/query.h @@ -11,6 +11,9 @@ void alsarawmidi_get_device_id_list(guint card_id, guint **entries, gsize *entry_count, GError **error); +void alsarawmidi_get_rawmidi_sysname(guint card_id, guint device_id, + char **sysname, GError **error); + G_END_DECLS #endif