base-modem-at: add optional wait before sending command in a sequence
Can be used for easier command retries where the generic sequence code handles the GTimeout source. Signed-off-by: Dan Williams <dcbw@redhat.com>
This commit is contained in:
committed by
Aleksander Morgado
parent
b3708636b1
commit
ded76a0abb
+34
-10
@@ -91,8 +91,13 @@ typedef struct {
|
||||
gpointer response_processor_context;
|
||||
GDestroyNotify response_processor_context_free;
|
||||
GVariant *result;
|
||||
guint next_command_wait_id;
|
||||
} AtSequenceContext;
|
||||
|
||||
static void at_sequence_parse_response (MMPortSerialAt *port,
|
||||
GAsyncResult *res,
|
||||
GTask *task);
|
||||
|
||||
static void
|
||||
at_sequence_context_free (AtSequenceContext *ctx)
|
||||
{
|
||||
@@ -109,6 +114,11 @@ at_sequence_context_free (AtSequenceContext *ctx)
|
||||
g_object_unref (ctx->parent_cancellable);
|
||||
}
|
||||
|
||||
if (ctx->next_command_wait_id > 0) {
|
||||
g_source_remove (ctx->next_command_wait_id);
|
||||
ctx->next_command_wait_id = 0;
|
||||
}
|
||||
|
||||
if (ctx->result)
|
||||
g_variant_unref (ctx->result);
|
||||
g_free (ctx);
|
||||
@@ -140,6 +150,28 @@ mm_base_modem_at_sequence_full_finish (MMBaseModem *self,
|
||||
return result;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
at_sequence_next_command (GTask *task)
|
||||
{
|
||||
AtSequenceContext *ctx;
|
||||
|
||||
ctx = g_task_get_task_data (task);
|
||||
ctx->next_command_wait_id = 0;
|
||||
|
||||
/* Schedule the next command in the probing group */
|
||||
mm_port_serial_at_command (
|
||||
ctx->port,
|
||||
ctx->current->command,
|
||||
ctx->current->timeout,
|
||||
FALSE,
|
||||
ctx->current->allow_cached,
|
||||
g_task_get_cancellable (task),
|
||||
(GAsyncReadyCallback)at_sequence_parse_response,
|
||||
task);
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
at_sequence_parse_response (MMPortSerialAt *port,
|
||||
GAsyncResult *res,
|
||||
@@ -201,16 +233,8 @@ at_sequence_parse_response (MMPortSerialAt *port,
|
||||
if (processor_result == MM_BASE_MODEM_AT_RESPONSE_PROCESSOR_RESULT_CONTINUE) {
|
||||
ctx->current++;
|
||||
if (ctx->current->command) {
|
||||
/* Schedule the next command in the probing group */
|
||||
mm_port_serial_at_command (
|
||||
ctx->port,
|
||||
ctx->current->command,
|
||||
ctx->current->timeout,
|
||||
FALSE,
|
||||
ctx->current->allow_cached,
|
||||
g_task_get_cancellable (task),
|
||||
(GAsyncReadyCallback)at_sequence_parse_response,
|
||||
task);
|
||||
g_assert (!ctx->next_command_wait_id);
|
||||
ctx->next_command_wait_id = g_timeout_add_seconds (ctx->current->wait_seconds, (GSourceFunc) at_sequence_next_command, task);
|
||||
return;
|
||||
}
|
||||
/* On last command, end. */
|
||||
|
||||
@@ -67,6 +67,8 @@ typedef struct {
|
||||
gboolean allow_cached;
|
||||
/* The response processor */
|
||||
MMBaseModemAtResponseProcessor response_processor;
|
||||
/* Time to wait before sending this command (in seconds) */
|
||||
guint wait_seconds;
|
||||
} MMBaseModemAtCommand;
|
||||
|
||||
/* Generic AT sequence handling, using the best AT port available and without
|
||||
@@ -220,6 +222,7 @@ typedef struct {
|
||||
guint timeout;
|
||||
gboolean allow_cached;
|
||||
MMBaseModemAtResponseProcessor response_processor;
|
||||
guint wait_seconds;
|
||||
} MMBaseModemAtCommandAlloc;
|
||||
|
||||
G_STATIC_ASSERT (sizeof (MMBaseModemAtCommandAlloc) == sizeof (MMBaseModemAtCommand));
|
||||
|
||||
Reference in New Issue
Block a user