[Xfce4-commits] <xfce4-cellmodem-plugin:master> Implement async response handling

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


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

commit 404fecd6de894b0b9bc423faa0d60dc02371f8c9
Author: Alvaro Lopes <alvieboy at alvie.com>
Date:   Tue Oct 13 19:24:59 2009 +0100

    Implement async response handling

 panel-plugin/cellmodem.c         |  139 +++++++++++++++---------
 panel-plugin/cellmodem.h         |    1 +
 panel-plugin/cellmodem_options.h |    1 +
 panel-plugin/preferences.c       |   20 ++++
 panel-plugin/preferences.h       |    1 +
 po/xfce4-cellmodem-plugin.pot    |  228 --------------------------------------
 6 files changed, 111 insertions(+), 279 deletions(-)

diff --git a/panel-plugin/cellmodem.c b/panel-plugin/cellmodem.c
index 99ebad5..ffed7ee 100644
--- a/panel-plugin/cellmodem.c
+++ b/panel-plugin/cellmodem.c
@@ -71,9 +71,12 @@ static gboolean cellmodem_t_open_modem (cellmodem_t * monitor);
 static void cellmodem_t_switch_status (cellmodem_t * monitor,
 				       modem_status_t status);
 static void cellmodem_t_set_ok (cellmodem_t * monitor);
-static gboolean cellmodem_t_start_work_from_timer (cellmodem_t * monitor);
+
 static void cellmodem_t_schedule_timer (cellmodem_t * monitor);
 
+#if 0
+static gboolean cellmodem_t_start_work_from_timer (cellmodem_t * monitor);
+
 
 /**
  * Schedule a command or series of commands to be run as soon as possible,
@@ -84,7 +87,7 @@ static gboolean cellmodem_t_schedule_command (cellmodem_t * monitor,
 					      void (*cellmodem_function)
 					      (cellmodem_t *), void *data);
 static void cellmodem_t_unschedule (cellmodem_t * monitor);
-
+#endif
 
 /* End Proto */
 
@@ -133,6 +136,15 @@ cellmodem_t_in_error_status (cellmodem_t * monitor)
 }
 
 static void
+cellmodem_t_go_idle (cellmodem_t * monitor)
+{
+  if (monitor->options.keep_modem_open)
+    monitor->modem_status = MODEM_IDLE;
+  else
+    cellmodem_t_close_modem(monitor);
+}
+
+static void
 cellmodem_t_switch_to_error (cellmodem_t * monitor, const char *fmt, ...)
 {
   va_list ap;
@@ -199,7 +211,8 @@ cellmodem_t_switch_status (cellmodem_t * monitor, modem_status_t status)
     case MODEM_WAIT_SET_CMGF_RESPONSE:
     case MODEM_WAIT_CMGL_READ_RESPONSE:
 #endif
-    case MODEM_WAIT_OHCIP_RESPONSE:
+	case MODEM_WAIT_OHCIP_RESPONSE:
+	case MODEM_IDLE:
       break;
     }
 
