[Xfce4-commits] <xfce4-cellmodem-plugin:master> Async processing now seems to work

Alvaro Lopes noreply at xfce.org
Tue Oct 13 21:28:05 CEST 2009


Updating branch refs/heads/master
         to d64aca7a77e1d0f3e17f0b88f6a54b9dfdb21284 (commit)
       from 404fecd6de894b0b9bc423faa0d60dc02371f8c9 (commit)

commit d64aca7a77e1d0f3e17f0b88f6a54b9dfdb21284
Author: Alvaro Lopes <alvieboy at alvie.com>
Date:   Tue Oct 13 20:28:42 2009 +0100

    Async processing now seems to work

 panel-plugin/cellmodem.c |  118 +++++++++++++++++++++++++++++++---------------
 1 files changed, 79 insertions(+), 39 deletions(-)

diff --git a/panel-plugin/cellmodem.c b/panel-plugin/cellmodem.c
index ffed7ee..27ca7cd 100644
--- a/panel-plugin/cellmodem.c
+++ b/panel-plugin/cellmodem.c
@@ -1866,7 +1866,7 @@ static void
 cellmodem_t_set_cmgf (cellmodem_t * monitor)
 {
   cellmodem_t_send_at_command (monitor, &cellmodem_t_set_cmgf_callback,
-			       "+CMGF=0", NULL);
+			       "+CMGF=0", "");
   cellmodem_t_switch_status (monitor, MODEM_WAIT_SET_CMGF_RESPONSE);
 }
 #endif
@@ -1889,7 +1889,7 @@ cellmodem_t_send_pin (cellmodem_t * monitor, const gchar * pin)
 
       cellmodem_t_send_at_command (monitor,
 				   &cellmodem_t_setpin_callback,
-				   g->str, NULL);
+				   g->str, "");
       g_string_free (g, TRUE);
 
       cellmodem_t_switch_status (monitor, MODEM_WAIT_PINE_RESPONSE);
