From: Takashi Sakamoto Date: Fri, 29 Nov 2019 06:42:21 +0000 (+0900) Subject: ctl: elem_value: add properties and constructor X-Git-Tag: v0.1.0~387 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=5fdc0e24f9597a28a785a6f1b5f61447704932da;p=alsa-gobject.git ctl: elem_value: add properties and constructor --- diff --git a/src/ctl/elem-value.c b/src/ctl/elem-value.c index edf5df6..dcd5455 100644 --- a/src/ctl/elem-value.c +++ b/src/ctl/elem-value.c @@ -1,14 +1,67 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "elem-value.h" -G_DEFINE_TYPE(ALSACtlElemValue, alsactl_elem_value, G_TYPE_OBJECT) +#include + +struct _ALSACtlElemValuePrivate { + struct snd_ctl_elem_value value; +}; +G_DEFINE_TYPE_WITH_PRIVATE(ALSACtlElemValue, alsactl_elem_value, G_TYPE_OBJECT) + +enum ctl_elem_value_prop_type { + CTL_ELEM_VALUE_PROP_ELEM_ID = 1, + CTL_ELEM_VALUE_PROP_COUNT, +}; +static GParamSpec *ctl_elem_value_props[CTL_ELEM_VALUE_PROP_COUNT] = { NULL, }; + +static void ctl_elem_value_get_property(GObject *obj, guint id, GValue *val, + GParamSpec *spec) +{ + ALSACtlElemValue *self = ALSACTL_ELEM_VALUE(obj); + ALSACtlElemValuePrivate *priv = + alsactl_elem_value_get_instance_private(self); + + switch (id) { + case CTL_ELEM_VALUE_PROP_ELEM_ID: + { + g_value_set_static_boxed(val, (const ALSACtlElemId *)&priv->value.id); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, id, spec); + break; + } +} static void alsactl_elem_value_class_init(ALSACtlElemValueClass *klass) { - return; + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->get_property = ctl_elem_value_get_property; + + ctl_elem_value_props[CTL_ELEM_VALUE_PROP_ELEM_ID] = + g_param_spec_boxed("elem-id", "elem-id", + "The identifier of element", + ALSACTL_TYPE_ELEM_ID, + G_PARAM_READABLE); + + g_object_class_install_properties(gobject_class, CTL_ELEM_VALUE_PROP_COUNT, + ctl_elem_value_props); } static void alsactl_elem_value_init(ALSACtlElemValue *self) { return; } + +/** + * alsactl_elem_value_new: + * + * Allocate and return an instance of ALSACtlElemValue. + * + * Returns: (transfer full): A #ALSACtlElemValue. + */ +ALSACtlElemValue *alsactl_elem_value_new() +{ + return g_object_new(ALSACTL_TYPE_ELEM_VALUE, NULL); +} diff --git a/src/ctl/elem-value.h b/src/ctl/elem-value.h index d89b9ce..c31efb7 100644 --- a/src/ctl/elem-value.h +++ b/src/ctl/elem-value.h @@ -5,6 +5,8 @@ #include #include +#include + G_BEGIN_DECLS #define ALSACTL_TYPE_ELEM_VALUE (alsactl_elem_value_get_type()) @@ -31,9 +33,12 @@ G_BEGIN_DECLS typedef struct _ALSACtlElemValue ALSACtlElemValue; typedef struct _ALSACtlElemValueClass ALSACtlElemValueClass; +typedef struct _ALSACtlElemValuePrivate ALSACtlElemValuePrivate; struct _ALSACtlElemValue { GObject parent_instance; + + ALSACtlElemValuePrivate *priv; }; struct _ALSACtlElemValueClass { @@ -42,6 +47,8 @@ struct _ALSACtlElemValueClass { GType alsactl_elem_value_get_type() G_GNUC_CONST; +ALSACtlElemValue *alsactl_elem_value_new(); + G_END_DECLS #endif diff --git a/tests/alsactl-elem-value b/tests/alsactl-elem-value index 50d06db..7e5675b 100644 --- a/tests/alsactl-elem-value +++ b/tests/alsactl-elem-value @@ -10,7 +10,9 @@ gi.require_version('ALSACtl', '0.0') from gi.repository import ALSACtl target = ALSACtl.ElemValue() -props = () +props = ( + 'elem-id', +) methods = () signals = ()