Changeset 1040 for trunk/org.modelica.mdt.omc/src/org/modelica/mdt
- Timestamp:
- 10/18/11 21:37:33 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/org.modelica.mdt.omc/src/org/modelica/mdt/omc/OMCProxy.java
r692 r1040 103 103 public class OMCProxy implements IModelicaCompiler 104 104 { 105 105 106 106 /* the CORBA object */ 107 107 private OmcCommunication omcc; 108 108 109 109 enum osType { WINDOWS, UNIX }; 110 110 111 111 private String corbaSession = "mdt"; 112 112 … … 123 123 /* number of compiler errors to show */ 124 124 private int numberOfErrors = 0; 125 125 126 126 127 127 /* indicates if the Modelica System Library has been loaded */ … … 129 129 130 130 private ArrayList<String> standardLibraryPackages = null; 131 131 132 132 /* should we trace the calls to sendExpression? */ 133 133 private boolean traceOMCCalls = false; 134 134 private boolean traceOMCStatus = true; 135 135 136 136 private boolean traceStatusPreferences = false; 137 137 private boolean traceCommandsPreferences = false; 138 138 private boolean traceErrorPreferences = false; 139 139 private boolean traceReplyPrefereces = false; 140 140 141 141 { 142 142 /* load debug options and set debug flag variables accordingly */ … … 154 154 } 155 155 } 156 156 157 157 private OutputStream consoleOutput = null; 158 158 159 159 private OMCThread fOMCThread = null; 160 160 private boolean fOMCThreadHasBeenScheduled = false; 161 161 162 162 //private ILock fOMCLock = null; 163 163 … … 245 245 * With the help of voodoo magic determines the path to the 246 246 * omc binary that user (probably) wants to use and the working 247 * direc oty of where that binary (most likely) should be started in247 * directory of where that binary (most likely) should be started in 248 248 * 249 249 * This will returns for example 'c:\openmodelica132\omc.exe' … … 272 272 * user specified that standard path to omc should be used, 273 273 * try to determine the omc path via the OPENMODELICAHOME and 274 * by checking in it's vari us subdirectory for the omc binary file274 * by checking in it's various subdirectory for the omc binary file 275 275 */ 276 276 logOMCStatus("Using OPENMODELICAHOME environment variable to find omc-binary", true); … … 285 285 final String m = "Environment variable OPENMODELICAHOME not set"; 286 286 logOMCStatus("Environment variable OPENMODELICAHOME not set,"+ 287 " don't know how to start OMC from standard path.", true);287 " don't know how to start OMC from standard path.", true); 288 288 throw new ConnectException(m); 289 289 } … … 330 330 logOMCStatus("file '" + omcBinary.getAbsolutePath() + "' does not exist", true); 331 331 throw new ConnectException("Specified omc-binary '" + omcBinary.getAbsolutePath() + 332 "' does not exist");332 "' does not exist"); 333 333 } 334 334 … … 350 350 351 351 if (parent.getName().equalsIgnoreCase("bin") || 352 parent.getName().equalsIgnoreCase("compiler"))352 parent.getName().equalsIgnoreCase("compiler")) 353 353 { 354 354 omcWorkingDirectory = parent.getParentFile(); … … 406 406 String args[] = {null}; 407 407 408 /* set the CORBA read timeout to a larger value as we send huge am mounts of data408 /* set the CORBA read timeout to a larger value as we send huge amounts of data 409 409 * from OMC to MDT 410 410 */ 411 411 System.setProperty("com.sun.CORBA.transport.ORBTCPReadTimeouts", "1:60000:300:1"); 412 412 413 413 ORB orb; 414 414 orb = ORB.init(args, null); … … 531 531 // communication with OMC 532 532 // old synchronization aka 'private synchronized String sendExpression(String command)' 533 // doesn t work when there is possibility of multiple instances of OMCProxy objects533 // doesn't work when there is possibility of multiple instances of OMCProxy objects 534 534 public ICompilerResult sendExpression(String command, boolean showInConsole) throws ConnectException 535 535 { … … 541 541 return CompilerResult.makeResult(retval, error); 542 542 } 543 543 544 544 if (numberOfErrors > showMaxErrors) return CompilerResult.makeResult(retval, error); 545 545 546 546 // trim the start and end spaces 547 547 command = command.trim(); … … 553 553 return CompilerResult.makeResult(retval, error); 554 554 } 555 555 556 556 if(hasInitialized == false) 557 557 { 558 558 init(); 559 559 } 560 560 561 561 if (command.equalsIgnoreCase("quit()")) 562 562 hasInitialized = false; … … 591 591 else 592 592 System.out.println(""); 593 */593 */ 594 594 return CompilerResult.makeResult(retval, error); 595 595 } … … 623 623 } 624 624 } 625 625 626 626 if (!traceOMCCalls) 627 627 { … … 630 630 System.out.println(">> " + expression); 631 631 } 632 632 633 633 public void setConsoleOutputStream(OutputStream outputStream) 634 634 { 635 635 consoleOutput = outputStream; 636 636 } 637 637 638 638 639 639 /** … … 653 653 } 654 654 } 655 655 656 656 if(!traceOMCCalls) 657 657 { … … 662 662 663 663 /** 664 * log gs the message conserning OMC status if the664 * logs the message concerning OMC status if the 665 665 * tracing flag traceOMCStatus is set 666 666 * @param message the message to log … … 677 677 } 678 678 } 679 679 680 680 if (!traceOMCStatus) 681 681 { … … 689 689 * the tracing flag (traceOMCCalls) is set 690 690 * 691 * @param reply the reply rec ieved from the OMC691 * @param reply the reply received from the OMC 692 692 */ 693 693 private void logOMCReply(String reply, boolean showInConsole) … … 702 702 } 703 703 } 704 704 705 705 if (!traceOMCCalls) 706 706 { … … 756 756 */ 757 757 public IModelicaClass.Restriction getRestriction(String className) 758 throws ConnectException, UnexpectedReplyException759 {758 throws ConnectException, UnexpectedReplyException 759 { 760 760 ICompilerResult result = sendExpression("getClassRestriction(" + className + ")", true); 761 761 … … 782 782 783 783 return type; 784 }784 } 785 785 786 786 /** … … 796 796 */ 797 797 return 798 (retval.toLowerCase().contains("error") /* &&798 (retval.toLowerCase().contains("error") /* && 799 799 !retval.startsWith("{")) || 800 800 retval.equals("{}"*/); … … 805 805 ParseResults results; 806 806 long lastModification; 807 807 808 808 public LazyLoadResult(ParseResults results, long lastModification) 809 809 { … … 813 813 } 814 814 private static Map<IPath, LazyLoadResult> lazyLoadList = new HashMap<IPath, LazyLoadResult>(); 815 815 816 816 public static Map<IPath, LazyLoadResult> getLazyLoadList() 817 817 { 818 818 return lazyLoadList; 819 819 } 820 820 821 821 /** 822 822 * Tries to load file into OMC which causes it to be parsed and the syntax … … 900 900 long lastModification = file.getModificationStamp(); 901 901 if (lastModification != IFile.NULL_STAMP) 902 getLazyLoadList().put(file.getFullPath(), new LazyLoadResult(res, lastModification));902 getLazyLoadList().put(file.getFullPath(), new LazyLoadResult(res, lastModification)); 903 903 } 904 904 } … … 917 917 */ 918 918 public DefinitionLocation getClassLocation(String className) 919 throws ConnectException, UnexpectedReplyException, InvocationError920 {919 throws ConnectException, UnexpectedReplyException, InvocationError 920 { 921 921 ICompilerResult res = sendExpression("getCrefInfo(" + className + ")", true); 922 922 … … 967 967 throw new 968 968 UnexpectedReplyException("Can't parse getCrefInfo() reply, "+ 969 "unexpected format");969 "unexpected format"); 970 970 } 971 971 972 972 return new DefinitionLocation(filePath, startLine, startColumn, endLine, endColumn); 973 }973 } 974 974 975 975 /** … … 997 997 */ 998 998 public Collection<ElementInfo> getElements(String className) 999 throws ConnectException, InvocationError, UnexpectedReplyException1000 {999 throws ConnectException, InvocationError, UnexpectedReplyException 1000 { 1001 1001 ICompilerResult res = sendExpression("getElementsInfo("+ className +")", true); 1002 1002 String retval = res.getFirstResult(); … … 1010 1010 { 1011 1011 /* 1012 * we found the begin ing of the list, send it to parser and1012 * we found the beginning of the list, send it to parser and 1013 1013 * hope for the best 1014 1014 */ … … 1052 1052 /* we have no idea what OMC returned */ 1053 1053 throw new UnexpectedReplyException("getElementsInfo("+ className +")" + "replies:'" + retval + "'"); 1054 }1054 } 1055 1055 1056 1056 public IClassInfo getClassInfo(String className) 1057 throws ConnectException, UnexpectedReplyException1058 {1057 throws ConnectException, UnexpectedReplyException 1058 { 1059 1059 ICompilerResult res = sendExpression("getClassInformation("+ className +")", true); 1060 1060 String retval = res.getFirstResult(); … … 1076 1076 1077 1077 return ci; 1078 }1078 } 1079 1079 1080 1080 … … 1139 1139 { 1140 1140 sendExpression("loadModel("+(String)lib+")", true); 1141 1141 1142 1142 } 1143 1143 … … 1154 1154 * the server 1155 1155 */ 1156 public ICompilerResult getClassString(String className) 1157 throws ConnectException, UnexpectedReplyException 1158 { 1156 public ICompilerResult getClassString(String className) throws ConnectException, UnexpectedReplyException { 1159 1157 ICompilerResult res = sendExpression("list("+ className +")", true); 1160 1158 … … 1163 1161 return res; 1164 1162 } 1165 1163 1166 1164 /** 1167 1165 * … … 1174 1172 private String message = null; 1175 1173 private String prefix = null; 1176 1174 1177 1175 public ConsoleWriter(OutputStream output, String prefix) 1178 1176 { … … 1184 1182 this.prefix = prefix; 1185 1183 } 1186 1184 1187 1185 public synchronized void setMessage(String what) 1188 1186 { 1189 1187 message = what; 1190 1188 } 1191 1189 1192 1190 public synchronized void run() 1193 1191 { … … 1204 1202 } 1205 1203 } 1206 1204 1207 1205 /** 1208 1206 * Evaluate command locally, don't sent it to OpenModelica Compiler … … 1217 1215 { 1218 1216 retval = 1219 "All the MDT Console local commands start with '!'.\n" +1220 "All commands not starting with '!' will be sent to the OpenModelica compiler.\n" +1221 "For a list of OpenModelica commands available type help().\n" +1222 "NOTE: The !trace* commands display traces of all OpenModelica<->MDT\n" +1223 " communication except the commands send from the console!\n" +1224 "Available local commands are:\n" +1225 "!help - toggle display help on local commands.\n" +1226 "!traceStatus - toggle display the status of the OpenModelica compiler.\n" +1227 "!traceError - toggle display errors talking with the OpenModelica compiler.\n" +1228 "!traceReply - toggle display the reply of the OpenModelica compiler.\n" +1229 "!traceCommand - toggle display the commands send to the OpenModelica compiler.\n" +1230 "!traceAll - toggle on the display of all the traces available.\n" +1231 "!traceNone - toggle off the display of all the traces available.\n";1232 } 1233 1217 "All the MDT Console local commands start with '!'.\n" + 1218 "All commands not starting with '!' will be sent to the OpenModelica compiler.\n" + 1219 "For a list of OpenModelica commands available type help().\n" + 1220 "NOTE: The !trace* commands display traces of all OpenModelica<->MDT\n" + 1221 " communication except the commands send from the console!\n" + 1222 "Available local commands are:\n" + 1223 "!help - toggle display help on local commands.\n" + 1224 "!traceStatus - toggle display the status of the OpenModelica compiler.\n" + 1225 "!traceError - toggle display errors talking with the OpenModelica compiler.\n" + 1226 "!traceReply - toggle display the reply of the OpenModelica compiler.\n" + 1227 "!traceCommand - toggle display the commands send to the OpenModelica compiler.\n" + 1228 "!traceAll - toggle on the display of all the traces available.\n" + 1229 "!traceNone - toggle off the display of all the traces available.\n"; 1230 } 1231 1234 1232 if (command.equals("traceStatus")) 1235 1233 { … … 1237 1235 retval = "Tracing of OpenModelica status is set to: " + traceStatusPreferences; 1238 1236 } 1239 1237 1240 1238 if (command.equals("traceError")) 1241 1239 { 1242 1240 traceErrorPreferences = traceErrorPreferences ? false : true; 1243 1241 retval = 1244 "Tracing of errors while talking with OpenModelica is set to: " + traceErrorPreferences;1242 "Tracing of errors while talking with OpenModelica is set to: " + traceErrorPreferences; 1245 1243 } 1246 1244 1247 1245 if (command.equals("traceReply")) 1248 1246 { … … 1256 1254 retval = "Tracing of commands sent to OpenModelica is set to: " + traceCommandsPreferences; 1257 1255 } 1258 1256 1259 1257 if (command.equals("traceAll")) 1260 1258 { … … 1265 1263 retval = "All tracing is now enabled!"; 1266 1264 } 1267 1265 1268 1266 if (command.equals("traceNone")) 1269 1267 { … … 1274 1272 retval = "All tracing is now disabled!"; 1275 1273 } 1276 1274 1277 1275 return "\n" + retval; 1278 1276 } 1279 1277 1280 1278 class OMCThread extends Thread 1281 1279 { 1282 1280 1283 1281 public OMCThread() 1284 1282 { … … 1310 1308 */ 1311 1309 long lastModified = 0; 1312 1313 1314 1315 1316 1317 1310 if(f.exists()) 1311 { 1312 logOMCStatus("Remember the creation time for old OMC object reference file.", true); 1313 lastModified = f.lastModified(); 1314 } 1315 1318 1316 Process proc = null; 1319 1317 StreamReaderThread outThread = null; … … 1322 1320 String command[] = { omcBinary.getAbsolutePath(), "+c="+corbaSession, "+d=interactiveCorba"}; 1323 1321 String extraCmds[] = PreferenceManager.getOMCCommandLineParametersArray(); 1324 ArrayList both = new ArrayList(command.length + extraCmds.length);1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1322 ArrayList<String> both = new ArrayList<String>(command.length + extraCmds.length); 1323 Collections.addAll(both, command); 1324 Collections.addAll(both, extraCmds); 1325 String cmd[] = new String[both.size()]; 1326 int nonNull = 0; 1327 for (int i=0; i < both.size(); i++) 1328 { 1329 String str = (String) both.get(i); 1330 if (str != null) 1331 { 1332 cmd[nonNull] = str; 1333 nonNull++; 1334 } 1335 } 1336 String fullCMD = ""; 1337 for (int i=0; i < nonNull; i++) 1338 fullCMD += cmd[i] + " "; 1341 1339 logOMCStatus("Running command: " + fullCMD, true); 1342 1340 logOMCStatus("Setting working directory to: " + workingDirectory.getAbsolutePath(), true); … … 1374 1372 if (lastModified == 0 || (lastModified != 0 && f.lastModified() != lastModified)) 1375 1373 break; 1376 1374 1377 1375 try 1378 1376 { … … 1416 1414 } 1417 1415 } 1418 1416 1419 1417 public boolean isRunning() 1420 1418 {
Note: See TracChangeset
for help on using the changeset viewer.