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=d237c83eb5afd5ab0c112111adaadeb2120b729e;hb=52bef206878a4384b43494243dd39813b2bdf5ad;hp=0000000000000000000000000000000000000000;hpb=034e25e65348f61edc54354e94b0ae9ea8b58317;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 new file mode 100644 index 0000000..d237c83 --- /dev/null +++ b/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java @@ -0,0 +1,94 @@ +package org.simantics.pythonlink; + +import java.io.Closeable; + +public class PythonContext implements Closeable { + private long contextID; + + PythonContext() { + contextID = openPythonContextImpl(); + } + + @Override + public void close() { + long id = contextID; + contextID = 0; + closePythonContextImpl(id); + } + + public void executePythonStatement(String statement) { + executePythonStatementImpl( contextID, statement ); + } + + public void setPythonIntegerVariable(String variableName, int value) { + setPythonIntegerVariableImpl(contextID, variableName, value); + } + public void setPythonDoubleVariable(String variableName, double value) { + setPythonDoubleVariableImpl(contextID, variableName, value); + } + public void setPythonStringVariable(String variableName, String value) { + setPythonStringVariableImpl(contextID, variableName, value); + } + + public void setPythonIntegerArrayVariable(String variableName, int[] value) { + setPythonIntegerArrayVariableImpl(contextID, variableName, value); + } + public void setPythonDoubleArrayVariable(String variableName, double[] value) { + setPythonDoubleArrayVariableImpl(contextID, variableName, value); + } + public void setPythonStringArrayVariable(String variableName, String[] value) { + setPythonStringArrayVariableImpl(contextID, variableName, value); + } + + public int getPythonIntegerVariable(String variableName) { + return getPythonIntegerVariableImpl(contextID, variableName); + } + public double getPythonDoubleVariable(String variableName) { + return getPythonDoubleVariableImpl(contextID, variableName); + } + public String getPythonStringVariable(String variableName) { + return getPythonStringVariableImpl(contextID, variableName); + } + + public int[] getPythonIntegerArrayVariable(String variableName) { + return getPythonIntegerArrayVariableImpl(contextID, variableName); + } + public double[] getPythonDoubleArrayVariable(String variableName) { + return getPythonDoubleArrayVariableImpl(contextID, variableName); + } + public String[] getPythonStringArrayVariable(String variableName) { + return getPythonStringArrayVariableImpl(contextID, variableName); + } + + public void setPythonNDArrayVariable(String variableName, NDArray value) { + setPythonNDArrayVariableImpl(contextID, variableName, value); + } + public NDArray getPythonNDArrayVariable(String variableName) { + return getPythonNDArrayVariableImpl(contextID, variableName); + } + + // Native function declarations + private static native long openPythonContextImpl(); + private static native void closePythonContextImpl(long contextID); + + private static native void 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); + private static native void setPythonStringVariableImpl(long contextID, String variableName, String value); + + private static native void setPythonIntegerArrayVariableImpl(long contextID, String variableName, int[] value); + private static native void setPythonDoubleArrayVariableImpl(long contextID, String variableName, double[] value); + private static native void setPythonStringArrayVariableImpl(long contextID, String variableName, String[] value); + + private static native int getPythonIntegerVariableImpl(long contextID, String variableName); + private static native double getPythonDoubleVariableImpl(long contextID, String variableName); + private static native String getPythonStringVariableImpl(long contextID, String variableName); + + private static native int[] getPythonIntegerArrayVariableImpl(long contextID, String variableName); + private static native double[] getPythonDoubleArrayVariableImpl(long contextID, String variableName); + private static native String[] getPythonStringArrayVariableImpl(long contextID, String variableName); + + private static native void setPythonNDArrayVariableImpl(long contextID, String variableName, NDArray value); + private static native NDArray getPythonNDArrayVariableImpl(long contextID, String variableName); +}