1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 02:09:35 +02:00

VoidMethod: in progress

This commit is contained in:
Nikolay Pultsin 2012-03-29 18:45:05 +01:00
parent cf9abfb502
commit 36d85ecbff
7 changed files with 85 additions and 11 deletions

View file

@ -41,6 +41,7 @@ LOCAL_SRC_FILES := \
NativeFormats/JavaNativeFormatPlugin.cpp \
NativeFormats/JavaPluginCollection.cpp \
NativeFormats/util/AndroidUtil.cpp \
NativeFormats/util/Method.cpp \
NativeFormats/util/VoidMethod.cpp \
NativeFormats/zlibrary/core/src/constants/ZLXMLNamespace.cpp \
NativeFormats/zlibrary/core/src/encoding/DummyEncodingConverter.cpp \

View file

@ -55,7 +55,7 @@ jmethodID AndroidUtil::MID_java_io_InputStream_close;
jmethodID AndroidUtil::MID_java_io_InputStream_read;
jmethodID AndroidUtil::MID_java_io_InputStream_skip;
jmethodID AndroidUtil::MID_java_io_PrintStream_println;
VoidMethod AndroidUtil::MID_java_io_PrintStream_println;
jmethodID AndroidUtil::SMID_ZLibrary_Instance;
jmethodID AndroidUtil::MID_ZLibrary_getVersionName;
@ -119,6 +119,7 @@ JNIEnv *AndroidUtil::getEnv() {
}
#define CHECK_NULL(value) if ((value) == 0) { return false; }
#define CHECK_METHOD(method) if (!(method).check()) { return false; }
bool AndroidUtil::init(JavaVM* jvm) {
ourJavaVM = jvm;

View file

@ -25,6 +25,8 @@
#include <string>
#include <vector>
#include "VoidMethod.h"
class ZLFile;
class ZLFileImage;
@ -65,7 +67,7 @@ public:
static jmethodID MID_java_io_InputStream_read;
static jmethodID MID_java_io_InputStream_skip;
static jmethodID MID_java_io_PrintStream_println;
static VoidMethod MID_java_io_PrintStream_println;
static jmethodID SMID_ZLibrary_Instance;
static jmethodID MID_ZLibrary_getVersionName;

View file

@ -0,0 +1,29 @@
/*
* 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 "Method.h"
Method::Method(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature) {
myEnv = env;
myId = env->GetMethodID(cls, name.c_str(), signature.c_str());
}
bool Method::check() {
return myId != 0;
}

View file

@ -0,0 +1,38 @@
/*
* 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 __METHOD_H__
#define __METHOD_H__
#include <jni.h>
#include <string>
class Method {
public:
Method(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature);
bool check();
protected:
JNIEnv *myEnv;
jmethodID myId;
};
#endif /* __METHOD_H__ */

View file

@ -19,7 +19,12 @@
#include "VoidMethod.h"
void VoidMethod::call(JNIEnv *env, jobject base, ...) {
va_start(args);
env->CallVoidMethod(base, myId, va_list);
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);
}

View file

@ -20,15 +20,13 @@
#ifndef __VOIDMETHOD_H__
#define __VOIDMETHOD_H__
#include <jni.h>
#include "Method.h"
class VoidMethod {
class VoidMethod : public Method {
public:
void call(JNIEnv *env, jobject base, ...);
private:
jmethodID myId;
VoidMethod(JNIEnv *env, jclass cls, const std::string &name, const std::string &signature);
void call(jobject base, ...);
};
#endif /* __VOIDMETHOD_H__ */