From bf9f8f2c56666222370641e939f3d355dccd67f6 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Thu, 2 Jun 2022 18:26:26 +0900 Subject: [PATCH] ctl: elem-info-common: add common interface for element information 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 --- src/ctl/alsactl.h | 2 + src/ctl/alsactl.map | 2 + src/ctl/elem-info-common.c | 135 +++++++++++++++++++++++++++++++++++++ src/ctl/elem-info-common.h | 20 ++++++ src/ctl/meson.build | 2 + src/ctl/privates.h | 23 +++++++ 6 files changed, 184 insertions(+) create mode 100644 src/ctl/elem-info-common.c create mode 100644 src/ctl/elem-info-common.h diff --git a/src/ctl/alsactl.h b/src/ctl/alsactl.h index b537978..5a7a593 100644 --- a/src/ctl/alsactl.h +++ b/src/ctl/alsactl.h @@ -14,6 +14,8 @@ #include +#include + #include #include #include diff --git a/src/ctl/alsactl.map b/src/ctl/alsactl.map index a3b62c0..335d29a 100644 --- a/src/ctl/alsactl.map +++ b/src/ctl/alsactl.map @@ -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 index 0000000..4ac6b0b --- /dev/null +++ b/src/ctl/elem-info-common.c @@ -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 index 0000000..3e95530 --- /dev/null +++ b/src/ctl/elem-info-common.h @@ -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 + +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 diff --git a/src/ctl/meson.build b/src/ctl/meson.build index 4dfc6f1..175303f 100644 --- a/src/ctl/meson.build +++ b/src/ctl/meson.build @@ -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( diff --git a/src/ctl/privates.h b/src/ctl/privates.h index 522d91c..d1db0eb 100644 --- a/src/ctl/privates.h +++ b/src/ctl/privates.h @@ -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 -- 2.47.3