From: Takashi Sakamoto Date: Sun, 9 Feb 2020 03:20:53 +0000 (+0900) Subject: timer: device_id: add accessor methods and constructors X-Git-Tag: v0.1.0~361 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=dcd983281ef8ea319ecb485267b50cd4da2b0703;p=alsa-gobject.git timer: device_id: add accessor methods and constructors Signed-off-by: Takashi Sakamoto --- diff --git a/src/timer/alsatimer.map b/src/timer/alsatimer.map index 5ecf1fb..6d9dcb2 100644 --- a/src/timer/alsatimer.map +++ b/src/timer/alsatimer.map @@ -11,6 +11,11 @@ ALSA_GOBJECT_0_0_0 { "alsatimer_get_devnode"; "alsatimer_device_id_get_type"; + "alsatimer_device_id_new"; + "alsatimer_device_id_get_class"; + "alsatimer_device_id_get_card_id"; + "alsatimer_device_id_get_device_id"; + "alsatimer_device_id_get_subdevice_id"; local: *; }; diff --git a/src/timer/device-id.c b/src/timer/device-id.c index e9238a0..65793e4 100644 --- a/src/timer/device-id.c +++ b/src/timer/device-id.c @@ -7,3 +7,80 @@ ALSATimerDeviceId *timer_device_id_copy(const ALSATimerDeviceId *self) } G_DEFINE_BOXED_TYPE(ALSATimerDeviceId, alsatimer_device_id, timer_device_id_copy, g_free) + +/** + * alsatimer_device_id_new: + * @class: The class of device, one of #ALSATImerClass. + * @card_id: The numerical ID of relevant sound card. + * @device_id: The numerical ID of relevant device. + * @subdevice_id: The numerical ID of relevant subdevice. + * + * Allocate and return an instance of ALSATimerDeviceId. + * + * Returns: (transfer full): A #ALSATimerDeviceId. + */ +ALSATimerDeviceId *alsatimer_device_id_new(ALSATimerClass class, + gint card_id, gint device_id, + gint subdevice_id) +{ + ALSATimerDeviceId *self = g_malloc0(sizeof(*self)); + + self->dev_class= class; + self->card = card_id; + self->device = device_id; + self->subdevice = subdevice_id; + + return self; +} + +/** + * alsatimer_device_id_get_class: + * @self: A #ALSATimerDeviceId. + * @class: (out): The class of timer, one of #ALSATimerClass. + * + * Get the class of timer. + */ +void alsatimer_device_id_get_class(const ALSATimerDeviceId *self, + ALSATimerClass *class) +{ + *class = self->dev_class; +} + +/** + * alsatimer_device_id_get_card_id: + * @self: A #ALSATimerDeviceId. + * @card_id: (out): The numerical ID of sound card to which the timer belongs. + * + * Get the numerical ID of sound card to which the device belongs. + */ +void alsatimer_device_id_get_card_id(const ALSATimerDeviceId *self, + gint *card_id) +{ + *card_id = self->card; +} + +/** + * alsatimer_device_id_get_device_id: + * @self: A #ALSATimerDeviceId. + * @device_id: (out): The numerical ID of device to which the timer belongs. + * + * Get the numerical ID of device to which the timer belongs. + */ +void alsatimer_device_id_get_device_id(const ALSATimerDeviceId *self, + gint *device_id) +{ + *device_id = self->device; +} + +/** + * alsatimer_device_id_get_subdevice_id: + * @self: A #ALSATimerDeviceId. + * @subdevice_id: (out): The numerical ID of subdevice to which the timer belongs. + * + * Get the numerical ID of subdevice to which the timer belongs. + */ +void alsatimer_device_id_get_subdevice_id(const ALSATimerDeviceId *self, + gint *subdevice_id) +{ + *subdevice_id = self->subdevice; +} diff --git a/src/timer/device-id.h b/src/timer/device-id.h index 069d620..85f9f94 100644 --- a/src/timer/device-id.h +++ b/src/timer/device-id.h @@ -5,6 +5,8 @@ #include #include +#include + #include G_BEGIN_DECLS @@ -15,6 +17,22 @@ typedef struct snd_timer_id ALSATimerDeviceId; GType alsatimer_device_id_get_type() G_GNUC_CONST; +ALSATimerDeviceId *alsatimer_device_id_new(ALSATimerClass class, + gint card_id, gint device_id, + gint subdevice_id); + +void alsatimer_device_id_get_class(const ALSATimerDeviceId *self, + ALSATimerClass *class); + +void alsatimer_device_id_get_card_id(const ALSATimerDeviceId *self, + gint *card_id); + +void alsatimer_device_id_get_device_id(const ALSATimerDeviceId *self, + gint *device_id); + +void alsatimer_device_id_get_subdevice_id(const ALSATimerDeviceId *self, + gint *subdevice_id); + G_END_DECLS #endif diff --git a/tests/alsatimer-device-id b/tests/alsatimer-device-id new file mode 100644 index 0000000..f5b1e25 --- /dev/null +++ b/tests/alsatimer-device-id @@ -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('ALSATimer', '0.0') +from gi.repository import ALSATimer + +target = ALSATimer.DeviceId() +props = ( + 'class', + 'slave-class', + 'card-id', + 'device-id', + 'subdevice-id', +) +methods = ( + 'new', +) +signals = () + +if not test(target, props, methods, signals): + exit(ENXIO)