X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.pythonlink%2Fsrc%2Forg%2Fsimantics%2Fpythonlink%2FPythonContext.java;fp=org.simantics.pythonlink%2Fsrc%2Forg%2Fsimantics%2Fpythonlink%2FPythonContext.java;h=5341cc233c16c02076e00bbfa8684aa09d14c001;hb=41e86809c6f381612bdc8ffd4f4013aba39d1db1;hp=d237c83eb5afd5ab0c112111adaadeb2120b729e;hpb=52bef206878a4384b43494243dd39813b2bdf5ad;p=simantics%2Fpython.git diff --git a/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java b/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java index d237c83..5341cc2 100644 --- a/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java +++ b/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java @@ -6,19 +6,27 @@ public class PythonContext implements Closeable { private long contextID; PythonContext() { - contextID = openPythonContextImpl(); + contextID = createContextImpl(); } @Override public void close() { long id = contextID; contextID = 0; - closePythonContextImpl(id); + if (id != 0) deleteContextImpl(id); + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + close(); } public void executePythonStatement(String statement) { executePythonStatementImpl( contextID, statement ); } + + // Setters public void setPythonIntegerVariable(String variableName, int value) { setPythonIntegerVariableImpl(contextID, variableName, value); @@ -39,6 +47,8 @@ public class PythonContext implements Closeable { public void setPythonStringArrayVariable(String variableName, String[] value) { setPythonStringArrayVariableImpl(contextID, variableName, value); } + + // Getters public int getPythonIntegerVariable(String variableName) { return getPythonIntegerVariableImpl(contextID, variableName); @@ -68,10 +78,10 @@ public class PythonContext implements Closeable { } // Native function declarations - private static native long openPythonContextImpl(); - private static native void closePythonContextImpl(long contextID); + private static native long createContextImpl(); + private static native void deleteContextImpl(long contextID); - private static native void executePythonStatementImpl(long contextID, String statement); + private static native int executePythonStatementImpl(long contextID, String statement); private static native void setPythonIntegerVariableImpl(long contextID, String variableName, int value); private static native void setPythonDoubleVariableImpl(long contextID, String variableName, double value);