]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
ctl: elem-info-common: add common interface for element information
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Thu, 2 Jun 2022 09:26:26 +0000 (18:26 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Thu, 2 Jun 2022 09:26:26 +0000 (18:26 +0900)
In UAPI of ALSA, element information is expressed with union to support
several types of element.

This commit adds common interface for the information. It should
implements four properties; the identifier, the type, the set of access
flags, and PID of owner.

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

index b53797877edfc09980f414028efb1e02a6b516ca..5a7a59322ead98ae9a555f90119c5691eb1e7df9 100644 (file)
@@ -14,6 +14,8 @@
 
 #include <elem-id.h>
 
+#include <elem-info-common.h>
+
 #include <card-info.h>
 #include <elem-info.h>
 #include <elem-value.h>
index a3b62c01ef203c6ced082a0df6cee403b2a555f3..335d29a8862e802adadcb698ede56021965925a7 100644 (file)
@@ -81,4 +81,6 @@ ALSA_GOBJECT_0_3_0 {
     "alsactl_elem_info_set_int64_data";
     "alsactl_elem_info_get_enum_data";
     "alsactl_elem_info_set_enum_data";
+
+    "alsactl_elem_info_common_get_type";
 } ALSA_GOBJECT_0_2_0;
diff --git a/src/ctl/elem-info-common.c b/src/ctl/elem-info-common.c
new file mode 100644 (file)
index 0000000..4ac6b0b
--- /dev/null
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: LGPL-3.0-or-later
+#include "privates.h"
+
+/**
+ * ALSACtlElemInfoCommon:
+ * An interface to express common features of element information.
+ *
+ * A [iface@ElemInfoCommon] should be implemented by any type of element information.
+ *
+ * Since: 0.3.
+ */
+
+static void alsactl_elem_info_common_default_init(ALSACtlElemInfoCommonInterface *iface);
+
+G_DEFINE_INTERFACE(ALSACtlElemInfoCommon, alsactl_elem_info_common, G_TYPE_OBJECT)
+
+static void alsactl_elem_info_common_default_init(ALSACtlElemInfoCommonInterface *iface)
+{
+    /**
+     * ALSACtlElemInfoCommon:elem-id:
+     *
+     * The identifier of element.
+     *
+     * Since: 0.3.
+     */
+    g_object_interface_install_property(iface,
+        g_param_spec_boxed(ELEM_ID_PROP_NAME, ELEM_ID_PROP_NAME,
+                           "The identifier of element",
+                           ALSACTL_TYPE_ELEM_ID,
+                           G_PARAM_READABLE));
+
+    /**
+     * ALSACtlElemInfoCommon:elem-type:
+     *
+     * The type of element, one of [enum@ElemType].
+     *
+     * Since: 0.3.
+     */
+    g_object_interface_install_property(iface,
+        g_param_spec_enum(ELEM_TYPE_PROP_NAME, ELEM_TYPE_PROP_NAME,
+                          "The type for element, one of ALSACtlElemType",
+                          ALSACTL_TYPE_ELEM_TYPE,
+                          ALSACTL_ELEM_TYPE_NONE,
+                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /**
+     * ALSACtlElemInfoCommon:access:
+     *
+     * The access permission for the element with [flags@ElemAccessFlag].
+     *
+     * Since: 0.3.
+     */
+    g_object_interface_install_property(iface,
+        g_param_spec_flags(ACCESS_PROP_NAME, ACCESS_PROP_NAME,
+                           "The access permission for the element with ALSACtlElemAccessFlag",
+                           ALSACTL_TYPE_ELEM_ACCESS_FLAG,
+                           ALSACTL_ELEM_ACCESS_FLAG_READ,
+                           G_PARAM_READWRITE));
+
+    /**
+     * ALSACtlElemInfoCommon:owner:
+     *
+     * The value of PID for process to own the element.
+     *
+     * Since: 0.3.
+     */
+    g_object_interface_install_property(iface,
+        g_param_spec_int(OWNER_PROP_NAME, OWNER_PROP_NAME,
+                         "The value of PID for process to own the element",
+                         G_MININT, G_MAXINT,
+                         -1,
+                         G_PARAM_READABLE));
+}
+
+void elem_info_common_class_override_properties(GObjectClass *gobject_class)
+{
+    g_object_class_override_property(gobject_class, ELEM_INFO_COMMON_PROP_ELEM_ID,
+                                     ELEM_ID_PROP_NAME);
+
+    g_object_class_override_property(gobject_class, ELEM_INFO_COMMON_PROP_ELEM_TYPE,
+                                     ELEM_TYPE_PROP_NAME);
+
+    g_object_class_override_property(gobject_class, ELEM_INFO_COMMON_PROP_ACCESS,
+                                     ACCESS_PROP_NAME);
+
+    g_object_class_override_property(gobject_class, ELEM_INFO_COMMON_PROP_OWNER,
+                                     OWNER_PROP_NAME);
+}
+
+void elem_info_common_set_property(struct snd_ctl_elem_info *data, GObject *obj, guint id,
+                                   const GValue *val, GParamSpec *spec)
+{
+    switch (id) {
+    case ELEM_INFO_COMMON_PROP_ELEM_ID:
+    {
+        const struct snd_ctl_elem_id *src = g_value_get_boxed(val);
+        data->id = *src;
+        break;
+    }
+    case ELEM_INFO_COMMON_PROP_ELEM_TYPE:
+        data->type = (snd_ctl_elem_type_t)g_value_get_enum(val);
+        break;
+    case ELEM_INFO_COMMON_PROP_ACCESS:
+        data->access = (unsigned int)g_value_get_flags(val);
+        break;
+    case ELEM_INFO_COMMON_PROP_OWNER:
+        data->owner = (__kernel_pid_t)g_value_get_int(val);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec);
+        break;
+    }
+}
+
+void elem_info_common_get_property(const struct snd_ctl_elem_info *data, GObject *obj, guint id,
+                                   GValue *val, GParamSpec *spec)
+{
+    switch (id) {
+    case ELEM_INFO_COMMON_PROP_ELEM_ID:
+        g_value_set_static_boxed(val, &data->id);
+        break;
+    case ELEM_INFO_COMMON_PROP_ELEM_TYPE:
+        g_value_set_enum(val, (ALSACtlElemType)data->type);
+        break;
+    case ELEM_INFO_COMMON_PROP_ACCESS:
+        g_value_set_flags(val, data->access);
+        break;
+    case ELEM_INFO_COMMON_PROP_OWNER:
+        g_value_set_int(val, data->owner);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec);
+        break;
+    }
+}
diff --git a/src/ctl/elem-info-common.h b/src/ctl/elem-info-common.h
new file mode 100644 (file)
index 0000000..3e95530
--- /dev/null
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: LGPL-3.0-or-later
+#ifndef __ALSA_GOBJECT_ALSACTL_ELEM_INFO_COMMON_H__
+#define __ALSA_GOBJECT_ALSACTL_ELEM_INFO_COMMON_H__
+
+#include <alsactl.h>
+
+G_BEGIN_DECLS
+
+#define ALSACTL_TYPE_ELEM_INFO_COMMON       (alsactl_elem_info_common_get_type())
+
+G_DECLARE_INTERFACE(ALSACtlElemInfoCommon, alsactl_elem_info_common, ALSACTL, ELEM_INFO_COMMON,
+                    GObject)
+
+struct _ALSACtlElemInfoCommonInterface {
+    GTypeInterface parent_iface;
+};
+
+G_END_DECLS
+
+#endif
index 4dfc6f1c6c1e16195e86110b6cbeda49abb38aa2..175303f134109e5a712eb498fdbfbe53a2f0ec68 100644 (file)
@@ -15,6 +15,7 @@ sources = files(
   'elem-id.c',
   'elem-info.c',
   'elem-value.c',
+  'elem-info-common.c',
 )
 
 headers = files(
@@ -24,6 +25,7 @@ headers = files(
   'elem-id.h',
   'elem-info.h',
   'elem-value.h',
+  'elem-info-common.h',
 )
 
 privates = files(
index 522d91c60e4371963d4580cfa0b4c95be0dd91a5..d1db0eb076da3bd5166d1f782bdaecb0b2a89f5f 100644 (file)
@@ -15,6 +15,29 @@ void ctl_elem_info_refer_private(ALSACtlElemInfo *self,
 void ctl_elem_value_refer_private(ALSACtlElemValue *self,
                                   struct snd_ctl_elem_value **value);
 
+#define ELEM_ID_PROP_NAME       "elem-id"
+#define ELEM_TYPE_PROP_NAME     "elem-type"
+#define ACCESS_PROP_NAME        "access"
+#define OWNER_PROP_NAME         "owner"
+
+enum elem_info_common_prop_type {
+    ELEM_INFO_COMMON_PROP_ELEM_ID = 1,
+    ELEM_INFO_COMMON_PROP_ELEM_TYPE,
+    ELEM_INFO_COMMON_PROP_ACCESS,
+    ELEM_INFO_COMMON_PROP_OWNER,
+    ELEM_INFO_COMMON_PROP_COUNT,
+};
+
+void elem_info_common_class_override_properties(GObjectClass *gobject_class);
+
+void elem_info_common_set_property(struct snd_ctl_elem_info *data, GObject *obj, guint id,
+                                   const GValue *val, GParamSpec *spec);
+
+void elem_info_common_get_property(const struct snd_ctl_elem_info *data, GObject *obj, guint id,
+                                   GValue *val, GParamSpec *spec);
+
+#define VALUE_COUNT_PROP_NAME   "value-count"
+
 G_END_DECLS
 
 #endif