From c3575589c123feddde3021699b2cfe446573cc93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grisez?= Date: Wed, 3 Sep 2014 17:03:44 +0200 Subject: [PATCH] Add two JNI functions for tunnels manipulation *Add LinphoneCore.tunnelGetServers() *Ass LinphoneCore.tunnelAddServer() --- coreapi/linphone_tunnel.h | 6 --- coreapi/linphonecore_jni.cc | 54 +++++++++++++++++++ .../org/linphone/core/LinphoneCore.java | 12 ++++- .../org/linphone/core/LinphoneCoreImpl.java | 13 +++++ 4 files changed, 78 insertions(+), 7 deletions(-) diff --git a/coreapi/linphone_tunnel.h b/coreapi/linphone_tunnel.h index 336351267..cee0b4fd8 100644 --- a/coreapi/linphone_tunnel.h +++ b/coreapi/linphone_tunnel.h @@ -171,12 +171,6 @@ LINPHONE_PUBLIC bool_t linphone_tunnel_enabled(LinphoneTunnel *tunnel); **/ bool_t linphone_tunnel_connected(LinphoneTunnel *tunnel); -/** - * @param tunnel object - * Returns a boolean indicating whether tunnel is connected successfully. -**/ -bool_t linphone_tunnel_connected(LinphoneTunnel *tunnel); - /** * @param tunnel object * Forces reconnection to the tunnel server. diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index fb244a201..ff2095151 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -3388,6 +3388,60 @@ extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelAddServerAndMirror env->ReleaseStringUTFChars(jHost, cHost); } +extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelAddServer(JNIEnv *env, jobject thiz, jlong pCore, jobject config) { + LinphoneTunnel *tunnel = linphone_core_get_tunnel((LinphoneCore *)pCore); + if(tunnel != NULL) { + jclass TunnelConfigClass = env->FindClass("org/linphone/core/TunnelConfig"); + jmethodID getHostMethod = env->GetMethodID(TunnelConfigClass, "getHost", "()Ljava/lang/String;"); + jmethodID getPortMethod = env->GetMethodID(TunnelConfigClass, "getPort", "()I"); + jmethodID getRemoteUdpMirrorPortMethod = env->GetMethodID(TunnelConfigClass, "getRemoteUdpMirrorPort", "()I"); + jmethodID getDelayMethod = env->GetMethodID(TunnelConfigClass, "getDelay", "()I"); + jstring hostString = (jstring)env->CallObjectMethod(config, getHostMethod); + const char *host = env->GetStringUTFChars(hostString, NULL); + if(host == NULL || strlen(host)==0) { + ms_error("LinphoneCore.tunnelAddServer(): no tunnel host defined"); + } + LinphoneTunnelConfig *tunnelConfig = linphone_tunnel_config_new(); + linphone_tunnel_config_set_host(tunnelConfig, host); + linphone_tunnel_config_set_port(tunnelConfig, env->CallIntMethod(config, getPortMethod)); + linphone_tunnel_config_set_remote_udp_mirror_port(tunnelConfig, env->CallIntMethod(config, getRemoteUdpMirrorPortMethod)); + linphone_tunnel_config_set_delay(tunnelConfig, env->CallIntMethod(config, getDelayMethod)); + linphone_tunnel_add_server(tunnel, tunnelConfig); + env->ReleaseStringUTFChars(hostString, host); + } else { + ms_error("LinphoneCore.tunnelAddServer(): tunnel feature is not enabled"); + } +} + +extern "C" jobjectArray Java_org_linphone_core_LinphoneCoreImpl_tunnelGetServers(JNIEnv *env, jobject thiz, jlong pCore) { + LinphoneTunnel *tunnel = linphone_core_get_tunnel((LinphoneCore *)pCore); + jclass TunnelConfigClass = env->FindClass("org/linphone/core/TunnelConfig"); + jmethodID setHostMethod = env->GetMethodID(TunnelConfigClass, "setHost", "(Ljava/lang/String;)V"); + jmethodID setPortMethod = env->GetMethodID(TunnelConfigClass, "setPort", "(I)V"); + jmethodID setRemoteUdpMirrorPortMethod = env->GetMethodID(TunnelConfigClass, "setRemoteUdpMirrorPort", "(I)V"); + jmethodID setDelayMethod = env->GetMethodID(TunnelConfigClass, "setDelay", "(I)V"); + jobjectArray tunnelConfigArray = NULL; + + if(tunnel != NULL) { + const MSList *servers = linphone_tunnel_get_servers(tunnel); + const MSList *it; + int i; + ms_message("servers=%p", (void *)servers); + ms_message("taille=%i", ms_list_size(servers)); + tunnelConfigArray = env->NewObjectArray(ms_list_size(servers), TunnelConfigClass, NULL); + for(it = servers, i=0; it != NULL; it = it->next, i++) { + const LinphoneTunnelConfig *conf = (const LinphoneTunnelConfig *)it->data; + jobject elt = env->AllocObject(TunnelConfigClass); + env->CallVoidMethod(elt, setHostMethod, env->NewStringUTF(linphone_tunnel_config_get_host(conf))); + env->CallVoidMethod(elt, setPortMethod, linphone_tunnel_config_get_port(conf)); + env->CallVoidMethod(elt, setRemoteUdpMirrorPortMethod, linphone_tunnel_config_get_remote_udp_mirror_port(conf)); + env->CallVoidMethod(elt, setDelayMethod, linphone_tunnel_config_get_delay(conf)); + env->SetObjectArrayElement(tunnelConfigArray, i, elt); + } + } + return tunnelConfigArray; +} + extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelSetHttpProxy(JNIEnv *env,jobject thiz,jlong pCore, jstring jHost, jint port, jstring username, jstring password) { diff --git a/java/common/org/linphone/core/LinphoneCore.java b/java/common/org/linphone/core/LinphoneCore.java index 4a903e187..4bf740b43 100644 --- a/java/common/org/linphone/core/LinphoneCore.java +++ b/java/common/org/linphone/core/LinphoneCore.java @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package org.linphone.core; +import java.util.List; import java.util.Vector; import org.linphone.mediastream.video.AndroidVideoWindowImpl; @@ -1246,6 +1247,16 @@ public interface LinphoneCore { * @param roundTripDelay udp packet round trip delay in ms considered as acceptable. recommended value is 1000 ms */ void tunnelAddServerAndMirror(String host, int port, int udpMirrorPort, int roundTripDelay); + /** + * Add a server to the list of tunnel servers. + * @param config Parameters of the server to add. + */ + void tunnelAddServer(TunnelConfig config); + /** + * Returns a list of configured servers. + * @return Array of server configs. + */ + TunnelConfig[] tunnelGetServers(); boolean isTunnelAvailable(); /** @@ -1640,5 +1651,4 @@ public interface LinphoneCore { * @param value the jitter buffer size in milliseconds. */ public void setVideoJittcomp(int value); - } diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java index b1a7c7bd9..61bfb4e23 100644 --- a/java/impl/org/linphone/core/LinphoneCoreImpl.java +++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java @@ -22,6 +22,7 @@ import static android.media.AudioManager.MODE_IN_CALL; import java.io.File; import java.io.IOException; +import java.util.List; import org.linphone.core.LinphoneCall.State; import org.linphone.mediastream.Log; @@ -750,6 +751,18 @@ class LinphoneCoreImpl implements LinphoneCore { public synchronized void tunnelAddServerAndMirror(String host, int port, int mirror, int ms) { tunnelAddServerAndMirror(nativePtr, host, port, mirror, ms); } + + private native void tunnelAddServer(long nativePtr, TunnelConfig config); + @Override + public synchronized void tunnelAddServer(TunnelConfig config) { + tunnelAddServer(nativePtr, config); + } + + private native final TunnelConfig[] tunnelGetServers(long nativePtr); + @Override + public synchronized final TunnelConfig[] tunnelGetServers() { + return tunnelGetServers(nativePtr); + } private native void tunnelAutoDetect(long nativePtr); @Override