[chronojump] Fixed (hope) hang on exit on windows after cancelling



commit 2e5699d75a4544e390907e8262d9cfc06b519895
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Apr 20 12:06:53 2011 +0200

    Fixed (hope) hang on exit on windows after cancelling

 howto_translate.txt    |    8 +---
 src/chronojump_mini.cs |    1 +
 src/chronopic.cs       |   27 ++++++++++++---
 src/gui/chronojump.cs  |   47 ++++++++------------------
 src/gui/chronopic.cs   |   86 +++++++++++++++++++++++++++++-------------------
 5 files changed, 91 insertions(+), 78 deletions(-)
---
diff --git a/howto_translate.txt b/howto_translate.txt
index b1b3264..d2c3947 100644
--- a/howto_translate.txt
+++ b/howto_translate.txt
@@ -33,14 +33,10 @@ msgmerge -o ca.po ca_old.po chronojump.pot
 mv es.po es_old.po
 msgmerge -o es.po es_old.po chronojump.pot
 
-5.- edit the ca.po with a multiporpose editor like vim, or a po editor like poedit
+5.- edit the ca.po with a multipurpose editor like vim, or a po editor like poedit
 poedit it's better because it fast finds what needs to be translated
 
-6.- generate the locales
-cd ..
-./compile_po_files.sh
-
-remember to compile (make) for see results
+6.- make, sudo make install
 ---------
 ---------
 
