opencv/android/service/engine/jni/JNIWrapper/OpenCVLibraryInfo.cpp

89 lines
2.1 KiB
C++
Raw Normal View History

#include "OpenCVLibraryInfo.h"
2012-12-04 20:34:53 +08:00
#include "EngineCommon.h"
#include <utils/Log.h>
#include <dlfcn.h>
JNIEXPORT jlong JNICALL Java_org_opencv_engine_OpenCVLibraryInfo_open
2012-12-04 20:34:53 +08:00
(JNIEnv * env, jobject, jstring str)
{
2012-12-04 20:34:53 +08:00
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
2012-12-04 20:34:53 +08:00
(JNIEnv* env, jobject, jlong handle)
{
InfoFunctionType info_func;
2012-12-04 20:34:53 +08:00
const char* result;
const char* error;
dlerror();
info_func = (InfoFunctionType)dlsym((void*)handle, "GetPackageName");
2012-12-04 20:34:53 +08:00
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
2012-12-04 20:34:53 +08:00
(JNIEnv* env, jobject, jlong handle)
{
InfoFunctionType info_func;
2012-12-04 20:34:53 +08:00
const char* result;
const char* error;
dlerror();
info_func = (InfoFunctionType)dlsym((void*)handle, "GetLibraryList");
2012-12-04 20:34:53 +08:00
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
2012-12-04 20:34:53 +08:00
(JNIEnv* env, jobject, jlong handle)
{
InfoFunctionType info_func;
2012-12-04 20:34:53 +08:00
const char* result;
const char* error;
dlerror();
info_func = (InfoFunctionType)dlsym((void*)handle, "GetRevision");
2012-12-04 20:34:53 +08:00
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
2012-12-04 20:34:53 +08:00
(JNIEnv*, jobject, jlong handle)
{
2012-12-04 20:34:53 +08:00
dlclose((void*)handle);
}