Commit faa60922 authored by Simon Morlat's avatar Simon Morlat
Browse files

fix crashes in android when doing things with LinphoneCore within the globalStateChanged callbacks.

Add wrappers for the http proxy api.
parent eb172d10
......@@ -659,6 +659,15 @@ public:
env->DeleteLocalRef(d);
}
}
static void setCoreIfNotDone(JNIEnv *env, jobject jcore, LinphoneCore *lc){
jclass objClass = env->GetObjectClass(jcore);
jfieldID myFieldID = env->GetFieldID(objClass, "nativePtr", "J");
jlong fieldVal = env->GetLongField(jcore, myFieldID);
if (fieldVal == 0){
env->SetLongField(jcore, myFieldID, (jlong)lc);
}
}
static void globalStateChange(LinphoneCore *lc, LinphoneGlobalState gstate,const char* message) {
JNIEnv *env = 0;
jint result = jvm->AttachCurrentThread(&env,NULL);
......@@ -668,6 +677,11 @@ public:
}
LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc);
LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table);
jobject jcore = lcData->core;
/*at this stage, the java object may not be aware of its C object, because linphone_core_new() hasn't returned yet.*/
setCoreIfNotDone(env,jcore, lc);
jstring msg = message ? env->NewStringUTF(message) : NULL;
env->CallVoidMethod(lcData->listener
,lcData->globalStateId
......@@ -6475,3 +6489,44 @@ JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneCallLogImpl_getCallId(J
return str ? env->NewStringUTF(str) : NULL;
}
/*
* Class: org_linphone_core_LinphoneCoreImpl
* Method: setHttpProxyHost
* Signature: (JLjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneCoreImpl_setHttpProxyHost(JNIEnv *env, jobject jobj, jlong core, jstring jhost){
const char *host = jhost ? env->GetStringUTFChars(jhost, NULL) : NULL;
linphone_core_set_http_proxy_host((LinphoneCore*)core, host);
if (host) env->ReleaseStringUTFChars(jhost, host);
}
/*
* Class: org_linphone_core_LinphoneCoreImpl
* Method: setHttpProxyPort
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneCoreImpl_setHttpProxyPort(JNIEnv *env, jobject jobj, jlong core, jint port){
linphone_core_set_http_proxy_port((LinphoneCore*)core, port);
}
/*
* Class: org_linphone_core_LinphoneCoreImpl
* Method: getHttpProxyHost
* Signature: (J)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneCoreImpl_getHttpProxyHost(JNIEnv *env , jobject jobj, jlong core){
const char * host = linphone_core_get_http_proxy_host((LinphoneCore *)core);
return host ? env->NewStringUTF(host) : NULL;
}
/*
* Class: org_linphone_core_LinphoneCoreImpl
* Method: getHttpProxyPort
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneCoreImpl_getHttpProxyPort(JNIEnv *env, jobject jobj, jlong core){
return linphone_core_get_http_proxy_port((LinphoneCore *)core);
}
......@@ -2179,4 +2179,22 @@ public interface LinphoneCore {
* Get the provisioning URI previously set.
**/
public String getProvisioningUri();
/**
* Set an http proxy hostname or IP address to use for SIP connection.
*/
public void setHttpProxyHost(String host);
/**
* Set an http proxy port to use for SIP connection.
*/
public void setHttpProxyPort(int port);
/**
* Get the http proxy host previously set.
**/
public String getHttpProxyHost();
/**
* Get the http proxy port previously set.
**/
public int getHttpProxyPort();
}
......@@ -1535,4 +1535,27 @@ class LinphoneCoreImpl implements LinphoneCore {
public GlobalState getGlobalState(){
return GlobalState.fromInt(getGlobalState(nativePtr));
}
private native void setHttpProxyHost(long nativePtr, String host);
@Override
public void setHttpProxyHost(String host){
setHttpProxyHost(nativePtr, host);
}
private native void setHttpProxyPort(long nativePtr, int port);
@Override
public void setHttpProxyPort(int port){
setHttpProxyPort(nativePtr, port);
}
private native String getHttpProxyHost(long nativePtr);
@Override
public String getHttpProxyHost(){
return getHttpProxyHost(nativePtr);
}
private native int getHttpProxyPort(long nativePtr);
@Override
public int getHttpProxyPort(){
return getHttpProxyPort(nativePtr);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment