mirror of https://github.com/kiwix/libkiwix.git
Add a wrapper for the Book class.
This commit is contained in:
parent
6b2f768c8f
commit
6535dc2e38
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Matthieu Gautier <mgautier@kymeria.fr>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
#include "org_kiwix_kiwixlib_Book.h"
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
#include "book.h"
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_org_kiwix_kiwixlib_Book_allocate(
|
||||||
|
JNIEnv* env, jobject thisObj)
|
||||||
|
{
|
||||||
|
allocate<kiwix::Book>(env, thisObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_org_kiwix_kiwixlib_Book_dispose(JNIEnv* env, jobject thisObj)
|
||||||
|
{
|
||||||
|
dispose<kiwix::Book>(env, thisObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define BOOK (getPtr<kiwix::Book>(env, thisObj))
|
||||||
|
|
||||||
|
#define METHOD(retType, name) JNIEXPORT retType JNICALL \
|
||||||
|
Java_org_kiwix_kiwixlib_Book_##name (JNIEnv* env, jobject thisObj) \
|
||||||
|
{ \
|
||||||
|
auto cRet = BOOK->name(); \
|
||||||
|
retType ret = c2jni(cRet, env); \
|
||||||
|
return ret; \
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(jstring, getId)
|
||||||
|
METHOD(jstring, getPath)
|
||||||
|
METHOD(jboolean, isPathValid)
|
||||||
|
METHOD(jstring, getTitle)
|
||||||
|
METHOD(jstring, getDescription)
|
||||||
|
METHOD(jstring, getLanguage)
|
||||||
|
METHOD(jstring, getCreator)
|
||||||
|
METHOD(jstring, getPublisher)
|
||||||
|
METHOD(jstring, getDate)
|
||||||
|
METHOD(jstring, getUrl)
|
||||||
|
METHOD(jstring, getName)
|
||||||
|
METHOD(jstring, getTags)
|
||||||
|
METHOD(jlong, getArticleCount)
|
||||||
|
METHOD(jlong, getMediaCount)
|
||||||
|
METHOD(jlong, getSize)
|
||||||
|
METHOD(jstring, getFavicon)
|
||||||
|
METHOD(jstring, getFaviconUrl)
|
||||||
|
METHOD(jstring, getFaviconMimeType)
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
kiwix_jni = custom_target('jni',
|
kiwix_jni = custom_target('jni',
|
||||||
input: ['org/kiwix/kiwixlib/JNIICU.java',
|
input: ['org/kiwix/kiwixlib/JNIICU.java',
|
||||||
|
'org/kiwix/kiwixlib/Book.java',
|
||||||
'org/kiwix/kiwixlib/JNIKiwixReader.java',
|
'org/kiwix/kiwixlib/JNIKiwixReader.java',
|
||||||
'org/kiwix/kiwixlib/JNIKiwixLibrary.java',
|
'org/kiwix/kiwixlib/JNIKiwixLibrary.java',
|
||||||
'org/kiwix/kiwixlib/JNIKiwixSearcher.java',
|
'org/kiwix/kiwixlib/JNIKiwixSearcher.java',
|
||||||
|
@ -11,6 +12,7 @@ kiwix_jni = custom_target('jni',
|
||||||
'org/kiwix/kiwixlib/JNIKiwixException.java',
|
'org/kiwix/kiwixlib/JNIKiwixException.java',
|
||||||
'org/kiwix/kiwixlib/Pair.java'],
|
'org/kiwix/kiwixlib/Pair.java'],
|
||||||
output: ['org_kiwix_kiwixlib_JNIKiwix.h',
|
output: ['org_kiwix_kiwixlib_JNIKiwix.h',
|
||||||
|
'org_kiwix_kiwixlib_Book.h',
|
||||||
'org_kiwix_kiwixlib_JNIKiwixReader.h',
|
'org_kiwix_kiwixlib_JNIKiwixReader.h',
|
||||||
'org_kiwix_kiwixlib_JNIKiwixLibrary.h',
|
'org_kiwix_kiwixlib_JNIKiwixLibrary.h',
|
||||||
'org_kiwix_kiwixlib_JNIKiwixServer.h',
|
'org_kiwix_kiwixlib_JNIKiwixServer.h',
|
||||||
|
@ -21,6 +23,7 @@ kiwix_jni = custom_target('jni',
|
||||||
|
|
||||||
kiwix_sources += [
|
kiwix_sources += [
|
||||||
'android/kiwixicu.cpp',
|
'android/kiwixicu.cpp',
|
||||||
|
'android/book.cpp',
|
||||||
'android/kiwixreader.cpp',
|
'android/kiwixreader.cpp',
|
||||||
'android/kiwixlibrary.cpp',
|
'android/kiwixlibrary.cpp',
|
||||||
'android/kiwixsearcher.cpp',
|
'android/kiwixsearcher.cpp',
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
|
||||||
|
package org.kiwix.kiwixlib;
|
||||||
|
|
||||||
|
public class Book
|
||||||
|
{
|
||||||
|
public Book() { allocate(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void finalize() { dispose(); }
|
||||||
|
|
||||||
|
public native String getId();
|
||||||
|
public native String getPath();
|
||||||
|
public native boolean isPathValid();
|
||||||
|
public native String getTitle();
|
||||||
|
public native String getDescription();
|
||||||
|
public native String getLanguage();
|
||||||
|
public native String getCreator();
|
||||||
|
public native String getPublisher();
|
||||||
|
public native String getDate();
|
||||||
|
public native String getUrl();
|
||||||
|
public native String getName();
|
||||||
|
public native String getTags();
|
||||||
|
|
||||||
|
public native long getArticleCount();
|
||||||
|
public native long getMediaCount();
|
||||||
|
public native long getSize();
|
||||||
|
|
||||||
|
public native String getFavicon();
|
||||||
|
public native String getFaviconUrl();
|
||||||
|
public native String getFaviconMimeType();
|
||||||
|
|
||||||
|
private native void allocate();
|
||||||
|
private native void dispose();
|
||||||
|
private long nativeHandle;
|
||||||
|
}
|
|
@ -29,6 +29,29 @@
|
||||||
|
|
||||||
extern pthread_mutex_t globalLock;
|
extern pthread_mutex_t globalLock;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void allocate(JNIEnv* env, jobject thisObj)
|
||||||
|
{
|
||||||
|
jclass thisClass = env->GetObjectClass(thisObj);
|
||||||
|
jfieldID fidNumber = env->GetFieldID(thisClass, "nativeHandle", "J");
|
||||||
|
T* ptr = new T();
|
||||||
|
env->SetLongField(thisObj, fidNumber, reinterpret_cast<jlong>(ptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T* getPtr(JNIEnv* env, jobject thisObj)
|
||||||
|
{
|
||||||
|
jclass thisClass = env->GetObjectClass(thisObj);
|
||||||
|
jfieldID fidNumber = env->GetFieldID(thisClass, "nativeHandle", "J");
|
||||||
|
return reinterpret_cast<T*>(env->GetLongField(thisObj, fidNumber));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void dispose(JNIEnv* env, jobject thisObj)
|
||||||
|
{
|
||||||
|
delete getPtr<T>(env, thisObj);
|
||||||
|
}
|
||||||
|
|
||||||
inline jfieldID getHandleField(JNIEnv* env, jobject obj)
|
inline jfieldID getHandleField(JNIEnv* env, jobject obj)
|
||||||
{
|
{
|
||||||
jclass c = env->GetObjectClass(obj);
|
jclass c = env->GetObjectClass(obj);
|
||||||
|
|
Loading…
Reference in New Issue