Browse Source

Enums are not anymore only 'Color'

JNI-44
Edouard Tisserant 9 years ago
parent
commit
ef28f29f0b
  1. 62
      src/gen_cpp_Engine.ysl2
  2. 3
      src/pEp.yml2

62
src/gen_cpp_Engine.ysl2

@ -39,10 +39,20 @@ tstylesheet {
{ {
PEP_SESSION session = (PEP_SESSION) callLongMethod(env, obj, "getHandle"); 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`); apply "parm[in]", mode=in;
choose {
when "count(parm[returns|creates]) > 1" {
apply "parm[creates|returns]", mode=out
}
when "count(parm[returns|creates]) = 1" {
apply "parm[creates|returns]", mode=out with "name", "'result'";
}
}
||
PEP_STATUS status = ::«@name»(session`apply "parm", mode=call`);
if ((status > PEP_STATUS_OK && status < PEP_UNENCRYPTED) |`> |` if ((status > PEP_STATUS_OK && status < PEP_UNENCRYPTED) |`> |`
status < PEP_STATUS_OK |`> |` status < PEP_STATUS_OK |`> |`
status >= PEP_TRUSTWORD_NOT_FOUND) { status >= PEP_TRUSTWORD_NOT_FOUND) {
@ -68,11 +78,10 @@ tstylesheet {
} }
when "count(parm[returns|creates]) = 1" choose { when "count(parm[returns|creates]) = 1" choose {
when "$rettype = 'Color'" apply "parm[returns|creates]", mode=return { when "ancestor::namespace/child::enum[@name=$rettype]" apply "parm[returns|creates]", mode=return {
with "name", "'result'"; with "name", "'result'";
with "jtype", "$jtype"; with "jtype", "$jtype";
with "jnitype", "'jint'"; with "jnitype", "'jint'";
with "retname", "$retname";
with "sig", "'(I)V'"; with "sig", "'(I)V'";
} }
@ -80,13 +89,11 @@ tstylesheet {
with "name", "'result'"; with "name", "'result'";
with "jtype", "$jtype"; with "jtype", "$jtype";
with "jnitype", "'jlong'"; with "jnitype", "'jlong'";
with "retname", "$retname";
with "sig", "'(J)V'"; with "sig", "'(J)V'";
} }
when "$rettype = 'stringlist'" apply "parm[returns|creates]", mode=return{ when "$rettype = 'stringlist'" apply "parm[returns|creates]", mode=return{
with "name", "'result'"; with "name", "'result'";
with "retname", "$retname";
} }
otherwise error | # not implemented: return type "«$rettype»" otherwise error | # not implemented: return type "«$rettype»"
@ -126,14 +133,14 @@ tstylesheet {
param "name", "name(*[3])"; param "name", "name(*[3])";
param "jnitype" choose { param "jnitype" choose {
when "$type = 'message'" > jlong when "$type = 'message'" > jlong
when "$type = 'Color'" > jint when "ancestor::namespace/child::enum[@name=$type]" > jint
when "$type = 'stringlist'" > jbyteArray when "$type = 'stringlist'" > jbyteArray
otherwise > otherwise >
} }
param "retname", "$name"; param "retname", "$name";
param "sig" choose { param "sig" choose {
when "$type = 'message'" > (J)V when "$type = 'message'" > (J)V
when "$type = 'Color'" > (I)V when "ancestor::namespace/child::enum[@name=$type]" > (I)V
when "$type = 'stringlist'" > (Ljava.lang.Object;)V when "$type = 'stringlist'" > (Ljava.lang.Object;)V
otherwise > ()V otherwise > ()V
} }
@ -147,19 +154,20 @@ tstylesheet {
|| ||
when "$jtype = 'Color'" when "ancestor::namespace/child::enum[@name=$jtype]" {
const "ljtype" call "lcase" with "text","$jtype";
|| ||
jobject «$name»_ = NULL; jobject «$name»_ = NULL;
{ {
jclass clazz_color = findClass(env, "org/pEp/jniadapter/Color"); jclass clazz_«$ljtype» = findClass(env, "org/pEp/jniadapter/«$jtype»");
assert(clazz_color); assert(clazz_«$ljtype»);
jmethodID method_values = env->GetStaticMethodID(clazz_color, "values", jmethodID method_values = env->GetStaticMethodID(clazz_«$ljtype», "values",
"()[Lorg/pEp/jniadapter/Color;"); "()[Lorg/pEp/jniadapter/«$jtype»;");
assert(method_values); assert(method_values);
jfieldID field_value = env->GetFieldID(clazz_color, "value", "I"); jfieldID field_value = env->GetFieldID(clazz_«$ljtype», "value", "I");
assert(field_value); assert(field_value);
jobjectArray values = (jobjectArray) env->CallStaticObjectMethod(clazz_color, jobjectArray values = (jobjectArray) env->CallStaticObjectMethod(clazz_«$ljtype»,
method_values); method_values);
assert(values); assert(values);
@ -168,7 +176,7 @@ tstylesheet {
jobject element = env->GetObjectArrayElement(values, i); jobject element = env->GetObjectArrayElement(values, i);
assert(element); assert(element);
jint value = env->GetIntField(element, field_value); jint value = env->GetIntField(element, field_value);
if (value == (jint) _color) { if (value == (jint) _«$name») {
«$name»_ = element; «$name»_ = element;
break; break;
} }
@ -176,6 +184,7 @@ tstylesheet {
} }
|| ||
}
otherwise { otherwise {
| jobject «$name»_ = NULL; | jobject «$name»_ = NULL;
@ -218,8 +227,8 @@ tstylesheet {
} }
template "parm", mode=out { template "parm", mode=out {
param "name", "name(*[3])";
const "type", "name(*[2])"; const "type", "name(*[2])";
const "name", "name(*[3])";
choose { choose {
when "ancestor::namespace/child::enum[@name=$type]" when "ancestor::namespace/child::enum[@name=$type]"
@ -234,9 +243,24 @@ tstylesheet {
const "name", "name(*[3])"; const "name", "name(*[3])";
> , > ,
if "$dir = 'creates' or $dir = 'returns'" > &
choose {
when "$dir = 'Cconst'"
value "*[3]";
when "$dir = 'creates' or $dir = 'returns'" {
> &
choose {
when "count(../parm[returns|creates]) = 1"
> _result
otherwise
> _«$name»
}
}
otherwise {
> _«$name» > _«$name»
} }
}
}
function "mangle" { function "mangle" {
const "convert", "count(parm/stringlist|parm/string|parm/identity) > 0"; const "convert", "count(parm/stringlist|parm/string|parm/identity) > 0";

3
src/pEp.yml2

@ -84,7 +84,8 @@ namespace pEp {
method encrypt_message( method encrypt_message(
in message src, in message src,
in stringlist extra, in stringlist extra,
creates message dst creates message dst,
Cconst PEP_enc_format encformat "PEP_enc_PEP"
); );
method decrypt_message( method decrypt_message(

Loading…
Cancel
Save