Browse Source

calling

JNI-44
Volker Birk 10 years ago
parent
commit
936c5a0f69
  1. 56
      src/gen_cpp_Engine.ysl2
  2. 20
      src/gen_java_Engine.ysl2
  3. 4
      src/jniutils.cc

56
src/gen_cpp_Engine.ysl2

@ -8,17 +8,21 @@ tstylesheet {
template "interface" document("org_pEp_jniadapter_{@name}.cc", "text") template "interface" document("org_pEp_jniadapter_{@name}.cc", "text")
|| ||
#include <assert.h> #include <assert.h>
#include <pEp/message_api.h>
#include "org_pEp_jniadapter_«@name».h" #include "org_pEp_jniadapter_«@name».h"
#include "jniutils.hh" #include "jniutils.hh"
using namespace pEp::JNIAdapter; using namespace pEp::JNIAdapter;
extern "C" {
`` apply "method", 0 `` apply "method", 0
} // extern "C"
|| ||
template "method" { template "method" {
const "mangled" call "mangle"; const "mangled" call "mangle";
const "jtype" call "CamelCase" with "text", "name(parm[creates|returns]/*[2])";
|| ||
JNIEXPORT jobject JNICALL «$mangled»( JNIEXPORT jobject JNICALL «$mangled»(
@ -26,13 +30,26 @@ tstylesheet {
jobject obj`apply "parm[in]", mode=sig` 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 { choose {
when "count(parm[returns|creates]) > 1" 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" { 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" { function "mangle" {
const "convert", "count(parm/stringlist|parm/string|parm/identity) > 0"; const "convert", "count(parm/stringlist|parm/string|parm/identity) > 0";

20
src/gen_java_Engine.ysl2

@ -140,9 +140,11 @@ tstylesheet {
const "type", "name(*[2])"; const "type", "name(*[2])";
const "name" call "lcase" with "text", "name(*[3])"; const "name" call "lcase" with "text", "name(*[3])";
if "$dir = 'in'" { if "$dir = 'in'" choose {
if "$type = 'string' or $type = 'stringlist'" | ¡$type _«$name» = AbstractEngine.toUTF8(«$name»); when "$type = 'string' or $type = 'stringlist'"
if "$type = 'identity'" | _Identity _«$name» = new _Identity(«$name»); | ¡$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])"; const "name" call "lcase" with "text", "name(*[3])";
if "$dir != 'in'" choose { if "$dir != 'in'" choose {
when "$type = 'string' or $type = 'stringlist'" | result.«$name» = AbstractEngine.toUTF16(_result.«$name»); when "$type = 'string' or $type = 'stringlist'"
if "$type = 'identity'" | result.«$name» = Identity(«$name»); | result.«$name» = AbstractEngine.toUTF16(_result.«$name»);
otherwise | result.«$name» = _result.«$name»; when "$type = 'identity'"
| result.«$name» = Identity(«$name»);
otherwise
| result.«$name» = _result.«$name»;
} }
} }
@ -162,7 +167,8 @@ tstylesheet {
const "type", "name(*[2])"; const "type", "name(*[2])";
const "name" call "lcase" with "text", "name(*[3])"; 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()" > , ` > «$name»`if "position()!=last()" > , `
} }
} }

4
src/jniutils.cc

@ -328,9 +328,13 @@ namespace pEp {
pEp_identity *ident = new_identity(NULL, NULL, NULL, NULL); pEp_identity *ident = new_identity(NULL, NULL, NULL, NULL);
ident->address = _getStringField(env, classname, obj, "address"); ident->address = _getStringField(env, classname, obj, "address");
ident->address_size = strlen(ident->address);
ident->fpr = _getStringField(env, classname, obj, "fpr"); 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 = _getStringField(env, classname, obj, "user_id");
ident->user_id_size = strlen(ident->user_id);
ident->username = _getStringField(env, classname, obj, "username"); ident->username = _getStringField(env, classname, obj, "username");
ident->username_size = strlen(ident->username);
jfieldID comm_type_id = getFieldID(env, classname, "comm_type", "I"); jfieldID comm_type_id = getFieldID(env, classname, "comm_type", "I");
ident->comm_type = (PEP_comm_type) (int) env->GetIntField(obj, comm_type_id); ident->comm_type = (PEP_comm_type) (int) env->GetIntField(obj, comm_type_id);

Loading…
Cancel
Save