diff --git a/src/Makefile b/src/Makefile index a18a33b..e4f845d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -42,12 +42,18 @@ $(LIBRARY): org_pEp_jniadapter_AbstractEngine.o org_pEp_jniadapter_Engine.o org_ org/pEp/jniadapter/pEpException.java: pEp.yml2 gen_java_exceptions.ysl2 yml2proc -y gen_java_exceptions.ysl2 $< -o $@ -org/pEp/jniadapter/Engine.java org/pEp/jniadapter/Message.java : pEp.yml2 gen_java_Message.ysl2 types_java.ysl2 +org/pEp/jniadapter/Message.java: pEp.yml2 gen_java_Message.ysl2 types_java.ysl2 yml2proc -y gen_java_Message.ysl2 $< -org_pEp_jniadapter_Engine.cc org_pEp_jniadapter_Message.cc : pEp.yml2 gen_cpp_Message.ysl2 types_c.ysl2 +org_pEp_jniadapter_Message.cc: pEp.yml2 gen_cpp_Message.ysl2 types_c.ysl2 yml2proc -y gen_cpp_Message.ysl2 $< +org/pEp/jniadapter/Engine.java: pEp.yml2 gen_java_Engine.ysl2 types_java.ysl2 + yml2proc -y gen_java_Engine.ysl2 $< + +org_pEp_jniadapter_Engine.cc: pEp.yml2 gen_cpp_Engine.ysl2 types_c.ysl2 + yml2proc -y gen_cpp_Engine.ysl2 $< + throw_pEp_exception.cc throw_pEp_exception.hh: pEp.yml2 gen_throw_pEp_exception.ysl2 textutils.ysl2 yml2proc -y gen_throw_pEp_exception.ysl2 $< -o throw_pEp_exception.cc diff --git a/src/gen_cpp_Engine.ysl2 b/src/gen_cpp_Engine.ysl2 new file mode 100644 index 0000000..c757f14 --- /dev/null +++ b/src/gen_cpp_Engine.ysl2 @@ -0,0 +1,7 @@ +include yslt.yml2 + +tstylesheet { + include ./types_c.ysl2 + +} + diff --git a/src/gen_cpp_Message.ysl2 b/src/gen_cpp_Message.ysl2 index 26210e0..de42452 100644 --- a/src/gen_cpp_Message.ysl2 +++ b/src/gen_cpp_Message.ysl2 @@ -116,15 +116,5 @@ tstylesheet { || } - - function "jni_type" { - param "type"; - - choose { - when "../enum[@name=$type]" > jint - when "$type = 'string'" > jbyteArray - otherwise > jobject - } - } } diff --git a/src/gen_java_Engine.ysl2 b/src/gen_java_Engine.ysl2 new file mode 100644 index 0000000..db2757a --- /dev/null +++ b/src/gen_java_Engine.ysl2 @@ -0,0 +1,181 @@ +include yslt.yml2 + +tstylesheet { + include ./types_java.ysl2 + + template "/namespace[@name='pEp']" apply "interface", 0; + + template "interface" { + const "cname" call "toJava" with "type", "@name"; + document("org/pEp/jniadapter/{$cname}.java", "text") + || + package org.pEp.jniadapter; + + import java.util.Vector; + + final public class «$cname» extends AbstractEngine { + public «$cname»() throws pEpException { } + + `` apply "method" + } + || + } + + function "returnJava" { + const "returning", "count(parm/creates|parm/returns)"; + const "returntype" call "toJava" with "type", "name(parm[creates|returns]/*[2])"; + + choose { + when "$returning = 0" > void + when "$returning = 1" > «$returntype» + otherwise > «@name»_Return + } + } + + function "returnInter" { + const "returning", "count(parm/creates|parm/returns)"; + const "returntype" call "toIntermediate" with "type", "name(parm[creates|returns]/*[2])"; + + choose { + when "$returning = 0" > void + when "$returning = 1" > «$returntype» + otherwise > _«@name»_Return + } + } + + template "method" { + const "convert", "count(parm/stringlist|parm/stringpairlist|parm/string|parm/identity|parm/identitylist|parm/bloblist) > 0"; + const "singlereturn", "count(parm/creates|parm/returns) = 1"; + const "multireturn", "count(parm/creates|parm/returns) > 1"; + + if "$convert" { + if "$multireturn" + || + private class _«@name»_Return { + `` apply "parm[creates|returns]", 1, mode=intermediate with "public", 1; + } + + || + || + private native `call "returnInter"` _«@name»( + `` apply "parm[in]", 2, mode=intermediate + ) throws pEpException; + + || + } + + if "$multireturn" + || + public class «@name»_Return { + `` apply "parm[creates|returns]", 1, mode=java with "public", 1; + } + + || + || + public `if "not($convert)" > native ``call "returnJava"` «@name»( + `` apply "parm[in]", 2, mode=java + ) throws pEpException`if "not($convert)" > ;` + { + `` apply "parm", mode=convertIn; + `if "$singlereturn or $multireturn" call "returnInter", copy "' _result = '"`_«@name»(`apply "parm[in]", mode=call`); + `` if "$singlereturn" |> return _result; + `` if "$multireturn" apply ".", mode=multireturn with "convert", "$convert"; + } + + || + } + + template "method", mode=multireturn { + param "convert"; + + choose { + when "$convert" + || + + «@name»_Return result = new «@name»_Return(); + `` apply "parm[creates|returns]", 0, mode=convertOut; + + return result; + || + otherwise | return _result; + } + } + + template "parm", mode=java { + param "public", 0; + const "dir", "name(*[1])"; + const "type", "name(*[2])"; + const "name", "name(*[3])"; + + indent(0); + + if "$public" > public + > †$type «translate($name,'-','_')» + choose { + when "$public" > ; + otherwise if "position()!=last()" > , + } + > \n + } + + template "parm", mode=intermediate { + param "public", 0; + const "dir", "name(*[1])"; + const "type", "name(*[2])"; + const "name", "name(*[3])"; + + indent(0); + + if "$public" > public + > ¡$type «translate($name,'-','_')» + choose { + when "$public" > ; + otherwise if "position()!=last()" > , + } + > \n + } + + template "parm", mode=convertIn { + const "dir", "name(*[1])"; + const "type", "name(*[2])"; + const "name" call "lcase" with "text", "name(*[3])"; + + if "$dir = 'in'" choose { + when "$type = 'string'" | ¡$type _«$name» = AbstractEngine.toUTF8(«$name»); + when "$type = 'stringlist'" + || + Vector _«$name» = new Vector(); + for (String s : «$name») { + _«$name».add(AbstractEngine.toUTF8(s); + } + || + } + } + + template "parm", mode=convertOut { + const "dir", "name(*[1])"; + const "type", "name(*[2])"; + const "name" call "lcase" with "text", "name(*[3])"; + + if "$dir != 'in'" choose { + when "$type = 'string'" | †$type «$name» = AbstractEngine.toUTF16(_«$name»); + when "$type = 'stringlist'" + || + Vector result.«$name» = new Vector(); + for (byte[] a : _result._«$name») { + result.«$name».add(AbstractEngine.toUTF16(a); + } + || + otherwise | result.«$name» = _result.«$name»; + } + } + + template "parm", mode=call { + const "type", "name(*[2])"; + const "name" call "lcase" with "text", "name(*[3])"; + + if "$type = 'string' or $type = 'stringlist'" > _ + > «$name»`if "position()!=last()" > , ` + } +} + diff --git a/src/gen_java_Message.ysl2 b/src/gen_java_Message.ysl2 index 01c124a..93be17f 100644 --- a/src/gen_java_Message.ysl2 +++ b/src/gen_java_Message.ysl2 @@ -3,24 +3,7 @@ include yslt.yml2 tstylesheet { include ./types_java.ysl2 - template "/namespace[@name='pEp']" apply "struct|interface|enum", 0; - - template "interface" { - const "cname" call "toJava" with "type", "@name"; - document("org/pEp/jniadapter/{$cname}.java", "text") - || - package org.pEp.jniadapter; - - import java.util.ArrayList; - import java.util.Vector; - - final public class «$cname» extends AbstractEngine { - public «$cname»() throws pEpException { } - - `` apply "interface|method" - } - || - } + template "/namespace[@name='pEp']" apply "struct|enum", 0; template "struct" { const "cname" call "toJava" with "type", "@name"; @@ -28,7 +11,6 @@ tstylesheet { || package org.pEp.jniadapter; - import java.util.ArrayList; import java.util.Vector; import java.util.Date; import java.util.HashMap; @@ -92,21 +74,6 @@ tstylesheet { || } - template "method" - || - public native void «@name»( - `` apply "parm", 2 - ) throws pEpException;`if "position()!=last()" > \n` - || - - template "parm" { - const "dir", "name(*[1])"; - const "type", "name(*[2])"; - const "name", "name(*[3])"; - - | `call "toJava" with "type", "$type"` «translate($name,'-','_')»`if "position()!=last()" > ,` - } - template "*", mode=entry { const "ctype", "name(.)"; const "type" call "toJava" with "type", "name(.)"; diff --git a/src/pEp.yml2 b/src/pEp.yml2 index 2242534..c485127 100644 --- a/src/pEp.yml2 +++ b/src/pEp.yml2 @@ -72,8 +72,7 @@ namespace pEp { method encrypt_message( in message src, in stringlist extra, - creates message dst, - in EncFormat enc_format + creates message dst ); method decrypt_message( diff --git a/src/types_c.ysl2 b/src/types_c.ysl2 index 585f31f..7b0bcfe 100644 --- a/src/types_c.ysl2 +++ b/src/types_c.ysl2 @@ -18,5 +18,15 @@ function "toC" { } } +function "jni_type" { + param "type"; + + choose { + when "../enum[@name=$type]" > jint + when "$type = 'string'" > jbyteArray + otherwise > jobject + } +} + define operator "√([$@]?[a-zA-Z0-9_]+)" as call "toC" with "type", "%1"; diff --git a/src/types_java.ysl2 b/src/types_java.ysl2 index ae021d7..b4bcd52 100644 --- a/src/types_java.ysl2 +++ b/src/types_java.ysl2 @@ -4,14 +4,14 @@ function "toJava" { param "type"; choose { - when "$type='stringlist'" > ArrayList + when "$type='stringlist'" > Vector when "$type='string'" > String when "$type='message'" > Message when "$type='identity'" > Identity - when "$type='identitylist'" > ArrayList + when "$type='identitylist'" > Vector when "$type='timestamp'" > Date when "$type='EncFormat'" > Message.EncFormat - when "$type='bloblist'" > ArrayList + when "$type='bloblist'" > Vector when "$type='stringpairlist'" > Vector> when "$type='message'" > Message @@ -23,12 +23,12 @@ function "toIntermediate" { param "type"; choose { - when "$type='stringlist'" > ArrayList + when "$type='stringlist'" > Vector when "$type='stringpairlist'" > Vector> when "$type='string'" > byte[] when "$type='identity'" > _Identity - when "$type='identitylist'" > ArrayList<_Identity> - when "$type='bloblist'" > ArrayList<_Blob> + when "$type='identitylist'" > Vector<_Identity> + when "$type='bloblist'" > Vector<_Blob> otherwise call "toJava" with "type", "$type"; }