Steven Thomas | 054f235 | 2017-05-09 14:48:37 -0700 | [diff] [blame] | 1 | #include <dlfcn.h> |
| 2 | #include <jni.h> |
| 3 | |
| 4 | #include <string> |
| 5 | |
| 6 | extern "C" { |
| 7 | |
| 8 | JNIEXPORT jlong JNICALL |
| 9 | Java_com_google_vr_platform_Dvr_nativeLoadLibrary( |
| 10 | JNIEnv* env, jclass, jstring java_library) { |
| 11 | if (!java_library) |
| 12 | return 0; |
| 13 | |
| 14 | // Convert the Java String object to a C++ null-terminated string. |
| 15 | const char* data = env->GetStringUTFChars(java_library, NULL); |
| 16 | size_t size = env->GetStringUTFLength(java_library); |
| 17 | std::string library(data, size); |
| 18 | env->ReleaseStringUTFChars(java_library, data); |
| 19 | |
| 20 | // Return the handle to the requested library. |
| 21 | return reinterpret_cast<jlong>( |
| 22 | dlopen(library.c_str(), RTLD_NOW | RTLD_LOCAL)); |
| 23 | } |
| 24 | |
| 25 | } // extern "C" |