diff --git a/src/gen_cpp_Engine.ysl2 b/src/gen_cpp_Engine.ysl2 index 4ffe80b..614dd16 100644 --- a/src/gen_cpp_Engine.ysl2 +++ b/src/gen_cpp_Engine.ysl2 @@ -8,17 +8,21 @@ tstylesheet { template "interface" document("org_pEp_jniadapter_{@name}.cc", "text") || #include + #include #include "org_pEp_jniadapter_«@name».h" #include "jniutils.hh" using namespace pEp::JNIAdapter; + extern "C" { + `` apply "method", 0 + } // extern "C" + || template "method" { const "mangled" call "mangle"; - const "jtype" call "CamelCase" with "text", "name(parm[creates|returns]/*[2])"; || JNIEXPORT jobject JNICALL «$mangled»( @@ -26,13 +30,26 @@ tstylesheet { jobject obj`apply "parm[in]", mode=sig` ) { + PEP_SESSION session = (PEP_SESSION) callLongMethod(env, obj, "getHandle"); + + `` apply "parm[in]", mode=in + `` apply "parm[creates|returns]", mode=out + + PEP_STATUS status = ::«@name»(session`apply "parm", mode=call``if "@name = 'encrypt_message'" > , PEP_enc_PEP`); + || choose { when "count(parm[returns|creates]) > 1" - |> jclass clazz = findClass(env, "org/pEp/jniadapter/_«@name»_Return"); + || + jclass clazz = findClass(env, "org/pEp/jniadapter/_«@name»_Return"); + || + when "count(parm[returns|creates]) = 1" { - |> jclass clazz = findClass(env, "org/pEp/jniadapter/«$jtype»"); + const "jtype" call "CamelCase" with "text", "name(parm[creates|returns]/*[2])"; + || + jclass clazz = findClass(env, "org/pEp/jniadapter/«$jtype»"); + || } } @@ -47,6 +64,39 @@ tstylesheet { || } + template "parm", mode=in { + const "type", "name(*[2])"; + const "name", "name(*[3])"; + + choose { + when "$type = 'message'" + | message *_«$name» = (message *) callLongMethod(env, «$name», "getHandle"); + otherwise + | √$type *_«$name» = to_«$type»(env, «$name»); + } + } + + template "parm", mode=out { + const "type", "name(*[2])"; + const "name", "name(*[3])"; + + choose { + when "$type = 'Color'" + | PEP_color _«$name»; + otherwise + | √$type *_«$name»; + } + } + + template "parm", mode=call { + const "dir", "name(*[1])"; + const "name", "name(*[3])"; + + > , + if "$dir = 'creates' or $dir = 'returns'" > & + > _«$name» + } + function "mangle" { const "convert", "count(parm/stringlist|parm/string|parm/identity) > 0"; diff --git a/src/gen_java_Engine.ysl2 b/src/gen_java_Engine.ysl2 index 02d1eff..80e6821 100644 --- a/src/gen_java_Engine.ysl2 +++ b/src/gen_java_Engine.ysl2 @@ -140,9 +140,11 @@ tstylesheet { const "type", "name(*[2])"; const "name" call "lcase" with "text", "name(*[3])"; - if "$dir = 'in'" { - if "$type = 'string' or $type = 'stringlist'" | ¡$type _«$name» = AbstractEngine.toUTF8(«$name»); - if "$type = 'identity'" | _Identity _«$name» = new _Identity(«$name»); + if "$dir = 'in'" choose { + when "$type = 'string' or $type = 'stringlist'" + | ¡$type _«$name» = AbstractEngine.toUTF8(«$name»); + when "$type = 'identity'" + | _Identity _«$name» = new _Identity(«$name»); } } @@ -152,9 +154,12 @@ tstylesheet { const "name" call "lcase" with "text", "name(*[3])"; if "$dir != 'in'" choose { - when "$type = 'string' or $type = 'stringlist'" | result.«$name» = AbstractEngine.toUTF16(_result.«$name»); - if "$type = 'identity'" | result.«$name» = Identity(«$name»); - otherwise | result.«$name» = _result.«$name»; + when "$type = 'string' or $type = 'stringlist'" + | result.«$name» = AbstractEngine.toUTF16(_result.«$name»); + when "$type = 'identity'" + | result.«$name» = Identity(«$name»); + otherwise + | result.«$name» = _result.«$name»; } } @@ -162,7 +167,8 @@ tstylesheet { const "type", "name(*[2])"; const "name" call "lcase" with "text", "name(*[3])"; - if "$type = 'string' or $type = 'stringlist'" > _ + if "$type = 'string' or $type = 'stringlist' or $type = 'identity'" + > _ > «$name»`if "position()!=last()" > , ` } } diff --git a/src/jniutils.cc b/src/jniutils.cc index 5e06379..49abb8b 100644 --- a/src/jniutils.cc +++ b/src/jniutils.cc @@ -328,9 +328,13 @@ namespace pEp { pEp_identity *ident = new_identity(NULL, NULL, NULL, NULL); ident->address = _getStringField(env, classname, obj, "address"); + ident->address_size = strlen(ident->address); ident->fpr = _getStringField(env, classname, obj, "fpr"); + ident->fpr_size = strlen(ident->fpr); ident->user_id = _getStringField(env, classname, obj, "user_id"); + ident->user_id_size = strlen(ident->user_id); ident->username = _getStringField(env, classname, obj, "username"); + ident->username_size = strlen(ident->username); jfieldID comm_type_id = getFieldID(env, classname, "comm_type", "I"); ident->comm_type = (PEP_comm_type) (int) env->GetIntField(obj, comm_type_id);