-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlibrary.cpp
More file actions
104 lines (85 loc) · 3 KB
/
library.cpp
File metadata and controls
104 lines (85 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* 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 "org_kiwix_libkiwix_Library.h"
#include "library.h"
#include "utils.h"
#define NATIVE_TYPE kiwix::Library
#define TYPENAME libkiwix_Library
#include "macros.h"
/* Kiwix Reader JNI functions */
METHOD0(jobject, buildNativeLibrary)
{
return NEW_RESOURCE(std::make_shared<NATIVE_TYPE>());
}
/* Kiwix library functions */
METHOD(jboolean, addBook, jobject book)
{
auto cBook = getPtr<kiwix::Book>(env, book);
try {
return THIS->addBook(*cBook);
} catch (std::exception& e) {
LOG("Unable to add the book");
LOG("%s", e.what()); }
return false;
}
METHOD(jobject, getBookById, jstring id) {
return BUILD_WRAPPER(THIS->getBookById(TO_C(id)));
}
METHOD(jobject, getArchiveById, jstring id) {
return BUILD_WRAPPER(THIS->getArchiveById(TO_C(id)));
}
METHOD(jboolean, removeBookById, jstring id) {
return TO_JNI(THIS->removeBookById(TO_C(id)));
}
METHOD(jboolean, writeToFile, jstring path) {
return TO_JNI(THIS->writeToFile(TO_C(path)));
}
METHOD(jboolean, writeBookmarksToFile, jstring path) {
return TO_JNI(THIS->writeBookmarksToFile(TO_C(path)));
}
METHOD(jint, getBookCount, jboolean localBooks, jboolean remoteBooks) {
return TO_JNI(THIS->getBookCount(TO_C(localBooks), TO_C(remoteBooks)));
}
GETTER(jobjectArray, getBooksIds)
METHOD(jobjectArray, filter, jobject filterObj) {
auto filter = getPtr<kiwix::Filter>(env, filterObj);
return c2jni(THIS->filter(*filter), env);
}
GETTER(jobjectArray, getBooksLanguages)
GETTER(jobjectArray, getBooksCategories)
GETTER(jobjectArray, getBooksCreators)
GETTER(jobjectArray, getBooksPublishers)
METHOD(void, addBookmark, jobject bookmark) {
auto cBookmark = getPtr<kiwix::Bookmark>(env, bookmark);
THIS->addBookmark(*cBookmark);
}
METHOD(jboolean, removeBookmark, jstring zimId, jstring url) {
return TO_JNI(THIS->removeBookmark(TO_C(zimId), TO_C(url)));
}
METHOD(jobjectArray, getBookmarks, jboolean onlyValidBookmarks) {
auto bookmarks = THIS->getBookmarks(TO_C(onlyValidBookmarks));
jobjectArray retArray = createArray(env, bookmarks.size(), "org/kiwix/libkiwix/Bookmark");
size_t index = 0;
for (auto bookmark: bookmarks) {
auto wrapper = BUILD_WRAPPER(bookmark);
env->SetObjectArrayElement(retArray, index++, wrapper);
}
return retArray;
}