summaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-08-13 10:07:32 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-08-13 10:07:32 (GMT)
commit459f406eb2a36d393bd3a2b6aa3d63d86eb99c07 (patch)
tree35593bb978fee75bb7547f3d2c84a9039413fe1f /contrib
parentbeac3e74f703148085947d75da6fdaa9fd7472b4 (diff)
downloaduscxml-459f406eb2a36d393bd3a2b6aa3d63d86eb99c07.zip
uscxml-459f406eb2a36d393bd3a2b6aa3d63d86eb99c07.tar.gz
uscxml-459f406eb2a36d393bd3a2b6aa3d63d86eb99c07.tar.bz2
Started Java datamodel and fixed memory leaks
Diffstat (limited to 'contrib')
-rw-r--r--contrib/dom/scripts/CodeGeneratorArabicaJSC.pm28
-rw-r--r--contrib/java/.classpath7
-rw-r--r--contrib/java/.project24
-rw-r--r--contrib/java/src/org/uscxml/tests/TestDataModel.java108
-rw-r--r--contrib/java/src/org/uscxml/tests/TestInvoker.java65
5 files changed, 226 insertions, 6 deletions
diff --git a/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm b/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm
index cc8debb..87ca6a9 100644
--- a/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm
+++ b/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm
@@ -209,10 +209,11 @@ END
}
if ($extensions->{'CustomIndexedGetter'}) {
- push(@headerContent, "\n static JSValueRef indexedPropertyCustomGetter(uint32_t, const JSC::AccessorInfo&);");
+ push(@headerContent, "\n static bool hasPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);");
+ push(@headerContent, "\n static JSValueRef getPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);");
}
if ($extensions->{'CustomIndexedSetter'}) {
- push(@headerContent, "\n static JSValueRef indexedPropertyCustomSetter(uint32_t, JSC::Local<JSC::Value>, const JSC::AccessorInfo&);");
+ push(@headerContent, "\n static JSValueRef setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);");
}
push(@headerContent, "\n");
@@ -229,6 +230,20 @@ END
classDef.staticValues = staticValues;
classDef.staticFunctions = staticFunctions;
classDef.finalize = jsDestructor;
+END
+ if ($extensions->{'CustomIndexedGetter'}) {
+ push(@headerContent, " classDef.hasProperty = hasPropertyCustomCallback;\n");
+ push(@headerContent, " classDef.getProperty = getPropertyCustomCallback;\n");
+ }
+ if ($extensions->{'CustomIndexedSetter'}) {
+ push(@headerContent, " classDef.setProperty = setPropertyCustomCallback;\n");
+ }
+ if (@{$interface->parents}) {
+ my $parent = @{$interface->parents}[0];
+ push(@headerContent, " classDef.parentClass = JSC${parent}::getTmpl();\n");
+ }
+
+ push(@headerContent, <<END);
Tmpl = JSClassCreate(&classDef);
JSClassRetain(Tmpl);
@@ -449,12 +464,12 @@ END
my $parameterIndex = 0;
my @argList;
foreach my $parameter (@{$function->parameters}) {
- my $value = "arguments[$parameterIndex]";
my $type = $parameter->type;
AddToImplIncludes("JSC".$type.".h") if (IsWrapperType($type));
my ($handle, $deref) = IdlToArgHandle($parameter->type, "local".ucfirst($parameter->name), "arguments[${parameterIndex}]");
push(@implContent, "\n ${handle}");
+# push(@implContent, "\n if (exception)\n return JSValueMakeUndefined(ctx);");
push(@argList, $deref);
$parameterIndex++;
@@ -666,8 +681,9 @@ sub IdlToArgHandle
"JSStringRef stringRef${localName} = JSValueToStringCopy(ctx, ${paramName}, exception);\n" .
"\t\tsize_t ${localName}MaxSize = JSStringGetMaximumUTF8CStringSize(stringRef${localName});\n" .
"\t\tchar* ${localName}Buffer = new char[${localName}MaxSize];\n" .
- "\t\tJSStringGetUTF8CString(stringRef${localName}, ${localName}Buffer, sizeof(${localName}Buffer));\n" .
- "\t\tstd::string ${localName}(${localName}Buffer, ${localName}MaxSize);\n" .
+ "\t\tJSStringGetUTF8CString(stringRef${localName}, ${localName}Buffer, ${localName}MaxSize);\n" .
+ "\t\tstd::string ${localName}(${localName}Buffer);\n" .
+ "\t\tJSStringRelease(stringRef${localName});\n" .
"\t\tfree(${localName}Buffer);\n",
"${localName}") ;
}
@@ -677,7 +693,7 @@ sub IdlToArgHandle
if (IsWrapperType($type)) {
my $wrapperType = IdlToWrapperType($type);
- return ("${wrapperType}* ${localName} = ((struct JSC${type}::JSC${type}Private*)JSObjectGetPrivate(thisObj))->nativeObj;", "*${localName}");
+ return ("${wrapperType}* ${localName} = ((struct JSC${type}::JSC${type}Private*)JSObjectGetPrivate(JSValueToObject(ctx, ${paramName}, exception)))->nativeObj;", "*${localName}");
}
print $type."\n";
diff --git a/contrib/java/.classpath b/contrib/java/.classpath
new file mode 100644
index 0000000..053c69a
--- /dev/null
+++ b/contrib/java/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="uscxml"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/contrib/java/.project b/contrib/java/.project
new file mode 100644
index 0000000..4c68397
--- /dev/null
+++ b/contrib/java/.project
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>uscxml</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+ <linkedResources>
+ <link>
+ <name>uscxml</name>
+ <type>2</type>
+ <location>/Users/sradomski/Documents/TK/Code/uscxml/build/cli/src/bindings/swig/java</location>
+ </link>
+ </linkedResources>
+</projectDescription>
diff --git a/contrib/java/src/org/uscxml/tests/TestDataModel.java b/contrib/java/src/org/uscxml/tests/TestDataModel.java
new file mode 100644
index 0000000..c9d8ae0
--- /dev/null
+++ b/contrib/java/src/org/uscxml/tests/TestDataModel.java
@@ -0,0 +1,108 @@
+package org.uscxml.tests;
+
+import org.uscxml.Data;
+import org.uscxml.Event;
+import org.uscxml.Factory;
+import org.uscxml.Interpreter;
+import org.uscxml.JavaDataModel;
+import org.uscxml.SWIGTYPE_p_Arabica__DOM__DocumentT_std__string_t;
+import org.uscxml.SWIGTYPE_p_Arabica__DOM__ElementT_std__string_t;
+import org.uscxml.SWIGTYPE_p_boost__shared_ptrT_uscxml__DataModelImpl_t;
+import org.uscxml.SWIGTYPE_p_uscxml__InterpreterImpl;
+import org.uscxml.StringSet;
+
+
+public class TestDataModel extends JavaDataModel {
+
+ @Override
+ public JavaDataModel create(Interpreter interpreter) {
+ return new JavaDataModel();
+ }
+
+ @Override
+ public StringSet getNames() {
+ StringSet ss = new StringSet();
+ ss.insert("java");
+ return ss;
+ }
+
+ @Override
+ public boolean validate(String location, String schema) {
+ return true;
+ }
+
+ @Override
+ public void setEvent(Event event) {
+ /* make sure the fields of event are available as _event to conform
+ * with the SCXML draft
+ */
+ }
+
+ @Override
+ public Data getStringAsData(String content) {
+ Data data = new Data();
+ return data;
+ }
+
+ @Override
+ public long getLength(String expr) {
+ return 0;
+ }
+
+ @Override
+ public void setForeach(String item, String array, String index, long iteration) {
+ }
+
+ @Override
+ public void eval(SWIGTYPE_p_Arabica__DOM__ElementT_std__string_t scriptElem, String expr) {
+ }
+
+ @Override
+ public String evalAsString(String expr) {
+ return "";
+ }
+
+ @Override
+ public boolean evalAsBool(String expr) {
+ return true;
+ }
+
+ @Override
+ public boolean isDeclared(String expr) {
+ return true;
+ }
+
+ @Override
+ public void assign(SWIGTYPE_p_Arabica__DOM__ElementT_std__string_t assignElem, SWIGTYPE_p_Arabica__DOM__DocumentT_std__string_t doc, String content) {
+ }
+
+ @Override
+ public void assign(String location, Data data) {
+ super.assign(location, data);
+ }
+
+ @Override
+ public void init(SWIGTYPE_p_Arabica__DOM__ElementT_std__string_t dataElem, SWIGTYPE_p_Arabica__DOM__DocumentT_std__string_t doc, String content) {
+ super.init(dataElem, doc, content);
+ }
+
+ @Override
+ public void init(String location, Data data) {
+ super.init(location, data);
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64_d.jnilib");
+
+ TestDataModel datamodel = new TestDataModel();
+ Factory.getInstance().registerDataModel(datamodel);
+
+ Interpreter interpreter = Interpreter.fromURI("/Users/sradomski/Documents/TK/Code/uscxml/test/samples/uscxml/test-java-datamodel.scxml");
+ while(true)
+ interpreter.interpret();
+ }
+
+}
diff --git a/contrib/java/src/org/uscxml/tests/TestInvoker.java b/contrib/java/src/org/uscxml/tests/TestInvoker.java
new file mode 100644
index 0000000..b41bd43
--- /dev/null
+++ b/contrib/java/src/org/uscxml/tests/TestInvoker.java
@@ -0,0 +1,65 @@
+package org.uscxml.tests;
+
+import org.uscxml.Data;
+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 Data getDataModelVariables() {
+ Data data = new Data();
+ data.getArray().add(new Data("foo", Data.Type.VERBATIM));
+ return data;
+ }
+
+ @Override
+ public void send(SendRequest req) {
+ System.out.println("send");
+ }
+
+ @Override
+ public void invoke(InvokeRequest req) {
+ System.out.println("invoke");
+
+ System.out.println(Data.toJSON(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();
+ }
+
+}