serial: don't run commands when there's already one in-progress
If there's already a command in-progress don't try to send another until the previous one has timed out. Also use g_timeout_add_seconds() since precision doesn't really matter for command timeouts.
This commit is contained in:
@@ -479,9 +479,15 @@ mm_serial_port_schedule_queue_process (MMSerialPort *self)
|
|||||||
MMSerialPortPrivate *priv = MM_SERIAL_PORT_GET_PRIVATE (self);
|
MMSerialPortPrivate *priv = MM_SERIAL_PORT_GET_PRIVATE (self);
|
||||||
GSource *source;
|
GSource *source;
|
||||||
|
|
||||||
if (priv->queue_schedule)
|
if (priv->timeout_id) {
|
||||||
|
/* A command is already in progress */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (priv->queue_schedule) {
|
||||||
/* Already scheduled */
|
/* Already scheduled */
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
source = g_idle_source_new ();
|
source = g_idle_source_new ();
|
||||||
g_source_set_closure (source, g_cclosure_new_object (G_CALLBACK (mm_serial_port_queue_process), G_OBJECT (self)));
|
g_source_set_closure (source, g_cclosure_new_object (G_CALLBACK (mm_serial_port_queue_process), G_OBJECT (self)));
|
||||||
@@ -568,7 +574,7 @@ mm_serial_port_queue_process (gpointer data)
|
|||||||
if (mm_serial_port_send_command (self, info->command, &error)) {
|
if (mm_serial_port_send_command (self, info->command, &error)) {
|
||||||
GSource *source;
|
GSource *source;
|
||||||
|
|
||||||
source = g_timeout_source_new (info->timeout);
|
source = g_timeout_source_new_seconds (info->timeout);
|
||||||
g_source_set_closure (source, g_cclosure_new_object (G_CALLBACK (mm_serial_port_timed_out), G_OBJECT (self)));
|
g_source_set_closure (source, g_cclosure_new_object (G_CALLBACK (mm_serial_port_timed_out), G_OBJECT (self)));
|
||||||
g_source_attach (source, NULL);
|
g_source_attach (source, NULL);
|
||||||
priv->timeout_id = g_source_get_id (source);
|
priv->timeout_id = g_source_get_id (source);
|
||||||
@@ -896,7 +902,7 @@ internal_queue_command (MMSerialPort *self,
|
|||||||
info = g_slice_new0 (MMQueueData);
|
info = g_slice_new0 (MMQueueData);
|
||||||
info->command = g_strdup (command);
|
info->command = g_strdup (command);
|
||||||
info->cached = cached;
|
info->cached = cached;
|
||||||
info->timeout = timeout_seconds * 1000;
|
info->timeout = timeout_seconds;
|
||||||
info->callback = callback;
|
info->callback = callback;
|
||||||
info->user_data = user_data;
|
info->user_data = user_data;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user