]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
modelica monitor
authorniemisto <niemisto@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 23 Feb 2010 12:38:03 +0000 (12:38 +0000)
committerniemisto <niemisto@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 23 Feb 2010 12:38:03 +0000 (12:38 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14348 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.modelica/src/org/simantics/modelica/IModelicaMonitor.java [new file with mode: 0644]
org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java

diff --git a/org.simantics.modelica/src/org/simantics/modelica/IModelicaMonitor.java b/org.simantics.modelica/src/org/simantics/modelica/IModelicaMonitor.java
new file mode 100644 (file)
index 0000000..2466983
--- /dev/null
@@ -0,0 +1,5 @@
+package org.simantics.modelica;\r
+\r
+public interface IModelicaMonitor {\r
+    void message(String message);\r
+}\r
index 72b69ca1f56b15c0b09ebb13c7f67c3d7e5bdc0d..b61f37e753c504d78cde0acc45f81f7da14b004e 100644 (file)
@@ -41,13 +41,13 @@ public class ModelicaManager {
         return new String(buffer);\r
     }\r
     \r
-    protected static void printProcessOutput(Process process) throws IOException {\r
+    protected static void printProcessOutput(Process process, IModelicaMonitor monitor) throws IOException {\r
         InputStream stream = process.getInputStream();\r
         while(true) {\r
             int c = stream.read();\r
             if(c <= 0)\r
                 break;\r
-            System.out.print((char)c);\r
+            monitor.message(new String(new char[] {(char)c}));\r
         }\r
     }\r
     \r
@@ -93,7 +93,8 @@ public class ModelicaManager {
                 );\r
     }\r
     \r
-    public static SimulationResult runModelica(String modelName, String modelText, Double startTime, Double stopTime) throws IOException {\r
+    public static SimulationResult runModelica(String modelName, String modelText,\r
+            IModelicaMonitor monitor, Double startTime, Double stopTime) throws IOException {\r
         SimulationLocation simulationLocation = \r
             createInputFiles(modelName, modelText, startTime, stopTime);\r
         \r
@@ -108,7 +109,7 @@ public class ModelicaManager {
                 .directory(simulationLocation.simulationDir.getAbsoluteFile())\r
                 .redirectErrorStream(true)\r
                 .start();\r
-            printProcessOutput(process);\r
+            printProcessOutput(process, monitor);\r
             \r
             SimulationResult result = new SimulationResult();\r
             result.read(simulationLocation.outputFile);\r
@@ -123,14 +124,5 @@ public class ModelicaManager {
         }       \r
         return null;\r
     }\r
-    \r
-    public static void main(String[] args) {\r
-        try {\r
-            runModelica("Testi2", "model Testi2 end Testi2;", 0.0, 10.0);\r
-        } catch (IOException e) {\r
-            // TODO Auto-generated catch block\r
-            e.printStackTrace();\r
-        }\r
-    }\r
 \r
 }\r