From 3a6d788bf47d31f08f5f699c96b60f720bf33421 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Sun, 9 Feb 2020 12:20:53 +0900 Subject: [PATCH] timer: user_instance: add an API to attach user instance to another instance as slave Signed-off-by: Takashi Sakamoto --- src/timer/user-instance.c | 33 +++++++++++++++++++++++++++++++++ src/timer/user-instance.h | 5 +++++ tests/alsatimer-user-instance | 1 + 3 files changed, 39 insertions(+) diff --git a/src/timer/user-instance.c b/src/timer/user-instance.c index 5d2143d..c5b8cbb 100644 --- a/src/timer/user-instance.c +++ b/src/timer/user-instance.c @@ -96,3 +96,36 @@ void alsatimer_user_instance_attach(ALSATimerUserInstance *self, if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_SELECT, &sel) < 0) generate_error(error, errno); } + +/** + * alsatimer_user_instance_attach_as_slave: + * @self: A #ALSATimerUserInstance. + * @slave_class: The class identifier of master instance, one of + * #ALSATimerSlaveClass. + * @slave_id: The numerical identifier of master instance. + * @error: A #GError. + * + * Attach the instance to timer device as an slave to another instance indicated + * by a pair of slave_class and slave_id. If the slave_class is for application + * (=ALSATIMER_SLAVE_CLASS_APPLICATION), the slave_id is for the PID of + * application process which owns the instance of timer. If the slave_class is + * for ALSA sequencer (=ALSATIMER_SLAVE_CLASS_SEQUENCER), the slave_id is the + * numerical ID of queue bound for timer device. + */ +void alsatimer_user_instance_attach_as_slave(ALSATimerUserInstance *self, + ALSATimerSlaveClass slave_class, + int slave_id, + GError **error) +{ + ALSATimerUserInstancePrivate *priv; + struct snd_timer_select sel = {0}; + + g_return_if_fail(ALSATIMER_IS_USER_INSTANCE(self)); + priv = alsatimer_user_instance_get_instance_private(self); + + sel.id.dev_class = SNDRV_TIMER_CLASS_SLAVE; + sel.id.dev_sclass = slave_class; + sel.id.device = slave_id; + if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_SELECT, &sel) < 0) + generate_error(error, errno); +} diff --git a/src/timer/user-instance.h b/src/timer/user-instance.h index 0041350..0b0fb8e 100644 --- a/src/timer/user-instance.h +++ b/src/timer/user-instance.h @@ -55,6 +55,11 @@ void alsatimer_user_instance_attach(ALSATimerUserInstance *self, ALSATimerDeviceId *device_id, GError **error); +void alsatimer_user_instance_attach_as_slave(ALSATimerUserInstance *self, + ALSATimerSlaveClass slave_class, + int slave_id, + GError **error); + G_END_DECLS #endif diff --git a/tests/alsatimer-user-instance b/tests/alsatimer-user-instance index 5e7c1a5..39a5656 100644 --- a/tests/alsatimer-user-instance +++ b/tests/alsatimer-user-instance @@ -15,6 +15,7 @@ methods = ( 'new', 'open', 'attach', + 'attach_as_slave', ) signals = () -- 2.47.3