@@ -745,7 +758,7 @@ static void
 cellmodem_t_delete (cellmodem_t * monitor)
 {
   CELLMODEM_DEBUG (7, "Destroying cellmodem object");
-  cellmodem_t_close_modem (monitor /*, TRUE */ );
+  cellmodem_t_close_modem (monitor);
 
   g_object_unref (monitor->tooltips);
 
@@ -763,7 +776,7 @@ cellmodem_t_delete (cellmodem_t * monitor)
  */
 
 static gboolean
-cellmodem_t_close_modem (cellmodem_t * monitor /*, gboolean failure */ )
+cellmodem_t_close_modem (cellmodem_t * monitor)
 {
   if (NULL == monitor->modem_instance)
     return FALSE;
@@ -794,7 +807,7 @@ cellmodem_t_request_pin (cellmodem_t * monitor)
 
       /* End here */
 
-      cellmodem_t_close_modem (monitor);
+      cellmodem_t_go_idle (monitor);
     }
   else
     {
@@ -875,12 +888,11 @@ cellmodem_t_registration_callback (gboolean success, GString * response,
     }
   else
     {
-      CELLMODEM_DEBUG (2, "Modem error in reply");
-      cellmodem_t_switch_to_error_and_restart (monitor,
-					       _
-					       ("Invalid CREG reply from modem"));
-      return;
-    }
+	  CELLMODEM_DEBUG (2, "Modem error in reply");
+	  cellmodem_t_switch_to_error_and_restart (monitor,
+											   _("Invalid CREG reply from modem"));
+	  return;
+	}
 
 
   if (monitor->registration_status != REGISTRATION_NOT_REGISTERED &&
@@ -1020,6 +1032,7 @@ cellmodem_t_save_or_release_pin (cellmodem_t * monitor, gchar * pin)
    */
 
   cellmodem_write_config (monitor->plugin, monitor);
+  return 0;
 }
 
 /**
@@ -1088,9 +1101,8 @@ cellmodem_t_pin_callback (gboolean success, GString * response, void *pvt)
     }
   else
     {
-      cellmodem_t_switch_to_error_and_restart (monitor,
-					       _
-					       ("Invalid CPIN reply from modem"));
+      CELLMODEM_DEBUG(0,"Invalid CPIN reply: '%s'", response->str);
+      cellmodem_t_switch_to_error_and_restart (monitor,_("Invalid CPIN reply from modem"));
 
       cellmodem_t_reschedule_open (monitor);
     }
@@ -1351,9 +1363,8 @@ cellmodem_t_quality_callback (gboolean success, GString * response, void *pvt)
 #endif
 
   CELLMODEM_DEBUG (3, "Got quality, restarting");
-  /* cellmodem_t_close_modem( monitor, FALSE ); - reschedule will close */
-  cellmodem_t_switch_status (monitor, MODEM_CLOSED);
-  cellmodem_t_reschedule_open (monitor /*, FALSE */ );
+  cellmodem_t_switch_status (monitor, MODEM_IDLE);
+  cellmodem_t_reschedule_open (monitor);
 }
 
 /**
@@ -1860,6 +1871,13 @@ cellmodem_t_set_cmgf (cellmodem_t * monitor)
 }
 #endif
 
+static gboolean
+cellmodem_t_handle_async (cellmodem_t *monitor,const gchar *buffer)
+{
+  CELLMODEM_DEBUG(0,"Async from modem: '%s'\n",buffer);
+  return FALSE;
+}
+
 static void
 cellmodem_t_send_pin (cellmodem_t * monitor, const gchar * pin)
 {
@@ -1902,6 +1920,9 @@ 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!!!!");
@@ -1954,9 +1975,9 @@ cellmodem_t_modem_handle_response (cellmodem_t * monitor, char *buffer)
   if (is_AT_success_reply (bstart))
     {
       CELLMODEM_DEBUG (4, "Got AT OK reply");
-      monitor->resp.reply_callback (TRUE,
-				    monitor->resp.reply_buffer,
-				    monitor->resp.reply_pvt);
+      (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;
@@ -1975,7 +1996,13 @@ cellmodem_t_modem_handle_response (cellmodem_t * monitor, char *buffer)
 	  (bstart, monitor->resp.reply_expect,
 	   strlen (monitor->resp.reply_expect)) != 0)
 	{
-	  CELLMODEM_DEBUG (3, "Ignoring reply from modem: '%s'\n", bstart);
+	  /* Send it for asynchronous processing */
+	  cellmodem_t_handle_async(monitor,bstart);
+
+	  /*CELLMODEM_DEBUG (3, "Ignoring reply from modem: '%s'\n", bstart);*/
+	  g_string_free (monitor->resp.reply_buffer, TRUE);
+	  monitor->resp.reply_buffer = NULL;
+
 	  return TRUE;
 	}
     }
@@ -2048,7 +2075,7 @@ cellmodem_t_modem_callback (GIOChannel * chan, GIOCondition c, gpointer data)
     {
       CELLMODEM_DEBUG (1, "Error reading from modem");
       cellmodem_t_switch_to_error (monitor, _("Error reading from modem"));
-      cellmodem_t_close_modem (monitor /*, TRUE */ );
+      cellmodem_t_close_modem (monitor);
       return FALSE;
     }
 
