From: Takashi Sakamoto Date: Thu, 2 Jun 2022 09:26:26 +0000 (+0900) Subject: ctl: elem-info-single-array: add interface for single array element information X-Git-Tag: v0.3.0~119 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=e0322a2d5aff426c0bb8f67d31477515c96d26c0;p=alsa-gobject.git ctl: elem-info-single-array: add interface for single array element information 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 --- diff --git a/src/ctl/alsactl.h b/src/ctl/alsactl.h index f82de62..5955d9d 100644 --- a/src/ctl/alsactl.h +++ b/src/ctl/alsactl.h @@ -15,6 +15,7 @@ #include #include +#include #include #include diff --git a/src/ctl/alsactl.map b/src/ctl/alsactl.map index d332d25..4a5efd4 100644 --- a/src/ctl/alsactl.map +++ b/src/ctl/alsactl.map @@ -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 index 0000000..37343f4 --- /dev/null +++ b/src/ctl/elem-info-single-array.c @@ -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 index 0000000..0cb37b5 --- /dev/null +++ b/src/ctl/elem-info-single-array.h @@ -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 + +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 diff --git a/src/ctl/meson.build b/src/ctl/meson.build index 4d38df2..9073ae7 100644 --- a/src/ctl/meson.build +++ b/src/ctl/meson.build @@ -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( diff --git a/src/ctl/privates.h b/src/ctl/privates.h index d1db0eb..14ac223 100644 --- a/src/ctl/privates.h +++ b/src/ctl/privates.h @@ -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