@@ -1920,19 +1920,6 @@ cellmodem_t_modem_handle_response (cellmodem_t * monitor, char *buffer)
 {
   char *bstart;
 
-  /* Move this to other place, so we can handle asynchronous
-   modem messages */
-
-  if (monitor->resp.reply_callback == NULL)
-    {
-      CELLMODEM_DEBUG (0, "No callback defined!!!!");
-      return TRUE;		/* No registered listener. */
-    }
-  if (monitor->resp.reply_buffer == NULL)
-    {
-      monitor->resp.reply_buffer = g_string_new (NULL);	/* Initialize to NULL */
-    }
-
   /* Remove trailing \r and \n */
 
   bstart = remove_leading_chars (buffer, "\n\r");
@@ -1959,36 +1946,69 @@ cellmodem_t_modem_handle_response (cellmodem_t * monitor, char *buffer)
 
   cellmodem_t_cancel_pending_at_command_timeout (monitor);
 
-  if (is_AT_error_reply (bstart))
-    {
+  if (monitor->resp.reply_callback) {
 
-      monitor->resp.reply_callback (FALSE,
-				    monitor->resp.reply_buffer,
-				    monitor->resp.reply_pvt);
+    modem_reply_callback_t cb =  monitor->resp.reply_callback;
 
-      g_string_free (monitor->resp.reply_buffer, TRUE);
-      monitor->resp.reply_buffer = NULL;
+    if (is_AT_error_reply (bstart))
+      {
+	CELLMODEM_DEBUG(7,"Resetting callback");
+	monitor->resp.reply_callback = NULL;
+	if (monitor->resp.reply_buffer == NULL)
+	  {
+	    monitor->resp.reply_buffer = g_string_new (NULL);	/* Initialize to NULL */
+	  }
+	CELLMODEM_DEBUG (4, "Got AT ERROR reply");
 
-      return TRUE;
-    }
+	cb (FALSE,
+	    monitor->resp.reply_buffer,
+	    monitor->resp.reply_pvt);
 
-  if (is_AT_success_reply (bstart))
-    {
-      CELLMODEM_DEBUG (4, "Got AT OK reply");
-      (void)monitor->resp.reply_callback (TRUE,
-					monitor->resp.reply_buffer,
-					  monitor->resp.reply_pvt);
+	g_string_free (monitor->resp.reply_buffer, TRUE);
+	monitor->resp.reply_buffer = NULL;
 
-      g_string_free (monitor->resp.reply_buffer, TRUE);
-      monitor->resp.reply_buffer = NULL;
 
-      return TRUE;
-    }
+	return TRUE;
+      }
 
+    if (is_AT_success_reply (bstart))
+      {
+	CELLMODEM_DEBUG(7,"Resetting callback");
+	monitor->resp.reply_callback = NULL;
+	if (monitor->resp.reply_buffer == NULL)
+	  {
+	    monitor->resp.reply_buffer = g_string_new (NULL);	/* Initialize to NULL */
+	  }
+
+	CELLMODEM_DEBUG (4, "Got AT OK reply");
+	cb(TRUE,
+	   monitor->resp.reply_buffer,
+	   monitor->resp.reply_pvt);
+
+	g_string_free (monitor->resp.reply_buffer, TRUE);
+	monitor->resp.reply_buffer = NULL;
+	return TRUE;
+      }
+  }
   /*
-     Check expectation. If expectation does not match,
-     we should add this message to some asynchronous event handling.
+   Check expectation. If expectation does not match,
+   we should add this message to some asynchronous event handling.
    */
+  /* Move this to other place, so we can handle asynchronous
+   modem messages */
+
+  if (monitor->resp.reply_callback == NULL)
+    {
+      CELLMODEM_DEBUG (6, "No callback defined. Assuming async");
+      	  /* Send it for asynchronous processing */
+      cellmodem_t_handle_async(monitor,bstart);
+
+      return TRUE;		/* No registered listener. */
+    }
+  if (monitor->resp.reply_buffer == NULL)
+    {
+      monitor->resp.reply_buffer = g_string_new (NULL);	/* Initialize to NULL */
+    }
 
   if (monitor->resp.reply_expect)
     {
@@ -2000,16 +2020,36 @@ cellmodem_t_modem_handle_response (cellmodem_t * monitor, char *buffer)
 	  cellmodem_t_handle_async(monitor,bstart);
 
 	  /*CELLMODEM_DEBUG (3, "Ignoring reply from modem: '%s'\n", bstart);*/
+	  if (monitor->resp.reply_buffer) {
+	    g_string_free (monitor->resp.reply_buffer, TRUE);
+	    monitor->resp.reply_buffer = NULL;
+	  }
+	  return TRUE;
+	}
+    } else {
+      if (monitor->resp.reply_callback == NULL) {
+	if (monitor->resp.reply_buffer) {
 	  g_string_free (monitor->resp.reply_buffer, TRUE);
 	  monitor->resp.reply_buffer = NULL;
-
-	  return TRUE;
 	}
+      }
+    }
+
+  if (monitor->resp.reply_callback == NULL)
+    {
+      CELLMODEM_DEBUG (0, "No callback defined!!!!");
+      return TRUE;		/* No registered listener. */
+    }
+
+  if (monitor->resp.reply_buffer == NULL)
+    {
+      monitor->resp.reply_buffer = g_string_new (NULL);	/* Initialize to NULL */
     }
 
   g_string_append (monitor->resp.reply_buffer, bstart);
   g_string_append (monitor->resp.reply_buffer, "\n");
 
+
   /* Reset expectation. We accept everything till we got an OK */
 
   monitor->resp.reply_expect = NULL;
@@ -2514,7 +2554,7 @@ cellmodem_t_initialize_modem (cellmodem_t * monitor)
   CELLMODEM_DEBUG (3, " ---- Initializing modem ---- ");
 
   cellmodem_t_switch_to_error (monitor, _("Modem initializing"));
-
+  cellmodem_t_close_modem(monitor);
   /*
      Cancel any pending timers
    */



More information about the Xfce4-commits mailing list