@@ -2130,7 +2157,7 @@ cellmodem_t_send_at_command (cellmodem_t * monitor,
     {
       CELLMODEM_DEBUG (1, "ERROR Command: '%s'\n", monitor->lastcmd);
       cellmodem_t_switch_to_error (monitor, _("Error writing to modem"));
-      cellmodem_t_close_modem (monitor /*, TRUE */ );
+      cellmodem_t_close_modem (monitor);
       return FALSE;
     }
 
@@ -2164,6 +2191,9 @@ cellmodem_t_cancel_pending_at_command_timeout (cellmodem_t * monitor)
 static gboolean
 cellmodem_t_open_modem (cellmodem_t * monitor)
 {
+  if (monitor->modem_status==MODEM_IDLE)
+    return TRUE;
+
   if (NULL == monitor->driver)
     {
       cellmodem_t_switch_to_error (monitor, _("No driver defined"));
@@ -2194,6 +2224,8 @@ cellmodem_t_open_modem (cellmodem_t * monitor)
 }
 
 
+#if 0
+
 static void
 cellmodem_t_unschedule (cellmodem_t * monitor)
 {
@@ -2242,63 +2274,64 @@ cellmodem_t_schedule_command (cellmodem_t * monitor,
 
 
 /**
- * Schedule a timer to start work
+ * Start work from outside a timer. Cancels any pending timer
  */
 
 static void
-cellmodem_t_schedule_timer (cellmodem_t * monitor)
+cellmodem_t_start_work (cellmodem_t * monitor)
 {
-
   if (monitor->info_timeout_id > 0)
     {
       g_source_remove (monitor->info_timeout_id);
     }
 
+  cellmodem_t_start_work_from_timer (monitor);
 
-  /* If we have an scheduled function here, call it */
-  if (NULL != monitor->scheduled_function)
-    {
-      monitor->scheduled_function (monitor->scheduled_function_arg0);
-      monitor->scheduled_function = NULL;
-    }
+}
+#endif
 
-  monitor->info_timeout_id = g_timeout_add (OPEN_TIMEOUT,
-					    (GSourceFunc)
-					    cellmodem_t_start_work_from_timer,
-					    monitor);
+static gboolean
+cellmodem_t_start_work_from_timer (cellmodem_t * monitor)
+{
+
+  get_network_info (monitor);
+  return TRUE;
 }
 
 /**
- * Start work from outside a timer. Cancels any pending timer
+ * Schedule a timer to start work
  */
 
 static void
-cellmodem_t_start_work (cellmodem_t * monitor)
+cellmodem_t_schedule_timer (cellmodem_t * monitor)
 {
+
   if (monitor->info_timeout_id > 0)
     {
       g_source_remove (monitor->info_timeout_id);
     }
 
-  cellmodem_t_start_work_from_timer (monitor);
-
-}
 
-static gboolean
-cellmodem_t_start_work_from_timer (cellmodem_t * monitor)
-{
-
-  get_network_info (monitor);
+  /* If we have an scheduled function here, call it */
+  if (NULL != monitor->scheduled_function)
+    {
+      monitor->scheduled_function (monitor->scheduled_function_arg0);
+      monitor->scheduled_function = NULL;
+    }
 
+  monitor->info_timeout_id = g_timeout_add (OPEN_TIMEOUT,
+					    (GSourceFunc)
+					    cellmodem_t_start_work_from_timer,
+					    monitor);
 }
 
-
 static gboolean
 cellmodem_t_reschedule_open (cellmodem_t * monitor /*, gboolean failure */ )
 {
   CELLMODEM_DEBUG (7, "RESCHEDULING OPEN");
-  cellmodem_t_close_modem (monitor /*, failure */ );
-
+  if (!monitor->options.keep_modem_open) {
+    cellmodem_t_close_modem (monitor);
+  }
   cellmodem_t_schedule_timer (monitor);
 
   return FALSE;			/* Cancel this timer */
@@ -2351,7 +2384,6 @@ cellmodem_read_config (XfcePanelPlugin * plugin, cellmodem_t * monitor)
 {
   char *file;
   const char *text;
-  const char *saved_pin;
   XfceRc *rc;
 
   if (!(file = xfce_panel_plugin_lookup_rc_file (plugin)))
@@ -2405,6 +2437,8 @@ cellmodem_read_config (XfcePanelPlugin * plugin, cellmodem_t * monitor)
   cellmodem_debug_level =
     xfce_rc_read_int_entry (rc, "debug_level", MAX_QUAL);
 #endif
+  monitor->options.keep_modem_open =
+    xfce_rc_read_bool_entry (rc, "keep_modem_open", FALSE);
 
   xfce_rc_close (rc);
 
@@ -2466,6 +2500,9 @@ cellmodem_write_config (XfcePanelPlugin * plugin, cellmodem_t * monitor)
 #ifdef DEBUG_ENABLED
   xfce_rc_write_int_entry (rc, "debug_level", cellmodem_debug_level);
 #endif
+  xfce_rc_write_bool_entry (rc, "keep_modem_open",
+			    monitor->options.keep_modem_open);
+
   CELLMODEM_DEBUG (7, "Done saving configuration");
   xfce_rc_close (rc);
 }
diff --git a/panel-plugin/cellmodem.h b/panel-plugin/cellmodem.h
index 30b0f40..8830f79 100644
--- a/panel-plugin/cellmodem.h
+++ b/panel-plugin/cellmodem.h
@@ -90,6 +90,7 @@ typedef enum
   MODEM_WAIT_SET_CMGF_RESPONSE,
   MODEM_WAIT_CMGL_READ_RESPONSE,
 #endif
+  MODEM_IDLE,
   MODEM_CLOSED
 } modem_status_t;
 
diff --git a/panel-plugin/cellmodem_options.h b/panel-plugin/cellmodem_options.h
index 192ef34..a41a679 100644
--- a/panel-plugin/cellmodem_options.h
+++ b/panel-plugin/cellmodem_options.h
@@ -35,6 +35,7 @@ typedef struct
   speed_t speed;
   gboolean check_for_sms;
   guint sms_check_interval;
+  gboolean keep_modem_open;
 } cellmodem_options_t;
 
 #endif
diff --git a/panel-plugin/preferences.c b/panel-plugin/preferences.c
index d65a022..65aa693 100644
--- a/panel-plugin/preferences.c
+++ b/panel-plugin/preferences.c
@@ -229,6 +229,8 @@ update_dialog (cellmodem_dialog_t * dialog)
 			     monitor->options.sms_check_interval);
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->check_sms_entry),
 				monitor->options.check_for_sms);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->keep_modem_open_entry),
