]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
ctl: elem-info-single-array: add interface for single array element information
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Thu, 2 Jun 2022 09:26:26 +0000 (18:26 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Thu, 2 Jun 2022 09:32:52 +0000 (18:32 +0900)
The most type of element has value array. The count of elements in the
array is expressed as count in structure.

This commit adds gobject interface for the type of information. It should
implements one property; the count of elements.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/ctl/alsactl.h
src/ctl/alsactl.map
src/ctl/elem-info-single-array.c [new file with mode: 0644]
src/ctl/elem-info-single-array.h [new file with mode: 0644]
src/ctl/meson.build
src/ctl/privates.h

index f82de62b5248d2e1eb7e72b0a62527c030e1ccaa..5955d9d44d58b616e258e620ed0dec20eda18d24 100644 (file)
@@ -15,6 +15,7 @@
 #include <elem-id.h>
 
 #include <elem-info-common.h>
+#include <elem-info-single-array.h>
 
 #include <card-info.h>
 #include <elem-info.h>
index d332d25cc7b44f361a4999b5623b51c65f292393..4a5efd459e065233cb0f139f46da9fbc8dd41f2e 100644 (file)
@@ -86,4 +86,6 @@ ALSA_GOBJECT_0_3_0 {
 
     "alsactl_elem_info_iec60958_get_type";
     "alsactl_elem_info_iec60958_new";
+
+    "alsactl_elem_info_single_array_get_type";
 } ALSA_GOBJECT_0_2_0;
diff --git a/src/ctl/elem-info-single-array.c b/src/ctl/elem-info-single-array.c
new file mode 100644 (file)
index 0000000..37343f4
--- /dev/null
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: LGPL-3.0-or-later
+#include "privates.h"
+
+/**
+ * ALSACtlElemInfoSingleArray:
+ * An interface to express information of element which has single value array.
+ *
+ * A [iface@ElemInfoSingleArray] should be implemented by the type of information for element
+ * whieh has single value array.
+ *
+ * Since: 0.3.
+ */
+
+static void alsactl_elem_info_single_array_default_init(ALSACtlElemInfoSingleArrayInterface *iface);
+
+G_DEFINE_INTERFACE(ALSACtlElemInfoSingleArray, alsactl_elem_info_single_array,
+                   ALSACTL_TYPE_ELEM_INFO_COMMON)
+
+static void alsactl_elem_info_single_array_default_init(ALSACtlElemInfoSingleArrayInterface *iface)
+{
+    /**
+     * ALSACtlElemInfoSingleArray:value-count:
+     *
+     * The count of elements in value array of the element.
+     *
+     * Since: 0.3.
+     */
+    g_object_interface_install_property(iface,
+        g_param_spec_uint(VALUE_COUNT_PROP_NAME, VALUE_COUNT_PROP_NAME,
+                          "The count of elements in value array of the element",
+                          0, G_MAXUINT,
+                          1,
+                          G_PARAM_READWRITE));
+}
+
+void elem_info_single_array_class_override_properties(GObjectClass *gobject_class)
+{
+    elem_info_common_class_override_properties(gobject_class);
+
+    g_object_class_override_property(gobject_class, ELEM_INFO_SINGLE_ARRAY_PROP_VALUE_COUNT,
+                                     VALUE_COUNT_PROP_NAME);
+}
+
+void elem_info_single_array_set_property(struct snd_ctl_elem_info *data, GObject *obj, guint id,
+                                         const GValue *val, GParamSpec *spec)
+{
+    switch (id) {
+    case ELEM_INFO_SINGLE_ARRAY_PROP_VALUE_COUNT:
+        data->count = g_value_get_uint(val);
+        break;
+    default:
+        elem_info_common_set_property(data, obj, id, val, spec);
+        break;
+    }
+}
+
+void elem_info_single_array_get_property(const struct snd_ctl_elem_info *data, GObject *obj, guint id,
+                                         GValue *val, GParamSpec *spec)
+{
+    switch (id) {
+    case ELEM_INFO_SINGLE_ARRAY_PROP_VALUE_COUNT:
+        g_value_set_uint(val, data->count);
+        break;
+    default:
+        elem_info_common_get_property(data, obj, id, val, spec);
+        break;
+    }
+}
diff --git a/src/ctl/elem-info-single-array.h b/src/ctl/elem-info-single-array.h
new file mode 100644 (file)
index 0000000..0cb37b5
--- /dev/null
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: LGPL-3.0-or-later
+#ifndef __ALSA_GOBJECT_ALSACTL_ELEM_INFO_SINGLE_ARRAY_H__
+#define __ALSA_GOBJECT_ALSACTL_ELEM_INFO_SINGLE_ARRAY_H__
+
+#include <alsactl.h>
+
+G_BEGIN_DECLS
+
+#define ALSACTL_TYPE_ELEM_INFO_SINGLE_ARRAY     (alsactl_elem_info_single_array_get_type())
+
+G_DECLARE_INTERFACE(ALSACtlElemInfoSingleArray, alsactl_elem_info_single_array, ALSACTL,
+                    ELEM_INFO_SINGLE_ARRAY, GObject)
+
+struct _ALSACtlElemInfoSingleArrayInterface {
+    GTypeInterface parent_iface;
+};
+
+G_END_DECLS
+
+#endif
index 4d38df23c3aa4484b398c83636cffa4eac97b9e4..9073ae7ebae9a025ec54aead18159ff635f3d466 100644 (file)
@@ -17,6 +17,7 @@ sources = files(
   'elem-value.c',
   'elem-info-common.c',
   'elem-info-iec60958.c',
+  'elem-info-single-array.c',
 )
 
 headers = files(
@@ -28,6 +29,7 @@ headers = files(
   'elem-value.h',
   'elem-info-common.h',
   'elem-info-iec60958.h',
+  'elem-info-single-array.h',
 )
 
 privates = files(
index d1db0eb076da3bd5166d1f782bdaecb0b2a89f5f..14ac223f3bc80f152e380448b335e9629c93dba8 100644 (file)
@@ -38,6 +38,19 @@ void elem_info_common_get_property(const struct snd_ctl_elem_info *data, GObject
 
 #define VALUE_COUNT_PROP_NAME   "value-count"
 
+enum elem_info_single_array_prop_type {
+    ELEM_INFO_SINGLE_ARRAY_PROP_VALUE_COUNT = ELEM_INFO_COMMON_PROP_COUNT,
+    ELEM_INFO_SINGLE_ARRAY_PROP_COUNT,
+};
+
+void elem_info_single_array_class_override_properties(GObjectClass *gobject_class);
+
+void elem_info_single_array_set_property(struct snd_ctl_elem_info *data, GObject *obj, guint id,
+                                      const GValue *val, GParamSpec *spec);
+
+void elem_info_single_array_get_property(const struct snd_ctl_elem_info *data, GObject *obj, guint id,
+                                      GValue *val, GParamSpec *spec);
+
 G_END_DECLS
 
 #endif