File: OpenCVLibraryInfo.cpp

package info (click to toggle)
opencv 2.4.9.1%2Bdfsg-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 126,800 kB
  • ctags: 62,729
  • sloc: xml: 509,055; cpp: 490,794; lisp: 23,208; python: 21,174; java: 19,317; ansic: 1,038; sh: 128; makefile: 72
file content (88 lines) | stat: -rw-r--r-- 2,197 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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)
{
    InfoFunctionType info_func;
    const char* result;
    const char* error;

    dlerror();
    info_func = (InfoFunctionType)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)
{
    InfoFunctionType info_func;
    const char* result;
    const char* error;

    dlerror();
    info_func = (InfoFunctionType)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)
{
    InfoFunctionType info_func;
    const char* result;
    const char* error;

    dlerror();
    info_func = (InfoFunctionType)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);
}