diff options
-rw-r--r-- | plugins/mm-plugin-zte.c | 2 | ||||
-rw-r--r-- | src/mm-plugin-base.c | 71 | ||||
-rw-r--r-- | src/mm-plugin-base.h | 2 |
3 files changed, 50 insertions, 25 deletions
diff --git a/plugins/mm-plugin-zte.c b/plugins/mm-plugin-zte.c index 81268cd5..37033e01 100644 --- a/plugins/mm-plugin-zte.c +++ b/plugins/mm-plugin-zte.c @@ -129,7 +129,7 @@ supports_port (MMPluginBase *base, * 1235f71b20c92cded4abd976ccc5010649aae1a0 and * f38ad328acfdc6ce29dd1380602c546b064161ae for more details. */ - mm_plugin_base_supports_task_set_custom_init_command (task, + mm_plugin_base_supports_task_add_custom_init_command (task, "ATE0+CPMS?", 3, custom_init_response_cb, diff --git a/src/mm-plugin-base.c b/src/mm-plugin-base.c index 2c5a08c2..336f78ca 100644 --- a/src/mm-plugin-base.c +++ b/src/mm-plugin-base.c @@ -93,6 +93,14 @@ G_DEFINE_TYPE (MMPluginBaseSupportsTask, mm_plugin_base_supports_task, G_TYPE_OB #define MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_PLUGIN_BASE_SUPPORTS_TASK, MMPluginBaseSupportsTaskPrivate)) typedef struct { + char *command; + guint32 tries; + guint32 delay_seconds; + MMBaseSupportsTaskCustomInitResultFunc callback; + gpointer callback_data; +} CustomInit; + +typedef struct { MMPluginBase *plugin; GUdevDevice *port; char *physdev_path; @@ -110,11 +118,9 @@ typedef struct { char *probe_resp; GError *probe_error; - char *custom_init; - guint32 custom_init_tries; - guint32 custom_init_delay_seconds; - MMBaseSupportsTaskCustomInitResultFunc custom_init_callback; - gpointer custom_init_callback_data; + /* Custom init commands plugins might want */ + GSList *custom; + GSList *cur_custom; /* Pointer to current custom init command */ MMSupportsPortResultFunc callback; gpointer callback_data; @@ -225,13 +231,14 @@ mm_plugin_base_supports_task_complete (MMPluginBaseSupportsTask *task, } void -mm_plugin_base_supports_task_set_custom_init_command (MMPluginBaseSupportsTask *task, +mm_plugin_base_supports_task_add_custom_init_command (MMPluginBaseSupportsTask *task, const char *cmd, guint32 delay_seconds, MMBaseSupportsTaskCustomInitResultFunc callback, gpointer callback_data) { MMPluginBaseSupportsTaskPrivate *priv; + CustomInit *custom; g_return_if_fail (task != NULL); g_return_if_fail (MM_IS_PLUGIN_BASE_SUPPORTS_TASK (task)); @@ -239,11 +246,13 @@ mm_plugin_base_supports_task_set_custom_init_command (MMPluginBaseSupportsTask * priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (task); - g_free (priv->custom_init); - priv->custom_init = g_strdup (cmd); - priv->custom_init_delay_seconds = delay_seconds; - priv->custom_init_callback = callback; - priv->custom_init_callback_data = callback_data; + custom = g_malloc0 (sizeof (*custom)); + custom->command = g_strdup (cmd); + custom->delay_seconds = delay_seconds ? delay_seconds : 3; + custom->callback = callback; + custom->callback_data = callback_data; + + priv->custom = g_slist_append (priv->custom, custom); } static void @@ -255,6 +264,7 @@ static void supports_task_dispose (GObject *object) { MMPluginBaseSupportsTaskPrivate *priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (object); + GSList *iter; if (MM_IS_SERIAL_PORT (priv->probe_port)) mm_serial_port_flash_cancel (MM_SERIAL_PORT (priv->probe_port)); @@ -264,7 +274,14 @@ supports_task_dispose (GObject *object) g_free (priv->driver); g_free (priv->probe_resp); g_clear_error (&(priv->probe_error)); - g_free (priv->custom_init); + + for (iter = priv->custom; iter; iter = g_slist_next (iter)) { + CustomInit *custom = iter->data; + + g_free (custom->command); + memset (custom, 0, sizeof (*custom)); + g_free (custom); + } if (priv->open_id) g_source_remove (priv->open_id); @@ -738,13 +755,13 @@ custom_init_response (MMAtSerialPort *port, { MMPluginBaseSupportsTask *task = MM_PLUGIN_BASE_SUPPORTS_TASK (user_data); MMPluginBaseSupportsTaskPrivate *task_priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (task); - MMBaseSupportsTaskCustomInitResultFunc callback = task_priv->custom_init_callback; + CustomInit *custom = task_priv->cur_custom->data; gboolean retry = FALSE; gboolean fail = FALSE; guint32 level = 0; - task_priv->custom_init_tries++; - retry = callback (task, response, error, task_priv->custom_init_tries, &fail, &level, task_priv->custom_init_callback_data); + custom->tries++; + retry = custom->callback (task, response, error, custom->tries, &fail, &level, custom->callback_data); if (fail) { /* Plugin said to fail the probe */ @@ -761,7 +778,15 @@ custom_init_response (MMAtSerialPort *port, if (retry) { /* Try the custom command again */ - flash_done (MM_SERIAL_PORT (port), NULL, user_data); + flash_done (MM_SERIAL_PORT (port), NULL, task); + return; + } + + /* Any more custom init commands? */ + task_priv->cur_custom = g_slist_next (task_priv->cur_custom); + if (task_priv->cur_custom) { + /* There are more custom init commands */ + flash_done (MM_SERIAL_PORT (port), NULL, task); return; } @@ -774,17 +799,16 @@ flash_done (MMSerialPort *port, GError *error, gpointer user_data) { MMPluginBaseSupportsTask *task = MM_PLUGIN_BASE_SUPPORTS_TASK (user_data); MMPluginBaseSupportsTaskPrivate *task_priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (task); - guint32 delay_secs = task_priv->custom_init_delay_seconds; /* Send the custom init command if any */ - if (task_priv->custom_init) { - if (!delay_secs) - delay_secs = 3; + if (task_priv->cur_custom) { + CustomInit *custom = task_priv->cur_custom->data; + mm_at_serial_port_queue_command (MM_AT_SERIAL_PORT (port), - task_priv->custom_init, - delay_secs, + custom->command, + custom->delay_seconds, custom_init_response, - user_data); + task); } else { /* Otherwise start normal probing */ start_generic_probing (task, MM_AT_SERIAL_PORT (port)); @@ -875,6 +899,7 @@ mm_plugin_base_probe_port (MMPluginBase *self, /* Open the port */ task_priv->probe_port = serial; + task_priv->cur_custom = task_priv->custom; task_priv->open_id = g_idle_add (try_open, task); return TRUE; } diff --git a/src/mm-plugin-base.h b/src/mm-plugin-base.h index bd07c147..a5440a51 100644 --- a/src/mm-plugin-base.h +++ b/src/mm-plugin-base.h @@ -90,7 +90,7 @@ guint32 mm_plugin_base_supports_task_get_probed_capabilities (MMPluginBaseSuppor void mm_plugin_base_supports_task_complete (MMPluginBaseSupportsTask *task, guint32 level); -void mm_plugin_base_supports_task_set_custom_init_command (MMPluginBaseSupportsTask *task, +void mm_plugin_base_supports_task_add_custom_init_command (MMPluginBaseSupportsTask *task, const char *cmd, guint32 delay_seconds, MMBaseSupportsTaskCustomInitResultFunc callback, |