[PATCH] add callback to handle response for custom-init-command. Can be used to detect eg a RS232 model just with a custom init command.



---
 src/mm-plugin-base.c |   32 ++++++++++++++++++++++++++++++--
 src/mm-plugin-base.h |   10 +++++++++-
 2 files changed, 39 insertions(+), 3 deletions(-)

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,
-- 
1.7.1



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]