From: Takashi Sakamoto Date: Sun, 21 Jun 2020 12:27:25 +0000 (+0900) Subject: timer: add an API to retrieve current version of protocol in timer interface X-Git-Tag: v0.1.0~6 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=96466ebbee52a7ac6d68228d6d901269fab0fd73;p=alsa-gobject.git timer: add an API to retrieve current version of protocol in timer interface Signed-off-by: Takashi Sakamoto --- diff --git a/src/timer/alsatimer.map b/src/timer/alsatimer.map index 5e42ba7..7cd0574 100644 --- a/src/timer/alsatimer.map +++ b/src/timer/alsatimer.map @@ -33,6 +33,7 @@ ALSA_GOBJECT_0_0_0 { "alsatimer_user_instance_get_type"; "alsatimer_user_instance_new"; "alsatimer_user_instance_open"; + "alsatimer_user_instance_get_protocol_version"; "alsatimer_user_instance_choose_event_data_type"; "alsatimer_user_instance_attach"; "alsatimer_user_instance_attach_as_slave"; diff --git a/src/timer/user-instance.c b/src/timer/user-instance.c index 9c92ebc..b7e49dc 100644 --- a/src/timer/user-instance.c +++ b/src/timer/user-instance.c @@ -26,6 +26,7 @@ struct _ALSATimerUserInstancePrivate { int fd; ALSATimerEventDataType event_data_type; + guint16 proto_ver_triplet[3]; }; G_DEFINE_TYPE_WITH_PRIVATE(ALSATimerUserInstance, alsatimer_user_instance, G_TYPE_OBJECT) @@ -121,6 +122,7 @@ void alsatimer_user_instance_open(ALSATimerUserInstance *self, gint open_flag, { ALSATimerUserInstancePrivate *priv; char *devnode; + int proto_ver; g_return_if_fail(ALSATIMER_IS_USER_INSTANCE(self)); priv = alsatimer_user_instance_get_instance_private(self); @@ -134,7 +136,20 @@ void alsatimer_user_instance_open(ALSATimerUserInstance *self, gint open_flag, g_free(devnode); if (priv->fd < 0) { generate_error(error, errno); + return; } + + // Remember the version of protocol currently used. + if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_PVERSION, &proto_ver) < 0) { + generate_error(error, errno); + close(priv->fd); + priv->fd = -1; + return; + } + + priv->proto_ver_triplet[0] = SNDRV_PROTOCOL_MAJOR(proto_ver); + priv->proto_ver_triplet[1] = SNDRV_PROTOCOL_MINOR(proto_ver); + priv->proto_ver_triplet[2] = SNDRV_PROTOCOL_MICRO(proto_ver); } ALSATimerUserInstance *alsatimer_user_instance_new() @@ -142,6 +157,35 @@ ALSATimerUserInstance *alsatimer_user_instance_new() return g_object_new(ALSATIMER_TYPE_USER_INSTANCE, NULL); } +/** + * alsatimer_user_instance_get_protocol_version: + * @self: A #ALSATimerUserInstance. + * @proto_ver_triplet: (array fixed-size=3)(out)(transfer none): The version of + * protocol currently used. + * @error: A #GError. + * + * Get the version of timer protocol currently used. The version is + * represented as the array with three elements; major, minor, and micro version + * in the order. The length of major version is 16 bit, the length of minor + * and micro version is 8 bit each. + */ +void alsatimer_user_instance_get_protocol_version(ALSATimerUserInstance *self, + const guint16 *proto_ver_triplet[3], + GError **error) +{ + ALSATimerUserInstancePrivate *priv; + + g_return_if_fail(ALSATIMER_IS_USER_INSTANCE(self)); + priv = alsatimer_user_instance_get_instance_private(self); + + if (priv->fd < 0) { + generate_error(error, ENXIO); + return; + } + + *proto_ver_triplet = (const guint16 *)priv->proto_ver_triplet; +} + /** * alsatimer_user_instance_choose_event_data_type: * @self: A #ALSATimerUserInstance. diff --git a/src/timer/user-instance.h b/src/timer/user-instance.h index 1ea4478..f6d8786 100644 --- a/src/timer/user-instance.h +++ b/src/timer/user-instance.h @@ -77,6 +77,10 @@ ALSATimerUserInstance *alsatimer_user_instance_new(); void alsatimer_user_instance_open(ALSATimerUserInstance *self, gint open_flag, GError **error); +void alsatimer_user_instance_get_protocol_version(ALSATimerUserInstance *self, + const guint16 *proto_ver_triplet[3], + GError **error); + void alsatimer_user_instance_choose_event_data_type(ALSATimerUserInstance *self, ALSATimerEventDataType event_data_type, GError **error); diff --git a/tests/alsatimer-user-instance b/tests/alsatimer-user-instance index 49e925a..fb34eed 100644 --- a/tests/alsatimer-user-instance +++ b/tests/alsatimer-user-instance @@ -14,6 +14,7 @@ props = () methods = ( 'new', 'open', + 'get_protocol_version', 'choose_event_data_type', 'attach', 'attach_as_slave',