From e3767be4f9c5874d9c996200f2e9705ce31a5976 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Wed, 25 Jun 2014 23:05:44 +0200 Subject: Work on bindings - Introduced exceptions into C# and Java - Moved binding examples to /embedding - Interpreter will now throw exceptions, beware! --- CMakeLists.txt | 4 +- contrib/csharp/embedding/embedding.sln | 20 -- contrib/csharp/embedding/embedding.suo | Bin 15872 -> 0 bytes contrib/csharp/embedding/embedding.userprefs | 12 - contrib/csharp/embedding/embedding/Program.cs | 35 -- .../embedding/embedding/Properties/AssemblyInfo.cs | 36 -- .../csharp/embedding/embedding/embedding.csproj | 66 ---- contrib/java/.classpath | 10 - contrib/java/.project | 39 -- contrib/java/build-java.xml | 91 +++++ contrib/java/src/js.jar | Bin 1134765 -> 0 bytes .../org/uscxml/datamodel/ecmascript/ECMAData.java | 110 ------ .../org/uscxml/datamodel/ecmascript/ECMAEvent.java | 126 ------- .../datamodel/ecmascript/ECMAScriptDataModel.java | 396 --------------------- contrib/java/src/org/uscxml/tests/TestData.java | 23 -- contrib/java/src/org/uscxml/tests/TestInvoker.java | 66 ---- .../org/uscxml/tests/TestJavaScriptDataModel.java | 26 -- contrib/java/src/org/uscxml/tests/TestW3CECMA.java | 40 --- contrib/local/compress_and_upload_deps.sh | 2 +- embedding/csharp/embedding/embedding.sln | 20 ++ embedding/csharp/embedding/embedding.suo | Bin 0 -> 15872 bytes embedding/csharp/embedding/embedding.userprefs | 12 + embedding/csharp/embedding/embedding/Program.cs | 35 ++ .../embedding/embedding/Properties/AssemblyInfo.cs | 36 ++ .../csharp/embedding/embedding/embedding.csproj | 66 ++++ embedding/java/.classpath | 9 + embedding/java/.gitignore | 1 + embedding/java/.project | 17 + embedding/java/lib/js.jar | Bin 0 -> 1134765 bytes .../org/uscxml/datamodel/ecmascript/ECMAData.java | 110 ++++++ .../org/uscxml/datamodel/ecmascript/ECMAEvent.java | 126 +++++++ .../datamodel/ecmascript/ECMAScriptDataModel.java | 396 +++++++++++++++++++++ embedding/java/src/org/uscxml/tests/TestData.java | 23 ++ .../tests/datamodel/TestJavaScriptDataModel.java | 27 ++ .../org/uscxml/tests/datamodel/TestW3CECMA.java | 41 +++ .../tests/execContent/TestCustomExecContent.java | 81 +++++ .../uscxml/tests/invoker/TestCustomInvoker.java | 69 ++++ .../uscxml/tests/ioprocessor/TestCustomIOProc.java | 54 +++ src/bindings/swig/csharp/CMakeLists.txt | 4 + .../swig/csharp/org/uscxml/InterpreterException.cs | 7 + src/bindings/swig/csharp/stl_list.i | 49 --- src/bindings/swig/csharp/stl_set.i | 73 ---- src/bindings/swig/csharp/uscxml.i | 180 +++++----- src/bindings/swig/java/CMakeLists.txt | 39 ++ .../swig/java/org/uscxml/InterpreterException.java | 9 + src/bindings/swig/java/uscxml.i | 166 +++------ src/bindings/swig/uscxml_beautify.i | 67 ++++ src/bindings/swig/uscxml_ignores.i | 54 +++ src/bindings/swig/wrapped/WrappedDataModel.cpp | 19 + src/bindings/swig/wrapped/WrappedDataModel.h | 19 + .../swig/wrapped/WrappedExecutableContent.cpp | 27 ++ .../swig/wrapped/WrappedExecutableContent.h | 86 +++++ src/bindings/swig/wrapped/WrappedIOProcessor.cpp | 27 ++ src/bindings/swig/wrapped/WrappedIOProcessor.h | 62 ++++ src/bindings/swig/wrapped/WrappedInvoker.cpp | 19 + src/bindings/swig/wrapped/WrappedInvoker.h | 19 + src/uscxml/Interpreter.cpp | 25 +- src/uscxml/Interpreter.h | 12 +- src/uscxml/URL.h | 4 +- src/uscxml/concurrency/tinythread.cpp | 21 +- src/uscxml/concurrency/tinythread.h | 4 +- src/uscxml/debug/DebuggerServlet.cpp | 2 +- test/w3c/confEcma.xsl | 2 +- test/w3c/ecma/test329.scxml | 1 - test/w3c/ecma/test350.scxml | 24 ++ test/w3c/ecma/test446.scxml | 2 +- test/w3c/ecma/test446.txt | 12 + test/w3c/ecma/test458.txt | 1 - test/w3c/ecma/test519.scxml | 2 +- test/w3c/ecma/test534.scxml | 2 +- test/w3c/txml/test350.txml | 6 +- test/w3c/txml/test446.txml | 2 +- test/w3c/txml/test446.txt | 12 + test/w3c/xpath/test350.scxml | 24 ++ test/w3c/xpath/test446.scxml | 2 +- test/w3c/xpath/test446.txt | 12 + 76 files changed, 1949 insertions(+), 1374 deletions(-) delete mode 100644 contrib/csharp/embedding/embedding.sln delete mode 100644 contrib/csharp/embedding/embedding.suo delete mode 100644 contrib/csharp/embedding/embedding.userprefs delete mode 100644 contrib/csharp/embedding/embedding/Program.cs delete mode 100644 contrib/csharp/embedding/embedding/Properties/AssemblyInfo.cs delete mode 100644 contrib/csharp/embedding/embedding/embedding.csproj delete mode 100644 contrib/java/.classpath delete mode 100644 contrib/java/.project create mode 100644 contrib/java/build-java.xml delete mode 100644 contrib/java/src/js.jar delete mode 100644 contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAData.java delete mode 100644 contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAEvent.java delete mode 100644 contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java delete mode 100644 contrib/java/src/org/uscxml/tests/TestData.java delete mode 100644 contrib/java/src/org/uscxml/tests/TestInvoker.java delete mode 100644 contrib/java/src/org/uscxml/tests/TestJavaScriptDataModel.java delete mode 100644 contrib/java/src/org/uscxml/tests/TestW3CECMA.java create mode 100644 embedding/csharp/embedding/embedding.sln create mode 100644 embedding/csharp/embedding/embedding.suo create mode 100644 embedding/csharp/embedding/embedding.userprefs create mode 100644 embedding/csharp/embedding/embedding/Program.cs create mode 100644 embedding/csharp/embedding/embedding/Properties/AssemblyInfo.cs create mode 100644 embedding/csharp/embedding/embedding/embedding.csproj create mode 100644 embedding/java/.classpath create mode 100644 embedding/java/.gitignore create mode 100644 embedding/java/.project create mode 100644 embedding/java/lib/js.jar create mode 100644 embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAData.java create mode 100644 embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAEvent.java create mode 100644 embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java create mode 100644 embedding/java/src/org/uscxml/tests/TestData.java create mode 100644 embedding/java/src/org/uscxml/tests/datamodel/TestJavaScriptDataModel.java create mode 100644 embedding/java/src/org/uscxml/tests/datamodel/TestW3CECMA.java create mode 100644 embedding/java/src/org/uscxml/tests/execContent/TestCustomExecContent.java create mode 100644 embedding/java/src/org/uscxml/tests/invoker/TestCustomInvoker.java create mode 100644 embedding/java/src/org/uscxml/tests/ioprocessor/TestCustomIOProc.java create mode 100644 src/bindings/swig/csharp/org/uscxml/InterpreterException.cs delete mode 100644 src/bindings/swig/csharp/stl_list.i delete mode 100644 src/bindings/swig/csharp/stl_set.i create mode 100644 src/bindings/swig/java/org/uscxml/InterpreterException.java create mode 100644 src/bindings/swig/uscxml_beautify.i create mode 100644 src/bindings/swig/uscxml_ignores.i create mode 100644 src/bindings/swig/wrapped/WrappedExecutableContent.cpp create mode 100644 src/bindings/swig/wrapped/WrappedExecutableContent.h create mode 100644 src/bindings/swig/wrapped/WrappedIOProcessor.cpp create mode 100644 src/bindings/swig/wrapped/WrappedIOProcessor.h create mode 100644 test/w3c/ecma/test350.scxml create mode 100644 test/w3c/ecma/test446.txt delete mode 100644 test/w3c/ecma/test458.txt create mode 100644 test/w3c/txml/test446.txt create mode 100644 test/w3c/xpath/test350.scxml create mode 100644 test/w3c/xpath/test446.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b03821..90e5316 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,8 +13,8 @@ endif() # specify USCXML version SET(USCXML_VERSION_MAJOR "0") -SET(USCXML_VERSION_MINOR "1") -SET(USCXML_VERSION_PATCH "2") +SET(USCXML_VERSION_MINOR "2") +SET(USCXML_VERSION_PATCH "0") SET(USCXML_VERSION ${USCXML_VERSION_MAJOR}.${USCXML_VERSION_MINOR}.${USCXML_VERSION_PATCH}) # build type has to be set before the project definition4 diff --git a/contrib/csharp/embedding/embedding.sln b/contrib/csharp/embedding/embedding.sln deleted file mode 100644 index 0f9a49e..0000000 --- a/contrib/csharp/embedding/embedding.sln +++ /dev/null @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "embedding", "embedding\embedding.csproj", "{75E5EE93-513B-45DA-AD50-64C570AAD0C0}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x86 = Debug|x86 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {75E5EE93-513B-45DA-AD50-64C570AAD0C0}.Debug|x86.ActiveCfg = Debug|x86 - {75E5EE93-513B-45DA-AD50-64C570AAD0C0}.Debug|x86.Build.0 = Debug|x86 - {75E5EE93-513B-45DA-AD50-64C570AAD0C0}.Release|x86.ActiveCfg = Release|x86 - {75E5EE93-513B-45DA-AD50-64C570AAD0C0}.Release|x86.Build.0 = Release|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/contrib/csharp/embedding/embedding.suo b/contrib/csharp/embedding/embedding.suo deleted file mode 100644 index f011087..0000000 Binary files a/contrib/csharp/embedding/embedding.suo and /dev/null differ diff --git a/contrib/csharp/embedding/embedding.userprefs b/contrib/csharp/embedding/embedding.userprefs deleted file mode 100644 index 05e379d..0000000 --- a/contrib/csharp/embedding/embedding.userprefs +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/contrib/csharp/embedding/embedding/Program.cs b/contrib/csharp/embedding/embedding/Program.cs deleted file mode 100644 index 3899178..0000000 --- a/contrib/csharp/embedding/embedding/Program.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Runtime.InteropServices; - -namespace embedding -{ - using org.uscxml; - - class Program - { - [DllImport("kernel32.dll", CharSet = CharSet.Auto)] - private static extern void SetDllDirectory(string lpPathName); - - static void Main(string[] args) - { - - /* - * Make sure this path contains the umundoNativeCSharp.dll! - */ - if (System.Environment.Is64BitProcess) - { - SetDllDirectory("C:\\Users\\sradomski\\Desktop\\build\\lib\\csharp64"); - } - else - { - SetDllDirectory("C:\\Users\\sradomski\\Desktop\\build\\lib\\csharp"); - } - - Interpreter interpreter = Interpreter.fromXML(""); - interpreter.interpret(); - } - } -} diff --git a/contrib/csharp/embedding/embedding/Properties/AssemblyInfo.cs b/contrib/csharp/embedding/embedding/Properties/AssemblyInfo.cs deleted file mode 100644 index bd9015e..0000000 --- a/contrib/csharp/embedding/embedding/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("embedding")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("embedding")] -[assembly: AssemblyCopyright("Copyright © 2014")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("0d270ead-e8cf-4cc1-a2c8-fa123e71812c")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/contrib/csharp/embedding/embedding/embedding.csproj b/contrib/csharp/embedding/embedding/embedding.csproj deleted file mode 100644 index 53e1eed..0000000 --- a/contrib/csharp/embedding/embedding/embedding.csproj +++ /dev/null @@ -1,66 +0,0 @@ - - - - Debug - x86 - 8.0.30703 - 2.0 - {75E5EE93-513B-45DA-AD50-64C570AAD0C0} - Exe - Properties - embedding - embedding - v4.0 - Client - 512 - - - x86 - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - - - - - - - x86 - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - ..\..\..\..\build\cli\lib\uscxmlCSharp.dll - - - - - - - - - \ No newline at end of file diff --git a/contrib/java/.classpath b/contrib/java/.classpath deleted file mode 100644 index 0830f8a..0000000 --- a/contrib/java/.classpath +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/contrib/java/.project b/contrib/java/.project deleted file mode 100644 index bed7874..0000000 --- a/contrib/java/.project +++ /dev/null @@ -1,39 +0,0 @@ - - - uscxml - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - - - applications - 2 - /Users/sradomski/Documents/TK/Code/uscxml/test/samples/uscxml/applications - - - bindings - 2 - /Users/sradomski/Documents/TK/Code/uscxml/src/bindings/swig/java - - - java - 2 - /Users/sradomski/Documents/TK/Code/uscxml/src/bindings/swig/java - - - uscxml - 2 - /Users/sradomski/Documents/TK/Code/uscxml/build/cli/src/bindings/swig/java - - - diff --git a/contrib/java/build-java.xml b/contrib/java/build-java.xml new file mode 100644 index 0000000..ca5cc88 --- /dev/null +++ b/contrib/java/build-java.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${echo.all.jni} + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/contrib/java/src/js.jar b/contrib/java/src/js.jar deleted file mode 100644 index 6f0dafb..0000000 Binary files a/contrib/java/src/js.jar and /dev/null differ diff --git a/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAData.java b/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAData.java deleted file mode 100644 index 56d7090..0000000 --- a/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAData.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.uscxml.datamodel.ecmascript; - -import org.mozilla.javascript.Scriptable; -import org.uscxml.Data; - -public class ECMAData implements Scriptable { - - protected Data data; - protected Scriptable parent; - protected Scriptable prototype; - - public ECMAData(Data data) { - this.data = data; - } - - @Override - public String getClassName() { - return "Data"; - } - - public Object unwrap(Data data) { - if (data.atom.length() > 0) { - return data.atom; - } - return new ECMAData(data); - - } - - @Override - public Object get(String name, Scriptable start) { - if (data.compound.containsKey(name)) - return unwrap(data.compound.get(name)); - return NOT_FOUND; - } - - @Override - public Object get(int index, Scriptable start) { - if (data.array.size() > index) - return unwrap(data.array.get(index)); - return NOT_FOUND; - } - - @Override - public boolean has(String name, Scriptable start) { - return data.compound.containsKey(name); - } - - @Override - public boolean has(int index, Scriptable start) { - return data.array.size() > index; - } - - @Override - public void put(String name, Scriptable start, Object value) { - } - - @Override - public void put(int index, Scriptable start, Object value) { - } - - @Override - public void delete(String name) { - } - - @Override - public void delete(int index) { - } - - @Override - public Scriptable getPrototype() { - return prototype; - } - - @Override - public void setPrototype(Scriptable prototype) { - this.prototype = prototype; - } - - @Override - public Scriptable getParentScope() { - return parent; - } - - @Override - public void setParentScope(Scriptable parent) { - this.parent = parent; - } - - @Override - public Object[] getIds() { - return data.compound.keySet().toArray(); - } - - @Override - public Object getDefaultValue(Class hint) { - return "[object Data]"; - } - - @Override - public boolean hasInstance(Scriptable instance) { - Scriptable proto = instance.getPrototype(); - while (proto != null) { - if (proto.equals(this)) - return true; - proto = proto.getPrototype(); - } - return false; - } - -} diff --git a/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAEvent.java b/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAEvent.java deleted file mode 100644 index 58fff72..0000000 --- a/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAEvent.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.uscxml.datamodel.ecmascript; - -import java.util.HashMap; -import java.util.Map; - -import org.mozilla.javascript.Scriptable; -import org.uscxml.Data; -import org.uscxml.Event; -import org.uscxml.ParamPair; -import org.uscxml.ParamPairVector; - -public class ECMAEvent implements Scriptable { - - protected Event event; - protected Scriptable parent; - protected Scriptable prototype; - - protected Map members = new HashMap(); - - public ECMAEvent(Event event) { - this.event = event; - - Data data = new Data(event.getData()); - - // insert params into event.data - ParamPairVector ppv = event.getParamPairs(); - for (int i = 0; i < ppv.size(); i++) { - ParamPair pp = ppv.get(i); - data.compound.put(pp.getFirst(), new Data(pp.getSecond())); - } - - members.put("type", event.getEventType().toString()); - members.put("data", new ECMAData(data)); - members.put("sendid", event.getSendId()); - members.put("origin", event.getOrigin()); - members.put("originType", event.getOriginType()); - // add others as necessary - - } - - @Override - public String getClassName() { - return "Event"; - } - - @Override - public Object get(String name, Scriptable start) { - if (members.containsKey(name)) - return members.get(name); - return NOT_FOUND; - } - - @Override - public Object get(int index, Scriptable start) { - return NOT_FOUND; - } - - @Override - public boolean has(String name, Scriptable start) { - return (members.containsKey(name)); - } - - @Override - public boolean has(int index, Scriptable start) { - return false; - } - - @Override - public void put(String name, Scriptable start, Object value) { - } - - @Override - public void put(int index, Scriptable start, Object value) { - } - - @Override - public void delete(String name) { - } - - @Override - public void delete(int index) { - } - - @Override - public Scriptable getPrototype() { - return prototype; - } - - @Override - public void setPrototype(Scriptable prototype) { - this.prototype = prototype; - } - - @Override - public Scriptable getParentScope() { - return parent; - } - - @Override - public void setParentScope(Scriptable parent) { - this.parent = parent; - } - - @Override - public Object[] getIds() { - return members.keySet().toArray(); - } - - @Override - public Object getDefaultValue(Class hint) { - return "[object Event]"; - } - - @Override - public boolean hasInstance(Scriptable instance) { - Scriptable proto = instance.getPrototype(); - while (proto != null) { - if (proto.equals(this)) - return true; - proto = proto.getPrototype(); - } - - return false; - } - -} diff --git a/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java b/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java deleted file mode 100644 index 3d77dc5..0000000 --- a/contrib/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java +++ /dev/null @@ -1,396 +0,0 @@ -package org.uscxml.datamodel.ecmascript; - -import java.lang.reflect.Method; - -import org.mozilla.javascript.Callable; -import org.mozilla.javascript.Context; -import org.mozilla.javascript.EvaluatorException; -import org.mozilla.javascript.FunctionObject; -import org.mozilla.javascript.NativeJSON; -import org.mozilla.javascript.Scriptable; -import org.mozilla.javascript.ScriptableObject; -import org.mozilla.javascript.Undefined; -import org.uscxml.Data; -import org.uscxml.DataNative; -import org.uscxml.Event; -import org.uscxml.Interpreter; -import org.uscxml.JavaDataModel; -import org.uscxml.StringSet; -import org.uscxml.StringVector; - -public class ECMAScriptDataModel extends JavaDataModel { - - public static boolean debug = true; - - private class NullCallable implements Callable { - @Override - public Object call(Context context, Scriptable scope, - Scriptable holdable, Object[] objects) { - return objects[1]; - } - } - - public Context ctx; - public Scriptable scope; - public Interpreter interpreter; - - public Data getScriptableAsData(Object object) { - Data data = new Data(); - - Scriptable s; - try { - s = (Scriptable) object; - String className = s.getClassName(); // ECMA class name - if (className.toLowerCase().equals("object")) { - ScriptableObject obj = (ScriptableObject) Context.toObject(s, - scope); - for (Object key : obj.getIds()) { - data.compound.put(Context.toString(key), - getScriptableAsData(obj.get(key))); - } - } - } catch (ClassCastException e) { - if (object instanceof Boolean) { - data.atom = (Context.toBoolean(object) ? "true" : "false"); - data.type = Data.Type.INTERPRETED; - } else if (object instanceof String) { - data.atom = (String) object; - data.type = Data.Type.VERBATIM; - } else if (object instanceof Integer) { - data.atom = ((Integer) object).toString(); - data.type = Data.Type.INTERPRETED; - } else { - throw new RuntimeException("Unhandled ECMA type " - + object.getClass().getName()); - } - } - - return data; - } - - public ScriptableObject getDataAsScriptable(Data data) { - throw new UnsupportedOperationException("Not implemented"); - } - - public static boolean jsIn(String stateName) { - return true; - } - - @Override - public JavaDataModel create(Interpreter interpreter) { - /** - * Called when an SCXML interpreter wants an instance of this datamodel - * Be careful to instantiate attributes of instance returned and not - * *this* - */ - - ECMAScriptDataModel newDM = new ECMAScriptDataModel(); - newDM.interpreter = interpreter; - newDM.ctx = Context.enter(); - - try { - newDM.scope = newDM.ctx.initStandardObjects(); - } catch (Exception e) { - System.err.println(e); - } - - newDM.scope.put("_name", newDM.scope, interpreter.getName()); - newDM.scope.put("_sessionid", newDM.scope, interpreter.getSessionId()); - - // ioProcessors - { - Data ioProcs = new Data(); - StringVector keys = interpreter.getIOProcessorKeys(); - for (int i = 0; i < keys.size(); i++) { - ioProcs.compound.put(keys.get(i), new Data(interpreter - .getIOProcessors().get(keys.get(i)) - .getDataModelVariables())); - } - newDM.scope - .put("_ioprocessors", newDM.scope, new ECMAData(ioProcs)); - } - - // invokers - { - Data invokers = new Data(); - StringVector keys = interpreter.getInvokerKeys(); - for (int i = 0; i < keys.size(); i++) { - invokers.compound.put(keys.get(i), new Data(interpreter - .getInvokers().get(keys.get(i)) - .getDataModelVariables())); - } - newDM.scope - .put("_ioprocessors", newDM.scope, new ECMAData(invokers)); - } - - // In predicate (not working as static is required) see: - // http://stackoverflow.com/questions/3441947/how-do-i-call-a-method-of-a-java-instance-from-javascript/16479685#16479685 - try { - Class[] parameters = new Class[] { String.class }; - Method inMethod = ECMAScriptDataModel.class.getMethod("jsIn", - parameters); - FunctionObject inFunc = new FunctionObject("In", inMethod, - newDM.scope); - newDM.scope.put("In", newDM.scope, inFunc); - } catch (SecurityException e) { - System.err.println(e); - } catch (NoSuchMethodException e) { - System.err.println(e); - } - - return newDM; - } - - @Override - public StringSet getNames() { - /** - * Register with the following names for the datamodel attribute at the - * scxml element. - */ - StringSet ss = new StringSet(); - ss.insert("ecmascript"); - return ss; - } - - @Override - public boolean validate(String location, String schema) { - /** - * Validate the datamodel. This make more sense for XML datamodels and - * is pretty much unused but required as per draft. - */ - return true; - } - - @Override - public void setEvent(Event event) { - if (debug) { - System.out.println(interpreter.getName() + " setEvent"); - } - - /** - * Make the current event available as the variable _event in the - * datamodel. - */ - ECMAEvent ecmaEvent = new ECMAEvent(event); - scope.put("_event", scope, ecmaEvent); - } - - @Override - public DataNative getStringAsData(String content) { - if (debug) { - System.out.println(interpreter.getName() + " getStringAsData"); - } - - /** - * Evaluate the string as a value expression and transform it into a - * JSON-like Data structure - */ - if (content.length() == 0) { - return Data.toNative(new Data()); - } - - // is it a json expression? - try { - Object json = NativeJSON.parse(ctx, scope, content, - new NullCallable()); - if (json != NativeJSON.NOT_FOUND) { - return Data.toNative(getScriptableAsData(json)); - } - } catch (org.mozilla.javascript.EcmaError e) { - System.err.println(e); - } - - // is it a function call or variable? - Object x = ctx.evaluateString(scope, content, "uscxml", 0, null); - if (x == Undefined.instance) { - // maybe a literal string? - x = ctx.evaluateString(scope, '"' + content + '"', "uscxml", 0, - null); - } - return Data.toNative(getScriptableAsData(x)); - } - - @Override - public long getLength(String expr) { - if (debug) { - System.out.println(interpreter.getName() + " getLength"); - } - - /** - * Return the length of the expression if it were an array, used by - * foreach element. - */ - - Object x = scope.get(expr, scope); - if (x == Undefined.instance) { - return 0; - } - - Scriptable result = Context.toObject(x, scope); - if (result.has("length", result)) { - return (long) Context.toNumber(result.get("length", result)); - } - return 0; - } - - @Override - public void setForeach(String item, String array, String index, - long iteration) { - if (debug) { - System.out.println(interpreter.getName() + " setForeach"); - } - - /** - * Prepare an iteration of the foreach element, by setting the variable - * in index to the current iteration and setting the variable in item to - * the current item from array. - */ - - try { - // get the array object - Scriptable arr = (Scriptable) scope.get(array, scope); - - if (arr.has((int) iteration, arr)) { - ctx.evaluateString(scope, item + '=' + array + '[' + iteration - + ']', "uscxml", 1, null); - if (index.length() > 0) { - ctx.evaluateString(scope, index + '=' + iteration, - "uscxml", 1, null); - } - } else { - handleException(""); - } - - } catch (ClassCastException e) { - System.err.println(e); - } - } - - @Override - public void eval(String scriptElem, String expr) { - if (debug) { - System.out.println(interpreter.getName() + " eval"); - } - - /** - * Evaluate the given expression in the datamodel. This is used foremost - * with script elements. - */ - ctx.evaluateString(scope, expr, "uscxml", 1, null); - - } - - @Override - public String evalAsString(String expr) { - if (debug) { - System.out.println(interpreter.getName() + " evalAsString: " + expr); - } - - /** - * Evaluate the expression as a string e.g. for the log element. - */ - if (!ctx.stringIsCompilableUnit(expr)) { - handleException(""); - return ""; - } - try { - Object result = ctx.evaluateString(scope, expr, "uscxml", 1, null); - return Context.toString(result); - } catch (IllegalStateException e) { - System.err.println(e); - handleException(""); - } catch (EvaluatorException e) { - System.err.println(e); - handleException(""); - } - return ""; - } - - @Override - public boolean evalAsBool(String elem, String expr) { - if (debug) { - System.out.println(interpreter.getName() + " evalAsBool"); - } - - /** - * Evaluate the expression as a boolean for cond attributes in if and - * transition elements. - */ - Object result = ctx.evaluateString(scope, expr, "uscxml", 1, null); - return Context.toBoolean(result); - } - - @Override - public boolean isDeclared(String expr) { - if (debug) { - System.out.println(interpreter.getName() + " isDeclared"); - } - - /** - * The interpreter is supposed to raise an error if we assign to an - * undeclared variable. This method is used to check whether a location - * from assign is declared. - */ - Object x = scope.get(expr, scope); - return x != Scriptable.NOT_FOUND; - } - - @Override - public void init(String dataElem, String location, String content) { - if (debug) { - System.out.println(interpreter.getName() + " init"); - } - - /** - * Called when we pass data elements. - */ - if (("null").equals(location)) - return; - - if (("null").equals(content) || content.length() == 0) { - scope.put(location, scope, Context.getUndefinedValue()); - return; - } - - try { - Object json = NativeJSON.parse(ctx, scope, content, - new NullCallable()); - if (json != NativeJSON.NOT_FOUND) { - scope.put(location, scope, json); - } else { - scope.put(location, scope, content); - } - } catch (org.mozilla.javascript.EcmaError e) { - scope.put(location, scope, content); - } - } - - @Override - public void assign(String assignElem, String location, String content) { - if (debug) { - System.out.println(interpreter.getName() + " assign"); - } - - /** - * Called when we evaluate assign elements - */ - if (("null").equals(location)) - return; - - if (("null").equals(content) || content.length() == 0) { - scope.put(location, scope, Context.getUndefinedValue()); - return; - } - - String expr = location + "=" + content; - ctx.evaluateString(scope, expr, "uscxml", 1, null); - } - - public void handleException(String cause) { - Event exceptionEvent = new Event(); - exceptionEvent.setName("error.execution"); - exceptionEvent.setEventType(Event.Type.PLATFORM); - - interpreter.receiveInternal(exceptionEvent); - } -} diff --git a/contrib/java/src/org/uscxml/tests/TestData.java b/contrib/java/src/org/uscxml/tests/TestData.java deleted file mode 100644 index 44f1ce0..0000000 --- a/contrib/java/src/org/uscxml/tests/TestData.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.uscxml.tests; - -import org.uscxml.Data; -import org.uscxml.DataNative; - -public class TestData { - - public static void main(String[] args) { - System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib"); - { - Data data = Data.fromJSON("[1,2,3,4,5]"); - DataNative nData2 = Data.toNative(data); - Data data2 = new Data(nData2); - System.out.println(data2); - } - { - Data data = Data.fromJSON("{ \"foo\": \"bar\", \"faz\": 12 }"); - DataNative nData2 = Data.toNative(data); - Data data2 = new Data(nData2); - System.out.println(data2); - } - } -} diff --git a/contrib/java/src/org/uscxml/tests/TestInvoker.java b/contrib/java/src/org/uscxml/tests/TestInvoker.java deleted file mode 100644 index 7807cda..0000000 --- a/contrib/java/src/org/uscxml/tests/TestInvoker.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.uscxml.tests; - -import org.uscxml.Data; -import org.uscxml.DataNative; -import org.uscxml.Event; -import org.uscxml.Factory; -import org.uscxml.Interpreter; -import org.uscxml.InvokeRequest; -import org.uscxml.JavaInvoker; -import org.uscxml.SendRequest; -import org.uscxml.StringSet; - -public class TestInvoker extends JavaInvoker { - - @Override - public StringSet getNames() { - StringSet ss = new StringSet(); - ss.insert("java"); - return ss; - } - - @Override - public DataNative getDataModelVariables() { - Data data = new Data(); - data.array.add(new Data("foo", Data.Type.VERBATIM)); - return Data.toNative(data); - } - - @Override - public void send(SendRequest req) { - System.out.println("send"); - } - - @Override - public void invoke(InvokeRequest req) { - System.out.println("invoke"); - - System.out.println(req.getData()); - System.out.println(req.getXML()); - - Event ev = new Event(); - ev.setName("foo"); - returnEvent(ev); - } - - @Override - public JavaInvoker create(Interpreter interpreter) { - return new TestInvoker(); - } - - /** - * @param args - */ - public static void main(String[] args) { - System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64_d.jnilib"); - - TestInvoker invoker = new TestInvoker(); - Factory.getInstance().registerInvoker(invoker); - - Interpreter interpreter = Interpreter - .fromURI("/Users/sradomski/Documents/TK/Code/uscxml/test/samples/uscxml/test-java-invoker.scxml"); - while (true) - interpreter.interpret(); - } - -} diff --git a/contrib/java/src/org/uscxml/tests/TestJavaScriptDataModel.java b/contrib/java/src/org/uscxml/tests/TestJavaScriptDataModel.java deleted file mode 100644 index 7399c94..0000000 --- a/contrib/java/src/org/uscxml/tests/TestJavaScriptDataModel.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.uscxml.tests; - -import org.uscxml.Factory; -import org.uscxml.Interpreter; -import org.uscxml.datamodel.ecmascript.ECMAScriptDataModel; - -public class TestJavaScriptDataModel { - - public static void main(String[] args) { - // load JNI library from build directory - System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib"); - - // register java datamodel at factory - ECMAScriptDataModel datamodel = new ECMAScriptDataModel(); - Factory.getInstance().registerDataModel(datamodel); - - // instantiate interpreter with document from file - Interpreter interpreter = Interpreter - .fromURI("/Users/sradomski/Documents/TK/Code/uscxml/test/uscxml/java/test-ecmascript-datamodel.scxml"); - - // wait until interpreter has finished - while (true) - interpreter.interpret(); - } - -} diff --git a/contrib/java/src/org/uscxml/tests/TestW3CECMA.java b/contrib/java/src/org/uscxml/tests/TestW3CECMA.java deleted file mode 100644 index 0949701..0000000 --- a/contrib/java/src/org/uscxml/tests/TestW3CECMA.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.uscxml.tests; - -import java.io.File; - -import org.uscxml.Capabilities; -import org.uscxml.Factory; -import org.uscxml.Interpreter; -import org.uscxml.InterpreterOptions; -import org.uscxml.datamodel.ecmascript.ECMAScriptDataModel; - -public class TestW3CECMA { - - public static String testDir = "/Users/sradomski/Documents/TK/Code/uscxml/test/w3c/ecma"; - - public static void main(String[] args) { - System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib"); - - ECMAScriptDataModel datamodel = new ECMAScriptDataModel(); - Factory.getInstance().registerDataModel(datamodel); - -// while(true) { -// System.out.println("### test235 #####"); -// Interpreter interpreter = Interpreter.fromURI("/Users/sradomski/Documents/TK/Code/uscxml/test/w3c/ecma/test144.scxml"); -// interpreter.interpret(); -// } - - File dir = new File(testDir); - File[] filesList = dir.listFiles(); - for (File file : filesList) { - if (file.isFile() && file.getName().endsWith(".scxml")) { - System.out.println("### " + file.getName() + " #####"); - Interpreter interpreter = Interpreter.fromURI(file.getAbsolutePath()); - interpreter.setCapabilities(1); - interpreter.interpret(); - } - } - - } - -} diff --git a/contrib/local/compress_and_upload_deps.sh b/contrib/local/compress_and_upload_deps.sh index 4abb4a9..76413de 100755 --- a/contrib/local/compress_and_upload_deps.sh +++ b/contrib/local/compress_and_upload_deps.sh @@ -33,7 +33,7 @@ ssh ${USCXML_PREBUILT_HOST} mkdir -p ${USCXML_PREBUILT_PATH}/${VERSION} PLATFORMS=`find . -maxdepth 1 -type d -regex ./[^\.].*` #PLATFORMS="linux-x86_64" #PLATFORMS="darwin-i386" -PLATFORMS="windows-x86" +#PLATFORMS="windows-x86" for FILE in ${PLATFORMS}; do PLATFORM=`basename $FILE` echo $FILE diff --git a/embedding/csharp/embedding/embedding.sln b/embedding/csharp/embedding/embedding.sln new file mode 100644 index 0000000..0f9a49e --- /dev/null +++ b/embedding/csharp/embedding/embedding.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "embedding", "embedding\embedding.csproj", "{75E5EE93-513B-45DA-AD50-64C570AAD0C0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {75E5EE93-513B-45DA-AD50-64C570AAD0C0}.Debug|x86.ActiveCfg = Debug|x86 + {75E5EE93-513B-45DA-AD50-64C570AAD0C0}.Debug|x86.Build.0 = Debug|x86 + {75E5EE93-513B-45DA-AD50-64C570AAD0C0}.Release|x86.ActiveCfg = Release|x86 + {75E5EE93-513B-45DA-AD50-64C570AAD0C0}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/embedding/csharp/embedding/embedding.suo b/embedding/csharp/embedding/embedding.suo new file mode 100644 index 0000000..f011087 Binary files /dev/null and b/embedding/csharp/embedding/embedding.suo differ diff --git a/embedding/csharp/embedding/embedding.userprefs b/embedding/csharp/embedding/embedding.userprefs new file mode 100644 index 0000000..681be08 --- /dev/null +++ b/embedding/csharp/embedding/embedding.userprefs @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/embedding/csharp/embedding/embedding/Program.cs b/embedding/csharp/embedding/embedding/Program.cs new file mode 100644 index 0000000..3899178 --- /dev/null +++ b/embedding/csharp/embedding/embedding/Program.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Runtime.InteropServices; + +namespace embedding +{ + using org.uscxml; + + class Program + { + [DllImport("kernel32.dll", CharSet = CharSet.Auto)] + private static extern void SetDllDirectory(string lpPathName); + + static void Main(string[] args) + { + + /* + * Make sure this path contains the umundoNativeCSharp.dll! + */ + if (System.Environment.Is64BitProcess) + { + SetDllDirectory("C:\\Users\\sradomski\\Desktop\\build\\lib\\csharp64"); + } + else + { + SetDllDirectory("C:\\Users\\sradomski\\Desktop\\build\\lib\\csharp"); + } + + Interpreter interpreter = Interpreter.fromXML(""); + interpreter.interpret(); + } + } +} diff --git a/embedding/csharp/embedding/embedding/Properties/AssemblyInfo.cs b/embedding/csharp/embedding/embedding/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..bd9015e --- /dev/null +++ b/embedding/csharp/embedding/embedding/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("embedding")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("embedding")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("0d270ead-e8cf-4cc1-a2c8-fa123e71812c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/embedding/csharp/embedding/embedding/embedding.csproj b/embedding/csharp/embedding/embedding/embedding.csproj new file mode 100644 index 0000000..53e1eed --- /dev/null +++ b/embedding/csharp/embedding/embedding/embedding.csproj @@ -0,0 +1,66 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {75E5EE93-513B-45DA-AD50-64C570AAD0C0} + Exe + Properties + embedding + embedding + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + + + + + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + ..\..\..\..\build\cli\lib\uscxmlCSharp.dll + + + + + + + + + \ No newline at end of file diff --git a/embedding/java/.classpath b/embedding/java/.classpath new file mode 100644 index 0000000..fa94b3c --- /dev/null +++ b/embedding/java/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/embedding/java/.gitignore b/embedding/java/.gitignore new file mode 100644 index 0000000..5e56e04 --- /dev/null +++ b/embedding/java/.gitignore @@ -0,0 +1 @@ +/bin diff --git a/embedding/java/.project b/embedding/java/.project new file mode 100644 index 0000000..9aecdf8 --- /dev/null +++ b/embedding/java/.project @@ -0,0 +1,17 @@ + + + uscxml + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/embedding/java/lib/js.jar b/embedding/java/lib/js.jar new file mode 100644 index 0000000..6f0dafb Binary files /dev/null and b/embedding/java/lib/js.jar differ diff --git a/embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAData.java b/embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAData.java new file mode 100644 index 0000000..56d7090 --- /dev/null +++ b/embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAData.java @@ -0,0 +1,110 @@ +package org.uscxml.datamodel.ecmascript; + +import org.mozilla.javascript.Scriptable; +import org.uscxml.Data; + +public class ECMAData implements Scriptable { + + protected Data data; + protected Scriptable parent; + protected Scriptable prototype; + + public ECMAData(Data data) { + this.data = data; + } + + @Override + public String getClassName() { + return "Data"; + } + + public Object unwrap(Data data) { + if (data.atom.length() > 0) { + return data.atom; + } + return new ECMAData(data); + + } + + @Override + public Object get(String name, Scriptable start) { + if (data.compound.containsKey(name)) + return unwrap(data.compound.get(name)); + return NOT_FOUND; + } + + @Override + public Object get(int index, Scriptable start) { + if (data.array.size() > index) + return unwrap(data.array.get(index)); + return NOT_FOUND; + } + + @Override + public boolean has(String name, Scriptable start) { + return data.compound.containsKey(name); + } + + @Override + public boolean has(int index, Scriptable start) { + return data.array.size() > index; + } + + @Override + public void put(String name, Scriptable start, Object value) { + } + + @Override + public void put(int index, Scriptable start, Object value) { + } + + @Override + public void delete(String name) { + } + + @Override + public void delete(int index) { + } + + @Override + public Scriptable getPrototype() { + return prototype; + } + + @Override + public void setPrototype(Scriptable prototype) { + this.prototype = prototype; + } + + @Override + public Scriptable getParentScope() { + return parent; + } + + @Override + public void setParentScope(Scriptable parent) { + this.parent = parent; + } + + @Override + public Object[] getIds() { + return data.compound.keySet().toArray(); + } + + @Override + public Object getDefaultValue(Class hint) { + return "[object Data]"; + } + + @Override + public boolean hasInstance(Scriptable instance) { + Scriptable proto = instance.getPrototype(); + while (proto != null) { + if (proto.equals(this)) + return true; + proto = proto.getPrototype(); + } + return false; + } + +} diff --git a/embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAEvent.java b/embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAEvent.java new file mode 100644 index 0000000..58fff72 --- /dev/null +++ b/embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAEvent.java @@ -0,0 +1,126 @@ +package org.uscxml.datamodel.ecmascript; + +import java.util.HashMap; +import java.util.Map; + +import org.mozilla.javascript.Scriptable; +import org.uscxml.Data; +import org.uscxml.Event; +import org.uscxml.ParamPair; +import org.uscxml.ParamPairVector; + +public class ECMAEvent implements Scriptable { + + protected Event event; + protected Scriptable parent; + protected Scriptable prototype; + + protected Map members = new HashMap(); + + public ECMAEvent(Event event) { + this.event = event; + + Data data = new Data(event.getData()); + + // insert params into event.data + ParamPairVector ppv = event.getParamPairs(); + for (int i = 0; i < ppv.size(); i++) { + ParamPair pp = ppv.get(i); + data.compound.put(pp.getFirst(), new Data(pp.getSecond())); + } + + members.put("type", event.getEventType().toString()); + members.put("data", new ECMAData(data)); + members.put("sendid", event.getSendId()); + members.put("origin", event.getOrigin()); + members.put("originType", event.getOriginType()); + // add others as necessary + + } + + @Override + public String getClassName() { + return "Event"; + } + + @Override + public Object get(String name, Scriptable start) { + if (members.containsKey(name)) + return members.get(name); + return NOT_FOUND; + } + + @Override + public Object get(int index, Scriptable start) { + return NOT_FOUND; + } + + @Override + public boolean has(String name, Scriptable start) { + return (members.containsKey(name)); + } + + @Override + public boolean has(int index, Scriptable start) { + return false; + } + + @Override + public void put(String name, Scriptable start, Object value) { + } + + @Override + public void put(int index, Scriptable start, Object value) { + } + + @Override + public void delete(String name) { + } + + @Override + public void delete(int index) { + } + + @Override + public Scriptable getPrototype() { + return prototype; + } + + @Override + public void setPrototype(Scriptable prototype) { + this.prototype = prototype; + } + + @Override + public Scriptable getParentScope() { + return parent; + } + + @Override + public void setParentScope(Scriptable parent) { + this.parent = parent; + } + + @Override + public Object[] getIds() { + return members.keySet().toArray(); + } + + @Override + public Object getDefaultValue(Class hint) { + return "[object Event]"; + } + + @Override + public boolean hasInstance(Scriptable instance) { + Scriptable proto = instance.getPrototype(); + while (proto != null) { + if (proto.equals(this)) + return true; + proto = proto.getPrototype(); + } + + return false; + } + +} diff --git a/embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java b/embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java new file mode 100644 index 0000000..dcafcb9 --- /dev/null +++ b/embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java @@ -0,0 +1,396 @@ +package org.uscxml.datamodel.ecmascript; + +import java.lang.reflect.Method; + +import org.mozilla.javascript.Callable; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.EvaluatorException; +import org.mozilla.javascript.FunctionObject; +import org.mozilla.javascript.NativeJSON; +import org.mozilla.javascript.Scriptable; +import org.mozilla.javascript.ScriptableObject; +import org.mozilla.javascript.Undefined; +import org.uscxml.Data; +import org.uscxml.DataNative; +import org.uscxml.Event; +import org.uscxml.Interpreter; +import org.uscxml.StringList; +import org.uscxml.StringVector; +import org.uscxml.WrappedDataModel; + +public class ECMAScriptDataModel extends WrappedDataModel { + + public static boolean debug = true; + + private class NullCallable implements Callable { + @Override + public Object call(Context context, Scriptable scope, + Scriptable holdable, Object[] objects) { + return objects[1]; + } + } + + public Context ctx; + public Scriptable scope; + public Interpreter interpreter; + + public Data getScriptableAsData(Object object) { + Data data = new Data(); + + Scriptable s; + try { + s = (Scriptable) object; + String className = s.getClassName(); // ECMA class name + if (className.toLowerCase().equals("object")) { + ScriptableObject obj = (ScriptableObject) Context.toObject(s, + scope); + for (Object key : obj.getIds()) { + data.compound.put(Context.toString(key), + getScriptableAsData(obj.get(key))); + } + } + } catch (ClassCastException e) { + if (object instanceof Boolean) { + data.atom = (Context.toBoolean(object) ? "true" : "false"); + data.type = Data.Type.INTERPRETED; + } else if (object instanceof String) { + data.atom = (String) object; + data.type = Data.Type.VERBATIM; + } else if (object instanceof Integer) { + data.atom = ((Integer) object).toString(); + data.type = Data.Type.INTERPRETED; + } else { + throw new RuntimeException("Unhandled ECMA type " + + object.getClass().getName()); + } + } + + return data; + } + + public ScriptableObject getDataAsScriptable(Data data) { + throw new UnsupportedOperationException("Not implemented"); + } + + public static boolean jsIn(String stateName) { + return true; + } + + @Override + public WrappedDataModel create(Interpreter interpreter) { + /** + * Called when an SCXML interpreter wants an instance of this datamodel + * Be careful to instantiate attributes of instance returned and not + * *this* + */ + + ECMAScriptDataModel newDM = new ECMAScriptDataModel(); + newDM.interpreter = interpreter; + newDM.ctx = Context.enter(); + + try { + newDM.scope = newDM.ctx.initStandardObjects(); + } catch (Exception e) { + System.err.println(e); + } + + newDM.scope.put("_name", newDM.scope, interpreter.getName()); + newDM.scope.put("_sessionid", newDM.scope, interpreter.getSessionId()); + + // ioProcessors + { + Data ioProcs = new Data(); + StringVector keys = interpreter.getIOProcessorKeys(); + for (int i = 0; i < keys.size(); i++) { + ioProcs.compound.put(keys.get(i), new Data(interpreter + .getIOProcessors().get(keys.get(i)) + .getDataModelVariables())); + } + newDM.scope + .put("_ioprocessors", newDM.scope, new ECMAData(ioProcs)); + } + + // invokers + { + Data invokers = new Data(); + StringVector keys = interpreter.getInvokerKeys(); + for (int i = 0; i < keys.size(); i++) { + invokers.compound.put(keys.get(i), new Data(interpreter + .getInvokers().get(keys.get(i)) + .getDataModelVariables())); + } + newDM.scope + .put("_ioprocessors", newDM.scope, new ECMAData(invokers)); + } + + // In predicate (not working as static is required) see: + // http://stackoverflow.com/questions/3441947/how-do-i-call-a-method-of-a-java-instance-from-javascript/16479685#16479685 + try { + Class[] parameters = new Class[] { String.class }; + Method inMethod = ECMAScriptDataModel.class.getMethod("jsIn", + parameters); + FunctionObject inFunc = new FunctionObject("In", inMethod, + newDM.scope); + newDM.scope.put("In", newDM.scope, inFunc); + } catch (SecurityException e) { + System.err.println(e); + } catch (NoSuchMethodException e) { + System.err.println(e); + } + + return newDM; + } + + @Override + public StringList getNames() { + /** + * Register with the following names for the datamodel attribute at the + * scxml element. + */ + StringList ss = new StringList(); + ss.add("ecmascript"); + return ss; + } + + @Override + public boolean validate(String location, String schema) { + /** + * Validate the datamodel. This make more sense for XML datamodels and + * is pretty much unused but required as per draft. + */ + return true; + } + + @Override + public void setEvent(Event event) { + if (debug) { + System.out.println(interpreter.getName() + " setEvent"); + } + + /** + * Make the current event available as the variable _event in the + * datamodel. + */ + ECMAEvent ecmaEvent = new ECMAEvent(event); + scope.put("_event", scope, ecmaEvent); + } + + @Override + public DataNative getStringAsData(String content) { + if (debug) { + System.out.println(interpreter.getName() + " getStringAsData"); + } + + /** + * Evaluate the string as a value expression and transform it into a + * JSON-like Data structure + */ + if (content.length() == 0) { + return Data.toNative(new Data()); + } + + // is it a json expression? + try { + Object json = NativeJSON.parse(ctx, scope, content, + new NullCallable()); + if (json != NativeJSON.NOT_FOUND) { + return Data.toNative(getScriptableAsData(json)); + } + } catch (org.mozilla.javascript.EcmaError e) { + System.err.println(e); + } + + // is it a function call or variable? + Object x = ctx.evaluateString(scope, content, "uscxml", 0, null); + if (x == Undefined.instance) { + // maybe a literal string? + x = ctx.evaluateString(scope, '"' + content + '"', "uscxml", 0, + null); + } + return Data.toNative(getScriptableAsData(x)); + } + + @Override + public long getLength(String expr) { + if (debug) { + System.out.println(interpreter.getName() + " getLength"); + } + + /** + * Return the length of the expression if it were an array, used by + * foreach element. + */ + + Object x = scope.get(expr, scope); + if (x == Undefined.instance) { + return 0; + } + + Scriptable result = Context.toObject(x, scope); + if (result.has("length", result)) { + return (long) Context.toNumber(result.get("length", result)); + } + return 0; + } + + @Override + public void setForeach(String item, String array, String index, + long iteration) { + if (debug) { + System.out.println(interpreter.getName() + " setForeach"); + } + + /** + * Prepare an iteration of the foreach element, by setting the variable + * in index to the current iteration and setting the variable in item to + * the current item from array. + */ + + try { + // get the array object + Scriptable arr = (Scriptable) scope.get(array, scope); + + if (arr.has((int) iteration, arr)) { + ctx.evaluateString(scope, item + '=' + array + '[' + iteration + + ']', "uscxml", 1, null); + if (index.length() > 0) { + ctx.evaluateString(scope, index + '=' + iteration, + "uscxml", 1, null); + } + } else { + handleException(""); + } + + } catch (ClassCastException e) { + System.err.println(e); + } + } + + @Override + public void eval(String scriptElem, String expr) { + if (debug) { + System.out.println(interpreter.getName() + " eval"); + } + + /** + * Evaluate the given expression in the datamodel. This is used foremost + * with script elements. + */ + ctx.evaluateString(scope, expr, "uscxml", 1, null); + + } + + @Override + public String evalAsString(String expr) { + if (debug) { + System.out.println(interpreter.getName() + " evalAsString: " + expr); + } + + /** + * Evaluate the expression as a string e.g. for the log element. + */ + if (!ctx.stringIsCompilableUnit(expr)) { + handleException(""); + return ""; + } + try { + Object result = ctx.evaluateString(scope, expr, "uscxml", 1, null); + return Context.toString(result); + } catch (IllegalStateException e) { + System.err.println(e); + handleException(""); + } catch (EvaluatorException e) { + System.err.println(e); + handleException(""); + } + return ""; + } + + @Override + public boolean evalAsBool(String elem, String expr) { + if (debug) { + System.out.println(interpreter.getName() + " evalAsBool"); + } + + /** + * Evaluate the expression as a boolean for cond attributes in if and + * transition elements. + */ + Object result = ctx.evaluateString(scope, expr, "uscxml", 1, null); + return Context.toBoolean(result); + } + + @Override + public boolean isDeclared(String expr) { + if (debug) { + System.out.println(interpreter.getName() + " isDeclared"); + } + + /** + * The interpreter is supposed to raise an error if we assign to an + * undeclared variable. This method is used to check whether a location + * from assign is declared. + */ + Object x = scope.get(expr, scope); + return x != Scriptable.NOT_FOUND; + } + + @Override + public void init(String dataElem, String location, String content) { + if (debug) { + System.out.println(interpreter.getName() + " init"); + } + + /** + * Called when we pass data elements. + */ + if (("null").equals(location)) + return; + + if (("null").equals(content) || content.length() == 0) { + scope.put(location, scope, Context.getUndefinedValue()); + return; + } + + try { + Object json = NativeJSON.parse(ctx, scope, content, + new NullCallable()); + if (json != NativeJSON.NOT_FOUND) { + scope.put(location, scope, json); + } else { + scope.put(location, scope, content); + } + } catch (org.mozilla.javascript.EcmaError e) { + scope.put(location, scope, content); + } + } + + @Override + public void assign(String assignElem, String location, String content) { + if (debug) { + System.out.println(interpreter.getName() + " assign"); + } + + /** + * Called when we evaluate assign elements + */ + if (("null").equals(location)) + return; + + if (("null").equals(content) || content.length() == 0) { + scope.put(location, scope, Context.getUndefinedValue()); + return; + } + + String expr = location + "=" + content; + ctx.evaluateString(scope, expr, "uscxml", 1, null); + } + + public void handleException(String cause) { + Event exceptionEvent = new Event(); + exceptionEvent.setName("error.execution"); + exceptionEvent.setEventType(Event.Type.PLATFORM); + + interpreter.receiveInternal(exceptionEvent); + } +} diff --git a/embedding/java/src/org/uscxml/tests/TestData.java b/embedding/java/src/org/uscxml/tests/TestData.java new file mode 100644 index 0000000..44f1ce0 --- /dev/null +++ b/embedding/java/src/org/uscxml/tests/TestData.java @@ -0,0 +1,23 @@ +package org.uscxml.tests; + +import org.uscxml.Data; +import org.uscxml.DataNative; + +public class TestData { + + public static void main(String[] args) { + System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib"); + { + Data data = Data.fromJSON("[1,2,3,4,5]"); + DataNative nData2 = Data.toNative(data); + Data data2 = new Data(nData2); + System.out.println(data2); + } + { + Data data = Data.fromJSON("{ \"foo\": \"bar\", \"faz\": 12 }"); + DataNative nData2 = Data.toNative(data); + Data data2 = new Data(nData2); + System.out.println(data2); + } + } +} diff --git a/embedding/java/src/org/uscxml/tests/datamodel/TestJavaScriptDataModel.java b/embedding/java/src/org/uscxml/tests/datamodel/TestJavaScriptDataModel.java new file mode 100644 index 0000000..7cfa793 --- /dev/null +++ b/embedding/java/src/org/uscxml/tests/datamodel/TestJavaScriptDataModel.java @@ -0,0 +1,27 @@ +package org.uscxml.tests.datamodel; + +import org.uscxml.Factory; +import org.uscxml.Interpreter; +import org.uscxml.InterpreterException; +import org.uscxml.datamodel.ecmascript.ECMAScriptDataModel; + +public class TestJavaScriptDataModel { + + public static void main(String[] args) throws InterpreterException { + // load JNI library from build directory + System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib"); + + // register java datamodel at factory + ECMAScriptDataModel datamodel = new ECMAScriptDataModel(); + Factory.getInstance().registerDataModel(datamodel); + + // instantiate interpreter with document from file + Interpreter interpreter = Interpreter + .fromURI("/Users/sradomski/Documents/TK/Code/uscxml/test/uscxml/java/test-ecmascript-datamodel.scxml"); + + // wait until interpreter has finished + while (true) + interpreter.interpret(); + } + +} diff --git a/embedding/java/src/org/uscxml/tests/datamodel/TestW3CECMA.java b/embedding/java/src/org/uscxml/tests/datamodel/TestW3CECMA.java new file mode 100644 index 0000000..c525fd1 --- /dev/null +++ b/embedding/java/src/org/uscxml/tests/datamodel/TestW3CECMA.java @@ -0,0 +1,41 @@ +package org.uscxml.tests.datamodel; + +import java.io.File; + +import org.uscxml.Capabilities; +import org.uscxml.Factory; +import org.uscxml.Interpreter; +import org.uscxml.InterpreterException; +import org.uscxml.InterpreterOptions; +import org.uscxml.datamodel.ecmascript.ECMAScriptDataModel; + +public class TestW3CECMA { + + public static String testDir = "/Users/sradomski/Documents/TK/Code/uscxml/test/w3c/ecma"; + + public static void main(String[] args) throws InterpreterException { + System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib"); + + ECMAScriptDataModel datamodel = new ECMAScriptDataModel(); + Factory.getInstance().registerDataModel(datamodel); + +// while(true) { +// System.out.println("### test235 #####"); +// Interpreter interpreter = Interpreter.fromURI("/Users/sradomski/Documents/TK/Code/uscxml/test/w3c/ecma/test144.scxml"); +// interpreter.interpret(); +// } + + File dir = new File(testDir); + File[] filesList = dir.listFiles(); + for (File file : filesList) { + if (file.isFile() && file.getName().endsWith(".scxml")) { + System.out.println("### " + file.getName() + " #####"); + Interpreter interpreter = Interpreter.fromURI(file.getAbsolutePath()); + interpreter.setCapabilities(1); + interpreter.interpret(); + } + } + + } + +} diff --git a/embedding/java/src/org/uscxml/tests/execContent/TestCustomExecContent.java b/embedding/java/src/org/uscxml/tests/execContent/TestCustomExecContent.java new file mode 100644 index 0000000..dd5e39a --- /dev/null +++ b/embedding/java/src/org/uscxml/tests/execContent/TestCustomExecContent.java @@ -0,0 +1,81 @@ +package org.uscxml.tests.execContent; + +import org.uscxml.Data; +import org.uscxml.Event; +import org.uscxml.Factory; +import org.uscxml.Interpreter; +import org.uscxml.InterpreterException; +import org.uscxml.WrappedExecutableContent; + +public class TestCustomExecContent extends WrappedExecutableContent { + + static int instanceId = 0; + public int id = 0; + + public TestCustomExecContent() { + id = instanceId++; + } + + @Override + public String getLocalName() { + return "custom"; + } + + @Override + public String getNamespace() { + return "http://www.w3.org/2005/07/scxml"; + } + + + @Override + public void enterElement(String node) { + System.out.println(id + " entering:" + node); + } + + @Override + public void exitElement(String node) { + System.out.println(id + " exiting:" + node); + } + + @Override + public boolean processChildren() { + return false; + } + + @Override + public WrappedExecutableContent create(Interpreter interpreter) { + return new TestCustomExecContent(); + } + + /** + * @param args + * @throws InterruptedException + * @throws InterpreterException + */ + public static void main(String[] args) throws InterruptedException, InterpreterException { + System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib"); + + TestCustomExecContent execContent = new TestCustomExecContent(); + Factory.getInstance().registerExecutableContent(execContent); + + Interpreter interpreter = Interpreter.fromXML( + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " " + + " \n" + + " " + + "\n" + ); + interpreter.interpret(); + Thread.sleep(1000); + } + +} diff --git a/embedding/java/src/org/uscxml/tests/invoker/TestCustomInvoker.java b/embedding/java/src/org/uscxml/tests/invoker/TestCustomInvoker.java new file mode 100644 index 0000000..9343c65 --- /dev/null +++ b/embedding/java/src/org/uscxml/tests/invoker/TestCustomInvoker.java @@ -0,0 +1,69 @@ +package org.uscxml.tests.invoker; + +import org.uscxml.Data; +import org.uscxml.DataNative; +import org.uscxml.Event; +import org.uscxml.Factory; +import org.uscxml.Interpreter; +import org.uscxml.InterpreterException; +import org.uscxml.InvokeRequest; +import org.uscxml.StringList; +import org.uscxml.WrappedInvoker; +import org.uscxml.SendRequest; +import org.uscxml.StringSet; + +public class TestCustomInvoker extends WrappedInvoker { + + @Override + public StringList getNames() { + StringList ss = new StringList(); + ss.add("java"); + return ss; + } + + @Override + public DataNative getDataModelVariables() { + Data data = new Data(); + data.array.add(new Data("foo", Data.Type.VERBATIM)); + return Data.toNative(data); + } + + @Override + public void send(SendRequest req) { + System.out.println("send"); + } + + @Override + public void invoke(InvokeRequest req) { + System.out.println("invoke"); + + System.out.println(req.getData()); + System.out.println(req.getXML()); + + Event ev = new Event(); + ev.setName("foo"); + returnEvent(ev); + } + + @Override + public WrappedInvoker create(Interpreter interpreter) { + return new TestCustomInvoker(); + } + + /** + * @param args + * @throws InterpreterException + */ + public static void main(String[] args) throws InterpreterException { + System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64_d.jnilib"); + + TestCustomInvoker invoker = new TestCustomInvoker(); + Factory.getInstance().registerInvoker(invoker); + + Interpreter interpreter = Interpreter + .fromURI("/Users/sradomski/Documents/TK/Code/uscxml/test/samples/uscxml/test-java-invoker.scxml"); + while (true) + interpreter.interpret(); + } + +} diff --git a/embedding/java/src/org/uscxml/tests/ioprocessor/TestCustomIOProc.java b/embedding/java/src/org/uscxml/tests/ioprocessor/TestCustomIOProc.java new file mode 100644 index 0000000..37b31a3 --- /dev/null +++ b/embedding/java/src/org/uscxml/tests/ioprocessor/TestCustomIOProc.java @@ -0,0 +1,54 @@ +package org.uscxml.tests.ioprocessor; + +import org.uscxml.Data; +import org.uscxml.DataNative; +import org.uscxml.Factory; +import org.uscxml.Interpreter; +import org.uscxml.InterpreterException; +import org.uscxml.SendRequest; +import org.uscxml.StringList; +import org.uscxml.WrappedIOProcessor; + +public class TestCustomIOProc extends WrappedIOProcessor { + + @Override + public StringList getNames() { + StringList ss = new StringList(); + ss.add("java"); + return ss; + } + + @Override + public DataNative getDataModelVariables() { + Data data = new Data(); + data.array.add(new Data("foo", Data.Type.VERBATIM)); + return Data.toNative(data); + } + + @Override + public void send(SendRequest req) { + System.out.println("send"); + } + + @Override + public WrappedIOProcessor create(Interpreter interpreter) { + return new TestCustomIOProc(); + } + + /** + * @param args + * @throws InterpreterException + */ + public static void main(String[] args) throws InterpreterException { + System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64_d.jnilib"); + + TestCustomIOProc ioproc = new TestCustomIOProc(); + Factory.getInstance().registerIOProcessor(ioproc); + + Interpreter interpreter = Interpreter + .fromURI("/Users/sradomski/Documents/TK/Code/uscxml/test/samples/uscxml/test-java-invoker.scxml"); + while (true) + interpreter.interpret(); + } + +} diff --git a/src/bindings/swig/csharp/CMakeLists.txt b/src/bindings/swig/csharp/CMakeLists.txt index 6310778..80d093e 100644 --- a/src/bindings/swig/csharp/CMakeLists.txt +++ b/src/bindings/swig/csharp/CMakeLists.txt @@ -59,6 +59,8 @@ if (DMCS_EXECUTABLE OR CSC_EXECUTABLE) # build managed code part if (CSC_EXECUTABLE) ADD_CUSTOM_TARGET(csharp + COMMAND ${CMAKE_COMMAND} -E + copy ${CMAKE_CURRENT_SOURCE_DIR}/org/uscxml/InterpreterException.cs ${PROJECT_BINARY_DIR}/src/bindings/swig/csharp/org/uscxml COMMAND ${CSC_EXECUTABLE} /target:library /out:${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/uscxmlCSharp.dll @@ -67,6 +69,8 @@ if (DMCS_EXECUTABLE OR CSC_EXECUTABLE) COMMENT "Creating umundoCSharp.dll for C# ...") else() ADD_CUSTOM_TARGET(csharp + COMMAND ${CMAKE_COMMAND} -E + copy ${CMAKE_CURRENT_SOURCE_DIR}/org/uscxml/InterpreterException.cs ${PROJECT_BINARY_DIR}/src/bindings/swig/csharp/org/uscxml COMMAND ${DMCS_EXECUTABLE} -target:library /out:${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/uscxmlCSharp.dll diff --git a/src/bindings/swig/csharp/org/uscxml/InterpreterException.cs b/src/bindings/swig/csharp/org/uscxml/InterpreterException.cs new file mode 100644 index 0000000..f86dc0e --- /dev/null +++ b/src/bindings/swig/csharp/org/uscxml/InterpreterException.cs @@ -0,0 +1,7 @@ +namespace org.uscxml { + class InterpreterException : System.ApplicationException { + public InterpreterException(string message) + : base(message) { + } + } +} \ No newline at end of file diff --git a/src/bindings/swig/csharp/stl_list.i b/src/bindings/swig/csharp/stl_list.i deleted file mode 100644 index aabd448..0000000 --- a/src/bindings/swig/csharp/stl_list.i +++ /dev/null @@ -1,49 +0,0 @@ -/* ----------------------------------------------------------------------------- - * See the LICENSE file for information on copyright, usage and redistribution - * of SWIG, and the README file for authors - http://www.swig.org/release.html. - * - * std_list.i - * ----------------------------------------------------------------------------- */ - -%include - -%{ -#include -#include -%} - -namespace std { - - template class list { - public: - typedef size_t size_type; - typedef T value_type; - typedef const value_type& const_reference; - list(); - size_type size() const; - %rename(isEmpty) empty; - bool empty() const; - void clear(); - %rename(add) push_back; - void push_back(const value_type& x); - %extend { - const_reference get(int i) throw (std::out_of_range) { - int size = int(self->size()); - int j; - if (i>=0 && i::const_iterator p; - p=self->begin(); - for (j=0; j - -// ------------------------------------------------------------------------ -// std::set -// ------------------------------------------------------------------------ - -%{ -#include -#include -#include -%} - -// exported class - -namespace std { - - template class set { - // add typemaps here - public: - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef V value_type; - set(); - set(const set &); - - unsigned int size() const; - bool empty() const; - void clear(); - %extend { - const V& get(const V& key) throw (std::out_of_range) { - std::set::iterator i = self->find(key); - if (i != self->end()) - return *i; - else - throw std::out_of_range("key not found"); - } - void insert(const V& key) { // Do NOT call this function 'set' ! - self->insert(key); - } - void del(const V& key) throw (std::out_of_range) { - std::set::iterator i = self->find(key); - if (i != self->end()) - self->erase(i); - else - throw std::out_of_range("key not found"); - } - bool has_key(const V& key) { - std::set::iterator i = self->find(key); - return i != self->end(); - } - } - }; - -} \ No newline at end of file diff --git a/src/bindings/swig/csharp/uscxml.i b/src/bindings/swig/csharp/uscxml.i index 07604c4..e7b7d62 100644 --- a/src/bindings/swig/csharp/uscxml.i +++ b/src/bindings/swig/csharp/uscxml.i @@ -20,9 +20,15 @@ typedef uscxml::Event Event; typedef uscxml::InvokeRequest InvokeRequest; typedef uscxml::SendRequest SendRequest; +%feature("director") uscxml::WrappedInvoker; +%feature("director") uscxml::WrappedDataModel; +%feature("director") uscxml::WrappedIOProcessor; +%feature("director") uscxml::WrappedExecutableContent; + // disable warning related to unknown base class #pragma SWIG nowarn=401 -//%ignore boost::enable_shared_from_this; +// do not warn when we override symbols via extend +#pragma SWIG nowarn=302 %csconst(1); @@ -31,14 +37,6 @@ typedef uscxml::SendRequest SendRequest; %rename(equals) operator==; %rename(isValid) operator bool; -%ignore operator!=; -%ignore operator<; -%ignore operator=; -%ignore operator[]; -%ignore operator std::list; -%ignore operator std::string; -%ignore operator std::map; -%ignore operator<<; //************************************************** @@ -49,6 +47,7 @@ typedef uscxml::SendRequest SendRequest; #include "../../../uscxml/Message.h" #include "../../../uscxml/Factory.h" +#include "../../../uscxml/concurrency/BlockingQueue.h" #include "../../../uscxml/Interpreter.h" //#include @@ -59,104 +58,89 @@ typedef uscxml::SendRequest SendRequest; #include "../wrapped/WrappedInvoker.h" #include "../wrapped/WrappedDataModel.h" +#include "../wrapped/WrappedExecutableContent.h" +#include "../wrapped/WrappedIOProcessor.h" using namespace uscxml; using namespace Arabica::DOM; #include "../wrapped/WrappedInvoker.cpp" #include "../wrapped/WrappedDataModel.cpp" +#include "../wrapped/WrappedExecutableContent.cpp" +#include "../wrapped/WrappedIOProcessor.cpp" %} -%ignore uscxml::NumAttr; -%ignore uscxml::SCXMLParser; -%ignore uscxml::InterpreterImpl; +// see http://binf.gmu.edu/software/SWIG/CSharp.html#csharp_exceptions +%insert(runtime) %{ + // Code to handle throwing of C# CustomApplicationException from C/C++ code. + // The equivalent delegate to the callback, CSharpExceptionCallback_t, is CustomExceptionDelegate + // and the equivalent customExceptionCallback instance is customDelegate + typedef void (SWIGSTDCALL* CSharpExceptionCallback_t)(const char *); + CSharpExceptionCallback_t customExceptionCallback = NULL; + + extern "C" SWIGEXPORT + void SWIGSTDCALL CustomExceptionRegisterCallback(CSharpExceptionCallback_t customCallback) { + customExceptionCallback = customCallback; + } + + // Note that SWIG detects any method calls named starting with + // SWIG_CSharpSetPendingException for warning 845 + static void SWIG_CSharpSetPendingExceptionCustom(const char *msg) { + customExceptionCallback(msg); + } +%} -%ignore create(); +%pragma(csharp) imclasscode=%{ + class CustomExceptionHelper { + // C# delegate for the C/C++ customExceptionCallback + public delegate void CustomExceptionDelegate(string message); + static CustomExceptionDelegate customDelegate = + new CustomExceptionDelegate(SetPendingCustomException); + + [System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="CustomExceptionRegisterCallback")] + public static extern + void CustomExceptionRegisterCallback(CustomExceptionDelegate customCallback); + + static void SetPendingCustomException(string message) { + SWIGPendingException.Set(new org.uscxml.InterpreterException(message)); + } + + static CustomExceptionHelper() { + CustomExceptionRegisterCallback(customDelegate); + } + } + static CustomExceptionHelper exceptionHelper = new CustomExceptionHelper(); +%} -%ignore uscxml::Interpreter::getDelayQueue(); -%ignore uscxml::WrappedInvoker::create(InterpreterImpl*); +%define WRAP_THROW_EXCEPTION( MATCH ) +%exception MATCH %{ +try { + $action +} catch (uscxml::Event& e) { + std::stringstream ss; + ss << std::endl << e; + SWIG_CSharpSetPendingExceptionCustom(ss.str().c_str()); +} +%} +%enddef -%ignore uscxml::WrappedDataModel::create(InterpreterImpl*); -%ignore uscxml::WrappedDataModel::init(const Arabica::DOM::Element&, const Arabica::DOM::Document&, const std::string&); -%ignore uscxml::WrappedDataModel::init(const std::string&, const Data&); -%ignore uscxml::WrappedDataModel::assign(const Arabica::DOM::Element&, const Arabica::DOM::Document&, const std::string&); -%ignore uscxml::WrappedDataModel::assign(const std::string&, const Data&); -%ignore uscxml::WrappedDataModel::eval(const Arabica::DOM::Element&, const std::string&); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::fromXML); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::fromURI); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::step); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::interpret); -%ignore uscxml::Event::Event(const Arabica::DOM::Node&); -%ignore uscxml::Event::getStrippedDOM; -%ignore uscxml::Event::getFirstDOMElement; -%ignore uscxml::Event::getDOM(); -%ignore uscxml::Event::setDOM(const Arabica::DOM::Document&); -%ignore uscxml::Event::toDocument(); -%template(DataList) std::list; -%template(DataMap) std::map; -%template(StringSet) std::set; -%template(StringVector) std::vector; -%template(ParamPair) std::pair; -%template(ParamPairVector) std::vector >; -%template(IOProcMap) std::map; -%template(InvokerMap) std::map; +%include "../uscxml_ignores.i" %rename Data DataNative; -%feature("director") uscxml::WrappedInvoker; -%feature("director") uscxml::WrappedDataModel; - // translate param multimap to Map > %rename(getParamsNative) uscxml::Event::getParams(); %csmethodmodifiers uscxml::Event::getParams() "private"; -%extend uscxml::Event { - std::vector > getParamPairs() { - std::vector > pairs; - std::multimap::iterator paramPairIter = self->getParams().begin(); - while(paramPairIter != self->getParams().end()) { - pairs.push_back(*paramPairIter); - paramPairIter++; - } - return pairs; - } -}; - -%extend uscxml::Interpreter { - std::vector getIOProcessorKeys() { - std::vector keys; - std::map::const_iterator iter = self->getIOProcessors().begin(); - while(iter != self->getIOProcessors().end()) { - keys.push_back(iter->first); - iter++; - } - return keys; - } - - std::vector getInvokerKeys() { - std::vector keys; - std::map::const_iterator iter = self->getInvokers().begin(); - while(iter != self->getInvokers().end()) { - keys.push_back(iter->first); - iter++; - } - return keys; - } - -}; - -%extend uscxml::Data { - std::vector getCompundKeys() { - std::vector keys; - std::map::const_iterator iter = self->compound.begin(); - while(iter != self->compound.end()) { - keys.push_back(iter->first); - iter++; - } - return keys; - } -}; - +%include "../uscxml_beautify.i" //*********************************************** @@ -167,19 +151,21 @@ using namespace Arabica::DOM; %include "../../../uscxml/Factory.h" %include "../../../uscxml/Message.h" %include "../../../uscxml/Interpreter.h" -#include "../../../uscxml/DOMUtils.h" - -# %include -# %include -# %include -# %include -# %include +%include "../../../uscxml/concurrency/BlockingQueue.h" %include "../wrapped/WrappedInvoker.h" %include "../wrapped/WrappedDataModel.h" +%include "../wrapped/WrappedExecutableContent.h" +%include "../wrapped/WrappedIOProcessor.h" + -# %template(XMLDocument) Arabica::DOM::Document; -# %template(XMLNode) Arabica::DOM::Node; -# %template(XMLElement) Arabica::DOM::Element; -# %template(XMLAttr) Arabica::DOM::Attr; -# %template(XMLText) Arabica::DOM::Text; +%template(DataList) std::list; +%template(DataMap) std::map; +%template(StringSet) std::set; +%template(StringVector) std::vector; +%template(StringList) std::list; +%template(ParamPair) std::pair; +%template(ParamPairVector) std::vector >; +%template(IOProcMap) std::map; +%template(InvokerMap) std::map; +%template(ParentQueue) uscxml::concurrency::BlockingQueue; diff --git a/src/bindings/swig/java/CMakeLists.txt b/src/bindings/swig/java/CMakeLists.txt index 51d67bb..3a7e9e0 100644 --- a/src/bindings/swig/java/CMakeLists.txt +++ b/src/bindings/swig/java/CMakeLists.txt @@ -33,3 +33,42 @@ set_target_properties(uscxmlNativeJava PROPERTIES COMPILE_FLAGS "-DSWIG") swig_link_libraries(uscxmlNativeJava uscxml) set(USCXML_LANGUAGE_BINDINGS ${USCXML_LANGUAGE_BINDINGS} PARENT_SCOPE) + +FIND_PROGRAM(ANT_EXECUTABLE ant PATHS $ENV{ANT_HOME}/bin ENV PATH ) +if (ANT_EXECUTABLE) + set(JAR_EXCLUDE_DEBUG OFF) + set(JAR_EXCLUDE_JNI OFF) + + # include all the JNI libraries prepared from DIST_PREPARE builds on the various desktop platforms + if (DIST_PREPARE) + if (CMAKE_CROSSCOMPILING) + if (ANDROID) + find_program(PROTOBUF_PROTOC_EXECUTABLE NAMES protoc protoc.exe) + set(JAR_EXCLUDE_JNI ON) # JNI inside jar not allowed with Android + SET(JAR_JNI_ROOT_PATH ${PROJECT_SOURCE_DIR}/package/cross-compiled/android) + else() + SET(JAR_JNI_ROOT_PATH ${PROJECT_SOURCE_DIR}/package/cross-compiled/${CMAKE_CROSSCOMPILING_TARGET_LC}) + endif() + else() + SET(JAR_JNI_ROOT_PATH ${PROJECT_SOURCE_DIR}/package) + endif() + else() + # when not preparing a distribution, just put the jar into the libs + SET(JAR_JNI_ROOT_PATH ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) + endif() + + ADD_CUSTOM_TARGET(java + COMMAND ${ANT_EXECUTABLE} + -Dlib.dir=${JAR_JNI_ROOT_PATH} + -Dsrc.dir=${PROJECT_SOURCE_DIR} + -Dbuild.dir=${PROJECT_BINARY_DIR} + -Dbuild.type=${CMAKE_BUILD_TYPE} + -Dexclude.debug=${JAR_EXCLUDE_DEBUG} + -Dexclude.jni=${JAR_EXCLUDE_JNI} + -f build-java.xml + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/contrib/java + COMMENT "Creating the jar ...") + +else() + message(STATUS "Could not find ant binary - will not build jars") +endif() \ No newline at end of file diff --git a/src/bindings/swig/java/org/uscxml/InterpreterException.java b/src/bindings/swig/java/org/uscxml/InterpreterException.java new file mode 100644 index 0000000..b089566 --- /dev/null +++ b/src/bindings/swig/java/org/uscxml/InterpreterException.java @@ -0,0 +1,9 @@ +package org.uscxml; + +public class InterpreterException extends Exception { + private static final long serialVersionUID = -3534919496547591015L; + + public InterpreterException(String msg) { + super(msg); + } +} diff --git a/src/bindings/swig/java/uscxml.i b/src/bindings/swig/java/uscxml.i index f72084e..b780f74 100644 --- a/src/bindings/swig/java/uscxml.i +++ b/src/bindings/swig/java/uscxml.i @@ -3,10 +3,6 @@ // provide a macro for the header files #define SWIGIMPORTED 1 -// import swig typemaps -//%include -//%include - %include %include %include @@ -22,25 +18,20 @@ typedef uscxml::Event Event; typedef uscxml::InvokeRequest InvokeRequest; typedef uscxml::SendRequest SendRequest; +%feature("director") uscxml::WrappedInvoker; +%feature("director") uscxml::WrappedDataModel; +%feature("director") uscxml::WrappedIOProcessor; +%feature("director") uscxml::WrappedExecutableContent; + // disable warning related to unknown base class #pragma SWIG nowarn=401 -//%ignore boost::enable_shared_from_this; +// do not warn when we override symbols via extend +#pragma SWIG nowarn=302 %javaconst(1); -# %shared_ptr(uscxml::dom::Element); -# %shared_ptr(uscxml::dom::Executable); - %rename(equals) operator==; %rename(isValid) operator bool; -%ignore operator!=; -%ignore operator<; -%ignore operator=; -%ignore operator[]; -%ignore operator std::list; -%ignore operator std::string; -%ignore operator std::map; -%ignore operator<<; //************************************************** @@ -52,113 +43,54 @@ typedef uscxml::SendRequest SendRequest; #include "../../../uscxml/Message.h" #include "../../../uscxml/Factory.h" #include "../../../uscxml/Interpreter.h" - -//#include -//#include -//#include -//#include -//#include +#include "../../../uscxml/concurrency/BlockingQueue.h" #include "../wrapped/WrappedInvoker.h" #include "../wrapped/WrappedDataModel.h" +#include "../wrapped/WrappedExecutableContent.h" +#include "../wrapped/WrappedIOProcessor.h" using namespace uscxml; using namespace Arabica::DOM; #include "../wrapped/WrappedInvoker.cpp" #include "../wrapped/WrappedDataModel.cpp" +#include "../wrapped/WrappedExecutableContent.cpp" +#include "../wrapped/WrappedIOProcessor.cpp" %} -%ignore uscxml::NumAttr; -%ignore uscxml::SCXMLParser; -%ignore uscxml::InterpreterImpl; - -%ignore create(); - -%ignore uscxml::Interpreter::getDelayQueue(); - -%ignore uscxml::WrappedInvoker::create(InterpreterImpl*); - -%ignore uscxml::WrappedDataModel::create(InterpreterImpl*); -%ignore uscxml::WrappedDataModel::init(const Arabica::DOM::Element&, const Arabica::DOM::Document&, const std::string&); -%ignore uscxml::WrappedDataModel::init(const std::string&, const Data&); -%ignore uscxml::WrappedDataModel::assign(const Arabica::DOM::Element&, const Arabica::DOM::Document&, const std::string&); -%ignore uscxml::WrappedDataModel::assign(const std::string&, const Data&); -%ignore uscxml::WrappedDataModel::eval(const Arabica::DOM::Element&, const std::string&); - -%ignore uscxml::Event::Event(const Arabica::DOM::Node&); -%ignore uscxml::Event::getStrippedDOM; -%ignore uscxml::Event::getFirstDOMElement; -%ignore uscxml::Event::getDOM(); -%ignore uscxml::Event::setDOM(const Arabica::DOM::Document&); -%ignore uscxml::Event::toDocument(); - -%template(DataList) std::list; -%template(DataMap) std::map; -%template(StringSet) std::set; -%template(StringVector) std::vector; -%template(ParamPair) std::pair; -%template(ParamPairVector) std::vector >; -%template(IOProcMap) std::map; -%template(InvokerMap) std::map; +%define WRAP_THROW_EXCEPTION( MATCH ) +%javaexception("org.uscxml.InterpreterException") MATCH { + try { + $action + } + catch ( uscxml::Event& e ) { + jclass eclass = jenv->FindClass("org/uscxml/InterpreterException"); + if ( eclass ) { + std::stringstream ss; + ss << std::endl << e; + jenv->ThrowNew( eclass, ss.str().c_str() ); + } + } +} +%enddef + +WRAP_THROW_EXCEPTION(uscxml::Interpreter::fromXML); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::fromURI); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::step); +WRAP_THROW_EXCEPTION(uscxml::Interpreter::interpret); + + +%include "../uscxml_ignores.i" %rename Data DataNative; -%feature("director") uscxml::WrappedInvoker; -%feature("director") uscxml::WrappedDataModel; - // translate param multimap to Map > %rename(getParamsNative) uscxml::Event::getParams(); %javamethodmodifiers uscxml::Event::getParams() "private"; -%extend uscxml::Event { - std::vector > getParamPairs() { - std::vector > pairs; - std::multimap::iterator paramPairIter = self->getParams().begin(); - while(paramPairIter != self->getParams().end()) { - pairs.push_back(*paramPairIter); - paramPairIter++; - } - return pairs; - } -}; - -%extend uscxml::Interpreter { - std::vector getIOProcessorKeys() { - std::vector keys; - std::map::const_iterator iter = self->getIOProcessors().begin(); - while(iter != self->getIOProcessors().end()) { - keys.push_back(iter->first); - iter++; - } - return keys; - } - - std::vector getInvokerKeys() { - std::vector keys; - std::map::const_iterator iter = self->getInvokers().begin(); - while(iter != self->getInvokers().end()) { - keys.push_back(iter->first); - iter++; - } - return keys; - } - -}; - -%extend uscxml::Data { - std::vector getCompundKeys() { - std::vector keys; - std::map::const_iterator iter = self->compound.begin(); - while(iter != self->compound.end()) { - keys.push_back(iter->first); - iter++; - } - return keys; - } -}; - +%include "../uscxml_beautify.i" //*********************************************** @@ -169,19 +101,21 @@ using namespace Arabica::DOM; %include "../../../uscxml/Factory.h" %include "../../../uscxml/Message.h" %include "../../../uscxml/Interpreter.h" -#include "../../../uscxml/DOMUtils.h" - -# %include -# %include -# %include -# %include -# %include +%include "../../../uscxml/concurrency/BlockingQueue.h" %include "../wrapped/WrappedInvoker.h" %include "../wrapped/WrappedDataModel.h" +%include "../wrapped/WrappedExecutableContent.h" +%include "../wrapped/WrappedIOProcessor.h" + -# %template(XMLDocument) Arabica::DOM::Document; -# %template(XMLNode) Arabica::DOM::Node; -# %template(XMLElement) Arabica::DOM::Element; -# %template(XMLAttr) Arabica::DOM::Attr; -# %template(XMLText) Arabica::DOM::Text; +%template(DataList) std::list; +%template(DataMap) std::map; +%template(StringSet) std::set; +%template(StringVector) std::vector; +%template(StringList) std::list; +%template(ParamPair) std::pair; +%template(ParamPairVector) std::vector >; +%template(IOProcMap) std::map; +%template(InvokerMap) std::map; +%template(ParentQueue) uscxml::concurrency::BlockingQueue; diff --git a/src/bindings/swig/uscxml_beautify.i b/src/bindings/swig/uscxml_beautify.i new file mode 100644 index 0000000..8b57e78 --- /dev/null +++ b/src/bindings/swig/uscxml_beautify.i @@ -0,0 +1,67 @@ +%extend uscxml::Event { + std::vector > getParamPairs() { + std::vector > pairs; + std::multimap::iterator paramPairIter = self->getParams().begin(); + while(paramPairIter != self->getParams().end()) { + pairs.push_back(*paramPairIter); + paramPairIter++; + } + return pairs; + } +}; + +%extend uscxml::Interpreter { + + std::vector getBasicConfiguration() { + Arabica::XPath::NodeSet nativeConfig = self->getBasicConfiguration(); + std::vector config; + for (int i = 0; i < nativeConfig.size(); i++) { + Arabica::DOM::Element elem(nativeConfig[i]); + config.push_back(elem.getAttribute("id")); + } + return config; + } + + std::vector getConfiguration() { + Arabica::XPath::NodeSet nativeConfig = self->getConfiguration(); + std::vector config; + for (int i = 0; i < nativeConfig.size(); i++) { + Arabica::DOM::Element elem(nativeConfig[i]); + config.push_back(elem.getAttribute("id")); + } + return config; + } + + std::vector getIOProcessorKeys() { + std::vector keys; + std::map::const_iterator iter = self->getIOProcessors().begin(); + while(iter != self->getIOProcessors().end()) { + keys.push_back(iter->first); + iter++; + } + return keys; + } + + std::vector getInvokerKeys() { + std::vector keys; + std::map::const_iterator iter = self->getInvokers().begin(); + while(iter != self->getInvokers().end()) { + keys.push_back(iter->first); + iter++; + } + return keys; + } + +}; + +%extend uscxml::Data { + std::vector getCompundKeys() { + std::vector keys; + std::map::const_iterator iter = self->compound.begin(); + while(iter != self->compound.end()) { + keys.push_back(iter->first); + iter++; + } + return keys; + } +}; diff --git a/src/bindings/swig/uscxml_ignores.i b/src/bindings/swig/uscxml_ignores.i new file mode 100644 index 0000000..4f8b2a3 --- /dev/null +++ b/src/bindings/swig/uscxml_ignores.i @@ -0,0 +1,54 @@ +%ignore uscxml::NumAttr; +%ignore uscxml::SCXMLParser; +%ignore uscxml::InterpreterImpl; + +%ignore create(); + +%ignore uscxml::Interpreter::getDelayQueue(); +%ignore uscxml::Interpreter::fromDOM; +%ignore uscxml::Interpreter::fromClone; +%ignore uscxml::Interpreter::start(); +%ignore uscxml::Interpreter::stop(); +%ignore uscxml::Interpreter::setCmdLineOptions(std::map); +%ignore uscxml::Interpreter::getDocument; +%ignore uscxml::Interpreter::getImpl; +%ignore uscxml::Interpreter::runOnMainThread; +%ignore uscxml::Interpreter::getHTTPServlet(); +%ignore uscxml::Interpreter::getNodeSetForXPath(const std::string&); +%ignore uscxml::Interpreter::isLegalConfiguration(const Arabica::XPath::NodeSet&); +%ignore uscxml::Interpreter::getInstances(); + +%ignore uscxml::WrappedInvoker::create(InterpreterImpl*); + +%ignore uscxml::WrappedDataModel::create(InterpreterImpl*); +%ignore uscxml::WrappedDataModel::init(const Arabica::DOM::Element&, const Arabica::DOM::Document&, const std::string&); +%ignore uscxml::WrappedDataModel::init(const Arabica::DOM::Element&, const Arabica::DOM::Node&, const std::string&); +%ignore uscxml::WrappedDataModel::init(const std::string&, const Data&); +%ignore uscxml::WrappedDataModel::assign(const Arabica::DOM::Element&, const Arabica::DOM::Document&, const std::string&); +%ignore uscxml::WrappedDataModel::assign(const Arabica::DOM::Element&, const Arabica::DOM::Node&, const std::string&); +%ignore uscxml::WrappedDataModel::assign(const std::string&, const Data&); +%ignore uscxml::WrappedDataModel::eval(const Arabica::DOM::Element&, const std::string&); +%ignore uscxml::WrappedDataModel::evalAsBool(const Arabica::DOM::Node&, const std::string&); + +%ignore uscxml::WrappedExecutableContent::create(InterpreterImpl*); +%ignore uscxml::WrappedExecutableContent::enterElement(const Arabica::DOM::Node&); +%ignore uscxml::WrappedExecutableContent::exitElement(const Arabica::DOM::Node&); + +%ignore uscxml::WrappedIOProcessor::create(InterpreterImpl*); + +%ignore uscxml::Event::Event(const Arabica::DOM::Node&); +%ignore uscxml::Event::getStrippedDOM; +%ignore uscxml::Event::getFirstDOMElement; +%ignore uscxml::Event::getDOM(); +%ignore uscxml::Event::setDOM(const Arabica::DOM::Document&); +%ignore uscxml::Event::toDocument(); + +%ignore operator!=; +%ignore operator<; +%ignore operator=; +%ignore operator[]; +%ignore operator std::list; +%ignore operator std::string; +%ignore operator std::map; +%ignore operator<<; + diff --git a/src/bindings/swig/wrapped/WrappedDataModel.cpp b/src/bindings/swig/wrapped/WrappedDataModel.cpp index 901d246..8ba57be 100644 --- a/src/bindings/swig/wrapped/WrappedDataModel.cpp +++ b/src/bindings/swig/wrapped/WrappedDataModel.cpp @@ -1,3 +1,22 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + #include "WrappedDataModel.h" namespace uscxml { diff --git a/src/bindings/swig/wrapped/WrappedDataModel.h b/src/bindings/swig/wrapped/WrappedDataModel.h index 2b1ad48..026bed2 100644 --- a/src/bindings/swig/wrapped/WrappedDataModel.h +++ b/src/bindings/swig/wrapped/WrappedDataModel.h @@ -1,3 +1,22 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + #ifndef WRAPPEDDATAMODEL_H_DBAAD6AF #define WRAPPEDDATAMODEL_H_DBAAD6AF diff --git a/src/bindings/swig/wrapped/WrappedExecutableContent.cpp b/src/bindings/swig/wrapped/WrappedExecutableContent.cpp new file mode 100644 index 0000000..a876754 --- /dev/null +++ b/src/bindings/swig/wrapped/WrappedExecutableContent.cpp @@ -0,0 +1,27 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + +#include "WrappedExecutableContent.h" + +namespace uscxml { + +WrappedExecutableContent::WrappedExecutableContent() {} +WrappedExecutableContent::~WrappedExecutableContent() {} + +} \ No newline at end of file diff --git a/src/bindings/swig/wrapped/WrappedExecutableContent.h b/src/bindings/swig/wrapped/WrappedExecutableContent.h new file mode 100644 index 0000000..24c6978 --- /dev/null +++ b/src/bindings/swig/wrapped/WrappedExecutableContent.h @@ -0,0 +1,86 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + +#ifndef WRAPPEDEXECUTABLECONTENT_H_F690F480 +#define WRAPPEDEXECUTABLECONTENT_H_F690F480 + +#include "../../../uscxml/Message.h" +#include "../../../uscxml/Factory.h" +#include "../../../uscxml/Interpreter.h" + +namespace uscxml { + +class WrappedExecutableContent : public ExecutableContentImpl { +public: + WrappedExecutableContent(); + virtual ~WrappedExecutableContent(); + + virtual WrappedExecutableContent* create(const Interpreter& interpreter) { + return new WrappedExecutableContent(); + } + + virtual boost::shared_ptr create(InterpreterImpl* interpreter) { + _interpreter = interpreter->shared_from_this(); + return boost::shared_ptr(create(_interpreter)); + } + + virtual std::string getLocalName() { + return ""; + } + + virtual std::string getNamespace() { + return "http://www.w3.org/2005/07/scxml"; + } + + virtual void enterElement(const Arabica::DOM::Node& node) { + std::ostringstream ssElement; + ssElement << node; + enterElement(ssElement.str()); + } + + virtual void exitElement(const Arabica::DOM::Node& node) { + std::ostringstream ssElement; + ssElement << node; + exitElement(ssElement.str()); + } + + virtual bool processChildren() { + return false; + } + + virtual void enterElement(const std::string& node) { + + } + + virtual void exitElement(const std::string& node) { + + } + + void croak() throw(Event) { + + } + +private: + Interpreter _interpreter; +}; + +} + + +#endif /* end of include guard: WRAPPEDEXECUTABLECONTENT_H_F690F480 */ diff --git a/src/bindings/swig/wrapped/WrappedIOProcessor.cpp b/src/bindings/swig/wrapped/WrappedIOProcessor.cpp new file mode 100644 index 0000000..2f39d80 --- /dev/null +++ b/src/bindings/swig/wrapped/WrappedIOProcessor.cpp @@ -0,0 +1,27 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + +#include "WrappedIOProcessor.h" + +namespace uscxml { + +WrappedIOProcessor::WrappedIOProcessor() {} +WrappedIOProcessor::~WrappedIOProcessor() {} + +} \ No newline at end of file diff --git a/src/bindings/swig/wrapped/WrappedIOProcessor.h b/src/bindings/swig/wrapped/WrappedIOProcessor.h new file mode 100644 index 0000000..70c400e --- /dev/null +++ b/src/bindings/swig/wrapped/WrappedIOProcessor.h @@ -0,0 +1,62 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + +#ifndef WRAPPEDIOPROCESSOR_H_AE98064A +#define WRAPPEDIOPROCESSOR_H_AE98064A + +#include "../../../uscxml/Message.h" +#include "../../../uscxml/Factory.h" +#include "../../../uscxml/Interpreter.h" + +namespace uscxml { + +class WrappedIOProcessor : public IOProcessorImpl { +public: + WrappedIOProcessor(); + virtual ~WrappedIOProcessor(); + + virtual WrappedIOProcessor* create(const Interpreter& interpreter) { + return new WrappedIOProcessor(); + } + + virtual boost::shared_ptr create(InterpreterImpl* interpreter) { + _interpreter = interpreter->shared_from_this(); + return boost::shared_ptr(create(_interpreter)); + } + virtual std::list getNames() { + return std::list(); + }; + + virtual Data getDataModelVariables() { + Data data; + return data; + } + + virtual void send(const SendRequest& req) { + + } + +private: + Interpreter _interpreter; +}; + +} + + +#endif /* end of include guard: WRAPPEDIOPROCESSOR_H_AE98064A */ diff --git a/src/bindings/swig/wrapped/WrappedInvoker.cpp b/src/bindings/swig/wrapped/WrappedInvoker.cpp index b775878..8187a9f 100644 --- a/src/bindings/swig/wrapped/WrappedInvoker.cpp +++ b/src/bindings/swig/wrapped/WrappedInvoker.cpp @@ -1,3 +1,22 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + #include "WrappedInvoker.h" namespace uscxml { diff --git a/src/bindings/swig/wrapped/WrappedInvoker.h b/src/bindings/swig/wrapped/WrappedInvoker.h index 61eedac..ff56b15 100644 --- a/src/bindings/swig/wrapped/WrappedInvoker.h +++ b/src/bindings/swig/wrapped/WrappedInvoker.h @@ -1,3 +1,22 @@ +/** + * @file + * @author 2012-2014 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) + * @copyright Simplified BSD + * + * @cond + * This program is free software: you can redistribute it and/or modify + * it under the terms of the FreeBSD license as published by the FreeBSD + * project. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the FreeBSD license along with this + * program. If not, see . + * @endcond + */ + #ifndef WRAPPEDINVOKER_H_F9725D47 #define WRAPPEDINVOKER_H_F9725D47 diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 4ffa92c..9770387 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -82,7 +82,8 @@ #define VALID_FROM_IDLE(newState) ( \ newState == InterpreterState::USCXML_DESTROYED || \ - newState == InterpreterState::USCXML_MICROSTEPPED \ + newState == InterpreterState::USCXML_MICROSTEPPED || \ + newState == InterpreterState::USCXML_MACROSTEPPED \ ) #define VALID_FROM_FINISHED(newState) ( \ @@ -90,6 +91,12 @@ newState == InterpreterState::USCXML_INSTANTIATED \ ) +#define THROW_ERROR_PLATFORM(msg) \ + Event e; \ + e.name = "error.platform"; \ + e.data.compound["cause"] = Data(msg, Data::VERBATIM); \ + throw e; \ + /// macro to catch exceptions in executeContent #define CATCH_AND_DISTRIBUTE(msg) \ @@ -378,8 +385,7 @@ Interpreter Interpreter::fromURI(const std::string& uri) { URL absUrl(uri); if (!absUrl.isAbsolute()) { if (!absUrl.toAbsoluteCwd()) { - LOG(ERROR) << "Given URL is not absolute or does not have file schema"; - return Interpreter(); + THROW_ERROR_PLATFORM("Given URL is not absolute or does not have file schema"); } } @@ -401,8 +407,7 @@ Interpreter Interpreter::fromURI(const std::string& uri) { std::stringstream ss; ss << absUrl; if (absUrl.downloadFailed()) { - LOG(ERROR) << "Downloading SCXML document from " << absUrl << " failed"; - return interpreter; + THROW_ERROR_PLATFORM("Downloading SCXML document from " + absUrl.asString() + " failed"); } interpreter = fromXML(ss.str()); } @@ -412,7 +417,7 @@ Interpreter Interpreter::fromURI(const std::string& uri) { interpreter._impl->_baseURI = URL::asBaseURL(absUrl); interpreter._impl->_sourceURI = absUrl; } else { - LOG(ERROR) << "Cannot create interpreter from URI '" << absUrl.asString() << "'"; + THROW_ERROR_PLATFORM("Cannot create interpreter from URI " + absUrl.asString() + "'"); } return interpreter; } @@ -439,8 +444,12 @@ Interpreter Interpreter::fromInputSource(Arabica::SAX::InputSource& interpreterImpl->setNameSpaceInfo(parser.nameSpace); interpreterImpl->_document = parser.getDocument(); } else { -// assert(parser.errorsReported()); - interpreterImpl->setInterpreterState(InterpreterState::USCXML_FAULTED, parser.errors()); + if (parser.errorsReported()) { + THROW_ERROR_PLATFORM(parser.errors()) + } else { + THROW_ERROR_PLATFORM("Failed to create interpreter"); +// interpreterImpl->setInterpreterState(InterpreterState::USCXML_FAULTED, parser.errors()); + } } return interpreter; } diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index d9aeac3..9a3e553 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -315,11 +315,11 @@ public: URL::toBaseURL(baseURI); _baseURI = baseURI; } - URL getBaseURI() { - return _baseURI; + std::string getBaseURI() { + return _baseURI.asString(); } - URL getSourceURI() { - return _sourceURI; + std::string getSourceURI() { + return _sourceURI.asString(); } void setCmdLineOptions(std::map params); @@ -652,10 +652,10 @@ public: void setSourceURI(std::string sourceURI) { return _impl->setSourceURI(sourceURI); } - URL getSourceURI() { + std::string getSourceURI() { return _impl->getSourceURI(); } - URL getBaseURI() { + std::string getBaseURI() { return _impl->getBaseURI(); } diff --git a/src/uscxml/URL.h b/src/uscxml/URL.h index 5f55454..fd89503 100644 --- a/src/uscxml/URL.h +++ b/src/uscxml/URL.h @@ -261,7 +261,9 @@ public: return _impl->pathComponents(); } const std::string asString() const { - return _impl->asString(); + if (_impl) + return _impl->asString(); + return ""; } static std::string tmpDir(); diff --git a/src/uscxml/concurrency/tinythread.cpp b/src/uscxml/concurrency/tinythread.cpp index 6167545..d46cda3 100644 --- a/src/uscxml/concurrency/tinythread.cpp +++ b/src/uscxml/concurrency/tinythread.cpp @@ -85,10 +85,27 @@ condition_variable::~condition_variable() { #endif #if defined(_TTHREAD_WIN32_) -void condition_variable::_wait() { +void condition_variable::_wait(unsigned int ms) { + if (ms <= 0) + ms = INFINITE; // Wait for either event to become signaled due to notify_one() or // notify_all() being called - int result = WaitForMultipleObjects(2, mEvents, FALSE, INFINITE); + int result = WaitForMultipleObjects(2, mEvents, FALSE, ms); + if (result == WAIT_FAILED) { + LPVOID lpMsgBuf; + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &lpMsgBuf, + 0, + NULL); +// UM_LOG_ERR("%s", lpMsgBuf); + LocalFree(lpMsgBuf); + + } // Check if we are the last waiter EnterCriticalSection(&mWaitersCountLock); diff --git a/src/uscxml/concurrency/tinythread.h b/src/uscxml/concurrency/tinythread.h index 9d211f4..867f036 100644 --- a/src/uscxml/concurrency/tinythread.h +++ b/src/uscxml/concurrency/tinythread.h @@ -421,7 +421,7 @@ public: // Release the mutex while waiting for the condition (will decrease // the number of waiters when done)... aMutex.unlock(); - _wait(); + _wait(0); aMutex.lock(); #else pthread_cond_wait(&mHandle, &aMutex.mHandle); @@ -483,7 +483,7 @@ public: private: #if defined(_TTHREAD_WIN32_) - void _wait(); + void _wait(unsigned int ms); HANDLE mEvents[2]; ///< Signal and broadcast event HANDLEs. unsigned int mWaitersCount; ///< Count of the number of waiters. CRITICAL_SECTION mWaitersCountLock; ///< Serialize access to mWaitersCount. diff --git a/src/uscxml/debug/DebuggerServlet.cpp b/src/uscxml/debug/DebuggerServlet.cpp index 17c11d6..d7528f0 100644 --- a/src/uscxml/debug/DebuggerServlet.cpp +++ b/src/uscxml/debug/DebuggerServlet.cpp @@ -228,7 +228,7 @@ void DebuggerServlet::processListSessions(const HTTPServer::Request& request) { Data sessionData; sessionData.compound["name"] = Data(instance->getName(), Data::VERBATIM); sessionData.compound["id"] = Data(instance->getSessionId(), Data::VERBATIM); - sessionData.compound["source"] = Data(instance->getSourceURI().asString(), Data::VERBATIM); + sessionData.compound["source"] = Data(instance->getSourceURI(), Data::VERBATIM); sessionData.compound["xml"].node = instance->getDocument(); replyData.compound["sessions"].array.push_back(sessionData); diff --git a/test/w3c/confEcma.xsl b/test/w3c/confEcma.xsl index 96c1708..b77e22c 100644 --- a/test/w3c/confEcma.xsl +++ b/test/w3c/confEcma.xsl @@ -674,7 +674,7 @@ the basic http tests. In the case of python, we have to import the regexp modul - _event.raw.search(/Var=/) !== -1 + _event.raw.search(=) !== -1 diff --git a/test/w3c/ecma/test329.scxml b/test/w3c/ecma/test329.scxml index 586f15a..9a95643 100644 --- a/test/w3c/ecma/test329.scxml +++ b/test/w3c/ecma/test329.scxml @@ -1,5 +1,4 @@ -