mirror of https://github.com/opencv/opencv.git
Merge pull request #204 from asmorkalov/manager_internal_lib
Feature #2565 implementationpull/212/merge
commit
2bf56961c0
9 changed files with 243 additions and 28 deletions
@ -0,0 +1,88 @@ |
||||
#include "OpenCVLibraryInfo.h" |
||||
#include "EngineCommon.h" |
||||
#include <utils/Log.h> |
||||
#include <dlfcn.h> |
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_open |
||||
(JNIEnv * env, jobject, jstring str) |
||||
{ |
||||
const char* infoLibPath = env->GetStringUTFChars(str, NULL); |
||||
if (infoLibPath == NULL) |
||||
return 0; |
||||
|
||||
LOGD("Trying to load info library \"%s\"", infoLibPath); |
||||
|
||||
void* handle; |
||||
|
||||
handle = dlopen(infoLibPath, RTLD_LAZY); |
||||
if (handle == NULL) |
||||
LOGI("Info library not found by path \"%s\"", infoLibPath); |
||||
|
||||
return (jlong)handle; |
||||
} |
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_getPackageName |
||||
(JNIEnv* env, jobject, jlong handle) |
||||
{ |
||||
const char* (*info_func)(); |
||||
const char* result; |
||||
const char* error; |
||||
|
||||
dlerror(); |
||||
*(void **) (&info_func) = dlsym((void*)handle, "GetPackageName"); |
||||
if ((error = dlerror()) == NULL) |
||||
result = (*info_func)(); |
||||
else |
||||
{ |
||||
LOGE("dlsym error: \"%s\"", error); |
||||
result = "unknown"; |
||||
} |
||||
|
||||
return env->NewStringUTF(result); |
||||
} |
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_getLibraryList |
||||
(JNIEnv* env, jobject, jlong handle) |
||||
{ |
||||
const char* (*info_func)(); |
||||
const char* result; |
||||
const char* error; |
||||
|
||||
dlerror(); |
||||
*(void **) (&info_func) = dlsym((void*)handle, "GetLibraryList"); |
||||
if ((error = dlerror()) == NULL) |
||||
result = (*info_func)(); |
||||
else |
||||
{ |
||||
LOGE("dlsym error: \"%s\"", error); |
||||
result = "unknown"; |
||||
} |
||||
|
||||
return env->NewStringUTF(result); |
||||
} |
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_getVersionName |
||||
(JNIEnv* env, jobject, jlong handle) |
||||
{ |
||||
const char* (*info_func)(); |
||||
const char* result; |
||||
const char* error; |
||||
|
||||
dlerror(); |
||||
*(void **) (&info_func) = dlsym((void*)handle, "GetRevision"); |
||||
if ((error = dlerror()) == NULL) |
||||
result = (*info_func)(); |
||||
else |
||||
{ |
||||
LOGE("dlsym error: \"%s\"", error); |
||||
result = "unknown"; |
||||
} |
||||
|
||||
return env->NewStringUTF(result); |
||||
} |
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_close |
||||
(JNIEnv*, jobject, jlong handle) |
||||
{ |
||||
dlclose((void*)handle); |
||||
} |
@ -0,0 +1,27 @@ |
||||
#include <jni.h> |
||||
|
||||
#ifndef _Included_org_opencv_engine_OpenCVLibraryInfo |
||||
#define _Included_org_opencv_engine_OpenCVLibraryInfo |
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
JNIEXPORT jlong JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_open |
||||
(JNIEnv *, jobject, jstring); |
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_getPackageName |
||||
(JNIEnv *, jobject, jlong); |
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_getLibraryList |
||||
(JNIEnv *, jobject, jlong); |
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_getVersionName |
||||
(JNIEnv *, jobject, jlong); |
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_close |
||||
(JNIEnv *, jobject, jlong); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
#endif |
@ -0,0 +1,40 @@ |
||||
package org.opencv.engine; |
||||
|
||||
public class OpenCVLibraryInfo { |
||||
public OpenCVLibraryInfo(String packagePath) { |
||||
mNativeObj = open(packagePath + "/libopencv_info.so"); |
||||
if (mNativeObj != 0) { |
||||
mPackageName = getPackageName(mNativeObj); |
||||
mLibraryList = getLibraryList(mNativeObj); |
||||
mVersionName = getVersionName(mNativeObj); |
||||
close(mNativeObj); |
||||
} |
||||
} |
||||
|
||||
public boolean status() { |
||||
return (mNativeObj != 0); |
||||
} |
||||
|
||||
public String packageName() { |
||||
return mPackageName; |
||||
} |
||||
|
||||
public String libraryList() { |
||||
return mLibraryList; |
||||
} |
||||
|
||||
public String versionName() { |
||||
return mVersionName; |
||||
} |
||||
|
||||
private long mNativeObj; |
||||
private String mPackageName; |
||||
private String mLibraryList; |
||||
private String mVersionName; |
||||
|
||||
private native long open(String packagePath); |
||||
private native String getPackageName(long obj); |
||||
private native String getLibraryList(long obj); |
||||
private native String getVersionName(long obj); |
||||
private native void close(long obj); |
||||
} |
Loading…
Reference in new issue