From a365a1e1c0014ac9ffb0d24e35ef8a2cb813e093 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Thu, 2 Jan 2014 16:40:50 +0100 Subject: [PATCH] + new JNI methods --- kiwix.c | 162 ++++++++++++++++++++++++ src/org/kiwix/kiwixmobile/JNIKiwix.java | 8 ++ 2 files changed, 170 insertions(+) diff --git a/kiwix.c b/kiwix.c index 5d04d0846..b9eafbbbb 100644 --- a/kiwix.c +++ b/kiwix.c @@ -254,6 +254,168 @@ JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwibx_getDescription return retVal; } +JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwibx_getLanguage +(JNIEnv *env, jobject obj, jobject languageObj) { + jboolean retVal = JNI_FALSE; + std::string cLanguage; + + pthread_mutex_lock(&readerLock); + try { + if (reader != NULL) { + std::string cLanguage = reader->getLanguage(); + setStringObjValue(cLanguage, languageObj, env); + retVal = JNI_TRUE; + } + } catch (exception &e) { + std::cerr << e.what() << std::endl; + } + pthread_mutex_unlock(&readerLock); + + return retVal; +} + +JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwibx_getDate +(JNIEnv *env, jobject obj, jobject dateObj) { + jboolean retVal = JNI_FALSE; + std::string cDate; + + pthread_mutex_lock(&readerLock); + try { + if (reader != NULL) { + std::string cDate = reader->getDate(); + setStringObjValue(cDate, dateObj, env); + retVal = JNI_TRUE; + } + } catch (exception &e) { + std::cerr << e.what() << std::endl; + } + pthread_mutex_unlock(&readerLock); + + return retVal; +} + +JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwibx_getCreator +(JNIEnv *env, jobject obj, jobject creatorObj) { + jboolean retVal = JNI_FALSE; + std::string cCreator; + + pthread_mutex_lock(&readerLock); + try { + if (reader != NULL) { + std::string cCreator = reader->getCreator(); + setStringObjValue(cCreator, creatorObj, env); + retVal = JNI_TRUE; + } + } catch (exception &e) { + std::cerr << e.what() << std::endl; + } + pthread_mutex_unlock(&readerLock); + + return retVal; +} + +JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwibx_getPublisher +(JNIEnv *env, jobject obj, jobject publisherObj) { + jboolean retVal = JNI_FALSE; + std::string cPublisher; + + pthread_mutex_lock(&readerLock); + try { + if (reader != NULL) { + std::string cPublisher = reader->getPublisher(); + setStringObjValue(cPublisher, publisherObj, env); + retVal = JNI_TRUE; + } + } catch (exception &e) { + std::cerr << e.what() << std::endl; + } + pthread_mutex_unlock(&readerLock); + + return retVal; +} + +JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwibx_getArticleCount +(JNIEnv *env, jobject obj, jobject articleCountObj) { + jboolean retVal = JNI_FALSE; + unsigned int cArticleCount = 0; + + pthread_mutex_lock(&readerLock); + try { + if (reader != NULL) { + cArticleCount = reader->getArticleCount(); + setIntObjValue(cArticleCount, articleCountObj, env); + retVal = JNI_TRUE; + } + } catch (exception &e) { + std::cerr << e.what() << std::endl; + } + pthread_mutex_unlock(&readerLock); + + return retVal; +} + +JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwibx_getMediaCount +(JNIEnv *env, jobject obj, jobject mediaCountObj) { + jboolean retVal = JNI_FALSE; + unsigned int cMediaCount = 0; + + pthread_mutex_lock(&readerLock); + try { + if (reader != NULL) { + cMediaCount = reader->getMediaCount(); + setIntObjValue(cMediaCount, mediaCountObj, env); + retVal = JNI_TRUE; + } + } catch (exception &e) { + std::cerr << e.what() << std::endl; + } + pthread_mutex_unlock(&readerLock); + + return retVal; +} + +JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwibx_getFileSize +(JNIEnv *env, jobject obj, jobject fileSizeObj) { + jboolean retVal = JNI_FALSE; + unsigned int cFileSize = 0; + + pthread_mutex_lock(&readerLock); + try { + if (reader != NULL) { + cFileSize = reader->getFileSize(); + setIntObjValue(cFileSize, fileSizeObj, env); + retVal = JNI_TRUE; + } + } catch (exception &e) { + std::cerr << e.what() << std::endl; + } + pthread_mutex_unlock(&readerLock); + + return retVal; +} + +JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwibx_getFavicon +(JNIEnv *env, jobject obj, jobject contentObj, jobject mimeTypeObj) { + jboolean retVal = JNI_FALSE; + std::string cContent; + std::string cMimeType; + + pthread_mutex_lock(&readerLock); + try { + if (reader != NULL) { + reader->getFavicon(cContent, cMimeType); + setStringObjValue(cContent, contentObj, env); + setStringObjValue(cMimeType, mimeTypeObj, env); + retVal = JNI_TRUE; + } + } catch (exception &e) { + std::cerr << e.what() << std::endl; + } + pthread_mutex_unlock(&readerLock); + + return retVal; +} + JNIEXPORT jboolean JNICALL Java_org_kiwix_kiwixmobile_JNIKiwix_getRandomPage (JNIEnv *env, jobject obj, jobject urlObj) { jboolean retVal = JNI_FALSE; diff --git a/src/org/kiwix/kiwixmobile/JNIKiwix.java b/src/org/kiwix/kiwixmobile/JNIKiwix.java index 0e957fc15..56d49c31a 100644 --- a/src/org/kiwix/kiwixmobile/JNIKiwix.java +++ b/src/org/kiwix/kiwixmobile/JNIKiwix.java @@ -29,6 +29,14 @@ public class JNIKiwix { public native boolean getPageUrlFromTitle(String title, JNIKiwixString url); public native boolean getTitle(JNIKiwixString title); public native boolean getDescription(JNIKiwixString title); + public native boolean getLanguage(JNIKiwixString language); + public native boolean getDate(JNIKiwixString language); + public native boolean getFavicon(JNIKiwixString content, JNIKiwixString mimeType); + public native boolean getCreator(JNIKiwixString creator); + public native boolean getPublisher(JNIKiwixString publisher); + public native boolean getFileSize(JNIKiwixInt size); + public native boolean getArticleCount(JNIKiwixInt count); + public native boolean getMediaCount(JNIKiwixInt count); public native boolean getRandomPage(JNIKiwixString url); static {