mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
jni envelope (in progress)
This commit is contained in:
parent
f4919b9a47
commit
4bc7d1541e
9 changed files with 84 additions and 98 deletions
|
@ -42,7 +42,6 @@ LOCAL_SRC_FILES := \
|
||||||
NativeFormats/JavaPluginCollection.cpp \
|
NativeFormats/JavaPluginCollection.cpp \
|
||||||
NativeFormats/util/AndroidUtil.cpp \
|
NativeFormats/util/AndroidUtil.cpp \
|
||||||
NativeFormats/util/Method.cpp \
|
NativeFormats/util/Method.cpp \
|
||||||
NativeFormats/util/VoidMethod.cpp \
|
|
||||||
NativeFormats/zlibrary/core/src/constants/ZLXMLNamespace.cpp \
|
NativeFormats/zlibrary/core/src/constants/ZLXMLNamespace.cpp \
|
||||||
NativeFormats/zlibrary/core/src/encoding/DummyEncodingConverter.cpp \
|
NativeFormats/zlibrary/core/src/encoding/DummyEncodingConverter.cpp \
|
||||||
NativeFormats/zlibrary/core/src/encoding/JavaEncodingConverter.cpp \
|
NativeFormats/zlibrary/core/src/encoding/JavaEncodingConverter.cpp \
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#APP_ABI := armeabi
|
APP_ABI := armeabi
|
||||||
#APP_ABI := armeabi armeabi-v7a x86 mips mips-r2 mips-r2-sf
|
#APP_ABI := armeabi armeabi-v7a x86 mips mips-r2 mips-r2-sf
|
||||||
APP_ABI := all
|
#APP_ABI := all
|
||||||
APP_STL := stlport_static
|
APP_STL := stlport_static
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <ZLFileImage.h>
|
#include <ZLFileImage.h>
|
||||||
|
|
||||||
#include "AndroidUtil.h"
|
#include "AndroidUtil.h"
|
||||||
|
#include "JniEnvelope.h"
|
||||||
|
|
||||||
JavaVM *AndroidUtil::ourJavaVM = 0;
|
JavaVM *AndroidUtil::ourJavaVM = 0;
|
||||||
|
|
||||||
|
@ -28,7 +29,6 @@ const char * const AndroidUtil::Class_java_lang_String = "java/lang/String";
|
||||||
const char * const AndroidUtil::Class_java_util_Collection = "java/util/Collection";
|
const char * const AndroidUtil::Class_java_util_Collection = "java/util/Collection";
|
||||||
const char * const AndroidUtil::Class_java_util_Locale = "java/util/Locale";
|
const char * const AndroidUtil::Class_java_util_Locale = "java/util/Locale";
|
||||||
const char * const AndroidUtil::Class_java_io_InputStream = "java/io/InputStream";
|
const char * const AndroidUtil::Class_java_io_InputStream = "java/io/InputStream";
|
||||||
const char * const AndroidUtil::Class_java_io_PrintStream = "java/io/PrintStream";
|
|
||||||
const char * const AndroidUtil::Class_ZLibrary = "org/geometerplus/zlibrary/core/library/ZLibrary";
|
const char * const AndroidUtil::Class_ZLibrary = "org/geometerplus/zlibrary/core/library/ZLibrary";
|
||||||
const char * const AndroidUtil::Class_NativeFormatPlugin = "org/geometerplus/fbreader/formats/NativeFormatPlugin";
|
const char * const AndroidUtil::Class_NativeFormatPlugin = "org/geometerplus/fbreader/formats/NativeFormatPlugin";
|
||||||
const char * const AndroidUtil::Class_PluginCollection = "org/geometerplus/fbreader/formats/PluginCollection";
|
const char * const AndroidUtil::Class_PluginCollection = "org/geometerplus/fbreader/formats/PluginCollection";
|
||||||
|
@ -51,11 +51,9 @@ jmethodID AndroidUtil::MID_java_util_Collection_toArray;
|
||||||
jmethodID AndroidUtil::SMID_java_util_Locale_getDefault;
|
jmethodID AndroidUtil::SMID_java_util_Locale_getDefault;
|
||||||
jmethodID AndroidUtil::MID_java_util_Locale_getLanguage;
|
jmethodID AndroidUtil::MID_java_util_Locale_getLanguage;
|
||||||
|
|
||||||
jmethodID AndroidUtil::MID_java_io_InputStream_close;
|
shared_ptr<VoidMethod> AndroidUtil::Method_java_io_InputStream_close;
|
||||||
jmethodID AndroidUtil::MID_java_io_InputStream_read;
|
shared_ptr<IntMethod> AndroidUtil::Method_java_io_InputStream_read;
|
||||||
jmethodID AndroidUtil::MID_java_io_InputStream_skip;
|
shared_ptr<LongMethod> AndroidUtil::Method_java_io_InputStream_skip;
|
||||||
|
|
||||||
VoidMethod AndroidUtil::MID_java_io_PrintStream_println;
|
|
||||||
|
|
||||||
jmethodID AndroidUtil::SMID_ZLibrary_Instance;
|
jmethodID AndroidUtil::SMID_ZLibrary_Instance;
|
||||||
jmethodID AndroidUtil::MID_ZLibrary_getVersionName;
|
jmethodID AndroidUtil::MID_ZLibrary_getVersionName;
|
||||||
|
@ -143,13 +141,9 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
||||||
env->DeleteLocalRef(cls);
|
env->DeleteLocalRef(cls);
|
||||||
|
|
||||||
CHECK_NULL( cls = env->FindClass(Class_java_io_InputStream) );
|
CHECK_NULL( cls = env->FindClass(Class_java_io_InputStream) );
|
||||||
CHECK_NULL( MID_java_io_InputStream_close = env->GetMethodID(cls, "close", "()V") );
|
Method_java_io_InputStream_close = new VoidMethod(env, cls, "close", "()");
|
||||||
CHECK_NULL( MID_java_io_InputStream_read = env->GetMethodID(cls, "read", "([BII)I") );
|
Method_java_io_InputStream_read = new IntMethod(env, cls, "read", "([BII)");
|
||||||
CHECK_NULL( MID_java_io_InputStream_skip = env->GetMethodID(cls, "skip", "(J)J") );
|
Method_java_io_InputStream_skip = new LongMethod(env, cls, "skip", "(J)");
|
||||||
env->DeleteLocalRef(cls);
|
|
||||||
|
|
||||||
CHECK_NULL( cls = env->FindClass(Class_java_io_PrintStream) );
|
|
||||||
CHECK_NULL( MID_java_io_PrintStream_println = env->GetMethodID(cls, "println", "(Ljava/lang/String;)V") );
|
|
||||||
env->DeleteLocalRef(cls);
|
env->DeleteLocalRef(cls);
|
||||||
|
|
||||||
CHECK_NULL( cls = env->FindClass(Class_ZLibrary) );
|
CHECK_NULL( cls = env->FindClass(Class_ZLibrary) );
|
||||||
|
|
|
@ -25,7 +25,13 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "VoidMethod.h"
|
#include <shared_ptr.h>
|
||||||
|
|
||||||
|
class VoidMethod;
|
||||||
|
class IntMethod;
|
||||||
|
class LongMethod;
|
||||||
|
class BooleanMethod;
|
||||||
|
class ObjectMethod;
|
||||||
|
|
||||||
class ZLFile;
|
class ZLFile;
|
||||||
class ZLFileImage;
|
class ZLFileImage;
|
||||||
|
@ -40,7 +46,6 @@ public:
|
||||||
static const char * const Class_java_util_Collection;
|
static const char * const Class_java_util_Collection;
|
||||||
static const char * const Class_java_util_Locale;
|
static const char * const Class_java_util_Locale;
|
||||||
static const char * const Class_java_io_InputStream;
|
static const char * const Class_java_io_InputStream;
|
||||||
static const char * const Class_java_io_PrintStream;
|
|
||||||
static const char * const Class_ZLibrary;
|
static const char * const Class_ZLibrary;
|
||||||
static const char * const Class_ZLFile;
|
static const char * const Class_ZLFile;
|
||||||
static const char * const Class_ZLFileImage;
|
static const char * const Class_ZLFileImage;
|
||||||
|
@ -63,11 +68,9 @@ public:
|
||||||
static jmethodID SMID_java_util_Locale_getDefault;
|
static jmethodID SMID_java_util_Locale_getDefault;
|
||||||
static jmethodID MID_java_util_Locale_getLanguage;
|
static jmethodID MID_java_util_Locale_getLanguage;
|
||||||
|
|
||||||
static jmethodID MID_java_io_InputStream_close;
|
static shared_ptr<VoidMethod> Method_java_io_InputStream_close;
|
||||||
static jmethodID MID_java_io_InputStream_read;
|
static shared_ptr<IntMethod> Method_java_io_InputStream_read;
|
||||||
static jmethodID MID_java_io_InputStream_skip;
|
static shared_ptr<LongMethod> Method_java_io_InputStream_skip;
|
||||||
|
|
||||||
static VoidMethod MID_java_io_PrintStream_println;
|
|
||||||
|
|
||||||
static jmethodID SMID_ZLibrary_Instance;
|
static jmethodID SMID_ZLibrary_Instance;
|
||||||
static jmethodID MID_ZLibrary_getVersionName;
|
static jmethodID MID_ZLibrary_getVersionName;
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __METHOD_H__
|
#ifndef __JNIENVELOPE_H__
|
||||||
#define __METHOD_H__
|
#define __JNIENVELOPE_H__
|
||||||
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
|
@ -28,11 +28,32 @@ class Method {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Method(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature);
|
Method(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature);
|
||||||
bool check();
|
virtual ~Method();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
JNIEnv *myEnv;
|
JNIEnv *myEnv;
|
||||||
jmethodID myId;
|
jmethodID myId;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __METHOD_H__ */
|
class VoidMethod : public Method {
|
||||||
|
|
||||||
|
public:
|
||||||
|
VoidMethod(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature);
|
||||||
|
void call(jobject base, ...);
|
||||||
|
};
|
||||||
|
|
||||||
|
class IntMethod : public Method {
|
||||||
|
|
||||||
|
public:
|
||||||
|
IntMethod(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature);
|
||||||
|
jint call(jobject base, ...);
|
||||||
|
};
|
||||||
|
|
||||||
|
class LongMethod : public Method {
|
||||||
|
|
||||||
|
public:
|
||||||
|
LongMethod(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature);
|
||||||
|
jlong call(jobject base, ...);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* __JNIENVELOPE_H__ */
|
|
@ -17,13 +17,44 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Method.h"
|
#include "JniEnvelope.h"
|
||||||
|
|
||||||
Method::Method(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature) {
|
Method::Method(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature) {
|
||||||
myEnv = env;
|
myEnv = env;
|
||||||
myId = env->GetMethodID(cls, name.c_str(), signature.c_str());
|
myId = env->GetMethodID(cls, name.c_str(), signature.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Method::check() {
|
Method::~Method() {
|
||||||
return myId != 0;
|
}
|
||||||
|
|
||||||
|
VoidMethod::VoidMethod(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature) : Method(env, cls, name, signature + "V") {
|
||||||
|
}
|
||||||
|
|
||||||
|
void VoidMethod::call(jobject base, ...) {
|
||||||
|
va_list lst;
|
||||||
|
va_start(lst, base);
|
||||||
|
myEnv->CallVoidMethod(base, myId, lst);
|
||||||
|
va_end(lst);
|
||||||
|
}
|
||||||
|
|
||||||
|
IntMethod::IntMethod(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature) : Method(env, cls, name, signature + "I") {
|
||||||
|
}
|
||||||
|
|
||||||
|
jint IntMethod::call(jobject base, ...) {
|
||||||
|
va_list lst;
|
||||||
|
va_start(lst, base);
|
||||||
|
jint result = myEnv->CallIntMethod(base, myId, lst);
|
||||||
|
va_end(lst);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
LongMethod::LongMethod(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature) : Method(env, cls, name, signature + "J") {
|
||||||
|
}
|
||||||
|
|
||||||
|
jlong LongMethod::call(jobject base, ...) {
|
||||||
|
va_list lst;
|
||||||
|
va_start(lst, base);
|
||||||
|
jlong result = myEnv->CallLongMethod(base, myId, lst);
|
||||||
|
va_end(lst);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2011-2012 Geometer Plus <contact@geometerplus.com>
|
|
||||||
*
|
|
||||||
* 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 2 of the License, or
|
|
||||||
* (at your option) 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 "VoidMethod.h"
|
|
||||||
|
|
||||||
VoidMethod::VoidMethod(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature) : Method(env, cls, name, signature + "V") {
|
|
||||||
}
|
|
||||||
|
|
||||||
void VoidMethod::call(jobject base, ...) {
|
|
||||||
va_list lst;
|
|
||||||
va_start(lst, base);
|
|
||||||
myEnv->CallVoidMethod(base, myId, lst);
|
|
||||||
va_end(lst);
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2011-2012 Geometer Plus <contact@geometerplus.com>
|
|
||||||
*
|
|
||||||
* 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 2 of the License, or
|
|
||||||
* (at your option) 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __VOIDMETHOD_H__
|
|
||||||
#define __VOIDMETHOD_H__
|
|
||||||
|
|
||||||
#include "Method.h"
|
|
||||||
|
|
||||||
class VoidMethod : public Method {
|
|
||||||
|
|
||||||
public:
|
|
||||||
VoidMethod(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature);
|
|
||||||
void call(jobject base, ...);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* __VOIDMETHOD_H__ */
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "JavaInputStream.h"
|
#include "JavaInputStream.h"
|
||||||
|
|
||||||
#include <AndroidUtil.h>
|
#include <AndroidUtil.h>
|
||||||
|
#include <JniEnvelope.h>
|
||||||
|
|
||||||
JavaInputStream::JavaInputStream(const std::string &name) : myName(name), myNeedRepositionToStart(false) {
|
JavaInputStream::JavaInputStream(const std::string &name) : myName(name), myNeedRepositionToStart(false) {
|
||||||
myJavaFile = 0;
|
myJavaFile = 0;
|
||||||
|
@ -63,7 +63,7 @@ void JavaInputStream::initStream(JNIEnv *env) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void JavaInputStream::closeStream(JNIEnv *env) {
|
void JavaInputStream::closeStream(JNIEnv *env) {
|
||||||
env->CallVoidMethod(myJavaInputStream, AndroidUtil::MID_java_io_InputStream_close);
|
AndroidUtil::Method_java_io_InputStream_close->call(myJavaInputStream);
|
||||||
if (env->ExceptionCheck()) {
|
if (env->ExceptionCheck()) {
|
||||||
env->ExceptionClear();
|
env->ExceptionClear();
|
||||||
}
|
}
|
||||||
|
@ -94,8 +94,8 @@ void JavaInputStream::ensureBufferCapacity(JNIEnv *env, size_t maxSize) {
|
||||||
size_t JavaInputStream::readToBuffer(JNIEnv *env, char *buffer, size_t maxSize) {
|
size_t JavaInputStream::readToBuffer(JNIEnv *env, char *buffer, size_t maxSize) {
|
||||||
ensureBufferCapacity(env, maxSize);
|
ensureBufferCapacity(env, maxSize);
|
||||||
|
|
||||||
jint result = env->CallIntMethod(myJavaInputStream,
|
jint result =
|
||||||
AndroidUtil::MID_java_io_InputStream_read, myJavaBuffer, (jint)0, (jint)maxSize);
|
AndroidUtil::Method_java_io_InputStream_read->call(myJavaInputStream, myJavaBuffer, (jint)0, (jint)maxSize);
|
||||||
if (env->ExceptionCheck()) {
|
if (env->ExceptionCheck()) {
|
||||||
env->ExceptionClear();
|
env->ExceptionClear();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -114,8 +114,8 @@ size_t JavaInputStream::readToBuffer(JNIEnv *env, char *buffer, size_t maxSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t JavaInputStream::skip(JNIEnv *env, size_t offset) {
|
size_t JavaInputStream::skip(JNIEnv *env, size_t offset) {
|
||||||
size_t result = (size_t) env->CallLongMethod(myJavaInputStream,
|
size_t result =
|
||||||
AndroidUtil::MID_java_io_InputStream_skip, (jlong)offset);
|
(size_t)AndroidUtil::Method_java_io_InputStream_skip->call(myJavaInputStream, (jlong)offset);
|
||||||
if (env->ExceptionCheck()) {
|
if (env->ExceptionCheck()) {
|
||||||
env->ExceptionClear();
|
env->ExceptionClear();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue