include yslt.yml2 tstylesheet { include ./textutils.ysl2 include ./types_c.ysl2 include ./types_java.ysl2 template "/namespace[@name='pEp']" apply "interface", 0; template "interface" document("org_pEp_jniadapter_{@name}.cc", "text") || #include #include #include "org_pEp_jniadapter_«@name».h" #include "throw_pEp_exception.hh" #include "jniutils.hh" using namespace pEp::JNIAdapter; extern "C" { `` apply "method", 0 } // extern "C" || template "method" { const "mangled" call "mangle"; const "rettype", "name(parm[creates|returns]/*[2])"; const "retname", "name(parm[creates|returns]/*[3])"; const "jtype" call "toJavaDeclare" with "type", "$rettype"; || JNIEXPORT jobject JNICALL «$mangled»( JNIEnv *env, 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`); if ((status > PEP_STATUS_OK && status < PEP_UNENCRYPTED) |`> |` status >= PEP_TRUSTWORD_NOT_FOUND) { throw_pEp_Exception(env, status); return NULL; } || choose { when "count(parm[returns|creates]) > 1" { apply "parm[returns|creates]", mode=return; apply "parm[1]", mode=return { with "name" > result with "jtype" > _«@name»_Result with "sig" > ()V with "jnitype" > } apply "parm[returns|creates]", mode=setresult with "jtype" > _«@name»_Result } when "count(parm[returns|creates]) = 1" choose { when "$rettype = 'Color'" apply "parm[returns|creates]", mode=return { with "name", "'result'"; with "jtype", "$jtype"; with "jnitype", "'jint'"; with "retname", "$retname"; with "sig", "'(I)V'"; } when "$rettype = 'message'" apply "parm[returns|creates]", mode=return { with "name", "'result'"; with "jtype", "$jtype"; with "jnitype", "'jlong'"; with "retname", "$retname"; with "sig", "'(J)V'"; } otherwise error | # not implemented: return type "«$rettype»" } } || return result_; } || } template "parm", mode=setresult { param "jtype"; const "sig" call "toSig" with "type", "name(*[2])"; const "name", "name(*[3])"; || jfieldID «$name»_field = getFieldID(env, "«$jtype»", "«$name»", "«$sig»"); env->SetObjectField(result_, «$name»_field, «$name»_); || } template "parm", mode=return { param "type", "name(*[2])"; param "jtype" call "toJavaDeclare" with "type", "$type"; param "name", "name(*[3])"; param "jnitype" choose { when "$type = 'message'" > jlong when "$type = 'Color'" > jint when "$type = 'stringlist'" > jbyteArray otherwise > } param "retname", "$name"; param "sig" choose { when "$type = 'message'" > (J)V when "$type = 'Color'" > (I)V when "$type = 'stringlist'" > (Ljava.lang.Object;)V otherwise > ()V } choose { when "$jnitype = 'jbyteArray'" || jobject «$name»_ = from_stringlist(env, _«$retname»); || otherwise { || jclass clazz_«$name»_ = findClass(env, "org/pEp/jniadapter/«$jtype»"); jmethodID constructor_«$name»_ = env->GetMethodID(clazz_«$name»_, "", "«$sig»"); assert(constructor_«$name»_); || indent(0); > jobject «$name»_ = env->NewObject(clazz_«$name»_, constructor_«$name»_ if "$jnitype != ''" > , («$jnitype») _«$retname» > );\n\n } } } 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"; choose { when "$convert" > «concat('Java_org_pEp_jniadapter_', ../@name, '__1', str:replace(@name, '_', '_1'))» otherwise > «concat('Java_org_pEp_jniadapter_', ../@name, '_', str:replace(@name, '_', '_1'))» } } template "parm", mode=sig { const "name", "name(*[3])"; > ,\n jobject «$name» } }