Hi, the attached patch adds the possibility to ModemManager to use a custom init response callback for mm_plugin_base_supports_task_set_custom_init_command(). This is useful if you can detect the modem just with eg the answer of the ATI at-cmd. Any comments? Tom
diff --git a/plugins/mm-plugin-zte.c b/plugins/mm-plugin-zte.c index bb2ee17..edc6dd4 100644 --- a/plugins/mm-plugin-zte.c +++ b/plugins/mm-plugin-zte.c @@ -113,7 +113,7 @@ supports_port (MMPluginBase *base, * 1235f71b20c92cded4abd976ccc5010649aae1a0 and * f38ad328acfdc6ce29dd1380602c546b064161ae for more details. */ - mm_plugin_base_supports_task_set_custom_init_command (task, "ATE0+CPMS?", 3, 4, FALSE); + mm_plugin_base_supports_task_set_custom_init_command (task, "ATE0+CPMS?", 3, 4, FALSE, NULL, NULL); if (mm_plugin_base_probe_port (base, task, NULL)) return MM_PLUGIN_SUPPORTS_PORT_IN_PROGRESS; diff --git a/src/mm-plugin-base.c b/src/mm-plugin-base.c index da8bc03..86fbd2b 100644 --- a/src/mm-plugin-base.c +++ b/src/mm-plugin-base.c @@ -115,6 +115,8 @@ typedef struct { guint32 custom_init_tries; guint32 custom_init_delay_seconds; gboolean custom_init_fail_if_timeout; + MMBaseSupportsTaskCustomInitResultFunc custom_init_callback; + gpointer custom_init_callback_data; MMSupportsPortResultFunc callback; gpointer callback_data; @@ -229,7 +231,9 @@ mm_plugin_base_supports_task_set_custom_init_command (MMPluginBaseSupportsTask * const char *cmd, guint32 delay_seconds, guint32 max_tries, - gboolean fail_if_timeout) + gboolean fail_if_timeout, + MMBaseSupportsTaskCustomInitResultFunc callback, + gpointer callback_data) { MMPluginBaseSupportsTaskPrivate *priv; @@ -243,6 +247,8 @@ mm_plugin_base_supports_task_set_custom_init_command (MMPluginBaseSupportsTask * priv->custom_init_max_tries = max_tries; priv->custom_init_delay_seconds = delay_seconds; priv->custom_init_fail_if_timeout = fail_if_timeout; + priv->custom_init_callback = callback; + priv->custom_init_callback_data = callback_data; } static void @@ -731,7 +737,7 @@ 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); - + if (error) { task_priv->custom_init_tries++; if (task_priv->custom_init_tries < task_priv->custom_init_max_tries) { @@ -745,6 +751,27 @@ custom_init_response (MMAtSerialPort *port, return; } } + } else { + //custom handle init response + MMPluginBaseClass* klass = MM_PLUGIN_BASE_GET_CLASS(task_priv->plugin); + if(klass->handle_custom_init_response != NULL) + { + klass->handle_custom_init_response(task, response); + } + } + + /* check for custom init callback */ + if(task_priv->custom_init_callback != NULL) + { + MMBaseSupportsTaskCustomInitResultFunc callback = (MMBaseSupportsTaskCustomInitResultFunc) task_priv->custom_init_callback; + guint32 level = callback(response, task_priv->custom_init_callback_data); + if(level > 0) + { + /* Plugin supports the modem */ + task_priv->probed_caps = level; + probe_complete(task); + return; + } } /* Otherwise proceed to probing */ @@ -1243,6 +1270,7 @@ mm_plugin_base_class_init (MMPluginBaseClass *klass) g_type_class_add_private (object_class, sizeof (MMPluginBasePrivate)); klass->handle_probe_response = real_handle_probe_response; + klass->handle_custom_init_response = NULL; /* Virtual methods */ object_class->get_property = get_property; diff --git a/src/mm-plugin-base.h b/src/mm-plugin-base.h index a32d53b..fa67c0a 100644 --- a/src/mm-plugin-base.h +++ b/src/mm-plugin-base.h @@ -56,6 +56,9 @@ typedef struct { GType mm_plugin_base_supports_task_get_type (void); +typedef guint32 (*MMBaseSupportsTaskCustomInitResultFunc) (GString* response, + gpointer user_data); + MMPlugin *mm_plugin_base_supports_task_get_plugin (MMPluginBaseSupportsTask *task); GUdevDevice *mm_plugin_base_supports_task_get_port (MMPluginBaseSupportsTask *task); @@ -73,7 +76,9 @@ void mm_plugin_base_supports_task_set_custom_init_command (MMPluginBaseSupportsT const char *cmd, guint32 delay_seconds, guint32 max_tries, - gboolean fail_if_timeout); + gboolean fail_if_timeout, + MMBaseSupportsTaskCustomInitResultFunc callback, + gpointer callback_data); #define MM_TYPE_PLUGIN_BASE (mm_plugin_base_get_type ()) #define MM_PLUGIN_BASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_BASE, MMPluginBase)) @@ -114,6 +119,9 @@ struct _MMPluginBaseClass { const char *response, const GError *error); + void (*handle_custom_init_response) (MMPluginBaseSupportsTask *task, + GString *response); + /* Signals */ void (*probe_result) (MMPluginBase *self, MMPluginBaseSupportsTask *task,
Attachment:
signature.asc
Description: This is a digitally signed message part