From b06b0f85fb5ae063c1d4089876124ddf7cda49a5 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Thu, 2 Jun 2022 18:26:26 +0900 Subject: [PATCH] ctl: elem-info-iec60958: add class for element information of IEC60958 type The element information of IEC60958 type doesn't deliver the count of value since the element has two types of data array according to IEC60958; channel status and user data. This commit adds gobject class for the information. Signed-off-by: Takashi Sakamoto --- src/ctl/alsactl.h | 1 + src/ctl/alsactl.map | 3 ++ src/ctl/elem-info-iec60958.c | 74 ++++++++++++++++++++++++++++++++ src/ctl/elem-info-iec60958.h | 22 ++++++++++ src/ctl/meson.build | 2 + tests/alsactl-elem-info-iec60958 | 25 +++++++++++ tests/meson.build | 1 + 7 files changed, 128 insertions(+) create mode 100644 src/ctl/elem-info-iec60958.c create mode 100644 src/ctl/elem-info-iec60958.h create mode 100644 tests/alsactl-elem-info-iec60958 diff --git a/src/ctl/alsactl.h b/src/ctl/alsactl.h index 5a7a593..f82de62 100644 --- a/src/ctl/alsactl.h +++ b/src/ctl/alsactl.h @@ -18,6 +18,7 @@ #include #include +#include #include #include diff --git a/src/ctl/alsactl.map b/src/ctl/alsactl.map index 335d29a..d332d25 100644 --- a/src/ctl/alsactl.map +++ b/src/ctl/alsactl.map @@ -83,4 +83,7 @@ ALSA_GOBJECT_0_3_0 { "alsactl_elem_info_set_enum_data"; "alsactl_elem_info_common_get_type"; + + "alsactl_elem_info_iec60958_get_type"; + "alsactl_elem_info_iec60958_new"; } ALSA_GOBJECT_0_2_0; diff --git a/src/ctl/elem-info-iec60958.c b/src/ctl/elem-info-iec60958.c new file mode 100644 index 0000000..5fc77dd --- /dev/null +++ b/src/ctl/elem-info-iec60958.c @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +#include "privates.h" + +/** + * ALSACtlElemInfoIec60958: + * An object to express information for iec60958 type of element. + * + * A [class@GObject.Object] derived object class for iec60958 type of element. + * + * The object wraps `struct snd_ctl_elem_info` in UAPI of Linux sound subsystem. + */ +typedef struct { + struct snd_ctl_elem_info data; +} ALSACtlElemInfoIec60958Private; + +static void elem_info_common_iface_init(ALSACtlElemInfoCommonInterface *iface); + +G_DEFINE_TYPE_WITH_CODE(ALSACtlElemInfoIec60958, alsactl_elem_info_iec60958, G_TYPE_OBJECT, + G_ADD_PRIVATE(ALSACtlElemInfoIec60958) + G_IMPLEMENT_INTERFACE(ALSACTL_TYPE_ELEM_INFO_COMMON, + elem_info_common_iface_init)) + +static void ctl_elem_info_iec60958_set_property(GObject *obj, guint id, const GValue *val, + GParamSpec *spec) +{ + ALSACtlElemInfoIec60958 *self = ALSACTL_ELEM_INFO_IEC60958(obj); + ALSACtlElemInfoIec60958Private *priv = alsactl_elem_info_iec60958_get_instance_private(self); + + elem_info_common_set_property(&priv->data, obj, id, val, spec); +} + +static void ctl_elem_info_iec60958_get_property(GObject *obj, guint id, GValue *val, + GParamSpec *spec) +{ + ALSACtlElemInfoIec60958 *self = ALSACTL_ELEM_INFO_IEC60958(obj); + ALSACtlElemInfoIec60958Private *priv = alsactl_elem_info_iec60958_get_instance_private(self); + + elem_info_common_get_property(&priv->data, obj, id, val, spec); +} + +static void alsactl_elem_info_iec60958_class_init(ALSACtlElemInfoIec60958Class *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->set_property = ctl_elem_info_iec60958_set_property; + gobject_class->get_property = ctl_elem_info_iec60958_get_property; + + elem_info_common_class_override_properties(gobject_class); +} + +static void alsactl_elem_info_iec60958_init(ALSACtlElemInfoIec60958 *self) +{ + ALSACtlElemInfoIec60958Private *priv = alsactl_elem_info_iec60958_get_instance_private(self); + // MEMO: ALSA control core check it but meaningless. + priv->data.count = 1; +} + +static void elem_info_common_iface_init(ALSACtlElemInfoCommonInterface *iface) +{ + return; +} + +/** + * alsactl_elem_info_iec60958_new: + * + * Allocate and return an instance of [class@ElemInfoIec60958]. + * + * Returns: An instance of [class@ElemInfoIec60958]. + */ +ALSACtlElemInfoIec60958 *alsactl_elem_info_iec60958_new() +{ + return g_object_new(ALSACTL_TYPE_ELEM_INFO_IEC60958, + ELEM_TYPE_PROP_NAME, ALSACTL_ELEM_TYPE_IEC60958, NULL); +} diff --git a/src/ctl/elem-info-iec60958.h b/src/ctl/elem-info-iec60958.h new file mode 100644 index 0000000..1f9f929 --- /dev/null +++ b/src/ctl/elem-info-iec60958.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +#ifndef __ALSA_GOBJECT_ALSACTL_ELEM_INFO_IEC60958_H__ +#define __ALSA_GOBJECT_ALSACTL_ELEM_INFO_IEC60958_H__ + +#include + +G_BEGIN_DECLS + +#define ALSACTL_TYPE_ELEM_INFO_IEC60958 (alsactl_elem_info_iec60958_get_type()) + +G_DECLARE_DERIVABLE_TYPE(ALSACtlElemInfoIec60958, alsactl_elem_info_iec60958, ALSACTL, + ELEM_INFO_IEC60958, GObject) + +struct _ALSACtlElemInfoIec60958Class { + GObjectClass parent_class; +}; + +ALSACtlElemInfoIec60958 *alsactl_elem_info_iec60958_new(); + +G_END_DECLS + +#endif diff --git a/src/ctl/meson.build b/src/ctl/meson.build index 175303f..4d38df2 100644 --- a/src/ctl/meson.build +++ b/src/ctl/meson.build @@ -16,6 +16,7 @@ sources = files( 'elem-info.c', 'elem-value.c', 'elem-info-common.c', + 'elem-info-iec60958.c', ) headers = files( @@ -26,6 +27,7 @@ headers = files( 'elem-info.h', 'elem-value.h', 'elem-info-common.h', + 'elem-info-iec60958.h', ) privates = files( diff --git a/tests/alsactl-elem-info-iec60958 b/tests/alsactl-elem-info-iec60958 new file mode 100644 index 0000000..5b98601 --- /dev/null +++ b/tests/alsactl-elem-info-iec60958 @@ -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.ElemInfoIec60958.new() +props = ( + 'elem-id', + 'elem-type', + 'access', + 'owner', +) +methods = ( + 'new', +) +signals = () + +if not test(target, props, methods, signals): + exit(ENXIO) diff --git a/tests/meson.build b/tests/meson.build index d667395..a6f3c16 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -7,6 +7,7 @@ tests = { 'alsactl-card', 'alsactl-card-info', 'alsactl-elem-info', + 'alsactl-elem-info-iec60958', 'alsactl-elem-value', ], 'timer': [ -- 2.47.3