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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| // Added by guodongAndroid on 2022/04/22 #ifdef __ANDROID__ static pthread_mutex_t mutex; #endif /* __ANDROID__ */
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *ajvm, void *reserved) { #ifdef __ANDROID__ ms_set_jvm(ajvm); int result = pthread_mutex_init(&mutex, NULL); __android_log_print(ANDROID_LOG_DEBUG, "guodongAndroid", "JNI_OnLoad, mutex init result = %d", result); #endif /* __ANDROID__ */ jvm = ajvm; return JNI_VERSION_1_2; }
// Added by guodongAndroid on 2022/04/22 JNIEXPORT void JNI_OnUnload(JavaVM *ajvm, void *reserved) { #ifdef __ANDROID__ int result = pthread_mutex_destroy(&mutex); __android_log_print(ANDROID_LOG_DEBUG, "guodongAndroid", "JNI_OnUnload, mutex destroy result = %d", result); #endif /* __ANDROID__ */ }
{{#objects}} JNIEXPORT jobject JNICALL get{{className}}(JNIEnv *env, {{classCName}} *cptr, bool_t takeref) { jobject jobj = nullptr;
if (cptr != nullptr) { // begin add {{#isLoggingService}} #ifdef __ANDROID__ pthread_mutex_lock(&mutex); #endif /* __ANDROID__ */ {{/isLoggingService}} // end add void *up = belle_sip_object_data_get((belle_sip_object_t *)cptr, belle_sip_java_user_data_key); LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_factory_get_user_data(linphone_factory_get()); if (!ljb) { ljb = new LinphoneJavaBindings(env); linphone_factory_set_user_data(linphone_factory_get(), ljb); }
jclass {{cPrefix}}_class = ljb->{{cPrefix}}_class; jmethodID {{cPrefix}}_constructor = ljb->{{cPrefix}}_class_constructor;
{{#isLoggingService}} #ifdef __ANDROID__ __android_log_print(ANDROID_LOG_DEBUG, "guodongAndroid", "up = %p", up); jobject temp_jobj1 = (jobject)up; jboolean up_available1 = env->IsSameObject(temp_jobj1, NULL); __android_log_print(ANDROID_LOG_DEBUG, "guodongAndroid", "up_available1 = %d", up_available1); jobject temp_jobj2 = (jobject)up; jboolean up_available2 = env->IsSameObject(temp_jobj2, nullptr); __android_log_print(ANDROID_LOG_DEBUG, "guodongAndroid", "up_available2 = %d", up_available2); #endif /* __ANDROID__ */ {{/isLoggingService}}
if (up == nullptr) { jobj = env->NewObject({{cPrefix}}_class, {{cPrefix}}_constructor, (jlong)cptr); belle_sip_object_data_set((belle_sip_object_t *)cptr, belle_sip_java_user_data_key, (void*)env->NewWeakGlobalRef(jobj), nullptr); if (takeref) {{#refCountable}}{{cPrefix}}_ref(cptr);{{/refCountable}} } else { jobj = env->NewLocalRef((jobject)up); if (jobj == nullptr) { // Delete weak ref ? env->DeleteWeakGlobalRef((jobject)up); // takes implicit local ref jobj = env->NewObject({{cPrefix}}_class, {{cPrefix}}_constructor, (jlong)cptr); belle_sip_object_data_set((belle_sip_object_t *)cptr, belle_sip_java_user_data_key, (void*)env->NewWeakGlobalRef(jobj), nullptr); if (takeref) {{#refCountable}}{{cPrefix}}_ref(cptr);{{/refCountable}} } } // begin add {{#isLoggingService}} pthread_mutex_unlock(&mutex); {{/isLoggingService}} // end add } return jobj; }
JNIEXPORT jboolean JNICALL Java_{{jniPrefix}}{{classImplName}}_unref(JNIEnv* env, jobject thiz, jlong ptr) { {{classCName}} *cptr = ({{classCName}}*)ptr; if (cptr == 0) { bctbx_error("Java_{{jniPrefix}}{{classImplName}}_unref's {{classCName}} C ptr is null!"); return TRUE; }
// begin add {{#isLoggingService}} #ifdef __ANDROID__ pthread_mutex_lock(&mutex); #endif /* __ANDROID__ */ {{/isLoggingService}} // end add jobject wref = (jobject)belle_sip_object_data_get((belle_sip_object_t *)cptr, belle_sip_java_user_data_key);
{{#isLoggingService}} #ifdef __ANDROID__ __android_log_print(ANDROID_LOG_DEBUG, "guodongAndroid", "unref wref = %p", wref); #endif /* __ANDROID__ */ {{/isLoggingService}}
belle_sip_object_data_set((belle_sip_object_t *)cptr, belle_sip_java_user_data_key, nullptr, nullptr); if (wref) { env->DeleteWeakGlobalRef(wref); } // begin add {{#isLoggingService}} pthread_mutex_unlock(&mutex); {{/isLoggingService}} // end add {{#refCountable}}return belle_sip_object_unref_2(cptr) == 1;{{/refCountable}} {{#notRefCountable}}return FALSE;{{/notRefCountable}} }
|