plugins: allow multiple custom init commands in sequence
Huawei will need this.
This commit is contained in:
@@ -129,7 +129,7 @@ supports_port (MMPluginBase *base,
|
|||||||
* 1235f71b20c92cded4abd976ccc5010649aae1a0 and
|
* 1235f71b20c92cded4abd976ccc5010649aae1a0 and
|
||||||
* f38ad328acfdc6ce29dd1380602c546b064161ae for more details.
|
* 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?",
|
"ATE0+CPMS?",
|
||||||
3,
|
3,
|
||||||
custom_init_response_cb,
|
custom_init_response_cb,
|
||||||
|
@@ -92,6 +92,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))
|
#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 {
|
typedef struct {
|
||||||
MMPluginBase *plugin;
|
MMPluginBase *plugin;
|
||||||
GUdevDevice *port;
|
GUdevDevice *port;
|
||||||
@@ -110,11 +118,9 @@ typedef struct {
|
|||||||
char *probe_resp;
|
char *probe_resp;
|
||||||
GError *probe_error;
|
GError *probe_error;
|
||||||
|
|
||||||
char *custom_init;
|
/* Custom init commands plugins might want */
|
||||||
guint32 custom_init_tries;
|
GSList *custom;
|
||||||
guint32 custom_init_delay_seconds;
|
GSList *cur_custom; /* Pointer to current custom init command */
|
||||||
MMBaseSupportsTaskCustomInitResultFunc custom_init_callback;
|
|
||||||
gpointer custom_init_callback_data;
|
|
||||||
|
|
||||||
MMSupportsPortResultFunc callback;
|
MMSupportsPortResultFunc callback;
|
||||||
gpointer callback_data;
|
gpointer callback_data;
|
||||||
@@ -225,13 +231,14 @@ mm_plugin_base_supports_task_complete (MMPluginBaseSupportsTask *task,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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,
|
const char *cmd,
|
||||||
guint32 delay_seconds,
|
guint32 delay_seconds,
|
||||||
MMBaseSupportsTaskCustomInitResultFunc callback,
|
MMBaseSupportsTaskCustomInitResultFunc callback,
|
||||||
gpointer callback_data)
|
gpointer callback_data)
|
||||||
{
|
{
|
||||||
MMPluginBaseSupportsTaskPrivate *priv;
|
MMPluginBaseSupportsTaskPrivate *priv;
|
||||||
|
CustomInit *custom;
|
||||||
|
|
||||||
g_return_if_fail (task != NULL);
|
g_return_if_fail (task != NULL);
|
||||||
g_return_if_fail (MM_IS_PLUGIN_BASE_SUPPORTS_TASK (task));
|
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);
|
priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (task);
|
||||||
|
|
||||||
g_free (priv->custom_init);
|
custom = g_malloc0 (sizeof (*custom));
|
||||||
priv->custom_init = g_strdup (cmd);
|
custom->command = g_strdup (cmd);
|
||||||
priv->custom_init_delay_seconds = delay_seconds;
|
custom->delay_seconds = delay_seconds ? delay_seconds : 3;
|
||||||
priv->custom_init_callback = callback;
|
custom->callback = callback;
|
||||||
priv->custom_init_callback_data = callback_data;
|
custom->callback_data = callback_data;
|
||||||
|
|
||||||
|
priv->custom = g_slist_append (priv->custom, custom);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -255,6 +264,7 @@ static void
|
|||||||
supports_task_dispose (GObject *object)
|
supports_task_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
MMPluginBaseSupportsTaskPrivate *priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (object);
|
MMPluginBaseSupportsTaskPrivate *priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (object);
|
||||||
|
GSList *iter;
|
||||||
|
|
||||||
if (MM_IS_SERIAL_PORT (priv->probe_port))
|
if (MM_IS_SERIAL_PORT (priv->probe_port))
|
||||||
mm_serial_port_flash_cancel (MM_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->driver);
|
||||||
g_free (priv->probe_resp);
|
g_free (priv->probe_resp);
|
||||||
g_clear_error (&(priv->probe_error));
|
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)
|
if (priv->open_id)
|
||||||
g_source_remove (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);
|
MMPluginBaseSupportsTask *task = MM_PLUGIN_BASE_SUPPORTS_TASK (user_data);
|
||||||
MMPluginBaseSupportsTaskPrivate *task_priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (task);
|
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 retry = FALSE;
|
||||||
gboolean fail = FALSE;
|
gboolean fail = FALSE;
|
||||||
guint32 level = 0;
|
guint32 level = 0;
|
||||||
|
|
||||||
task_priv->custom_init_tries++;
|
custom->tries++;
|
||||||
retry = callback (task, response, error, task_priv->custom_init_tries, &fail, &level, task_priv->custom_init_callback_data);
|
retry = custom->callback (task, response, error, custom->tries, &fail, &level, custom->callback_data);
|
||||||
|
|
||||||
if (fail) {
|
if (fail) {
|
||||||
/* Plugin said to fail the probe */
|
/* Plugin said to fail the probe */
|
||||||
@@ -761,7 +778,15 @@ custom_init_response (MMAtSerialPort *port,
|
|||||||
|
|
||||||
if (retry) {
|
if (retry) {
|
||||||
/* Try the custom command again */
|
/* 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -774,17 +799,16 @@ flash_done (MMSerialPort *port, GError *error, gpointer user_data)
|
|||||||
{
|
{
|
||||||
MMPluginBaseSupportsTask *task = MM_PLUGIN_BASE_SUPPORTS_TASK (user_data);
|
MMPluginBaseSupportsTask *task = MM_PLUGIN_BASE_SUPPORTS_TASK (user_data);
|
||||||
MMPluginBaseSupportsTaskPrivate *task_priv = MM_PLUGIN_BASE_SUPPORTS_TASK_GET_PRIVATE (task);
|
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 */
|
/* Send the custom init command if any */
|
||||||
if (task_priv->custom_init) {
|
if (task_priv->cur_custom) {
|
||||||
if (!delay_secs)
|
CustomInit *custom = task_priv->cur_custom->data;
|
||||||
delay_secs = 3;
|
|
||||||
mm_at_serial_port_queue_command (MM_AT_SERIAL_PORT (port),
|
mm_at_serial_port_queue_command (MM_AT_SERIAL_PORT (port),
|
||||||
task_priv->custom_init,
|
custom->command,
|
||||||
delay_secs,
|
custom->delay_seconds,
|
||||||
custom_init_response,
|
custom_init_response,
|
||||||
user_data);
|
task);
|
||||||
} else {
|
} else {
|
||||||
/* Otherwise start normal probing */
|
/* Otherwise start normal probing */
|
||||||
start_generic_probing (task, MM_AT_SERIAL_PORT (port));
|
start_generic_probing (task, MM_AT_SERIAL_PORT (port));
|
||||||
@@ -875,6 +899,7 @@ mm_plugin_base_probe_port (MMPluginBase *self,
|
|||||||
|
|
||||||
/* Open the port */
|
/* Open the port */
|
||||||
task_priv->probe_port = serial;
|
task_priv->probe_port = serial;
|
||||||
|
task_priv->cur_custom = task_priv->custom;
|
||||||
task_priv->open_id = g_idle_add (try_open, task);
|
task_priv->open_id = g_idle_add (try_open, task);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@@ -90,7 +90,7 @@ guint32 mm_plugin_base_supports_task_get_probed_capabilities (MMPluginBaseSuppor
|
|||||||
void mm_plugin_base_supports_task_complete (MMPluginBaseSupportsTask *task,
|
void mm_plugin_base_supports_task_complete (MMPluginBaseSupportsTask *task,
|
||||||
guint32 level);
|
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,
|
const char *cmd,
|
||||||
guint32 delay_seconds,
|
guint32 delay_seconds,
|
||||||
MMBaseSupportsTaskCustomInitResultFunc callback,
|
MMBaseSupportsTaskCustomInitResultFunc callback,
|
||||||
|
Reference in New Issue
Block a user