说明
这个很短, 自己看。
native函数
private native long newPresenceNoteImpl(String content, String lang);
private native void unref(long nativePtr);
private native String getContent(long nativePtr);
private native int setContent(long nativePtr, String content);
private native String getLang(long nativePtr);
private native int setLang(long nativePtr, String lang);
具体的函数分析
newPresenceNoteImpl
/*
* Class: org_linphone_core_PresenceNoteImpl
* Method: newPresenceNoteImpl
* Signature: (Ljava/lang/String;Ljava/lang/String;)J
*/
JNIEXPORT jlong JNICALL Java_org_linphone_core_PresenceNoteImpl_newPresenceNoteImpl(JNIEnv *env, jobject jobj, jstring content, jstring lang) {
LinphonePresenceNote *note;
const char *ccontent = content ? env->GetStringUTFChars(content, NULL) : NULL;
const char *clang = lang ? env->GetStringUTFChars(lang, NULL) : NULL;
note = linphone_presence_note_new(ccontent, clang);
note = linphone_presence_note_ref(note);
if (clang) env->ReleaseStringUTFChars(lang, clang);
if (ccontent) env->ReleaseStringUTFChars(content, ccontent);
return (jlong)note;
}
linphone_presence_note_new
LinphonePresenceNote * linphone_presence_note_new(const char *content, const char *lang) {
LinphonePresenceNote *note;
if (content == NULL) return NULL;
note = ms_new0(LinphonePresenceNote, 1);
note->refcnt = 1;
note->content = ms_strdup(content);
if (lang != NULL) {
note->lang = ms_strdup(lang);
}
return note;
}
linphone_presence_note_ref
LinphonePresenceNote * linphone_presence_note_ref(LinphonePresenceNote *note) {
note->refcnt++;
return note;
}
unref
/*
* Class: org_linphone_core_PresenceNoteImpl
* Method: unref
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_org_linphone_core_PresenceNoteImpl_unref(JNIEnv *env, jobject jobj, jlong ptr) {
LinphonePresenceNote *note = (LinphonePresenceNote *)ptr;
linphone_presence_note_unref(note);
}
linphone_presence_note_unref
LinphonePresenceNote * linphone_presence_note_unref(LinphonePresenceNote *note) {
note->refcnt--;
if (note->refcnt == 0) {
presence_note_delete(note);
return NULL;
}
return note;
}
presence_note_delete
static void presence_note_delete(LinphonePresenceNote *note) {
ms_free(note->content);
if (note->lang != NULL) {
ms_free(note->lang);
}
ms_free(note);
}
getContent
/*
* Class: org_linphone_core_PresenceNoteImpl
* Method: getContent
* Signature: (J)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_linphone_core_PresenceNoteImpl_getContent(JNIEnv *env, jobject jobj, jlong ptr) {
LinphonePresenceNote *note = (LinphonePresenceNote *)ptr;
const char *ccontent = linphone_presence_note_get_content(note);
return ccontent ? env->NewStringUTF(ccontent) : NULL;
}
linphone_presence_note_get_content
const char * linphone_presence_note_get_content(const LinphonePresenceNote *note) {
if (note == NULL)
return NULL;
return note->content;
}
setContent
/*
* Class: org_linphone_core_PresenceNoteImpl
* Method: setContent
* Signature: (JLjava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_linphone_core_PresenceNoteImpl_setContent(JNIEnv *env, jobject jobj, jlong ptr, jstring content) {
LinphonePresenceNote *note = (LinphonePresenceNote *)ptr;
const char *ccontent = content ? env->GetStringUTFChars(content, NULL) : NULL;
linphone_presence_note_set_content(note, ccontent);
if (ccontent) env->ReleaseStringUTFChars(content, ccontent);
return (jint)0;
}
linphone_presence_note_set_content
int linphone_presence_note_set_content(LinphonePresenceNote *note, const char *content) {
if (content == NULL) return -1;
if (note->content != NULL) {
ms_free(note->content);
}
note->content = ms_strdup(content);
return 0;
}
getLang
/*
* Class: org_linphone_core_PresenceNoteImpl
* Method: getLang
* Signature: (J)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_linphone_core_PresenceNoteImpl_getLang(JNIEnv *env, jobject jobj, jlong ptr) {
LinphonePresenceNote *note = (LinphonePresenceNote *)ptr;
const char *clang = linphone_presence_note_get_lang(note);
return clang ? env->NewStringUTF(clang) : NULL;
}
linphone_presence_note_get_lang
const char * linphone_presence_note_get_lang(const LinphonePresenceNote *note) {
if (note == NULL)
return NULL;
return note->lang;
}
setLang
/*
* Class: org_linphone_core_PresenceNoteImpl
* Method: setLang
* Signature: (JLjava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_org_linphone_core_PresenceNoteImpl_setLang(JNIEnv *env, jobject jobj, jlong ptr, jstring lang) {
LinphonePresenceNote *note = (LinphonePresenceNote *)ptr;
const char *clang = lang ? env->GetStringUTFChars(lang, NULL) : NULL;
linphone_presence_note_set_lang(note, clang);
if (clang) env->ReleaseStringUTFChars(lang, clang);
return (jint)0;
}
linphone_presence_note_set_lang
int linphone_presence_note_set_lang(LinphonePresenceNote *note, const char *lang) {
if (note->lang != NULL) {
ms_free(note->lang);
note->lang = NULL;
}
if (lang != NULL) {
note->lang = ms_strdup(lang);
}
return 0;
}