diff options
Diffstat (limited to 'embedding')
10 files changed, 95 insertions, 41 deletions
diff --git a/embedding/csharp/uSCXMLEmbedding.suo b/embedding/csharp/uSCXMLEmbedding.suo Binary files differindex 9bacedf..823eecc 100644 --- a/embedding/csharp/uSCXMLEmbedding.suo +++ b/embedding/csharp/uSCXMLEmbedding.suo diff --git a/embedding/csharp/uSCXMLEmbedding/Extensions/CustomDataModel.cs b/embedding/csharp/uSCXMLEmbedding/Extensions/CustomDataModel.cs index b2ee1de..65e517a 100644 --- a/embedding/csharp/uSCXMLEmbedding/Extensions/CustomDataModel.cs +++ b/embedding/csharp/uSCXMLEmbedding/Extensions/CustomDataModel.cs @@ -10,7 +10,9 @@ namespace embedding {
public override DataModel create(Interpreter interpreter)
{
- return new CustomDataModel();
+ CustomDataModel dm = new CustomDataModel();
+ dm.swigCMemOwn = false;
+ return dm;
}
public override void eval(string scriptElem, string expr)
diff --git a/embedding/csharp/uSCXMLEmbedding/Extensions/CustomExecutableContent.cs b/embedding/csharp/uSCXMLEmbedding/Extensions/CustomExecutableContent.cs index 94cf111..ac79065 100644 --- a/embedding/csharp/uSCXMLEmbedding/Extensions/CustomExecutableContent.cs +++ b/embedding/csharp/uSCXMLEmbedding/Extensions/CustomExecutableContent.cs @@ -25,7 +25,9 @@ namespace embedding public override ExecutableContent create(Interpreter interpreter)
{
- return new CustomExecutableContent();
+ CustomExecutableContent execContent = new CustomExecutableContent();
+ execContent.swigCMemOwn = false;
+ return execContent;
}
diff --git a/embedding/csharp/uSCXMLEmbedding/Extensions/CustomIOProc.cs b/embedding/csharp/uSCXMLEmbedding/Extensions/CustomIOProc.cs index 0480a34..866c148 100644 --- a/embedding/csharp/uSCXMLEmbedding/Extensions/CustomIOProc.cs +++ b/embedding/csharp/uSCXMLEmbedding/Extensions/CustomIOProc.cs @@ -3,6 +3,9 @@ using System.Collections.Generic; using System.Linq;
using System.Text;
using org.uscxml;
+using System.Xml;
+using System.Xml.XPath;
+using System.IO;
namespace embedding
{
@@ -10,7 +13,9 @@ namespace embedding {
public override IOProcessor create(Interpreter interpreter)
{
- return new CustomIOProc();
+ CustomIOProc ioProc = new CustomIOProc();
+ ioProc.swigCMemOwn = false;
+ return ioProc;
}
public override Data getDataModelVariables()
@@ -22,12 +27,39 @@ namespace embedding public override StringList getNames()
{
StringList names = new StringList();
- names.add("simple");
+ names.add("custom");
return names;
}
public override void send(SendRequest req)
{
+ Console.WriteLine(req);
+ // send in s1.onentry
+ if ("This is some content!" == req.getContent())
+ {
+ returnEvent(new Event("received1"));
+ return;
+ }
+ // send in s2.onentry
+ if (req.getParams().ContainsKey("foo")
+ && "bar" == (req.getParams()["foo"][0].getAtom()))
+ {
+ returnEvent(new Event("received2"));
+ return;
+ }
+ // send in s3
+ if (req.getXML().Length > 0)
+ {
+ XmlReaderSettings set = new XmlReaderSettings();
+ set.ConformanceLevel = ConformanceLevel.Fragment;
+ XPathDocument doc = new XPathDocument(XmlReader.Create(new StringReader(req.getXML()), set));
+ XPathNavigator nav = doc.CreateNavigator();
+
+ Console.WriteLine("Root element :" + nav.SelectSingleNode("/").Value);
+ returnEvent(new Event("received3"));
+ return;
+ }
+
}
}
}
diff --git a/embedding/csharp/uSCXMLEmbedding/Extensions/CustomInvoker.cs b/embedding/csharp/uSCXMLEmbedding/Extensions/CustomInvoker.cs index da941b0..7c174ed 100644 --- a/embedding/csharp/uSCXMLEmbedding/Extensions/CustomInvoker.cs +++ b/embedding/csharp/uSCXMLEmbedding/Extensions/CustomInvoker.cs @@ -13,7 +13,9 @@ namespace embedding {
public override Invoker create(Interpreter interpreter)
{
- return new CustomInvoker();
+ CustomInvoker invoker = new CustomInvoker();
+ invoker.swigCMemOwn = false;
+ return invoker;
}
public override Data getDataModelVariables()
@@ -31,20 +33,20 @@ namespace embedding public override void invoke(InvokeRequest req)
{
- }
-
- public override void send(SendRequest req)
- {
Console.WriteLine(req);
// send in s1.onentry
- if ("This is some content!" == req.getContent())
+ if ("Some string content" == req.getContent())
{
- returnEvent(new Event("received1"));
+ returnEvent(new Event("received1"), true);
return;
}
+ }
+
+ public override void send(SendRequest req)
+ {
+ Console.WriteLine(req);
// send in s2.onentry
- if (req.getParams().ContainsKey("foo")
- && "bar" == (req.getParams()["foo"][0].getAtom()))
+ if (req.getName() == "foo")
{
returnEvent(new Event("received2"));
return;
diff --git a/embedding/csharp/uSCXMLEmbedding/RunTests.cs b/embedding/csharp/uSCXMLEmbedding/RunTests.cs index d98bca1..38e3736 100644 --- a/embedding/csharp/uSCXMLEmbedding/RunTests.cs +++ b/embedding/csharp/uSCXMLEmbedding/RunTests.cs @@ -29,14 +29,19 @@ namespace embedding SetDllDirectory("C:\\Users\\sradomski\\Desktop\\build\\uscxml\\lib\\csharp");
}
- testLifeCycle();
- testExecutableContent();
- testIOProcessor();
- testInvoker();
+ int i = 1;
+ while (i-- > 0)
+ {
+ testLifeCycle();
+ testExecutableContent();
+ testIOProcessor();
+ testInvoker();
+ }
Console.ReadKey();
}
public static void testInvoker() {
+ Console.WriteLine("testInvoker");
CustomInvoker invoker = new CustomInvoker();
// just register prototype at global factory
Factory.getInstance().registerInvoker(invoker);
@@ -47,13 +52,15 @@ namespace embedding " <invoke type=\"custom\" id=\"custominvoker1\">" +
" <content>Some string content</content>" +
" </invoke>" +
- " <invoke type=\"java\" id=\"custominvoker2\" />" +
+ " <invoke type=\"custom\" id=\"custominvoker2\" />" +
" <state id=\"s11\">" +
- " <transition event=\"received1\" target=\"s12\" />" +
+ " <transition event=\"received1\" target=\"s12\">" +
+ " </transition>" +
" </state>" +
" <state id=\"s12\">" +
" <onentry>" +
" <send target=\"#_custominvoker2\" event=\"foo\" />" +
+ " <log label=\"label\" expr=\"foo\" />" +
" </onentry>" +
" <transition event=\"received2\" target=\"done\" />" +
" </state>" +
@@ -69,6 +76,7 @@ namespace embedding public static void testIOProcessor()
{
+ Console.WriteLine("testIOProcessor");
CustomIOProc ioproc = new CustomIOProc();
// just register prototype at global factory
Factory.getInstance().registerIOProcessor(ioproc);
@@ -77,7 +85,7 @@ namespace embedding "<scxml>" +
" <state id=\"s1\">" +
" <onentry>" +
- " <send type=\"java\">" +
+ " <send type=\"custom\">" +
" <content>This is some content!</content>" +
" </send>" +
" </onentry>" +
@@ -85,7 +93,7 @@ namespace embedding " </state>" +
" <state id=\"s2\">" +
" <onentry>" +
- " <send type=\"java\">" +
+ " <send type=\"custom\">" +
" <param name=\"foo\" expr=\"bar\" />" +
" </send>" +
" </onentry>" +
@@ -93,7 +101,7 @@ namespace embedding " </state>" +
" <state id=\"s3\">" +
" <onentry>" +
- " <send type=\"java\">" +
+ " <send type=\"custom\">" +
" <content>" +
" <this><is><xml/></is></this>" +
" </content>" +
@@ -112,6 +120,7 @@ namespace embedding public static void testExecutableContent()
{
+ Console.WriteLine("testExecutableContent");
CustomExecutableContent execContent = new CustomExecutableContent();
Factory.getInstance().registerExecutableContent(execContent);
@@ -119,12 +128,12 @@ namespace embedding "<scxml>\n" +
" <state id=\"s0\">\n" +
" <onentry>\n" +
- " <custom foo=\"bar\">\n" +
+ " <!-- custom foo=\"bar\">\n" +
" <something></something>\n" +
" </custom>\n" +
" <custom foo=\"bar\">\n" +
" <something></something>\n" +
- " </custom>\n" +
+ " </custom -->\n" +
" </onentry>\n" +
" <transition target=\"exit\" />" +
" </state>\n" +
@@ -132,10 +141,12 @@ namespace embedding "</scxml>\n"
);
interpreter.interpret();
+ interpreter.Dispose();
}
public static void testLifeCycle()
{
+ Console.WriteLine("testLifeCycle");
// syntactic xml parse error -> throws
try
{
@@ -145,7 +156,7 @@ namespace embedding }
catch (InterpreterException e)
{
- Console.WriteLine(e);
+// Console.WriteLine(e);
}
// semantic xml parse error -> throws
@@ -159,7 +170,7 @@ namespace embedding }
catch (InterpreterException e)
{
- Console.WriteLine(e);
+// Console.WriteLine(e);
}
// request unknown datamodel
@@ -179,7 +190,7 @@ namespace embedding }
catch (InterpreterException e)
{
- Console.WriteLine(e);
+// Console.WriteLine(e);
}
diff --git a/embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java b/embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java index 0b2b576..679581d 100644 --- a/embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java +++ b/embedding/java/src/org/uscxml/datamodel/ecmascript/ECMAScriptDataModel.java @@ -1,6 +1,7 @@ package org.uscxml.datamodel.ecmascript; import java.lang.reflect.Method; +import java.util.Map; import org.mozilla.javascript.Callable; import org.mozilla.javascript.Context; @@ -14,8 +15,9 @@ import org.uscxml.Data; import org.uscxml.DataModel; import org.uscxml.Event; import org.uscxml.Interpreter; +import org.uscxml.NativeIOProcessor; +import org.uscxml.NativeInvoker; import org.uscxml.StringList; -import org.uscxml.StringVector; public class ECMAScriptDataModel extends DataModel { @@ -84,6 +86,7 @@ public class ECMAScriptDataModel extends DataModel { */ ECMAScriptDataModel newDM = new ECMAScriptDataModel(); + newDM.swigReleaseOwnership(); newDM.interpreter = interpreter; newDM.ctx = Context.enter(); @@ -99,11 +102,9 @@ public class ECMAScriptDataModel extends DataModel { // ioProcessors { Data ioProcs = new Data(); - StringVector keys = interpreter.getIOProcessorKeys(); - for (int i = 0; i < keys.size(); i++) { - ioProcs.put(keys.get(i), interpreter - .getIOProcessors().get(keys.get(i)) - .getDataModelVariables()); + Map<String, NativeIOProcessor> ioProcNatives = interpreter.getIOProcessors(); + for (String key : ioProcNatives.keySet()) { + ioProcs.put(key, ioProcNatives.get(key).getDataModelVariables()); } newDM.scope .put("_ioprocessors", newDM.scope, new ECMAData(ioProcs)); @@ -112,11 +113,9 @@ public class ECMAScriptDataModel extends DataModel { // invokers { Data invokers = new Data(); - StringVector keys = interpreter.getInvokerKeys(); - for (int i = 0; i < keys.size(); i++) { - invokers.put(keys.get(i), interpreter - .getInvokers().get(keys.get(i)) - .getDataModelVariables()); + Map<String, NativeInvoker> invokersNatives = interpreter.getInvokers(); + for (String key : invokersNatives.keySet()) { + invokers.put(key, invokersNatives.get(key).getDataModelVariables()); } newDM.scope .put("_ioprocessors", newDM.scope, new ECMAData(invokers)); diff --git a/embedding/java/src/org/uscxml/tests/execContent/TestCustomExecContent.java b/embedding/java/src/org/uscxml/tests/execContent/TestCustomExecContent.java index 7a97ab4..805e6f7 100644 --- a/embedding/java/src/org/uscxml/tests/execContent/TestCustomExecContent.java +++ b/embedding/java/src/org/uscxml/tests/execContent/TestCustomExecContent.java @@ -42,7 +42,9 @@ public class TestCustomExecContent extends ExecutableContent { @Override public ExecutableContent create(Interpreter interpreter) { - return new TestCustomExecContent(); + TestCustomExecContent execContent = new TestCustomExecContent(); + execContent.swigReleaseOwnership(); + return execContent; } /** diff --git a/embedding/java/src/org/uscxml/tests/invoker/TestCustomInvoker.java b/embedding/java/src/org/uscxml/tests/invoker/TestCustomInvoker.java index 25420ed..ecbff9b 100644 --- a/embedding/java/src/org/uscxml/tests/invoker/TestCustomInvoker.java +++ b/embedding/java/src/org/uscxml/tests/invoker/TestCustomInvoker.java @@ -47,7 +47,9 @@ public class TestCustomInvoker extends Invoker { @Override public Invoker create(Interpreter interpreter) { - return new TestCustomInvoker(); + TestCustomInvoker invoker = new TestCustomInvoker(); + invoker.swigReleaseOwnership(); + return invoker; } /** @@ -73,6 +75,7 @@ public class TestCustomInvoker extends Invoker { " </state>" + " <state id=\"s12\">" + " <onentry>" + + " <log label=\"label\" expr=\"foo\" />" + " <send target=\"#_javainvoker2\" event=\"foo\" />" + " </onentry>" + " <transition event=\"received2\" target=\"done\" />" + diff --git a/embedding/java/src/org/uscxml/tests/ioprocessor/TestCustomIOProc.java b/embedding/java/src/org/uscxml/tests/ioprocessor/TestCustomIOProc.java index 277c505..8a72abe 100644 --- a/embedding/java/src/org/uscxml/tests/ioprocessor/TestCustomIOProc.java +++ b/embedding/java/src/org/uscxml/tests/ioprocessor/TestCustomIOProc.java @@ -89,6 +89,7 @@ public class TestCustomIOProc extends IOProcessor { public IOProcessor create(Interpreter interpreter) { TestCustomIOProc ioProc = new TestCustomIOProc(); ioProc.interpreter = interpreter; + ioProc.swigReleaseOwnership(); return ioProc; } @@ -102,7 +103,7 @@ public class TestCustomIOProc extends IOProcessor { TestCustomIOProc ioproc = new TestCustomIOProc(); // just register prototype at global factory Factory.getInstance().registerIOProcessor(ioproc); - + String xml = "<scxml>" + " <state id=\"s1\">" + |