mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-10 07:48:30 -04:00
+ some imp.
This commit is contained in:
parent
239daec094
commit
7c405a54d3
@ -10,10 +10,10 @@ extern "C" {
|
|||||||
/*
|
/*
|
||||||
* Class: JNIKiwix
|
* Class: JNIKiwix
|
||||||
* Method: nativeLoadZIM
|
* Method: nativeLoadZIM
|
||||||
* Signature: ()Ljava/lang/Boolean;
|
* Signature: (Ljava/lang/String;)Z
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jobject JNICALL Java_JNIKiwix_nativeLoadZIM
|
JNIEXPORT jboolean JNICALL Java_JNIKiwix_nativeLoadZIM
|
||||||
(JNIEnv *, jobject);
|
(JNIEnv *, jobject, jstring);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: JNIKiwix
|
* Class: JNIKiwix
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
public class JNIKiwix {
|
public class JNIKiwix {
|
||||||
public native Boolean nativeLoadZIM();
|
public native boolean nativeLoadZIM(String path);
|
||||||
public native String nativeGetContent(String url);
|
public native String nativeGetContent(String url);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -7,6 +7,16 @@ public class JNIKiwix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
JNIKiwix self = new JNIKiwix();
|
||||||
|
|
||||||
|
try {
|
||||||
|
self.nativeLoadZIM("test.zim");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
System.out.println("Message " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
13
compile.sh
Executable file
13
compile.sh
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Compile the JNI class, this will create JNIKiwix.class
|
||||||
|
javac JNIKiwix.java
|
||||||
|
|
||||||
|
# Create the JNI header file, this will create JNIKiwix.h
|
||||||
|
javah -jni JNIKiwix
|
||||||
|
|
||||||
|
# Compile the native lib libkiwix.so
|
||||||
|
g++ -shared -fpic -o libkiwix.so -I/usr/lib/jvm/java-7-openjdk-i386/include/ kiwix.c
|
||||||
|
|
||||||
|
# Run the code
|
||||||
|
java -Djava.library.path=./ JNIKiwix
|
29
kiwix.c
29
kiwix.c
@ -1,11 +1,32 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include "JNIKiwix.h"
|
#include "JNIKiwix.h"
|
||||||
|
|
||||||
JNIEXPORT jobject JNICALL Java_JNIKiwix_nativeLoadZIM(JNIEnv *env, jobject obj) {
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
/* c2jni type conversion functions */
|
||||||
|
jboolean c2jni(const bool &val) {
|
||||||
|
return val ? JNI_TRUE : JNI_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
jstring c2jni(const std::string &val, JNIEnv *env) {
|
||||||
|
return env->NewStringUTF(val.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* jni2c type conversion functions */
|
||||||
|
bool jni2c(const jboolean &val) {
|
||||||
|
return val == JNI_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string jni2c(const jstring &val, JNIEnv *env) {
|
||||||
|
return std::string(env->GetStringUTFChars(val, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Kiwix library functions */
|
||||||
|
JNIEXPORT jboolean JNICALL Java_JNIKiwix_nativeLoadZIM(JNIEnv *env, jobject obj, jstring path) {
|
||||||
|
return c2jni(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL Java_JNIKiwix_nativeGetContent(JNIEnv *env, jobject obj, jstring url) {
|
JNIEXPORT jstring JNICALL Java_JNIKiwix_nativeGetContent(JNIEnv *env, jobject obj, jstring url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user