[chronojump] Cancel tests now cancel immediately, no need touch platform and pushing more buttons



commit 6b9d7a4b1766b5848e53fe9235605da3b7099dc1
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sun Nov 20 04:53:01 2016 +0100

    Cancel tests now cancel immediately, no need touch platform and pushing more buttons

 src/chronopic.cs      |   17 +++++++++++++++--
 src/execute/event.cs  |    4 ++--
 src/execute/jump.cs   |   15 +++++++++++----
 src/gui/chronojump.cs |   20 ++++++++++++++------
 4 files changed, 42 insertions(+), 14 deletions(-)
---
diff --git a/src/chronopic.cs b/src/chronopic.cs
index 9e2d65f..53b200b 100644
--- a/src/chronopic.cs
+++ b/src/chronopic.cs
@@ -306,6 +306,7 @@ public class Chronopic {
                //-- esperados para la trama. (En el caso de id son 4). Si hay un 
                //-- timeout se aborta
                count=0;
+               CancelDo = false;
                do {
                        //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
@@ -314,10 +315,20 @@ public class Chronopic {
                                try {
                                        n = sp.Read(respuesta,count,5-count);
                                        LogB.Warning("respuesta = ");
-                                       LogB.Warning(respuesta.ToString());
+                                       LogB.Warning(respuesta[count].ToString());
                                        count+=n;
                                        success = true;
-                               } catch {}
+                               } catch {
+                                       //LogB.Warning("catched at Read_cambio");
+                                       //if cancel is clicked, CancelDo will be true. Stop reading
+                                       if(CancelDo)
+                                       {
+                                               //-- Wait a bit and empty buffer
+                                               Thread.Sleep(ErrorTimeout);
+                                               this.flushByTimeOut();
+                                               return false;
+                                       }
+                               }
                        } while (!success);
                } while (count<5 && n!=-1);
 
@@ -348,6 +359,8 @@ public class Chronopic {
 
        public bool AbortFlush; 
 
+       public bool CancelDo;
+
        //-- Vaciar buffer de entrada
        //-- De momento se hace leyendo muchos datos y descartando
        private void flush()
diff --git a/src/execute/event.cs b/src/execute/event.cs
index 7293295..249a2e0 100644
--- a/src/execute/event.cs
+++ b/src/execute/event.cs
@@ -523,7 +523,7 @@ public class EventExecute
        public virtual void MultiChronopicWrite(bool tempTable) {
                LogB.Information("at event.cs");
        }
-                       
+
        public Gtk.Button FakeButtonUpdateGraph {
                get { return fakeButtonUpdateGraph; }
        }
@@ -550,7 +550,7 @@ public class EventExecute
                get { return finish; }
                set { finish = value; }
        }
-       
+
        //called from chronojump.cs for cancelling events
        public bool Cancel
        {
diff --git a/src/execute/jump.cs b/src/execute/jump.cs
index 3fb707a..83b6749 100644
--- a/src/execute/jump.cs
+++ b/src/execute/jump.cs
@@ -279,8 +279,14 @@ public class JumpExecute : EventExecute
                do {
                        if(simulated)
                                ok = true;
-                       else 
+                       else
+                       {
+                               LogB.Information("calling Read_event");
                                ok = cp.Read_event(out timestamp, out platformState);
+                       }
+
+                       LogB.Information("Read_event done!");
+
 
 
                        /*
@@ -421,11 +427,12 @@ public class JumpExecute : EventExecute
                                        loggedState = States.OFF;
                                }
                        }
-//Log.WriteLine("PREEXIT");
                } while ( ! success && ! cancel );
-//Log.WriteLine("EXIT");
+
+               LogB.Information("Exited waitEvent main bucle");
                
-               if(cancel) {
+               if(cancel)
+               {
                        //event will be raised, and managed in chronojump.cs
                        fakeButtonFinished.Click();
 
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index b98187b..280fad1 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -3422,11 +3422,14 @@ public partial class ChronoJumpWindow
 
                LogB.Information("cancel clicked one");
 
-               //this will cancel jumps or runs
+               //this will mark the test as cancelled
                currentEventExecute.Cancel = true;
 
-               if(cp2016.StoredCanCaptureContacts)
-                       checkCancelTotally(o, args);
+               //this will actually cancel Read_cambio and then Read_event in order to really cancel
+               cp2016.CP.CancelDo = true;
+
+               //if(cp2016.StoredCanCaptureContacts)
+               //      checkCancelTotally(o, args);
 
                //let update stats
                //nothing changed, but stats update button cannot be insensitive,
@@ -3443,14 +3446,18 @@ public partial class ChronoJumpWindow
        {
                LogB.Information("cancel multi clicked one");
 
-               //this will cancel jumps or runs
+               //this will mark the test as cancelled
                currentEventExecute.Cancel = true;
 
-               if(cp2016.StoredCanCaptureContacts)
-                       checkCancelMultiTotally(o, args);
+               //this will actually cancel Read_cambio and then Read_event in order to really cancel
+               cp2016.CP.CancelDo = true;
+
+               //if(cp2016.StoredCanCaptureContacts)
+               //      checkCancelMultiTotally(o, args);
        }
 
 
+       /*
        //if user doesn't touch the platform after pressing "cancel", sometimes it gets waiting a Read_event
        //now the event cancels ok, and next will be ok, also   
        private void checkCancelTotally (object o, EventArgs args) 
@@ -3512,6 +3519,7 @@ public partial class ChronoJumpWindow
                        errorWin.Button_accept.Clicked += new EventHandler(checkCancelMultiTotally);
                }
        }
+       */
                
                
        private void on_finish_clicked (object o, EventArgs args) 


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