Adrien BĂ©raud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame^] | 1 | #include "logger.h" |
| 2 | |
| 3 | JavaVM *gJavaVM; |
| 4 | const char *ksflphoneservicePath = "cx/ring/service/RingserviceJNI"; |
| 5 | |
| 6 | void deinitClassHelper(JNIEnv *env, jobject obj) { |
| 7 | SFL_INFO("deinitClassHelper"); |
| 8 | |
| 9 | /* delete cached object instances */ |
| 10 | env->DeleteGlobalRef(obj); |
| 11 | SFL_INFO("deinitClassHelper: object %x deleted", obj); |
| 12 | } |
| 13 | |
| 14 | JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { |
| 15 | JNIEnv *env; |
| 16 | jclass clazz; |
| 17 | jint r; |
| 18 | |
| 19 | SFL_INFO("JNI_OnLoad"); |
| 20 | |
| 21 | //Assume it is c++ |
| 22 | r = vm->GetEnv ((void **) &env, JNI_VERSION_1_6); |
| 23 | if (r != JNI_OK) { |
| 24 | RING_ERR("JNI_OnLoad: failed to get the environment using GetEnv()"); |
| 25 | return -1; |
| 26 | } |
| 27 | SFL_INFO("JNI_Onload: GetEnv %p", env); |
| 28 | |
| 29 | clazz = env->FindClass (ksflphoneservicePath); |
| 30 | if (!clazz) { |
| 31 | RING_ERR("JNI_Onload: whoops, %s class not found!", ksflphoneservicePath); |
| 32 | } |
| 33 | gJavaVM = vm; |
| 34 | SFL_INFO("JNI_Onload: JavaVM %p", gJavaVM); |
| 35 | |
| 36 | /* put instances of class object we need into cache */ |
| 37 | //initClassHelper(env, kManagerPath, &gManagerObject); |
| 38 | |
| 39 | JNINativeMethod methods[] = { |
| 40 | |
| 41 | $defs |
| 42 | |
| 43 | }; |
| 44 | |
| 45 | r = env->RegisterNatives (clazz, methods, (int) (sizeof(methods) / sizeof(methods[0]))); |
| 46 | return JNI_VERSION_1_6; |
| 47 | } |
| 48 | |
| 49 | void JNI_OnUnLoad(JavaVM* vm, void* reserved) { |
| 50 | JNIEnv* env; |
| 51 | jclass clazz; |
| 52 | |
| 53 | SFL_INFO("JNI_OnUnLoad"); |
| 54 | |
| 55 | /* get env */ |
| 56 | if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { |
| 57 | RING_ERR("JNI_OnUnLoad: failed to get the environment using GetEnv()"); |
| 58 | return; |
| 59 | } |
| 60 | SFL_INFO("JNI_OnUnLoad: GetEnv %p", env); |
| 61 | |
| 62 | /* Get jclass with env->FindClass */ |
| 63 | clazz = env->FindClass(ksflphoneservicePath); |
| 64 | if (!clazz) { |
| 65 | RING_ERR("JNI_OnUnLoad: whoops, %s class not found!", ksflphoneservicePath); |
| 66 | } |
| 67 | |
| 68 | /* remove instances of class object we need into cache */ |
| 69 | //deinitClassHelper(env, gManagerObject); |
| 70 | |
| 71 | env->UnregisterNatives(clazz); |
| 72 | SFL_INFO("JNI_OnUnLoad: Native functions unregistered"); |
| 73 | } |