diff --git a/src/chronojump_mini.cs b/src/chronojump_mini.cs
index c4d7345..c12cf11 100644
--- a/src/chronojump_mini.cs
+++ b/src/chronojump_mini.cs
@@ -147,6 +147,7 @@ class Test {
 
 		//-- Crear objeto chronopic, para acceder al chronopic
 		Chronopic cp = new Chronopic(sp);
+		cp.Flush();
 
 
 		//-- Obtener el estado inicial de la plataforma
diff --git a/src/chronopic.cs b/src/chronopic.cs
index 47d68fd..db80ba8 100644
--- a/src/chronopic.cs
+++ b/src/chronopic.cs
@@ -48,6 +48,12 @@ public class Chronopic {
 	//  CONSTRUCTORES Y DESTRUCTORES
 	//******************************
 
+	//-- Fake Constructor
+	//only used when there's a problem in detection and must return a Chronopic instance
+	//see gui/chronopic.cs chronopicInit
+	public Chronopic() {
+	}
+
 	//-- Constructor
 	public Chronopic(SerialPort sp)
 	{
@@ -75,9 +81,9 @@ Console.Write("3");
 		this.sp = sp;
 
 Console.Write("4");
-		//-- Vaciar buffer
-		this.flush();
-Console.Write("5");
+//		//-- Vaciar buffer
+//		//done in a separate method
+//		this.flush();
 	}
 
 	//-- Destructor
@@ -295,6 +301,8 @@ Console.Write(" o3 ");
 		return status;
 	}
 
+	public bool AbortFlush;	
+
 	//-- Vaciar buffer de entrada
 	//-- De momento se hace leyendo muchos datos y descartando
 	private void flush()
@@ -304,13 +312,20 @@ Console.Write(" o3 ");
 		//try, catch done because mono-1.2.3 throws an exception when there's a timeout
 		//http://bugzilla.gnome.org/show_bug.cgi?id=420520
 		bool success = false;
+		AbortFlush = false;
 		do{
 			try{
 				sp.Read(buffer,0,256);
 				success = true;
-			} catch {}
-
-		} while(!success);
+				Log.Write(" spReaded ");
+			} catch {
+				Log.Write(" catchedTimeOut ");
+			}
+
+		} while(! success && ! AbortFlush);
+		if(AbortFlush) {
+			Log.WriteLine("Abort flush");
+		}
 	}
 
 	public void Flush() {
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 89c4928..a603a8c 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2077,42 +2077,24 @@ public partial class ChronoJumpWindow
 	 */
 	
 	private void on_delete_event (object o, DeleteEventArgs args) {
-		Log.WriteLine("Bye!");
-    
-		if(chronopicWin.Connected == true) {
-			chronopicWin.SerialPortsClose();
-		}
-	
-		try {	
-			File.Delete(runningFileName);
-		} catch {
-			new DialogMessage(Constants.MessageTypes.WARNING, 
-					string.Format(Catalog.GetString("Could not delete file:\n{0}"), runningFileName));
-		}
-
-		if(File.Exists(Util.GetDatabaseTempDir() + Path.DirectorySeparatorChar + "chronojump.db"))
-			File.Move(Util.GetDatabaseTempDir() + Path.DirectorySeparatorChar + "chronojump.db",
-				Util.GetDatabaseDir() + Path.DirectorySeparatorChar + "chronojump.db");
-		
-		Log.WriteLine("Bye2!");
+		args.RetVal = true;
+		on_quit1_activate (new object(), new EventArgs ());
+	}
 
-		System.Console.Out.Close();
-		//Log.End();
-		//Log.Delete();
-		Log.WriteLine("Bye3!");
 
+	private void on_quit1_activate (object o, EventArgs args) {
 		if(chronopicCancelledTimes > 0 && Util.IsWindows()) {
-			new DialogMessage(Constants.MessageTypes.WARNING, 
-					Catalog.GetString("Attention, current version of Chronojump gets hanged on exit\nif user has cancelled detection of Chronopic.") + "\n\n" +
+		//if(chronopicCancelledTimes > 0) {
+			confirmWinJumpRun = ConfirmWindowJumpRun.Show( 
+					Catalog.GetString("Attention, current version of Chronojump gets hanged on exit\nif user has cancelled detection of Chronopic."),
 					Catalog.GetString("Sorry, you will have to close Chronojump using CTRL + ALT + DEL."));
-		}
-		
-		Log.WriteLine("Bye4!");
-		
-		Application.Quit();
+			confirmWinJumpRun.Button_accept.Clicked += new EventHandler(on_quit2_activate);
+		} else
+			on_quit2_activate(new object(), new EventArgs());
 	}
+		
 
-	private void on_quit1_activate (object o, EventArgs args) {
+	private void on_quit2_activate (object o, EventArgs args) {
 		Log.WriteLine("Bye!");
     
 		if(chronopicWin.Connected == true) {
@@ -2132,10 +2114,11 @@ public partial class ChronoJumpWindow
 		
 		Log.WriteLine("Bye2!");
 		System.Console.Out.Close();
-		//Log.End();
-		//Log.Delete();
 		Log.WriteLine("Bye3!");
 		Application.Quit();
+		Log.WriteLine("Bye4!");
+		Environment.Exit(Environment.ExitCode);
+		Log.WriteLine("Bye5!");
 	}
 	
 	/* ---------------------------------------------------------
diff --git a/src/gui/chronopic.cs b/src/gui/chronopic.cs
index 1e28df2..0be91b8 100644
--- a/src/gui/chronopic.cs
+++ b/src/gui/chronopic.cs
@@ -411,7 +411,7 @@ Log.WriteLine("bbb");
 				Util.StringArrayToString(SerialPort.GetPortNames(),"\n"));
 		textview_ports_found_explanation.Buffer = UtilGtk.TextViewPrint(
 				Catalog.GetString("These are USB devices like Chronopic but also pendrives, USB printers...") + "\n" + 
-				Catalog.GetString("If you just connected Chronopic, close and open again this window.") +
+				Catalog.GetString("If you just plugged Chronopic cable and expected port is not listed, close and open again this window.") +
 				saferPorts
 				);
 	}
@@ -456,7 +456,8 @@ Log.WriteLine("bbb");
 	}
 
 	//chronopic init should not touch  gtk, for the threads
-	private Chronopic chronopicInit (Chronopic myCp, out SerialPort mySp, Chronopic.Plataforma myPS, string myPort, out string returnString, out bool success) 
+	//private Chronopic chronopicInit (out Chronopic myCp, out SerialPort mySp, Chronopic.Plataforma myPS, string myPort, out string returnString, out bool success) 
+	private void chronopicInit (out Chronopic myCp, out SerialPort mySp, Chronopic.Plataforma myPS, string myPort, out string returnString, out bool success) 
 	{
 		Log.WriteLine ( Catalog.GetString ("starting connection with chronopic") );
 		//if(isWindows)
@@ -472,29 +473,41 @@ Log.WriteLine("bbb");
 			Log.WriteLine("chronopicInit-2");		
 			//-- Create chronopic object, for accessing chronopic
 			myCp = new Chronopic(mySp);
-
-			Log.WriteLine("chronopicInit-3");		
-			//on windows, this check make a crash 
-			//i think the problem is: as we don't really know the Timeout on Windows (.NET) and this variable is not defined on chronopic.cs
-			//the Read_platform comes too much soon (when cp is not totally created), and this makes crash
-
-			//-- Obtener el estado inicial de la plataforma
-
-			bool ok=false;
-			Log.WriteLine("chronopicInit-4");		
-			do {
-				Log.WriteLine("chronopicInit-5");		
-				ok=myCp.Read_platform(out myPS);
-				Log.WriteLine("chronopicInit-6");		
-			} while(!ok);
-			Log.WriteLine("chronopicInit-7");		
-			if (!ok) {
-				//-- Si hay error terminar
-				Log.WriteLine(string.Format("Error: {0}", myCp.Error));
+			
+			Log.WriteLine("chronopicInit-2.1");		
+			myCp.Flush();
+			
+			//if myCp has been cancelled
+			if(myCp.AbortFlush) {
+				Log.WriteLine("chronopicInit-2.2 cancelled");
 				success = false;
+				myCp = new Chronopic(); //fake constructor
+			} else {
+				Log.WriteLine("chronopicInit-3");		
+				//on windows, this check make a crash 
+				//i think the problem is: as we don't really know the Timeout on Windows (.NET) and this variable is not defined on chronopic.cs
+				//the Read_platform comes too much soon (when cp is not totally created), and this makes crash
+
+				//-- Obtener el estado inicial de la plataforma
+
+				bool ok=false;
+				Log.WriteLine("chronopicInit-4");		
+				do {
+					Log.WriteLine("chronopicInit-5");		
+					ok=myCp.Read_platform(out myPS);
+					Log.WriteLine("chronopicInit-6");		
+				} while(!ok);
+				Log.WriteLine("chronopicInit-7");		
+				if (!ok) {
+					//-- Si hay error terminar
+					Log.WriteLine(string.Format("Error: {0}", myCp.Error));
+					success = false;
+				}
 			}
 		} catch {
+			Log.WriteLine("chronopicInit-2.a catched");
 			success = false;
+			myCp = new Chronopic(); //fake constructor
 		}
 			
 		returnString = "";
@@ -502,7 +515,6 @@ Log.WriteLine("bbb");
 			if(currentCp == 1)
 				connected = true;
 			returnString = string.Format(Catalog.GetString("<b>Connected</b> to Chronopic on port: {0}"), myPort);
-			//appbar2.Push( 1, returnString);
 		}
 		if(! success) {
 			returnString = Catalog.GetString("Problems communicating to chronopic.");
@@ -510,11 +522,6 @@ Log.WriteLine("bbb");
 				returnString += " " + Catalog.GetString("Changed platform to 'Simulated'");
 				returnString += Catalog.GetString("\n\nWe recommend to remove and connect USB cable.");
 			}
-			//if(isWindows) {
-				//returnString += Catalog.GetString("\n\nOn Windows we recommend to remove and connect USB or serial cable from the computer after every unsuccessful port test.");
-				//returnString += Catalog.GetString("\n... And after cancelling Chronopic detection.");
-				//returnString += Catalog.GetString("\n\n... Later, when you close Chronojump it will probably get frozen. If this happens, let's press CTRL+C on the black screen.");
-			//}
 
 			//this will raise on_radiobutton_simulated_ativate and 
 			//will put cpRunning to false, and simulated to true and cp.Close()
@@ -522,7 +529,7 @@ Log.WriteLine("bbb");
 				connected = false;
 			}
 		}
-		return myCp;
+//		return myCp;
 	}
 	
 	private void on_checkbutton_multi_show_clicked(object o, EventArgs args) {
@@ -578,7 +585,6 @@ Log.WriteLine("bbb");
 
 
 	void prepareChronopicConnection() {
-		//ChronopicConnection chronopicConnectionWin = ChronopicConnection.Show();
 		chronopicConnectionWin = ChronopicConnection.Show();
 		chronopicConnectionWin.LabelFeedBackReset();
 
@@ -587,11 +593,13 @@ Log.WriteLine("bbb");
 		fakeConnectionButton = new Gtk.Button();
 		fakeConnectionButton.Clicked += new EventHandler(on_chronopic_detection_ended);
 
+		needUpdateChronopicWin = false;
 		thread = new Thread(new ThreadStart(waitChronopicStart));
 		GLib.Idle.Add (new GLib.IdleHandler (PulseGTK));
 		thread.Start(); 
 	}
-	
+
+	static Chronopic cpDoing;	
 	protected void waitChronopicStart () 
 	{
 		chronopicConnectionWin.Button_cancel.Clicked += new EventHandler(on_chronopic_cancelled);
@@ -613,7 +621,9 @@ Log.WriteLine("bbb");
 			
 		if(currentCp == 1) {
 			myPort = ((ChronopicPortData) cpd[0]).Port;
-			cp = chronopicInit(cp, out sp, platformState, myPort, out message, out success);
+			cpDoing = cp;
+			chronopicInit(out cpDoing, out sp, platformState, myPort, out message, out success);
+			cp = cpDoing;
 			if(success) {
 				((ChronopicPortData) cpd[0]).Connected=true;
 				button_connect_cp1.Sensitive = false;
@@ -643,7 +653,9 @@ Log.WriteLine("bbb");
 		}
 		else if(currentCp == 2) {
 			myPort = ((ChronopicPortData) cpd[1]).Port;
-			cp2 = chronopicInit(cp2, out sp2, platformState2, myPort, out message, out success);
+			cpDoing = cp2;
+			chronopicInit(out cpDoing, out sp2, platformState2, myPort, out message, out success);
+			cp2 = cpDoing;
 			if(success) {
 				((ChronopicPortData) cpd[1]).Connected=true;
 				button_connect_cp2.Sensitive = false;
@@ -669,7 +681,9 @@ Log.WriteLine("bbb");
 		}
 		else if(currentCp == 3) {
 			myPort = ((ChronopicPortData) cpd[2]).Port;
-			cp3 = chronopicInit(cp3, out sp3, platformState3, myPort, out message, out success);
+			cpDoing = cp3;
+			chronopicInit(out cpDoing, out sp3, platformState3, myPort, out message, out success);
+			cp3 = cpDoing;
 			if(success) {
 				((ChronopicPortData) cpd[2]).Connected=true;
 				button_connect_cp3.Sensitive = false;
@@ -691,7 +705,9 @@ Log.WriteLine("bbb");
 		}
 		else if(currentCp == 4) {
 			myPort = ((ChronopicPortData) cpd[3]).Port;
-			cp4 = chronopicInit(cp4, out sp4, platformState4, myPort, out message, out success);
+			cpDoing = cp4;
+			chronopicInit(out cpDoing, out sp4, platformState4, myPort, out message, out success);
+			cp4 = cpDoing;
 			if(success) {
 				((ChronopicPortData) cpd[3]).Connected=true;
 				button_connect_cp4.Sensitive = false;
@@ -734,6 +750,8 @@ Log.WriteLine("bbb");
 		Log.WriteLine("cancelled-----");
 		fakeButtonCancelled.Click(); //just to show message of crashing on windows exiting
 		
+		cpDoing.AbortFlush = true;
+
 		//kill the chronopicInit function that is waiting event 
 		//thread.Abort();
 		//http://stackoverflow.com/questions/2853072/thread-does-not-abort-on-application-closing



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