+ few new methods

This commit is contained in:
kelson42 2013-04-03 12:11:20 +02:00
parent 5348c75c31
commit b88909e0ae
3 changed files with 33 additions and 6 deletions

View File

@ -18,10 +18,10 @@ JNIEXPORT jboolean JNICALL Java_JNIKiwix_nativeLoadZIM
/*
* Class: JNIKiwix
* Method: nativeGetContent
* Signature: (Ljava/lang/String;)Ljava/lang/String;
* Signature: (Ljava/lang/String;LJNIKiwixString;LJNIKiwixInt;LJNIKiwixBool;)[B
*/
JNIEXPORT jstring JNICALL Java_JNIKiwix_nativeGetContent
(JNIEnv *, jobject, jstring);
JNIEXPORT jbyteArray JNICALL Java_JNIKiwix_nativeGetContent
(JNIEnv *, jobject, jstring, jobject, jobject, jobject);
#ifdef __cplusplus
}

View File

@ -1,6 +1,7 @@
public class JNIKiwix {
public native boolean nativeLoadZIM(String path);
public native byte[] nativeGetContent(String url, JNIKiwixString mimeType, JNIKiwixInt size);
public native byte[] nativeGetContent(String url, JNIKiwixString mimeType,
JNIKiwixInt size, JNIKiwixBool isOk);
static {
System.loadLibrary("kiwix");
@ -14,8 +15,11 @@ public class JNIKiwix {
JNIKiwixString mimeTypeObj = new JNIKiwixString();
JNIKiwixInt sizeObj = new JNIKiwixInt();
self.nativeGetContent("/A/Wikipedia.html", mimeTypeObj, sizeObj);
JNIKiwixBool isOkObj = new JNIKiwixBool();
self.nativeGetContent("/A/Wikipedia.html", mimeTypeObj, sizeObj, isOkObj);
System.out.println(mimeTypeObj.value);
System.out.println(sizeObj.value);
System.out.println(isOkObj.value);
}
catch (Exception e) {
System.out.println("Message " + e.getMessage());
@ -32,4 +36,8 @@ class JNIKiwixString {
class JNIKiwixInt {
int value;
}
class JNIKiwixBool {
boolean value;
}

21
kiwix.c
View File

@ -41,12 +41,31 @@ void setStringObjValue(const std::string &value, const jobject obj, JNIEnv *env)
env->SetObjectField(obj, objFid, c2jni(value, env));
}
void setIntObjValue(const int value, const jobject obj, JNIEnv *env) {
int tmp = value;
jclass objClass = env->GetObjectClass(obj);
jfieldID objFid = env->GetFieldID(objClass, "value", "I");
env->SetIntField(obj, objFid, c2jni(tmp));
}
void setBoolObjValue(const bool value, const jobject obj, JNIEnv *env) {
jclass objClass = env->GetObjectClass(obj);
jfieldID objFid = env->GetFieldID(objClass, "value", "Z");
env->SetIntField(obj, objFid, c2jni(value));
}
/* Kiwix library functions */
JNIEXPORT jboolean JNICALL Java_JNIKiwix_nativeLoadZIM(JNIEnv *env, jobject obj, jstring path) {
return c2jni(true);
}
JNIEXPORT jbyteArray JNICALL Java_JNIKiwix_nativeGetContent(JNIEnv *env, jobject obj, jstring url,
jobject mimeTypeObj, jobject sizeObj) {
jobject mimeTypeObj, jobject sizeObj,
jobject isOkObj) {
setStringObjValue("42", mimeTypeObj, env);
setIntObjValue(42, sizeObj, env);
setBoolObjValue(false, isOkObj, env);
// Java program dies otherwise (please keep this "useless" line)
std::cout << "";
}