@ -0,0 +1,64 @@ | |||
include yslt.yml2 | |||
tstylesheet { | |||
include ./textutils.ysl2 | |||
template "/" { | |||
apply "namespace", 0; | |||
document "throw_pEp_exception.hh", "text" | |||
|| | |||
#pragma once | |||
#include <jni.h> | |||
namespace pEp { | |||
namespace JNIAdapter { | |||
jint throw_pEp_Exception(JNIEnv *env, PEP_STATUS status); | |||
}; | |||
}; | |||
|| | |||
} | |||
template "namespace" | |||
|| | |||
#include <assert.h> | |||
#include <pEp/pEpEngine.h> | |||
#include "throw_pEp_exception.hh" | |||
namespace pEp { | |||
namespace JNIAdapter { | |||
jint throw_pEp_Exception(JNIEnv *env, PEP_STATUS status) | |||
{ | |||
jclass ex; | |||
const char *ex_name; | |||
switch (status) { | |||
`` apply "enum/*", 4, mode=case | |||
default: | |||
assert(0); | |||
ex_name = "Exception"; | |||
} | |||
ex = env->FindClass(ex_name); | |||
assert(ex); | |||
if (ex == NULL) { | |||
ex = env->FindClass("java/lang/NoClassDefFoundError"); | |||
assert(ex); | |||
} | |||
return env->ThrowNew(ex, ex_name); | |||
} | |||
}; | |||
}; | |||
|| | |||
template "*", mode=case { | |||
| case `call "UCASE" with "text", "name(.)"`: | |||
| ex_name = "org/pEp/jniadapter/`call "CamelCase" with "text", "name(.)"`"; | |||
| break; | |||
} | |||
} | |||
@ -0,0 +1,40 @@ | |||
#include "jniutils.hh" | |||
#include <stdexcept> | |||
#include <typeinfo> | |||
#include <assert.h> | |||
namespace pEp { | |||
namespace JNIAdapter { | |||
jfieldID getFieldID( | |||
JNIEnv *env, | |||
const char *classname, | |||
const char *fieldname, | |||
const char *signature | |||
) | |||
{ | |||
jclass engine = env->FindClass(classname); | |||
assert(engine); | |||
if (engine == NULL) { | |||
jclass ex = env->FindClass("java/lang/NoClassDefFoundError"); | |||
assert(ex); | |||
env->ThrowNew(ex, classname); | |||
throw std::bad_cast(); | |||
} | |||
jfieldID field = env->GetFieldID(engine, fieldname, signature); | |||
assert(field); | |||
if (field == NULL) { | |||
jclass ex = env->FindClass("java/lang/NoSuchFieldError"); | |||
assert(ex); | |||
env->ThrowNew(ex, fieldname); | |||
throw std::invalid_argument(fieldname); | |||
} | |||
return field; | |||
} | |||
}; | |||
}; | |||
@ -0,0 +1,15 @@ | |||
#pragma once | |||
#include <jni.h> | |||
namespace pEp { | |||
namespace JNIAdapter { | |||
jfieldID getFieldID( | |||
JNIEnv *env, | |||
const char *classname, | |||
const char *fieldname, | |||
const char *signature | |||
); | |||
}; | |||
}; | |||
@ -0,0 +1,22 @@ | |||
package org.pEp.jniadapter; | |||
abstract class AbstractEngine implements AutoCloseable { | |||
static { | |||
System.loadLibrary("pEpJNI"); | |||
} | |||
protected native void init() throws pEpException; | |||
protected native void release(); | |||
private long handle; | |||
protected long getHandle() { return handle; } | |||
public AbstractEngine() throws pEpException { | |||
init(); | |||
} | |||
public void close() { | |||
release(); | |||
} | |||
} | |||
@ -1,21 +1,7 @@ | |||
package org.pEp.jniadapter; | |||
public class Engine implements AutoCloseable { | |||
static { | |||
System.loadLibrary("pEpJNI"); | |||
} | |||
protected native void init() throws pEpException; | |||
protected native void release(); | |||
private long handle; | |||
public class Engine extends AbstractEngine { | |||
public Engine() throws pEpException { | |||
init(); | |||
} | |||
public void close() { | |||
release(); | |||
} | |||
} | |||
@ -0,0 +1,32 @@ | |||
function "UCASE" { | |||
param "text"; | |||
value "translate($text, 'abcdefghijklmnopqrstuvwxyz-', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_')"; | |||
} | |||
function "lcase" { | |||
param "text"; | |||
value "translate($text, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-', 'abcdefghijklmnopqrstuvwxyz_')"; | |||
} | |||
function "CamelCase" { | |||
param "text"; | |||
choose { | |||
when "contains($text, '-')" { | |||
const "tokens", "str:tokenize($text, '-')"; | |||
for "$tokens" { | |||
choose { | |||
when ".='pEp'" > pEp | |||
otherwise { | |||
call "UCASE" with "text", "substring(., 1, 1)"; | |||
call "lcase" with "text", "substring(., 2)"; | |||
} | |||
} | |||
} | |||
} | |||
otherwise | unsupported | |||
} | |||
} | |||