Commit 81cb36b084bacbd496115c94902712847c8dc786
1 parent
7ba5974b
removed jni
Showing
2 changed files
with
0 additions
and
115 deletions
openbr/plugins/cmake/jni.cmake deleted
| 1 | -set(BR_WITH_JAVA OFF CACHE BOOL "Use Java Code") | |
| 2 | - | |
| 3 | -if (${BR_WITH_JAVA}) | |
| 4 | - find_package(JNI REQUIRED) | |
| 5 | - find_package(JAVA REQUIRED) | |
| 6 | - set(BR_THIRDPARTY_LIBS ${BR_THIRDPARTY_LIBS} ${JNI_LIBRARIES}) | |
| 7 | - | |
| 8 | - include_directories(${JAVA_INCLUDE_PATH}) | |
| 9 | - include_directories(${JAVA_INCLUDE_PATH2}) | |
| 10 | -else() | |
| 11 | - set(BR_EXCLUDED_PLUGINS ${BR_EXCLUDED_PLUGINS} plugins/core/jni.cpp) | |
| 12 | -endif() |
openbr/plugins/core/jni.cpp deleted
| 1 | -//Need to include location of jvm.dll (jdk version) and its parent directory in the environment variables | |
| 2 | - | |
| 3 | -#include <limits> | |
| 4 | -#include <openbr/plugins/openbr_internal.h> | |
| 5 | -#include <openbr/core/resource.h> | |
| 6 | -#include <jni.h> | |
| 7 | - | |
| 8 | -namespace br | |
| 9 | -{ | |
| 10 | - | |
| 11 | -/*! | |
| 12 | - * \ingroup initializers | |
| 13 | - * \brief Initialize JNI | |
| 14 | - * \author Jordan Cheney \cite jcheney | |
| 15 | - */ | |
| 16 | -class JNIInitializer : public Initializer | |
| 17 | -{ | |
| 18 | - Q_OBJECT | |
| 19 | - public: | |
| 20 | - static JavaVM* jvm; | |
| 21 | - static JavaVMInitArgs vm_args; | |
| 22 | - | |
| 23 | - void initialize() const | |
| 24 | - { | |
| 25 | - JNIEnv *env; | |
| 26 | - JavaVMOption options[1]; | |
| 27 | - | |
| 28 | - //Location of Java files | |
| 29 | - QByteArray classpath = QString("-Djava.class.path=").append(Globals->sdkPath).append(QString("/share/openbr/Java/jniLibraries/")).toLocal8Bit(); | |
| 30 | - char *charClasspath = classpath.data(); | |
| 31 | - | |
| 32 | - options[0].optionString = charClasspath; | |
| 33 | - vm_args.version = JNI_VERSION_1_6; | |
| 34 | - vm_args.nOptions = 1; | |
| 35 | - vm_args.options = options; | |
| 36 | - vm_args.ignoreUnrecognized = JNI_FALSE; | |
| 37 | - | |
| 38 | - JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); | |
| 39 | - | |
| 40 | - Globals->abbreviations.insert("JNIHelloWorld","Open+JNI(HelloWorld)"); | |
| 41 | - } | |
| 42 | - | |
| 43 | - void finalize() const | |
| 44 | - { | |
| 45 | - jvm->DestroyJavaVM(); | |
| 46 | - } | |
| 47 | -}; | |
| 48 | - | |
| 49 | -JavaVM *JNIInitializer::jvm; | |
| 50 | -JavaVMInitArgs JNIInitializer::vm_args; | |
| 51 | - | |
| 52 | -BR_REGISTER(Initializer, JNIInitializer) | |
| 53 | - | |
| 54 | -/*! | |
| 55 | - * \ingroup transforms | |
| 56 | - * \brief Execute Java code from OpenBR using the JNI | |
| 57 | - * \author Jordan Cheney \cite jcheney | |
| 58 | - */ | |
| 59 | -class JNITransform : public UntrainableTransform | |
| 60 | -{ | |
| 61 | - Q_OBJECT | |
| 62 | - Q_PROPERTY(QString className READ get_className WRITE set_className RESET reset_className STORED false) | |
| 63 | - BR_PROPERTY(QString, className, "") | |
| 64 | - | |
| 65 | - void project(const Template &src, Template &dst) const | |
| 66 | - { | |
| 67 | - (void)dst; //Eliminates a compiler warning. | |
| 68 | - | |
| 69 | - JNIEnv *env; | |
| 70 | - | |
| 71 | - //Attach current thread to the thread of the JavaVM and access env | |
| 72 | - JNIInitializer::jvm->AttachCurrentThreadAsDaemon((void**)&env, NULL); | |
| 73 | - if (JNIInitializer::jvm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { | |
| 74 | - qFatal("Failed to initialize JNI environment"); | |
| 75 | - } | |
| 76 | - | |
| 77 | - //Convert QString to const char* | |
| 78 | - QByteArray tmpClass = className.toLocal8Bit(); | |
| 79 | - const char* charClassName = tmpClass.constData(); | |
| 80 | - | |
| 81 | - //Call java method | |
| 82 | - jclass cls = env->FindClass(charClassName); | |
| 83 | - if (cls == NULL) { qFatal("Class not found"); } | |
| 84 | - jmethodID mid = env->GetStaticMethodID(cls, "project", "(Ljava/lang/String;)V"); | |
| 85 | - if (mid == NULL) { qFatal("MethodID not found"); } | |
| 86 | - | |
| 87 | - QByteArray tmp = src.file.name.toLocal8Bit(); | |
| 88 | - const char* fileName = tmp.constData(); | |
| 89 | - | |
| 90 | - //Convert char* to java compatible string | |
| 91 | - jstring jfileName = env->NewStringUTF(fileName); | |
| 92 | - | |
| 93 | - env->CallStaticObjectMethod(cls, mid, jfileName); | |
| 94 | - | |
| 95 | - JNIInitializer::jvm->DetachCurrentThread(); | |
| 96 | - } | |
| 97 | -}; | |
| 98 | - | |
| 99 | -BR_REGISTER(Transform, JNITransform) | |
| 100 | - | |
| 101 | -} // namespace br | |
| 102 | - | |
| 103 | -#include "jni.moc" |