Added new methods to android JNI

This commit is contained in:
mhutti1 2016-08-19 19:22:01 +01:00
parent a7fb23bc83
commit 8677ea790a
7 changed files with 91 additions and 22 deletions

View File

@ -579,6 +579,7 @@ for arch in ARCHS:
'kiwix.c %(kwsrc)s/kiwix/reader.cpp ' 'kiwix.c %(kwsrc)s/kiwix/reader.cpp '
'%(kwsrc)s/stringTools.cpp ' '%(kwsrc)s/stringTools.cpp '
'%(kwsrc)s/pathTools.cpp ' '%(kwsrc)s/pathTools.cpp '
'%(kwsrc)s/base64.cpp '
'-I%(include_paths)s ' '-I%(include_paths)s '
% {'platform': platform, % {'platform': platform,
'arch_full': arch_full, 'arch_full': arch_full,
@ -598,7 +599,7 @@ for arch in ARCHS:
link_cmd = ('g++ -fPIC -shared -B%(platform)s/sysroot ' link_cmd = ('g++ -fPIC -shared -B%(platform)s/sysroot '
'--sysroot %(platform)s/sysroot ' '--sysroot %(platform)s/sysroot '
'-nostdlib ' '-nostdlib '
'kiwix.o reader.o stringTools.o pathTools.o ' 'kiwix.o reader.o stringTools.o pathTools.o base64.o '
'%(platform)s/lib/gcc/%(arch_full)s/%(gccver)s/crtbegin.o ' '%(platform)s/lib/gcc/%(arch_full)s/%(gccver)s/crtbegin.o '
'%(platform)s/lib/gcc/%(arch_full)s/%(gccver)s/crtend.o ' '%(platform)s/lib/gcc/%(arch_full)s/%(gccver)s/crtend.o '
'%(platform)s/lib/libzim.a %(platform)s/lib/liblzma.a ' '%(platform)s/lib/libzim.a %(platform)s/lib/liblzma.a '
@ -638,7 +639,7 @@ for arch in ARCHS:
syscall(compile_cmd) syscall(compile_cmd)
syscall(link_cmd) syscall(link_cmd)
for obj in ('kiwix.o', 'reader.o', 'stringTools.o', 'pathTools.o', for obj in ('kiwix.o', 'reader.o', 'stringTools.o', 'pathTools.o', 'base64.o',
'src/{}_JNIKiwix.h'.format("_".join(PACKAGE.split('.')))): 'src/{}_JNIKiwix.h'.format("_".join(PACKAGE.split('.')))):
os.remove(obj) os.remove(obj)

94
kiwix.c
View File

@ -9,6 +9,7 @@
#include "unicode/putil.h" #include "unicode/putil.h"
#include <kiwix/reader.h> #include <kiwix/reader.h>
#include <base64.h>
#include <android/log.h> #include <android/log.h>
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, "kiwix", __VA_ARGS__) #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, "kiwix", __VA_ARGS__)
@ -104,6 +105,76 @@ JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getId(JNIEnv *env,
return id; return id;
} }
JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getCreator(JNIEnv *env, jobject obj) {
jstring creator;
pthread_mutex_lock(&readerLock);
if (reader != NULL) {
try {
std::string cCreator = reader->getCreator();
creator = c2jni(cCreator, env);
} catch (exception &e) {
std::cerr << e.what() << std::endl;
}
}
pthread_mutex_unlock(&readerLock);
return creator;
}
JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getPublisher(JNIEnv *env, jobject obj) {
jstring publisher;
pthread_mutex_lock(&readerLock);
if (reader != NULL) {
try {
std::string cPublisher = reader->getPublisher();
publisher = c2jni(cPublisher, env);
} catch (exception &e) {
std::cerr << e.what() << std::endl;
}
}
pthread_mutex_unlock(&readerLock);
return publisher;
}
JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getFavicon(JNIEnv *env, jobject obj) {
jstring favicon;
pthread_mutex_lock(&readerLock);
if (reader != NULL) {
try {
std::string cContent;
std::string cMime;
reader->getFavicon(cContent, cMime);
favicon = c2jni(base64_encode(reinterpret_cast<const unsigned char*>(cContent.c_str()), cContent.length()), env);
} catch (exception &e) {
std::cerr << e.what() << std::endl;
}
}
pthread_mutex_unlock(&readerLock);
return favicon;
}
JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getDate(JNIEnv *env, jobject obj) {
jstring date;
pthread_mutex_lock(&readerLock);
if (reader != NULL) {
try {
std::string cDate = reader->getDate();
date = c2jni(cDate, env);
} catch (exception &e) {
std::cerr << e.what() << std::endl;
}
}
pthread_mutex_unlock(&readerLock);
return date;
}
JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getLanguage(JNIEnv *env, jobject obj) { JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getLanguage(JNIEnv *env, jobject obj) {
jstring language; jstring language;
@ -273,24 +344,21 @@ JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getTitle
} }
JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwibx_getDescription JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getDescription(JNIEnv *env, jobject obj) {
(JNIEnv *env, jobject obj, jobject descriptionObj) { jstring description;
jboolean retVal = JNI_FALSE;
std::string cDescription;
pthread_mutex_lock(&readerLock); pthread_mutex_lock(&readerLock);
try { if (reader != NULL) {
if (reader != NULL) { try {
std::string cDescription = reader->getDescription(); std::string cDescription = reader->getDescription();
setStringObjValue(cDescription, descriptionObj, env); description = c2jni(cDescription, env);
retVal = JNI_TRUE; } catch (exception &e) {
std::cerr << e.what() << std::endl;
} }
} catch (exception &e) {
std::cerr << e.what() << std::endl;
} }
pthread_mutex_unlock(&readerLock); pthread_mutex_unlock(&readerLock);
return retVal; return description;
} }
JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getRandomPage JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getRandomPage

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -45,21 +45,21 @@ public class JNIKiwix {
public native boolean getTitle(JNIKiwixString title); public native boolean getTitle(JNIKiwixString title);
public native boolean getDescription(JNIKiwixString title); public native String getDescription();
public native boolean getDate(JNIKiwixString language); public native String getDate();
public native boolean getFavicon(JNIKiwixString content, JNIKiwixString mimeType); public native String getFavicon();
public native boolean getCreator(JNIKiwixString creator); public native String getCreator();
public native boolean getPublisher(JNIKiwixString publisher); public native String getPublisher();
public native boolean getFileSize(JNIKiwixInt size); public native boolean getFileSize(JNIKiwixInt size);
public native boolean getArticleCount(JNIKiwixInt count); public native int getArticleCount();
public native boolean getMediaCount(JNIKiwixInt count); public native int getMediaCount();
public native boolean getRandomPage(JNIKiwixString url); public native boolean getRandomPage(JNIKiwixString url);