You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
197 lines
6.6 KiB
197 lines
6.6 KiB
include yslt.yml2
|
|
include yslt.yml2
|
|
|
|
tstylesheet {
|
|
include ./textutils.ysl2
|
|
include ./types_c.ysl2
|
|
|
|
template "/namespace[@name='pEp']" apply "struct", 0;
|
|
|
|
template "struct" {
|
|
const "jname" call "CamelCase" with "text", "@name";
|
|
|
|
document("foundation_pEp_jniadapter_{$jname}.cc", "text") {
|
|
||
|
|
#include <exception>
|
|
#include <new>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include <pEp/«@name».h>
|
|
#include <pEp/mime.h>
|
|
#include <pEp/pEpLog.hh>
|
|
|
|
#include "jniutils.hh"
|
|
#include "throw_pEp_exception.hh"
|
|
#include "foundation_pEp_jniadapter_«$jname».h"
|
|
|
|
using namespace std;
|
|
|
|
namespace pEp {
|
|
namespace JNIAdapter {
|
|
static ::«@name» *«@name»_ptr(JNIEnv *env, jobject me) {
|
|
jfieldID handle;
|
|
|
|
try {
|
|
handle = getFieldID(env, "foundation/pEp/jniadapter/«$jname»", "handle", "J");
|
|
}
|
|
catch (std::exception& ex) {
|
|
assert(0);
|
|
return NULL;
|
|
}
|
|
|
|
return (::«@name» *) (intptr_t) (int64_t) env->GetLongField(me, handle);
|
|
}
|
|
};
|
|
};
|
|
|
|
extern "C" {
|
|
|
|
using namespace pEp::JNIAdapter;
|
|
|
|
JNIEXPORT jlong JNICALL Java_foundation_pEp_jniadapter_«$jname»_init(JNIEnv *env, jobject obj)
|
|
{
|
|
pEpLog("called");
|
|
::«@name» * _obj = ::new_«@name»(PEP_dir_incoming);
|
|
if (!_obj) {
|
|
outOfMemory(env);
|
|
return (jlong) 0;
|
|
}
|
|
return (jlong) (int64_t) (intptr_t) _obj;
|
|
}
|
|
|
|
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_«$jname»_release(JNIEnv *env, jobject obj, jlong value)
|
|
{
|
|
pEpLog("called");
|
|
if (value) {
|
|
::«@name» *_obj = (::«@name» *) (intptr_t) (int64_t) value;
|
|
::free_«@name»(_obj);
|
|
}
|
|
}
|
|
|
|
JNIEXPORT jlong JNICALL Java_foundation_pEp_jniadapter_«$jname»__1«$jname»(JNIEnv *env, jobject msg, jbyteArray mime_text)
|
|
{
|
|
pEpLog("called");
|
|
char *_mime_text = to_string(env, mime_text);
|
|
size_t _size = (size_t) env->GetArrayLength(mime_text);
|
|
|
|
::«@name» *_msg = nullptr;
|
|
PEP_STATUS status = mime_decode_«@name»(_mime_text, _size, &_msg);
|
|
if (status)
|
|
throw_pEp_Exception(env, status);
|
|
return (jlong) (int64_t) (intptr_t) _msg;
|
|
}
|
|
|
|
JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_«$jname»__1encodeMIME(JNIEnv *env, jobject msg)
|
|
{
|
|
pEpLog("called");
|
|
«@name» *_obj = «@name»_ptr(env, msg);
|
|
char *mime_text = nullptr;
|
|
PEP_STATUS status = ::mime_encode_«@name»(_obj, false, &mime_text);
|
|
if (status)
|
|
throw_pEp_Exception(env, status);
|
|
jbyteArray result = from_string(env, mime_text);
|
|
free(mime_text);
|
|
return result;
|
|
}
|
|
|
|
||
|
|
apply "*[name(.)!='enum']", 0, mode=entry {
|
|
with "name", "@name";
|
|
with "class" call "CamelCase" with "text", "@name";
|
|
}
|
|
||
|
|
} // extern "C"
|
|
|
|
||
|
|
}
|
|
}
|
|
|
|
function "mangle" {
|
|
param "type";
|
|
param "name";
|
|
param "classname" call "CamelCase" with "text", "../@name";
|
|
const "convert", "$type != 'timestamp'";
|
|
|
|
choose {
|
|
when "$convert"
|
|
> «concat('Java_foundation_pEp_jniadapter_', $classname, '__1', str:replace($name, '_', '_1'))»
|
|
otherwise
|
|
> «concat('Java_foundation_pEp_jniadapter_', $classname, '_', str:replace($name, '_', '_1'))»
|
|
}
|
|
}
|
|
|
|
template "*", mode=entry {
|
|
param "name";
|
|
param "class";
|
|
const "ctype" call "toC" with "type", "name(.)";
|
|
const "jname" call "CamelCase" with "text", "name(*[1])";
|
|
const "cname" call "lcase" with "text", "name(*[1])";
|
|
const "type", "name(.)";
|
|
const "getname" call "mangle" {
|
|
with "type", "$type";
|
|
with "name", "concat('get', $jname)";
|
|
}
|
|
const "setname" call "mangle" {
|
|
with "type", "$type";
|
|
with "name", "concat('set', $jname)";
|
|
}
|
|
||
|
|
JNIEXPORT `call "jni_type" with "type", "name(.)"` JNICALL «$getname»(JNIEnv *env, jobject obj)
|
|
{
|
|
pEpLog("called");
|
|
«$name» *_obj = «$name»_ptr(env, obj);
|
|
||
|
|
choose {
|
|
when "../enum[@name=$type]"
|
|
|> return (jint) _obj->«$cname»;
|
|
otherwise
|
|
|> return from_«$type»(env, _obj->«$cname»);
|
|
}
|
|
||
|
|
}
|
|
|
|
JNIEXPORT void JNICALL «$setname»(JNIEnv *env, jobject obj, `call "jni_type" with "type", "name(.)"` value)
|
|
{
|
|
pEpLog("called");
|
|
«$name» *_obj = «$name»_ptr(env, obj);
|
|
||
|
|
choose {
|
|
when "../enum[@name=$type]"
|
|
|> _obj->«$cname» = («$ctype») (int) value;
|
|
otherwise {
|
|
choose {
|
|
when "$type = 'string'" {
|
|
|> free(_obj->«$cname»);
|
|
}
|
|
otherwise {
|
|
const "free" choose {
|
|
when "$ctype = 'pEp_identity'" > identity
|
|
when "contains($ctype, '_t')" value "substring-before($ctype, '_t')";
|
|
otherwise value "$ctype";
|
|
}
|
|
|
|
|> free_«$free»(_obj->«$cname»);
|
|
}
|
|
}
|
|
|> if(value){
|
|
choose {
|
|
when "$type = 'string'" {
|
|
|>> _obj->«$cname» = to_«$type»(env, value);
|
|
}
|
|
otherwise {
|
|
|>> _obj->«$cname» = to_«$type»(env, value);
|
|
}
|
|
}
|
|
|> }else{
|
|
|> _obj->«$cname» = NULL;
|
|
|> }
|
|
}
|
|
}
|
|
||
|
|
}
|
|
|
|
||
|
|
}
|
|
}
|
|
|
|
|