+				monitor->options.keep_modem_open);
 
   if (!monitor->options.check_for_sms)
     {
@@ -355,6 +357,14 @@ cb_check_sms_entry_toggled (GtkCheckButton * button,
 #endif
 
 static void
+cb_keep_modem_open_entry_toggled (GtkCheckButton * button,
+				  cellmodem_dialog_t * dialog)
+{
+  dialog->monitor->options.keep_modem_open =
+    gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+}
+
+static void
 autodetect_dialog_callback (GtkDialog * dlg, int response,
 			    cellmodem_dialog_t * dialog)
 {
@@ -679,6 +689,16 @@ cellmodem_create_options (XfcePanelPlugin * plugin, cellmodem_t * monitor)
 		    G_CALLBACK (cb_sms_check_interval_entry_changed), dialog);
 #endif
 
+  MAKEHBOX(hbox);
+  dialog->keep_modem_open_entry =
+    gtk_check_button_new_with_mnemonic (_("Keep modem open"));
+  gtk_box_pack_start (GTK_BOX (hbox), dialog->keep_modem_open_entry, 0,
+		      FALSE, FALSE);
+  g_signal_connect (dialog->keep_modem_open_entry, "toggled",
+		    G_CALLBACK (cb_keep_modem_open_entry_toggled), dialog);
+
+  gtk_widget_show (dialog->keep_modem_open_entry);
+
   update_dialog (dialog);
 
 
diff --git a/panel-plugin/preferences.h b/panel-plugin/preferences.h
index 9584b9e..8484439 100644
--- a/panel-plugin/preferences.h
+++ b/panel-plugin/preferences.h
@@ -34,6 +34,7 @@ typedef struct
   GtkWidget *speed_entry;
 
   GtkWidget *networktype_combo;
+  GtkWidget *keep_modem_open_entry;
 
 #ifdef HAVE_SMS_SUPPORT
   GtkWidget *check_sms_entry;
diff --git a/po/xfce4-cellmodem-plugin.pot b/po/xfce4-cellmodem-plugin.pot
deleted file mode 100644
index b1aec25..0000000
--- a/po/xfce4-cellmodem-plugin.pot
+++ /dev/null
@@ -1,228 +0,0 @@
-# SOME DESCRIPTIVE TITLE.
-# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
-# This file is distributed under the same license as the PACKAGE package.
-# FIRST AUTHOR <EMAIL at ADDRESS>, YEAR.
-#
-#, fuzzy
-msgid ""
-msgstr ""
-"Project-Id-Version: PACKAGE VERSION\n"
-"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2008-07-22 19:01+0100\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
-"Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
-"Language-Team: LANGUAGE <LL at li.org>\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=CHARSET\n"
-"Content-Transfer-Encoding: 8bit\n"
-
-#: ../panel-plugin/cellmodem.c:482
-msgid "Initializing plugin now"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:505
-#, c-format
-msgid ""
-"Error detected:\n"
-"%s"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:511
-msgid "Not registered"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:514
-msgid "Modem needs PIN"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:517
-msgid "Registering"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:520
-#, c-format
-msgid ""
-"Registered [GPRS] to %s\n"
-"Quality: %d (%d%%)"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:523
-#, c-format
-msgid ""
-"Registered [UMTS] to %s\n"
-"Quality: %d (%d%%)"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:526
-#, c-format
-msgid ""
-"Registered [HSDPA] to %s\n"
-"Quality: %d (%d%%)"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:529
-#, c-format
-msgid ""
-"Registered to %s\n"
-"Quality: %d (%d%%)"
-msgstr ""
-
-#. Error
-#: ../panel-plugin/cellmodem.c:687
-msgid "Error in modem reply to CREG"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:696
-msgid "Invalid reply to +CREG"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:721
-msgid "Invalid CREG reply from modem"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:760
-msgid "Error in modem reply to COPS"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:816
-msgid "Invalid COPS reply from modem"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:844
-msgid "Error in modem reply to CPIN"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:870
-msgid "Invalid CPIN reply from modem"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:875
-msgid "Unsupportted CPIN reply from modem"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:919 ../panel-plugin/cellmodem.c:973
-msgid "Invalid OHCIP reply from modem"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:923 ../panel-plugin/cellmodem.c:977
-msgid "Unsupportted OHCIP reply from modem"
-msgstr ""
-
-#. Error
-#: ../panel-plugin/cellmodem.c:1019
-msgid "Cannot send PIN to modem"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:1055
-msgid "Error in modem reply to CSQ"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:1075
-msgid "Invalid CSQ reply from modem"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:1276 ../panel-plugin/cellmodem.c:1603
-msgid "Cannot open modem"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:1429
-msgid "Error reading from modem"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:1507
-msgid "Error writing to modem"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:1523
-msgid "Modem did not reply to command"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:1541
-msgid "No driver defined"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:1546
-msgid "No modem instance"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:1720
-msgid "Modem initializing"
-msgstr ""
-
-#: ../panel-plugin/cellmodem.c:1755
-msgid "Invalid driver specified"
-msgstr ""
-
-#. Error.
-#: ../panel-plugin/pin_helper.c:31
-msgid "Invalid PIN entered. PIN has 4 digits"
-msgstr ""
-
-#: ../panel-plugin/pin_helper.c:65
-msgid "Enter PIN"
-msgstr ""
-
-#: ../panel-plugin/pin_helper.c:77
-msgid "Please enter PIN:"
-msgstr ""
-
-#: ../panel-plugin/preferences.c:285
-msgid "Close"
-msgstr ""
-
-#: ../panel-plugin/preferences.c:290
-msgid "No known device found."
-msgstr ""
-
-#: ../panel-plugin/preferences.c:292
-msgid "The following devices were found:"
-msgstr ""
-
-#: ../panel-plugin/preferences.c:299
-msgid "Use this device"
-msgstr ""
-
-#: ../panel-plugin/preferences.c:343
-msgid "Configure Cell Modem Monitor"
-msgstr ""
-
-#. The header - this was most copied from other sources
-#: ../panel-plugin/preferences.c:356
-msgid "Cellular Modem Monitor"
-msgstr ""
-
-#: ../panel-plugin/preferences.c:387
-msgid "Modem driver:"
-msgstr ""
-
-#: ../panel-plugin/preferences.c:409
-msgid "Modem speed:"
-msgstr ""
-
-#: ../panel-plugin/preferences.c:422
-msgid "Modem device:"
-msgstr ""
-
-#: ../panel-plugin/preferences.c:434
-msgid "Autodetect modem..."
-msgstr ""
-
-#: ../panel-plugin/preferences.c:444
-msgid "Maximum quality:"
-msgstr ""
-
-#: ../panel-plugin/preferences.c:455
-msgid "Low quality percentage:"
-msgstr ""
-
-#: ../panel-plugin/preferences.c:465
-msgid "Critical quality percentage:"
-msgstr ""
-
-#: ../panel-plugin/preferences.c:479
-msgid "Check for SMS every"
-msgstr ""
-
-#: ../panel-plugin/preferences.c:481
-msgid "minutes"
-msgstr ""



More information about the Xfce4-commits mailing list