]> gerrit.simantics Code Review - simantics/python.git/blob - org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java
d237c83eb5afd5ab0c112111adaadeb2120b729e
[simantics/python.git] / org.simantics.pythonlink / src / org / simantics / pythonlink / PythonContext.java
1 package org.simantics.pythonlink;\r
2 \r
3 import java.io.Closeable;\r
4 \r
5 public class PythonContext implements Closeable {\r
6     private long contextID;\r
7     \r
8     PythonContext() {\r
9         contextID = openPythonContextImpl();\r
10     }\r
11     \r
12     @Override\r
13     public void close() {\r
14         long id = contextID;\r
15         contextID = 0;\r
16         closePythonContextImpl(id);\r
17     }\r
18     \r
19     public void executePythonStatement(String statement) {\r
20         executePythonStatementImpl( contextID, statement );\r
21     }\r
22     \r
23     public void setPythonIntegerVariable(String variableName, int value) {\r
24         setPythonIntegerVariableImpl(contextID, variableName, value);\r
25     }\r
26     public void setPythonDoubleVariable(String variableName, double value) {\r
27         setPythonDoubleVariableImpl(contextID, variableName, value);\r
28     }\r
29     public void setPythonStringVariable(String variableName, String value) {\r
30         setPythonStringVariableImpl(contextID, variableName, value);\r
31     }\r
32     \r
33     public void setPythonIntegerArrayVariable(String variableName, int[] value) {\r
34         setPythonIntegerArrayVariableImpl(contextID, variableName, value);\r
35     }\r
36     public void setPythonDoubleArrayVariable(String variableName, double[] value) {\r
37         setPythonDoubleArrayVariableImpl(contextID, variableName, value);\r
38     }\r
39     public void setPythonStringArrayVariable(String variableName, String[] value) {\r
40         setPythonStringArrayVariableImpl(contextID, variableName, value);\r
41     }\r
42     \r
43     public int getPythonIntegerVariable(String variableName) {\r
44         return getPythonIntegerVariableImpl(contextID, variableName);\r
45     }\r
46     public double getPythonDoubleVariable(String variableName) {\r
47         return getPythonDoubleVariableImpl(contextID, variableName);\r
48     }\r
49     public String getPythonStringVariable(String variableName) {\r
50         return getPythonStringVariableImpl(contextID, variableName);\r
51     }\r
52     \r
53     public int[] getPythonIntegerArrayVariable(String variableName) {\r
54         return getPythonIntegerArrayVariableImpl(contextID, variableName);\r
55     }\r
56     public double[] getPythonDoubleArrayVariable(String variableName) {\r
57         return getPythonDoubleArrayVariableImpl(contextID, variableName);\r
58     }\r
59     public String[] getPythonStringArrayVariable(String variableName) {\r
60         return getPythonStringArrayVariableImpl(contextID, variableName);\r
61     }\r
62     \r
63     public void setPythonNDArrayVariable(String variableName, NDArray value) {\r
64         setPythonNDArrayVariableImpl(contextID, variableName, value);\r
65     }\r
66     public NDArray getPythonNDArrayVariable(String variableName) {\r
67         return getPythonNDArrayVariableImpl(contextID, variableName);\r
68     }\r
69 \r
70     // Native function declarations\r
71     private static native long openPythonContextImpl();\r
72     private static native void closePythonContextImpl(long contextID);\r
73     \r
74     private static native void executePythonStatementImpl(long contextID, String statement);\r
75     \r
76     private static native void setPythonIntegerVariableImpl(long contextID, String variableName, int value);\r
77     private static native void setPythonDoubleVariableImpl(long contextID, String variableName, double value);\r
78     private static native void setPythonStringVariableImpl(long contextID, String variableName, String value);\r
79     \r
80     private static native void setPythonIntegerArrayVariableImpl(long contextID, String variableName, int[] value);\r
81     private static native void setPythonDoubleArrayVariableImpl(long contextID, String variableName, double[] value);\r
82     private static native void setPythonStringArrayVariableImpl(long contextID, String variableName, String[] value);\r
83     \r
84     private static native int getPythonIntegerVariableImpl(long contextID, String variableName);\r
85     private static native double getPythonDoubleVariableImpl(long contextID, String variableName);\r
86     private static native String getPythonStringVariableImpl(long contextID, String variableName);\r
87     \r
88     private static native int[] getPythonIntegerArrayVariableImpl(long contextID, String variableName);\r
89     private static native double[] getPythonDoubleArrayVariableImpl(long contextID, String variableName);\r
90     private static native String[] getPythonStringArrayVariableImpl(long contextID, String variableName);\r
91     \r
92     private static native void setPythonNDArrayVariableImpl(long contextID, String variableName, NDArray value);\r
93     private static native NDArray getPythonNDArrayVariableImpl(long contextID, String variableName);\r
94 }\r