From: Takashi Sakamoto Date: Mon, 18 Nov 2019 04:22:44 +0000 (+0900) Subject: ctl: elem_id: add access methods and constructor X-Git-Tag: v0.1.0~417 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=1ea369785cc1da71848a209d3fb21bc21059fbc5;p=alsa-gobject.git ctl: elem_id: add access methods and constructor --- diff --git a/src/ctl/alsactl.map b/src/ctl/alsactl.map index 1abe9b2..df95f63 100644 --- a/src/ctl/alsactl.map +++ b/src/ctl/alsactl.map @@ -19,6 +19,14 @@ ALSA_GOBJECT_0_0_0 { "alsactl_card_info_get_type"; "alsactl_elem_id_get_type"; + "alsactl_elem_id_new_by_numid"; + "alsactl_elem_id_new_by_name"; + "alsactl_elem_id_get_numid"; + "alsactl_elem_id_get_iface"; + "alsactl_elem_id_get_device_id"; + "alsactl_elem_id_get_subdevice_id"; + "alsactl_elem_id_get_name"; + "alsactl_elem_id_get_index"; local: *; }; diff --git a/src/ctl/elem-id.c b/src/ctl/elem-id.c index d0ab59b..3ff9969 100644 --- a/src/ctl/elem-id.c +++ b/src/ctl/elem-id.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: LGPL-3.0-or-later #include "elem-id.h" +#include "privates.h" ALSACtlElemId *ctl_elem_id_copy(const ALSACtlElemId *self) { @@ -7,3 +8,125 @@ ALSACtlElemId *ctl_elem_id_copy(const ALSACtlElemId *self) } G_DEFINE_BOXED_TYPE(ALSACtlElemId, alsactl_elem_id, ctl_elem_id_copy, g_free); + +/** + * alsactl_elem_id_new_by_numid: + * @numid: The numerical ID of the element. + * + * Allocates and return an instance of ALSACtlElemId by the numerical ID. + * + * Returns: (transfer full): A #ALSACtlElemId. + */ +ALSACtlElemId *alsactl_elem_id_new_by_numid(guint numid) +{ + struct snd_ctl_elem_id *id; + + id = g_malloc0(sizeof(*id)); + id->numid = numid; + + return (ALSACtlElemId *)id; +} + +/** + * alsactl_elem_id_new_by_name: + * @iface: The interface of element, one of ALSACtlElemIfaceType. + * @device_id: The numerical ID of device to which the element belongs. + * @subdevice_id: The numerical ID of subdevice to which the element belongs. + * @name: The name of element, up to 44 byte + * (=SNDRV_CTL_ELEM_ID_NAME_MAXLEN) including terminator. + * @index: The index of element in a set of elements with the same name. + * + * Allocates and return an instance of ALSACtlElemId by the name. + * + * Returns: (transfer full): A #ALSACtlElemId. + */ +ALSACtlElemId *alsactl_elem_id_new_by_name(ALSACtlElemIfaceType iface, + guint device_id, guint subdevice_id, + const gchar *name, guint index) +{ + struct snd_ctl_elem_id *id; + + id = g_malloc0(sizeof(*id)); + + id->iface = iface; + id->device = device_id; + id->subdevice = subdevice_id; + g_strlcpy((char *)id->name, name, sizeof(id->name)); + id->index = index; + + return (ALSACtlElemId *)id; +} + +/** + * alsactl_elem_id_get_numid: + * @self: A #ALSACtlElemId. + * @numid: (out): The numerical ID of element. + * + * Get the numerical ID of element. + */ +void alsactl_elem_id_get_numid(const ALSACtlElemId *self, guint *numid) +{ + *numid = self->numid; +} + +/** + * alsactl_elem_id_get_iface: + * @self: A #ALSACtlElemId. + * @iface: (out): The interface of element. + * + * Get the interface of element. + */ +void alsactl_elem_id_get_iface(const ALSACtlElemId *self, + ALSACtlElemIfaceType *iface) +{ + *iface = self->iface; +} + +/** + * alsactl_elem_id_get_device_id: + * @self: A #ALSACtlElemId. + * @device_id: (out): The numerical ID of device to which the element belongs. + * + * Get the numerical ID of device to which the element belongs. + */ +void alsactl_elem_id_get_device_id(const ALSACtlElemId *self, guint *device_id) +{ + *device_id = self->device; +} + +/** + * alsactl_elem_id_get_subdevice_id: + * @self: A #ALSACtlElemId. + * @subdevice_id: (out): The numerical ID of subdevice to which the element belongs. + * + * Get the numerical ID of element. + */ +void alsactl_elem_id_get_subdevice_id(const ALSACtlElemId *self, + guint *subdevice_id) +{ + *subdevice_id = self->subdevice; +} + +/** + * alsactl_elem_id_get_name: + * @self: A #ALSACtlElemId. + * @name: (transfer none)(out): The name of element. + * + * Get the name of element. + */ +void alsactl_elem_id_get_name(const ALSACtlElemId *self, const gchar **name) +{ + *name = (const gchar *)self->name; +} + +/** + * alsactl_elem_id_get_index: + * @self: A #ALSACtlElemId. + * @index: (out): The index of element. + * + * Get the index of element. + */ +void alsactl_elem_id_get_index(const ALSACtlElemId *self, guint *index) +{ + *index = self->index; +} diff --git a/src/ctl/elem-id.h b/src/ctl/elem-id.h index 7d62c53..7482348 100644 --- a/src/ctl/elem-id.h +++ b/src/ctl/elem-id.h @@ -5,6 +5,8 @@ #include #include +#include + #include G_BEGIN_DECLS @@ -15,6 +17,20 @@ typedef struct snd_ctl_elem_id ALSACtlElemId; GType alsactl_elem_id_get_type() G_GNUC_CONST; +ALSACtlElemId *alsactl_elem_id_new_by_numid(guint numid); +ALSACtlElemId *alsactl_elem_id_new_by_name(ALSACtlElemIfaceType iface, + guint device_id, guint subdevice_id, + const gchar *name, guint index); + +void alsactl_elem_id_get_numid(const ALSACtlElemId *self, guint *numid); +void alsactl_elem_id_get_iface(const ALSACtlElemId *self, + ALSACtlElemIfaceType *iface); +void alsactl_elem_id_get_device_id(const ALSACtlElemId *self, guint *device_id); +void alsactl_elem_id_get_subdevice_id(const ALSACtlElemId *self, + guint *subdevice_id); +void alsactl_elem_id_get_name(const ALSACtlElemId *self, const gchar **name); +void alsactl_elem_id_get_index(const ALSACtlElemId *self, guint *index); + G_END_DECLS #endif diff --git a/tests/alsactl-elem-id b/tests/alsactl-elem-id new file mode 100644 index 0000000..155b141 --- /dev/null +++ b/tests/alsactl-elem-id @@ -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.ElemId() +props = ( + 'numid', + 'iface', + 'device', + 'subdevice', + 'name', + 'index', +) +methods = () +signals = () + +if not test(target, props, methods, signals): + exit(ENXIO)