X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.fmil.core%2Fsrc%2Forg%2Fsimantics%2Ffmil%2Fcore%2FFMIL.java;h=0e413afcef29ff63c1cd7c98ee01044d917d7b6d;hb=HEAD;hp=7301caf4c8209883e9d77aaaa3fc3e5bc6a5aa17;hpb=7cdd9e0931c9905bde72e01038d16589a3040ee6;p=simantics%2Ffmil.git diff --git a/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java b/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java index 7301caf..0e413af 100644 --- a/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java +++ b/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java @@ -6,6 +6,7 @@ import java.io.RandomAccessFile; import java.net.URL; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; +import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; @@ -31,11 +32,14 @@ public class FMIL { private static final Logger LOGGER = LoggerFactory.getLogger(FMIL.class); + private static final boolean DEBUG = false; + /** * Static variables */ private static int OK = 0; private static int ERROR = 1; + private static int PENDING = 2; private static String UNSATISFIED_LINK = "Method not found. DLL might not be loaded properly."; public static final String TEMP_FMU_DIRECTORY_NAME = "fmil"; public static String TEMP_FMU_COMMON_DIRECTORY; @@ -119,7 +123,9 @@ public class FMIL { private String[] declaredTypeQuantities; private String[] declaredTypeUnits; - private TObjectIntHashMap variableMap = new TObjectIntHashMap(); + private static int NO_VARIABLE_KEY = -1; + + private TObjectIntHashMap variableMap = new TObjectIntHashMap(10, 0.5f, NO_VARIABLE_KEY); private Set subscriptionSet = new HashSet(); private TIntArrayList subscription = new TIntArrayList(); @@ -133,7 +139,7 @@ public class FMIL { synchronized(syncObject) { // Safety check int vr = variableMap.get(name); - if(vr == 0) return false; + if(vr == NO_VARIABLE_KEY) return false; if(!subscriptionSet.add(name)) return false; subscribedNames.add(name); subscription.add(vr); @@ -180,9 +186,14 @@ public class FMIL { * @throws FMILException */ private int fmuN = 0; - private boolean fmuLoaded = false; + private boolean instantiated = false; public void loadFMUFile(String path) throws FMILException { + if (!Files.exists(Paths.get(path))) + throw new FMILException("File " + path + " does not exist"); + if (!Files.isRegularFile(Paths.get(path))) + throw new FMILException("Path " + path + " is not a file"); + synchronized(syncObject) { if(fmuN % 2 == 0) { @@ -193,21 +204,23 @@ public class FMIL { fmuN = 0; } - File tempDir = new File(fmuDir); - if(tempDir.isDirectory()) { + java.nio.file.Path tempDir = Paths.get(fmuDir); + if(Files.exists(tempDir) && Files.isDirectory(tempDir)) { try { - FileUtils.deleteAll(tempDir); + FileUtils.emptyDirectory(tempDir); } catch (IOException e) { - throw new FMILException("Could not create temp folder for fmu"); + throw new FMILException("Could not delete existing files from temp folder for fmu " + path, e); } - tempDir.mkdir(); } else { - tempDir.mkdir(); + try { + Files.createDirectory(tempDir); + } catch (IOException e) { + throw new FMILException("Could not create temp folder for fmu " + path, e); + } } - try { - String tmpPath = tempDir.getAbsolutePath(); + String tmpPath = tempDir.toString(); if(!tmpPath.endsWith("\\") && !tmpPath.endsWith("/")) tmpPath = tmpPath + "/"; id = loadFMUFile_(path, tmpPath); @@ -218,8 +231,8 @@ public class FMIL { for(int i=0;i