From a0e857c8da67baf2cb0b5a2fa278de9c726a9f6a Mon Sep 17 00:00:00 2001
From: Ludovic Apvrille <ludovic.apvrille@telecom-paristech.fr>
Date: Mon, 21 Feb 2011 14:34:24 +0000
Subject: [PATCH] DIPLODOCUS: Update on LOTOS code generation: code is now
 generated in a one-pass process

---
 src/launcher/ExecutionThread.java           | 35 +++++++------
 src/launcher/RshServer.java                 | 10 +++-
 src/ui/GTURTLEModeling.java                 |  5 ++
 src/ui/MainGUI.java                         | 57 ++++++++++++++-------
 src/ui/window/JDialogSystemCGeneration.java |  2 +-
 5 files changed, 70 insertions(+), 39 deletions(-)

diff --git a/src/launcher/ExecutionThread.java b/src/launcher/ExecutionThread.java
index 00cdc3489c..79cf1a14ef 100755
--- a/src/launcher/ExecutionThread.java
+++ b/src/launcher/ExecutionThread.java
@@ -46,6 +46,7 @@ knowledge of the CeCILL license and that you accept its terms.
 
 package launcher;
 
+import myutil.*;
 
 import java.io.*;
 import java.net.*;
@@ -93,7 +94,7 @@ class ExecutionThread extends Thread {
     public synchronized void waitingForPipe() {
         while(pipe == null) {
             try {
-                System.out.println("Waiting for pipe");
+                TraceManager.addDev("Waiting for pipe");
                 wait();
             } catch (InterruptedException ie) {
                 
@@ -125,13 +126,13 @@ class ExecutionThread extends Thread {
     
     private Socket waitForClient() {
         Socket s = null;
-        System.out.println("process " + port + " is waiting for client");
+        TraceManager.addDev("process " + port + " is waiting for client");
         try {
             s = server.accept();
         } catch (Exception e) {
             return null;
         }
-        System.out.println("processe " + port + " got client");
+        TraceManager.addDev("processe " + port + " got client");
         return s;
     }
     
@@ -146,7 +147,7 @@ class ExecutionThread extends Thread {
         go = false;
         proc.destroy();
         proc_in = null;
-        //System.out.println("Stop process");
+        //TraceManager.addDev("Stop process");
     }
     
     private void respond(PrintStream out, String s) {
@@ -160,7 +161,7 @@ class ExecutionThread extends Thread {
     
     public void run() {
         isStarted = true;
-        System.out.println("Starting process for command " + cmd);
+        TraceManager.addDev("Starting process for command " + cmd);
         proc = null;
         BufferedReader in = null;
         String str;
@@ -170,12 +171,12 @@ class ExecutionThread extends Thread {
             try {
                 proc = Runtime.getRuntime().exec(cmd);
                 if (piped) {
-                    System.out.println("Giving my pipe to the other");
+                    TraceManager.addDev("Giving my pipe to the other");
                     et.setMyPipe(proc.getOutputStream());
                 }
-                System.out.println("Waiting for pipe");
+                TraceManager.addDev("Waiting for pipe");
                 waitingForPipe();
-                System.out.println("Got pipe");
+                TraceManager.addDev("Got pipe");
                 proc_in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
                 try {
                     while (((str = proc_in.readLine()) != null) && (go == true)){
@@ -185,21 +186,21 @@ class ExecutionThread extends Thread {
                     
                 }
             } catch (Exception e) {
-                System.out.println("Exception [" + e.getMessage() + "] occured when executing " + cmd);
+                TraceManager.addDev("Exception [" + e.getMessage() + "] occured when executing " + cmd);
             }
             try {
                 pipe.flush();
                 pipe.close();
             } catch (Exception e) {
-                System.out.println("Exception [" + e.getMessage() + "] occured when executing " + cmd);
+                TraceManager.addDev("Exception [" + e.getMessage() + "] occured when executing " + cmd);
             }
-            System.out.println("Ending command " + cmd);
+            TraceManager.addDev("Ending command " + cmd);
             
             // print output on socket
         } else {
             Socket s =  waitForClient();
             if (s == null) {
-                System.out.println("Client did not connect on time");
+                TraceManager.addDev("Client did not connect on time");
                 rsh.removeProcess(this);
                 return;
             }
@@ -207,13 +208,13 @@ class ExecutionThread extends Thread {
             PrintStream out = null;
             
             try {
-                System.out.println("Going to start command " + cmd);
+                TraceManager.addDev("Going to start command " + cmd);
                 out = new PrintStream(s.getOutputStream(), true);
                 
                 proc = Runtime.getRuntime().exec(cmd);
                 
                 if (piped) {
-                    System.out.println("Giving my pipe to the other");
+                    TraceManager.addDev("Giving my pipe to the other");
                     et.setMyPipe(proc.getOutputStream());
                 }
                 
@@ -223,14 +224,14 @@ class ExecutionThread extends Thread {
                 
                 
                 while (((str = proc_in.readLine()) != null) && (go == true)){
-                    System.out.println("out " + str);
+                    TraceManager.addDev("out " + str);
                     respond(out, "4" + str);
                 }
                 
             } catch (Exception e) {
-                System.out.println("Exception [" + e.getMessage() + "] occured when executing " + cmd);
+                TraceManager.addDev("Exception [" + e.getMessage() + "] occured when executing " + cmd);
             }
-            System.out.println("Ending command " + cmd);
+            TraceManager.addDev("Ending command " + cmd);
             respond(out, "5");
             if (s != null) {
                 closeConnect(s);
diff --git a/src/launcher/RshServer.java b/src/launcher/RshServer.java
index d615accbdb..3a06a5d30e 100755
--- a/src/launcher/RshServer.java
+++ b/src/launcher/RshServer.java
@@ -47,6 +47,8 @@
 package launcher;
 
 
+import myutil.*;
+
 import java.io.*;
 import java.net.*;
 import java.util.*;
@@ -62,9 +64,12 @@ public class RshServer {
     public static final String VERSION = "0.61";
     private int BUFSIZE = 511;
     private boolean []sessions = new boolean[10]; // 0 is never used.
+	
+	private static int MAX_NB_TRY = 25;
+	private int nbTry = 0;
 
     public RshServer() {
-		System.out.println("Using port: " + port);
+		TraceManager.addDev("Using port: " + port);
         processes = new Vector();
         try {
             server = new ServerSocket(port);
@@ -101,6 +106,7 @@ public class RshServer {
         try {
             s = server.accept();
         } catch (Exception e) {
+			nbTry ++;
             return null;
         }
         return s;
@@ -482,7 +488,7 @@ public class RshServer {
         Socket s = null;
         
         
-        while(true) {
+        while(nbTry < MAX_NB_TRY) {
             // Wait for client request
             printProcessRunning();
             
diff --git a/src/ui/GTURTLEModeling.java b/src/ui/GTURTLEModeling.java
index 2f48c78076..ab5b3c8af5 100755
--- a/src/ui/GTURTLEModeling.java
+++ b/src/ui/GTURTLEModeling.java
@@ -314,14 +314,19 @@ public class GTURTLEModeling {
 
 	public void generateLOTOS(File f) {
 		//tm.print();
+		TraceManager.addDev("Generating Lotos");
 		TURTLETranslator tt = new TURTLETranslator(tm);
 		rtlotos = tt.generateLOTOS(true);
 		warnings = tt.getWarnings();
+		TraceManager.addDev("Lotos generated");
 
+		
+		
 		nbRTLOTOS ++;
 		if (f != null) {
 			saveInFile(f, rtlotos);
 		}
+		TraceManager.addDev("LOTOS to file done");
 		languageID = LOTOS;
 		mgui.setMode(MainGUI.RTLOTOS_OK);
 	}
diff --git a/src/ui/MainGUI.java b/src/ui/MainGUI.java
index 34d4fdba67..384c1cc79a 100755
--- a/src/ui/MainGUI.java
+++ b/src/ui/MainGUI.java
@@ -2959,8 +2959,9 @@ public	class MainGUI implements ActionListener, WindowListener, KeyListener {
     
     
     public boolean generateRTLOTOS(boolean automatic) {
+		int ret = 0;
 		if (gtm.getTURTLEModelingState() > 0) {
-			if (!generateTURTLEModelingFromState(gtm.getTURTLEModelingState(), automatic, RT_LOTOS)) {
+			if ((ret = generateTURTLEModelingFromState(gtm.getTURTLEModelingState(), automatic, RT_LOTOS)) == -1) {
 				return false;
 			}
 		}
@@ -2970,7 +2971,9 @@ public	class MainGUI implements ActionListener, WindowListener, KeyListener {
         gtm.reinitRG();
         gtm.reinitRGAUT();
         gtm.reinitRGAUTPROJDOT();
-        gtm.generateRTLOTOS(lotosfile);
+		if (ret == 0) {
+			gtm.generateRTLOTOS(lotosfile);
+		}
 		if (!automatic) {
 			JOptionPane.showMessageDialog(frame,
 				"RT-LOTOS specification generated",
@@ -2987,8 +2990,10 @@ public	class MainGUI implements ActionListener, WindowListener, KeyListener {
 	
 	
     public boolean generateLOTOS(boolean automatic) {
+		int ret = 0;
 		if (gtm.getTURTLEModelingState() > 0) {
-			if (!generateTURTLEModelingFromState(gtm.getTURTLEModelingState(), automatic, LOTOS)) {
+			ret = generateTURTLEModelingFromState(gtm.getTURTLEModelingState(), automatic, LOTOS);
+			if (ret == -1) {
 				dtree.toBeUpdated();
 				TraceManager.addDev("Generate from state failed");
 				return false;
@@ -2999,15 +3004,17 @@ public	class MainGUI implements ActionListener, WindowListener, KeyListener {
 		}
 		
 		//System.out.println("generate LOTOS");
-        gtm.generateFullLOTOS(lotosfile);
-		//System.out.println("LOTOS generated");
-		if (!automatic) {
-			JOptionPane.showMessageDialog(frame,
-				"LOTOS specification generated (" + getCheckingWarnings().size() + " warning(s))",
-				"LOTOS specification",
-				JOptionPane.INFORMATION_MESSAGE);
+		if (ret == 0) {
+			gtm.generateFullLOTOS(lotosfile);
+			//System.out.println("LOTOS generated");
+			if (!automatic) {
+				JOptionPane.showMessageDialog(frame,
+					"LOTOS specification generated (" + getCheckingWarnings().size() + " warning(s))",
+					"LOTOS specification",
+					JOptionPane.INFORMATION_MESSAGE);
+			}
 		}
-		
+		setMode(MainGUI.RTLOTOS_OK);
         dtree.toBeUpdated();
 		return true;
     }
@@ -3017,19 +3024,31 @@ public	class MainGUI implements ActionListener, WindowListener, KeyListener {
 		dtree.toBeUpdated();
 	}
 	
-	public boolean generateTURTLEModelingFromState(int state, boolean automatic, int generator) {
+	// -1 : error
+	// 0: ok
+	// 1: ok, code already generated
+	public int generateTURTLEModelingFromState(int state, boolean automatic, int generator) {
 		if (state == 1) {
-			return generateTIFFromMapping(automatic, generator);
+			if (generateTIFFromMapping(automatic, generator)) {
+				return 1;
+			}
+			return -1;
 		}
 		if (state == 2) {
 			TraceManager.addDev("Generating from state 2");
-			return generateTIFFromTMLModeling(automatic, generator);
+			if (generateTIFFromTMLModeling(automatic, generator)) {
+				return 0;
+			}
+			return -1;
 		}
 		if (state == 3) {
 			TraceManager.addDev("Generating from state 3 (Avatar)");
-			return generateTIFFromAvatarSpecification(automatic, generator);
+			if (generateTIFFromAvatarSpecification(automatic, generator)) {
+				return 0;
+			}
+			return -1;
 		}
-		return false;
+		return -1;
 	}
 	
 	public boolean generateTIFFromAvatarSpecification(boolean automatic, int generator) {
@@ -3151,7 +3170,7 @@ public	class MainGUI implements ActionListener, WindowListener, KeyListener {
 				}
 				return;
 			} else {
-				if (!generateTURTLEModelingFromState(gtm.getTURTLEModelingState(), false, UPPAAL)) {
+				if (generateTURTLEModelingFromState(gtm.getTURTLEModelingState(), false, UPPAAL) == -1) {
 					return;
 				}
 				JDialogUPPAALGeneration jgen = new JDialogUPPAALGeneration(frame, this, "UPPAAL code generation", ConfigurationTTool.UPPAALCodeDirectory, JDialogUPPAALGeneration.DIPLODOCUS_MODE);
@@ -3207,7 +3226,7 @@ public	class MainGUI implements ActionListener, WindowListener, KeyListener {
     public void generateJava() {
 		
 		if (gtm.getTURTLEModelingState() == 1) {
-			if (!generateTURTLEModelingFromState(gtm.getTURTLEModelingState(), false, JAVA)) {
+			if (generateTURTLEModelingFromState(gtm.getTURTLEModelingState(), false, JAVA) == -1) {
 				return;
 			}
 		}
@@ -3350,7 +3369,7 @@ public	class MainGUI implements ActionListener, WindowListener, KeyListener {
     
     public void generateDesign() {
 		if (gtm.getTURTLEModelingState() == 1) {
-			if (!generateTURTLEModelingFromState(gtm.getTURTLEModelingState(), false, DESIGN)) {
+			if (generateTURTLEModelingFromState(gtm.getTURTLEModelingState(), false, DESIGN) == -1) {
 				return;
 			}
 		}
diff --git a/src/ui/window/JDialogSystemCGeneration.java b/src/ui/window/JDialogSystemCGeneration.java
index f0bf29e5a3..bf0e0f41d1 100755
--- a/src/ui/window/JDialogSystemCGeneration.java
+++ b/src/ui/window/JDialogSystemCGeneration.java
@@ -308,7 +308,7 @@ public class JDialogSystemCGeneration extends javax.swing.JDialog implements Act
         // validated list
         panele2Tepe = new JPanel();
         panele2Tepe.setLayout(new BorderLayout());
-        panele2Tepe.setBorder(new javax.swing.border.TitledBorder("EBRDDs taken into account"));
+        panele2Tepe.setBorder(new javax.swing.border.TitledBorder("TEPE Diagrams taken into account"));
         listValidatedTepe = new JList(valTepe);
         //listValidated.setPreferredSize(new Dimension(200, 250));
         listValidatedTepe.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
-- 
GitLab