]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
timer: user_instance: add API to choose the type of event to read
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Fri, 12 Jun 2020 13:24:02 +0000 (22:24 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Fri, 12 Jun 2020 22:49:01 +0000 (07:49 +0900)
Currently ALSATimer.UserInstance has any attach API to decide the type of
event to read. In design of ALSA Timer core, the attach API has two
functionality; to attach or to detach with error for absent timer device.
Current implementation has inconvenient for the functionality due to
execution to choose the type of event in advance. The execution fails
when the instance is already attached.

This commit adds a new API to choose the type of event and split the
call from any attach API.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/timer/alsatimer.map
src/timer/user-instance.c
src/timer/user-instance.h
tests/alsatimer-user-instance

index 616660c96e7937951399c206f785a291fa13fdb8..f8113048f378861abc7b16aa248bd714739e5a4b 100644 (file)
@@ -32,6 +32,7 @@ ALSA_GOBJECT_0_0_0 {
     "alsatimer_user_instance_get_type";
     "alsatimer_user_instance_new";
     "alsatimer_user_instance_open";
+    "alsatimer_user_instance_choose_event_data_type";
     "alsatimer_user_instance_attach";
     "alsatimer_user_instance_attach_as_slave";
     "alsatimer_user_instance_get_info";
index e025b4286a058c5e45300cda2a1d90763f84f904..3d7db23cea70bc7e50b8ab71a90a168acd3cf2ce 100644 (file)
@@ -139,35 +139,55 @@ ALSATimerUserInstance *alsatimer_user_instance_new()
     return g_object_new(ALSATIMER_TYPE_USER_INSTANCE, NULL);
 }
 
+/**
+ * alsatimer_user_instance_choose_event_data_type:
+ * @self: A #ALSATimerUserInstance.
+ * @event_data_type: The type of event data, one of ALSATimerEventDataType.
+ * @error: A #GError.
+ *
+ * Choose the type of event data to receive.
+ *
+ * The call of function is successful just before the instance is not attached
+ * yet. ALSATIMER_EVENT_DATA_TYPE_TICK is used as a default if the function is
+ * not called for ALSATIMER_EVENT_DATA_TYPE_TSTAMP explicitly.
+ */
+void alsatimer_user_instance_choose_event_data_type(ALSATimerUserInstance *self,
+                                        ALSATimerEventDataType event_data_type,
+                                        GError **error)
+{
+    ALSATimerUserInstancePrivate *priv;
+    int tread;
+
+    g_return_if_fail(ALSATIMER_IS_USER_INSTANCE(self));
+    priv = alsatimer_user_instance_get_instance_private(self);
+
+    tread = (int)event_data_type;
+    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_TREAD, &tread) < 0)
+        generate_error(error, errno);
+    else
+        priv->event_data_type = event_data_type;
+}
+
 /**
  * alsatimer_user_instance_attach:
  * @self: A #ALSATimerUserInstance.
  * @device_id: A #ALSATimerDeviceId to which the instance is attached.
- * @event_data_type: The type of event data, one of ALSATimerEventDataType.
  * @error: A #GError.
  *
- * Attach the instance to the timer device.
+ * Attach the instance to the timer device. If the given device_id is for
+ * absent timer device, the instance can be detached with error.
  */
 void alsatimer_user_instance_attach(ALSATimerUserInstance *self,
                                     ALSATimerDeviceId *device_id,
-                                    ALSATimerEventDataType event_data_type,
                                     GError **error)
 {
     ALSATimerUserInstancePrivate *priv;
-    int tread;
     struct snd_timer_select sel = {0};
 
     g_return_if_fail(ALSATIMER_IS_USER_INSTANCE(self));
     g_return_if_fail(device_id != NULL);
     priv = alsatimer_user_instance_get_instance_private(self);
 
-    tread = (int)event_data_type;
-    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_TREAD, &tread) < 0) {
-        generate_error(error, errno);
-        return;
-    }
-    priv->event_data_type = event_data_type;
-
     sel.id = *device_id;
     if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_SELECT, &sel) < 0)
         generate_error(error, errno);
@@ -179,7 +199,6 @@ void alsatimer_user_instance_attach(ALSATimerUserInstance *self,
  * @slave_class: The class identifier of master instance, one of
  *               #ALSATimerSlaveClass.
  * @slave_id: The numerical identifier of master instance.
- * @event_data_type: The type of event data, one of ALSATimerEventDataType.
  * @error: A #GError.
  *
  * Attach the instance to timer device as an slave to another instance indicated
@@ -188,27 +207,21 @@ void alsatimer_user_instance_attach(ALSATimerUserInstance *self,
  * 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.
+ *
+ * Attach the instance to the timer device. If the given device_id is for
+ * absent timer device, the instance can be detached with error.
  */
 void alsatimer_user_instance_attach_as_slave(ALSATimerUserInstance *self,
                                         ALSATimerSlaveClass slave_class,
                                         int slave_id,
-                                        ALSATimerEventDataType event_data_type,
                                         GError **error)
 {
     ALSATimerUserInstancePrivate *priv;
-    int tread;
     struct snd_timer_select sel = {0};
 
     g_return_if_fail(ALSATIMER_IS_USER_INSTANCE(self));
     priv = alsatimer_user_instance_get_instance_private(self);
 
-    tread = (int)event_data_type;
-    if (ioctl(priv->fd, SNDRV_TIMER_IOCTL_TREAD, &tread) < 0) {
-        generate_error(error, errno);
-        return;
-    }
-    priv->event_data_type = event_data_type;
-
     sel.id.dev_class = SNDRV_TIMER_CLASS_SLAVE;
     sel.id.dev_sclass = slave_class;
     sel.id.device = slave_id;
index dfdce98326e84da0cbcd4431278347366c6b36fe..7ceab6fa5ae522750698cfce34e3bd056e8b2cd0 100644 (file)
@@ -77,15 +77,17 @@ ALSATimerUserInstance *alsatimer_user_instance_new();
 void alsatimer_user_instance_open(ALSATimerUserInstance *self, gint open_flag,
                                   GError **error);
 
+void alsatimer_user_instance_choose_event_data_type(ALSATimerUserInstance *self,
+                                        ALSATimerEventDataType event_data_type,
+                                        GError **error);
+
 void alsatimer_user_instance_attach(ALSATimerUserInstance *self,
                                     ALSATimerDeviceId *device_id,
-                                    ALSATimerEventDataType event_data_type,
                                     GError **error);
 
 void alsatimer_user_instance_attach_as_slave(ALSATimerUserInstance *self,
                                         ALSATimerSlaveClass slave_class,
                                         int slave_id,
-                                        ALSATimerEventDataType event_data_type,
                                         GError **error);
 
 void alsatimer_user_instance_get_info(ALSATimerUserInstance *self,
index 48de47ee5fb15f49da335495fb8ddac7702dbc2a..49e925ac77040187e3154f5524105c05caf118e5 100644 (file)
@@ -14,6 +14,7 @@ props = ()
 methods = (
     'new',
     'open',
+    'choose_event_data_type',
     'attach',
     'attach_as_slave',
     'get_info',