"alsahwdep_get_device_id_list";
"alsahwdep_get_hwdep_sysname";
"alsahwdep_get_hwdep_devnode";
+ "alsahwdep_get_device_info";
"alsahwdep_device_info_get_type";
local:
// SPDX-License-Identifier: LGPL-3.0-or-later
-#include "device-info.h"
-
-#include <sound/asound.h>
+#include "privates.h"
struct _ALSAHwdepDeviceInfoPrivate {
struct snd_hwdep_info info;
switch (id) {
case HWDEP_DEVICE_INFO_PROP_DEVICE_ID:
- priv->info.device = g_value_get_uint(val);
+ g_value_set_uint(val, priv->info.device);
break;
case HWDEP_DEVICE_INFO_PROP_CARD_ID:
- priv->info.card = g_value_get_int(val);
+ g_value_set_int(val, priv->info.card);
break;
case HWDEP_DEVICE_INFO_PROP_ID:
- strncpy((char *)priv->info.id, g_value_get_string(val), sizeof(priv->info.id));
+ g_value_set_static_string(val, (char *)priv->info.id);
break;
case HWDEP_DEVICE_INFO_PROP_NAME:
- strncpy((char *)priv->info.name, g_value_get_string(val), sizeof(priv->info.name));
+ g_value_set_static_string(val, (char *)priv->info.name);
break;
case HWDEP_DEVICE_INFO_PROP_IFACE:
- priv->info.iface = (int)g_value_get_enum(val);
+ g_value_set_enum(val, (ALSAHwdepIfaceType)priv->info.iface);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec);
{
return;
}
+
+void hwdep_device_info_refer_private(ALSAHwdepDeviceInfo *self,
+ struct snd_hwdep_info **info)
+{
+ ALSAHwdepDeviceInfoPrivate *priv =
+ alsahwdep_device_info_get_instance_private(self);
+
+ *info = &priv->info;
+}
#ifndef __ALSA_GOBJECT_ALSAHWDEP_PRIVATES__H__
#define __ALSA_GOBJECT_ALSAHWDEP_PRIVATES__H__
+#include "device-info.h"
+
+#include <sound/asound.h>
+
G_BEGIN_DECLS
GQuark alsahwdep_error_quark(void);
g_set_error(err, alsahwdep_error_quark(), errno, \
__FILE__ ":%d: %s", __LINE__, strerror(errno))
+void hwdep_device_info_refer_private(ALSAHwdepDeviceInfo *self,
+ struct snd_hwdep_info **info);
+
G_END_DECLS
#endif
// 'C' is required apart from emulation of Open Sound System.
#define PREFIX_SYSNAME_TEMPLATE "hwC%u"
#define HWDEP_SYSNAME_TEMPLATE "hwC%uD%u"
+#define CTL_SYSNAME_TEMPLATE "controlC%u"
static void prepare_udev_enum(struct udev_enumerate **enumerator, GError **error)
{
udev_device_unref(dev);
udev_unref(ctx);
}
+
+static void hwdep_perform_ctl_ioctl(guint card_id, long request, void *data,
+ GError **error)
+{
+ unsigned int length;
+ char *sysname;
+ struct udev *ctx;
+ struct udev_device *dev;
+ const char *devnode;
+ int fd;
+
+ length = strlen(CTL_SYSNAME_TEMPLATE) + calculate_digits(card_id) + 1;
+ sysname = g_try_malloc0(length);
+ if (sysname == NULL) {
+ generate_error(error, ENOMEM);
+ return;
+ }
+ snprintf(sysname, length, CTL_SYSNAME_TEMPLATE, card_id);
+
+ ctx = udev_new();
+ if (ctx == NULL) {
+ generate_error(error, errno);
+ goto err_sysname;
+ }
+
+ dev = udev_device_new_from_subsystem_sysname(ctx, "sound", sysname);
+ if (dev == NULL) {
+ generate_error(error, errno);
+ goto err_ctx;
+ }
+
+ devnode = udev_device_get_devnode(dev);
+ if (devnode == NULL) {
+ generate_error(error, ENODEV);
+ goto err_device;
+ }
+
+ fd = open(devnode, O_RDONLY | O_NONBLOCK);
+ if (fd < 0) {
+ generate_error(error, errno);
+ goto err_device;
+ }
+
+ if (ioctl(fd, request, data) < 0)
+ generate_error(error, errno);
+err_device:
+ udev_device_unref(dev);
+err_ctx:
+ udev_unref(ctx);
+err_sysname:
+ g_free(sysname);
+}
+
+/**
+ * alsahwdep_get_device_info:
+ * @card_id: The numberical value for sound card to query.
+ * @device_id: The numerical value of hwdep device to query.
+ * @device_info: (out): The information of the device.
+ * @error: A #GError.
+ */
+void alsahwdep_get_device_info(guint card_id, guint device_id,
+ ALSAHwdepDeviceInfo **device_info,
+ GError **error)
+{
+ struct snd_hwdep_info *info;
+
+ g_return_if_fail(device_info != NULL);
+
+ *device_info = g_object_new(ALSAHWDEP_TYPE_DEVICE_INFO, NULL);
+ hwdep_device_info_refer_private(*device_info, &info);
+
+ info->device = device_id;
+ info->card = card_id;
+ hwdep_perform_ctl_ioctl(card_id, SNDRV_CTL_IOCTL_HWDEP_INFO, info, error);
+ if (*error != NULL)
+ g_object_unref(*device_info);
+}
#include <glib.h>
#include <glib-object.h>
+#include <hwdep/device-info.h>
+
G_BEGIN_DECLS
void alsahwdep_get_device_id_list(guint card_id, guint **entries,
void 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);
+
G_END_DECLS
#endif