
9 changed files with 186 additions and 63 deletions
@ -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; |
package org.pEp.jniadapter; |
||||
|
|
||||
public class Engine implements AutoCloseable { |
public class Engine extends AbstractEngine { |
||||
static { |
|
||||
System.loadLibrary("pEpJNI"); |
|
||||
} |
|
||||
|
|
||||
protected native void init() throws pEpException; |
|
||||
protected native void release(); |
|
||||
|
|
||||
private long handle; |
|
||||
|
|
||||
public Engine() throws pEpException { |
public Engine() throws pEpException { |
||||
init(); |
|
||||
} |
|
||||
|
|
||||
public void close() { |
|
||||
release(); |
|
||||
} |
} |
||||
} |
} |
||||
|
|
||||
|
@ -1,45 +1,11 @@ |
|||||
#include "org_pEp_jniadapter_Engine.h" |
#include "org_pEp_jniadapter_AbstractEngine.h" |
||||
|
|
||||
#include <stdexcept> |
#include <stdexcept> |
||||
#include <typeinfo> |
|
||||
#include <assert.h> |
#include <assert.h> |
||||
#include <pEp/pEpEngine.h> |
#include <pEp/pEpEngine.h> |
||||
|
|
||||
#include "throw_pEp_exception.hh" |
#include "throw_pEp_exception.hh" |
||||
|
#include "jniutils.hh" |
||||
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; |
|
||||
} |
|
||||
}; |
|
||||
}; |
|
||||
|
|
||||
extern "C" { |
extern "C" { |
||||
using namespace pEp::JNIAdapter; |
using namespace pEp::JNIAdapter; |
@ -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 |
||||
|
} |
||||
|
} |
||||
|
|
Loading…
Reference in new issue