From 25cb19addc5ad95ebee9fee7c9007653ef191bd9 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Thu, 2 Jun 2022 18:26:26 +0900 Subject: [PATCH] ctl: elem-info-boolean: add class for element information of boolean type Nothing specific. Signed-off-by: Takashi Sakamoto --- src/ctl/alsactl.h | 1 + src/ctl/alsactl.map | 3 ++ src/ctl/elem-info-boolean.c | 82 +++++++++++++++++++++++++++++++++ src/ctl/elem-info-boolean.h | 22 +++++++++ src/ctl/meson.build | 2 + tests/alsactl-elem-info-boolean | 26 +++++++++++ tests/meson.build | 1 + 7 files changed, 137 insertions(+) create mode 100644 src/ctl/elem-info-boolean.c create mode 100644 src/ctl/elem-info-boolean.h create mode 100644 tests/alsactl-elem-info-boolean diff --git a/src/ctl/alsactl.h b/src/ctl/alsactl.h index 5955d9d..710e13f 100644 --- a/src/ctl/alsactl.h +++ b/src/ctl/alsactl.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include diff --git a/src/ctl/alsactl.map b/src/ctl/alsactl.map index 4a5efd4..96aa3ea 100644 --- a/src/ctl/alsactl.map +++ b/src/ctl/alsactl.map @@ -88,4 +88,7 @@ ALSA_GOBJECT_0_3_0 { "alsactl_elem_info_iec60958_new"; "alsactl_elem_info_single_array_get_type"; + + "alsactl_elem_info_boolean_get_type"; + "alsactl_elem_info_boolean_new"; } ALSA_GOBJECT_0_2_0; diff --git a/src/ctl/elem-info-boolean.c b/src/ctl/elem-info-boolean.c new file mode 100644 index 0000000..331d744 --- /dev/null +++ b/src/ctl/elem-info-boolean.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +#include "privates.h" + +/** + * ALSACtlElemInfoBoolean: + * An object to express information for boolean type of element. + * + * A [class@GObject.Object] derived object class for boolean 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; +} ALSACtlElemInfoBooleanPrivate; + +static void elem_info_common_iface_init(ALSACtlElemInfoCommonInterface *iface); +static void elem_info_single_array_iface_init(ALSACtlElemInfoSingleArrayInterface *iface); + +G_DEFINE_TYPE_WITH_CODE(ALSACtlElemInfoBoolean, alsactl_elem_info_boolean, G_TYPE_OBJECT, + G_ADD_PRIVATE(ALSACtlElemInfoBoolean) + G_IMPLEMENT_INTERFACE(ALSACTL_TYPE_ELEM_INFO_COMMON, + elem_info_common_iface_init) + G_IMPLEMENT_INTERFACE(ALSACTL_TYPE_ELEM_INFO_SINGLE_ARRAY, + elem_info_single_array_iface_init)) + +static void ctl_elem_info_boolean_set_property(GObject *obj, guint id, const GValue *val, + GParamSpec *spec) +{ + ALSACtlElemInfoBoolean *self = ALSACTL_ELEM_INFO_BOOLEAN(obj); + ALSACtlElemInfoBooleanPrivate *priv = alsactl_elem_info_boolean_get_instance_private(self); + struct snd_ctl_elem_info *data = &priv->data; + + elem_info_single_array_set_property(data, obj, id, val, spec); +} + +static void ctl_elem_info_boolean_get_property(GObject *obj, guint id, GValue *val, + GParamSpec *spec) +{ + ALSACtlElemInfoBoolean *self = ALSACTL_ELEM_INFO_BOOLEAN(obj); + ALSACtlElemInfoBooleanPrivate *priv = alsactl_elem_info_boolean_get_instance_private(self); + const struct snd_ctl_elem_info *data = &priv->data; + + elem_info_single_array_get_property(data, obj, id, val, spec); +} + +static void alsactl_elem_info_boolean_class_init(ALSACtlElemInfoBooleanClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->set_property = ctl_elem_info_boolean_set_property; + gobject_class->get_property = ctl_elem_info_boolean_get_property; + + elem_info_single_array_class_override_properties(gobject_class); +} + +static void alsactl_elem_info_boolean_init(ALSACtlElemInfoBoolean *self) +{ + return; +} + +static void elem_info_single_array_iface_init(ALSACtlElemInfoSingleArrayInterface *iface) +{ + return; +} + +static void elem_info_common_iface_init(ALSACtlElemInfoCommonInterface *iface) +{ + return; +} + +/** + * alsactl_elem_info_boolean_new: + * + * Allocate and return an instance of [class@ElemInfoBoolean]. + * + * Returns: An instance of [class@ElemInfoBoolean]. + */ +ALSACtlElemInfoBoolean *alsactl_elem_info_boolean_new() +{ + return g_object_new(ALSACTL_TYPE_ELEM_INFO_BOOLEAN, + ELEM_TYPE_PROP_NAME, ALSACTL_ELEM_TYPE_BOOLEAN, NULL); +} diff --git a/src/ctl/elem-info-boolean.h b/src/ctl/elem-info-boolean.h new file mode 100644 index 0000000..0567859 --- /dev/null +++ b/src/ctl/elem-info-boolean.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later +#ifndef __ALSA_GOBJECT_ALSACTL_ELEM_INFO_BOOLEAN_H__ +#define __ALSA_GOBJECT_ALSACTL_ELEM_INFO_BOOLEAN_H__ + +#include + +G_BEGIN_DECLS + +#define ALSACTL_TYPE_ELEM_INFO_BOOLEAN (alsactl_elem_info_boolean_get_type()) + +G_DECLARE_DERIVABLE_TYPE(ALSACtlElemInfoBoolean, alsactl_elem_info_boolean, ALSACTL, + ELEM_INFO_BOOLEAN, GObject) + +struct _ALSACtlElemInfoBooleanClass { + GObjectClass parent_class; +}; + +ALSACtlElemInfoBoolean *alsactl_elem_info_boolean_new(); + +G_END_DECLS + +#endif diff --git a/src/ctl/meson.build b/src/ctl/meson.build index 9073ae7..2e49ab4 100644 --- a/src/ctl/meson.build +++ b/src/ctl/meson.build @@ -18,6 +18,7 @@ sources = files( 'elem-info-common.c', 'elem-info-iec60958.c', 'elem-info-single-array.c', + 'elem-info-boolean.c', ) headers = files( @@ -30,6 +31,7 @@ headers = files( 'elem-info-common.h', 'elem-info-iec60958.h', 'elem-info-single-array.h', + 'elem-info-boolean.h', ) privates = files( diff --git a/tests/alsactl-elem-info-boolean b/tests/alsactl-elem-info-boolean new file mode 100644 index 0000000..5000201 --- /dev/null +++ b/tests/alsactl-elem-info-boolean @@ -0,0 +1,26 @@ +#!/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.ElemInfoBoolean.new() +props = ( + 'elem-id', + 'elem-type', + 'access', + 'owner', + 'value-count', +) +methods = ( + 'new', +) +signals = () + +if not test(target, props, methods, signals): + exit(ENXIO) diff --git a/tests/meson.build b/tests/meson.build index a6f3c16..015cd68 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -8,6 +8,7 @@ tests = { 'alsactl-card-info', 'alsactl-elem-info', 'alsactl-elem-info-iec60958', + 'alsactl-elem-info-boolean', 'alsactl-elem-value', ], 'timer': [ -- 2.47.3