From 47d87ed4e6ef2820459f0927da6ef0b82613eb70 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Sun, 14 Jun 2015 18:57:53 +0200 Subject: [PATCH] ... --- src/gen_cpp_Message.ysl2 | 59 +++++++++++++++++++++++++++++++++++++-- src/gen_java_Message.ysl2 | 15 +++++++++- src/types_c.ysl2 | 7 +++-- 3 files changed, 74 insertions(+), 7 deletions(-) diff --git a/src/gen_cpp_Message.ysl2 b/src/gen_cpp_Message.ysl2 index f111ec8..ddf47db 100644 --- a/src/gen_cpp_Message.ysl2 +++ b/src/gen_cpp_Message.ysl2 @@ -7,17 +7,53 @@ tstylesheet { template "struct" { const "jname" call "CamelCase" with "text", "@name"; + document("org_pEp_jniadapter_{$jname}.cc", "text") || + #include + #include + #include + #include + + #include "jniutils.hh" #include "org_pEp_jniadapter_«$jname».h" - `` apply "*[name(.)!='enum']", mode=entry with "class" call "CamelCase" with "text", "@name"; + using namespace pEp::JNIAdapter; + + JNIEXPORT jlong JNICALL + Java_org_pEp_jniadapter_«$jname»_init(JNIEnv *env, jobject obj) { + ::«@name» * _obj = ::new_«@name»(PEP_dir_incoming); + // BUG: test for out of memory missing + return (jlong) (int64_t) (intptr_t) _obj; + } + + JNIEXPORT void JNICALL + Java_org_pEp_jniadapter_«$jname»_release(JNIEnv *env, jobject obj, jlong value) { + ::«@name» *_obj = (::«@name» *) (intptr_t) (int64_t) value; + ::free_«@name»(_obj); + } + + static ::message *ptr(JNIEnv *env, jobject me) { + jfieldID handle; + + try { + handle = getFieldID(env, "org/pEp/jniadapter/«$jname»", "handle", "J"); + } + catch (std::exception& ex) { + assert(0); + return NULL; + } + + return (::«@name» *) (intptr_t) (int64_t) env->GetLongField(me, handle); } + + `` apply "*[name(.)!='enum']", 0, mode=entry with "class" call "CamelCase" with "text", "@name"; || } template "interface" { const "jname" call "CamelCase" with "text", "@name"; + document("org_pEp_jniadapter_{$jname}.cc", "text") || #include "org_pEp_jniadapter_«$jname».h" @@ -27,11 +63,28 @@ tstylesheet { template "*", mode=entry { param "class"; + const "_class" call "lcase" with "text", "$class"; const "ctype" call "toC" with "type", "name(.)"; + const "jname" call "CamelCase" with "text", "name(*[1])"; + const "cname" call "lcase" with "text", "name(*[1])"; + || - JNIEXPORT jobject JNICALL Java_org_pEp_jniadapter_«$class»_getDir(JNIEnv *env, jobject obj) { - + JNIEXPORT jobject JNICALL + Java_org_pEp_jniadapter_«$class»_get«$jname»(JNIEnv *env, jobject obj) { + «$_class» *_obj = ptr(env, obj); + jobject result = NULL; + + _obj->«$cname»; + return result; + } + + JNIEXPORT void JNICALL + Java_org_pEp_jniadapter_Message_set«$jname»(JNIEnv *env, jobject obj, jobject value) { + «$_class» *_obj = ptr(env, obj); + «$ctype» *_value; + _obj->«$cname»; } + || } } diff --git a/src/gen_java_Message.ysl2 b/src/gen_java_Message.ysl2 index 7851e5f..44db636 100644 --- a/src/gen_java_Message.ysl2 +++ b/src/gen_java_Message.ysl2 @@ -33,7 +33,20 @@ tstylesheet { import java.util.Date; import java.util.HashMap; - public class «$cname» { + public class «$cname» implements AutoCloseable { + private final long handle; + + native long init(); + native void release(long handle); + + public «$cname»() { + handle = init(); + } + + public final void close() { + release(handle); + } + `` apply "enum", mode=inner `` apply "*[name(.)!='enum']", mode=entry } diff --git a/src/types_c.ysl2 b/src/types_c.ysl2 index 08f9769..8e49f45 100644 --- a/src/types_c.ysl2 +++ b/src/types_c.ysl2 @@ -5,13 +5,14 @@ function "toC" { choose { when "$type='stringlist'" > stringlist_t - when "$type='string'" > char * + when "$type='string'" > char when "$type='identity'" > pEp_identity - when "$type='identitylist'" > identity_list_t + when "$type='identitylist'" > identity_list when "$type='timestamp'" > timestamp when "$type='EncFormat'" > PEP_enc_format when "$type='bloblist'" > bloblist_t - when "$type='stringpairlist'" > stringpairlist_t + when "$type='stringpairlist'" > stringpair_list_t + when "$type='direction'" > PEP_direction otherwise value "$type"; }