diff --git a/src/gen_cpp_Engine.ysl2 b/src/gen_cpp_Engine.ysl2 index 4222d19..0322d46 100644 --- a/src/gen_cpp_Engine.ysl2 +++ b/src/gen_cpp_Engine.ysl2 @@ -192,6 +192,7 @@ tstylesheet { } template "parm", mode=in { + const "dir", "name(*[1])"; const "type", "name(*[2])"; const "name", "name(*[3])"; @@ -202,8 +203,10 @@ tstylesheet { | √$type _«$name» = to_«$type»(env, «$name»); when "$type='bool'" | bool _«$name» = (bool) «$name»; - when "$type='int'" + when "$type='int' and $dir='in'" | int _«$name» = (int) «$name»; + when "$type='int' and $dir='inout'" + | √$type _«$name» = to_Integer(env, «$name»); otherwise | √$type *_«$name» = to_«$type»(env, «$name»); } @@ -237,8 +240,10 @@ tstylesheet { value "*[3]"; when "($dir = 'creates' or $dir = 'returns') and $type='sstring'" > &_«$name», &_«$name»_size - when "$dir = 'creates' or $dir = 'returns'" + when "$dir = 'creates' or $dir = 'returns'" > &_«$name» + when "$dir = 'inout' and $type='int'" + > (unsigned int *) &_«$name» otherwise > _«$name» } @@ -257,7 +262,7 @@ tstylesheet { template "parm", mode=sig { const "name", "name(*[3])"; - > ,\n `call "jni_type" with "type", "name(*[2])"` «$name» + > ,\n `call "jni_type" with "type", "name(*[2])", with "dir", "name(*[1])"` «$name» } } diff --git a/src/gen_java_Engine.ysl2 b/src/gen_java_Engine.ysl2 index 328c03a..c702115 100644 --- a/src/gen_java_Engine.ysl2 +++ b/src/gen_java_Engine.ysl2 @@ -242,7 +242,8 @@ tstylesheet { indent(0); if "$public" > public - > †$type «translate($name,'-','_')» + call "toJava" with "type", "$type"; + > «translate($name,'-','_')» choose { when "$public" > ; otherwise if "position()!=last()" > , @@ -259,7 +260,8 @@ tstylesheet { indent(0); if "$public" > public - > ¡$type «translate($name,'-','_')» + call "toIntermediate" with "type", "$type", with "dir", "$dir"; + > «translate($name,'-','_')» choose { when "$public" > ; otherwise if "position()!=last()" > , diff --git a/src/jniutils.cc b/src/jniutils.cc index 4625c6b..000465b 100644 --- a/src/jniutils.cc +++ b/src/jniutils.cc @@ -186,6 +186,26 @@ namespace pEp { return env->ThrowNew(ex, ex_name); } + jobject from_Integer(JNIEnv *env, int val) + { + assert(env); + jclass clazz = findClass(env, "java/lang/Integer"); + jmethodID constructor = env->GetMethodID(clazz, "", "(I)V"); + assert(constructor); + jobject obj = env->NewObject(clazz, constructor, val); + assert(obj); + + env->DeleteLocalRef(clazz); + return obj; + } + + int to_Integer(JNIEnv *env, jobject obj) + { + assert(env && obj); + int _val = callIntMethod(env, obj, "intValue"); + return _val; + } + jbyteArray from_string(JNIEnv *env, const char *str) { if (str && str[0]) { diff --git a/src/jniutils.hh b/src/jniutils.hh index 75a7db5..55e613c 100644 --- a/src/jniutils.hh +++ b/src/jniutils.hh @@ -151,6 +151,9 @@ namespace pEp { jint outOfMemory(JNIEnv *env); + jobject from_Integer(JNIEnv *env, int val); + int to_Integer(JNIEnv *env, jobject obj); + jbyteArray from_string(JNIEnv *env, const char *str); char *to_string(JNIEnv *env, jbyteArray str); diff --git a/src/pEp.yml2 b/src/pEp.yml2 index ac6a8f9..ac6dad4 100644 --- a/src/pEp.yml2 +++ b/src/pEp.yml2 @@ -174,8 +174,7 @@ namespace pEp { creates message dst, creates stringlist keylist, returns Rating rating, - /* TODO replace with int, this is a OR of multipla DecryptFlags */ - returns DecryptFlags flags + inout int flags ); method re_evaluate_message_rating( diff --git a/src/types_c.ysl2 b/src/types_c.ysl2 index 6b16ed9..a313a18 100644 --- a/src/types_c.ysl2 +++ b/src/types_c.ysl2 @@ -22,12 +22,14 @@ function "toC" { function "jni_type" { param "type"; + param "dir"; choose { when "../enum[@name=$type]" > jint when "$type = 'string' or $type = 'sstring'" > jbyteArray when "$type='bool'" > jboolean - when "$type='int'" > jint + when "$type='int' and $dir!='inout'" > jint + when "$type='int' and $dir='inout'" > jobject otherwise > jobject } } diff --git a/src/types_java.ysl2 b/src/types_java.ysl2 index de0029d..a96cc89 100644 --- a/src/types_java.ysl2 +++ b/src/types_java.ysl2 @@ -35,6 +35,7 @@ function "toSig" { > L choose { when "$type='timestamp'" > java/util/Date + when "$type='int'" > java/lang/Integer when "$type='identity'" > org/pEp/jniadapter/_Identity when "$type='message'" > org/pEp/jniadapter/Message @@ -58,10 +59,12 @@ function "toSig" { function "toIntermediate" { param "type"; + param "dir"; choose { when "$type='bool'" > boolean - when "$type='int'" > int + when "$type='int' and $dir!='inout'" > int + when "$type='int' and $dir='inout'" > Integer when "$type='string' or $type='sstring'" > byte[] when "$type='bloblist'" > Vector<_Blob>