Commit c3575589 authored by François Grisez's avatar François Grisez
Browse files

Add two JNI functions for tunnels manipulation

*Add LinphoneCore.tunnelGetServers()
*Ass LinphoneCore.tunnelAddServer()
parent 46b4817a
......@@ -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.
......
......@@ -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) {
......
......@@ -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);
}
......@@ -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
......
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