]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
ctl: elem_id: add access methods and constructor
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 18 Nov 2019 04:22:44 +0000 (13:22 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 1 Dec 2019 05:38:53 +0000 (14:38 +0900)
src/ctl/alsactl.map
src/ctl/elem-id.c
src/ctl/elem-id.h
tests/alsactl-elem-id [new file with mode: 0644]

index 1abe9b27546f4f99280775738cd8a9c41ce902be..df95f633da9d25ccc863e73e189bed1ae0c989a8 100644 (file)
@@ -19,6 +19,14 @@ ALSA_GOBJECT_0_0_0 {
     "alsactl_card_info_get_type";
 
     "alsactl_elem_id_get_type";
+    "alsactl_elem_id_new_by_numid";
+    "alsactl_elem_id_new_by_name";
+    "alsactl_elem_id_get_numid";
+    "alsactl_elem_id_get_iface";
+    "alsactl_elem_id_get_device_id";
+    "alsactl_elem_id_get_subdevice_id";
+    "alsactl_elem_id_get_name";
+    "alsactl_elem_id_get_index";
   local:
     *;
 };
index d0ab59b858891efc690ced42cd9fdb4750477d8d..3ff99696a0c2cc99c664963746d7791e71175c9d 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: LGPL-3.0-or-later
 #include "elem-id.h"
+#include "privates.h"
 
 ALSACtlElemId *ctl_elem_id_copy(const ALSACtlElemId *self)
 {
@@ -7,3 +8,125 @@ ALSACtlElemId *ctl_elem_id_copy(const ALSACtlElemId *self)
 }
 
 G_DEFINE_BOXED_TYPE(ALSACtlElemId, alsactl_elem_id, ctl_elem_id_copy, g_free);
+
+/**
+ * alsactl_elem_id_new_by_numid:
+ * @numid: The numerical ID of the element.
+ *
+ * Allocates and return an instance of ALSACtlElemId by the numerical ID.
+ *
+ * Returns: (transfer full): A #ALSACtlElemId.
+ */
+ALSACtlElemId *alsactl_elem_id_new_by_numid(guint numid)
+{
+    struct snd_ctl_elem_id *id;
+
+    id = g_malloc0(sizeof(*id));
+    id->numid = numid;
+
+    return (ALSACtlElemId *)id;
+}
+
+/**
+ * alsactl_elem_id_new_by_name:
+ * @iface:          The interface of element, one of ALSACtlElemIfaceType.
+ * @device_id:      The numerical ID of device to which the element belongs.
+ * @subdevice_id:   The numerical ID of subdevice to which the element belongs.
+ * @name:           The name of element, up to 44 byte
+ *                  (=SNDRV_CTL_ELEM_ID_NAME_MAXLEN) including terminator.
+ * @index:          The index of element in a set of elements with the same name.
+ *
+ * Allocates and return an instance of ALSACtlElemId by the name.
+ *
+ * Returns: (transfer full): A #ALSACtlElemId.
+ */
+ALSACtlElemId *alsactl_elem_id_new_by_name(ALSACtlElemIfaceType iface,
+                                           guint device_id, guint subdevice_id,
+                                           const gchar *name, guint index)
+{
+    struct snd_ctl_elem_id *id;
+
+    id = g_malloc0(sizeof(*id));
+
+    id->iface = iface;
+    id->device = device_id;
+    id->subdevice = subdevice_id;
+    g_strlcpy((char *)id->name, name, sizeof(id->name));
+    id->index = index;
+
+    return (ALSACtlElemId *)id;
+}
+
+/**
+ * alsactl_elem_id_get_numid:
+ * @self: A #ALSACtlElemId.
+ * @numid: (out): The numerical ID of element.
+ *
+ * Get the numerical ID of element.
+ */
+void alsactl_elem_id_get_numid(const ALSACtlElemId *self, guint *numid)
+{
+    *numid = self->numid;
+}
+
+/**
+ * alsactl_elem_id_get_iface:
+ * @self: A #ALSACtlElemId.
+ * @iface: (out): The interface of element.
+ *
+ * Get the interface of element.
+ */
+void alsactl_elem_id_get_iface(const ALSACtlElemId *self,
+                               ALSACtlElemIfaceType *iface)
+{
+    *iface = self->iface;
+}
+
+/**
+ * alsactl_elem_id_get_device_id:
+ * @self: A #ALSACtlElemId.
+ * @device_id: (out): The numerical ID of device to which the element belongs.
+ *
+ * Get the numerical ID of device to which the element belongs.
+ */
+void alsactl_elem_id_get_device_id(const ALSACtlElemId *self, guint *device_id)
+{
+    *device_id = self->device;
+}
+
+/**
+ * alsactl_elem_id_get_subdevice_id:
+ * @self: A #ALSACtlElemId.
+ * @subdevice_id: (out): The numerical ID of subdevice to which the element belongs.
+ *
+ * Get the numerical ID of element.
+ */
+void alsactl_elem_id_get_subdevice_id(const ALSACtlElemId *self,
+                                      guint *subdevice_id)
+{
+    *subdevice_id = self->subdevice;
+}
+
+/**
+ * alsactl_elem_id_get_name:
+ * @self: A #ALSACtlElemId.
+ * @name: (transfer none)(out): The name of element.
+ *
+ * Get the name of element.
+ */
+void alsactl_elem_id_get_name(const ALSACtlElemId *self, const gchar **name)
+{
+    *name = (const gchar *)self->name;
+}
+
+/**
+ * alsactl_elem_id_get_index:
+ * @self: A #ALSACtlElemId.
+ * @index: (out): The index of element.
+ *
+ * Get the index of element.
+ */
+void alsactl_elem_id_get_index(const ALSACtlElemId *self, guint *index)
+{
+    *index = self->index;
+}
index 7d62c53d3506ac0c0c6cb1c4dccbfdca144c9747..748234868fb792b402ee1714f4740c2cc29c08ae 100644 (file)
@@ -5,6 +5,8 @@
 #include <glib.h>
 #include <glib-object.h>
 
+#include <ctl/alsactl-enums.h>
+
 #include <sound/asound.h>
 
 G_BEGIN_DECLS
@@ -15,6 +17,20 @@ typedef struct snd_ctl_elem_id ALSACtlElemId;
 
 GType alsactl_elem_id_get_type() G_GNUC_CONST;
 
+ALSACtlElemId *alsactl_elem_id_new_by_numid(guint numid);
+ALSACtlElemId *alsactl_elem_id_new_by_name(ALSACtlElemIfaceType iface,
+                                           guint device_id, guint subdevice_id,
+                                           const gchar *name, guint index);
+
+void alsactl_elem_id_get_numid(const ALSACtlElemId *self, guint *numid);
+void alsactl_elem_id_get_iface(const ALSACtlElemId *self,
+                               ALSACtlElemIfaceType *iface);
+void alsactl_elem_id_get_device_id(const ALSACtlElemId *self, guint *device_id);
+void alsactl_elem_id_get_subdevice_id(const ALSACtlElemId *self,
+                                      guint *subdevice_id);
+void alsactl_elem_id_get_name(const ALSACtlElemId *self, const gchar **name);
+void alsactl_elem_id_get_index(const ALSACtlElemId *self, guint *index);
+
 G_END_DECLS
 
 #endif
diff --git a/tests/alsactl-elem-id b/tests/alsactl-elem-id
new file mode 100644 (file)
index 0000000..155b141
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+
+from sys import exit
+from errno import ENXIO
+
+from helper import test
+
+import gi
+gi.require_version('ALSACtl', '0.0')
+from gi.repository import ALSACtl
+
+target = ALSACtl.ElemId()
+props = (
+    'numid',
+    'iface',
+    'device',
+    'subdevice',
+    'name',
+    'index',
+)
+methods = ()
+signals = ()
+
+if not test(target, props, methods, signals):
+    exit(ENXIO)