mirror of https://github.com/kiwix/libkiwix.git
63 lines
1.8 KiB
C++
63 lines
1.8 KiB
C++
/*
|
||
* Copyright (C) 2019-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 <android/log.h>
|
||
#include "org_kiwix_kiwixlib_Library.h"
|
||
|
||
#include "library.h"
|
||
#include "reader.h"
|
||
#include "utils.h"
|
||
|
||
/* Kiwix Reader JNI functions */
|
||
JNIEXPORT void JNICALL
|
||
Java_org_kiwix_kiwixlib_Library_allocate(
|
||
JNIEnv* env, jobject thisObj)
|
||
{
|
||
allocate<kiwix::Library>(env, thisObj);
|
||
}
|
||
|
||
JNIEXPORT void JNICALL
|
||
Java_org_kiwix_kiwixlib_Library_dispose(JNIEnv* env, jobject thisObj)
|
||
{
|
||
dispose<kiwix::Library>(env, thisObj);
|
||
}
|
||
|
||
#define LIBRARY (getPtr<kiwix::Library>(env, thisObj))
|
||
|
||
/* Kiwix library functions */
|
||
JNIEXPORT jboolean JNICALL
|
||
Java_org_kiwix_kiwixlib_Library_addBook(
|
||
JNIEnv* env, jobject thisObj, jstring path)
|
||
{
|
||
auto cPath = jni2c(path, env);
|
||
|
||
try {
|
||
kiwix::Reader reader(cPath);
|
||
kiwix::Book book;
|
||
book.update(reader);
|
||
return LIBRARY->addBook(book);
|
||
} catch (std::exception& e) {
|
||
__android_log_print(ANDROID_LOG_ERROR, "kiwix", "Unable to add the book");
|
||
__android_log_print(ANDROID_LOG_ERROR, "kiwix", e.what());
|
||
}
|
||
return false;
|
||
}
|