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

rework TunnelConfig java wrapper to make it state of art and in the public interfaces.

parent a5938f1a
......@@ -162,7 +162,7 @@ static void linphone_tunnel_add_server_intern(LinphoneTunnel *tunnel, LinphoneTu
linphone_tunnel_config_get_remote_udp_mirror_port(tunnel_config),
linphone_tunnel_config_get_delay(tunnel_config));
}
tunnel->config_list = ms_list_append(tunnel->config_list, tunnel_config);
tunnel->config_list = ms_list_append(tunnel->config_list, linphone_tunnel_config_ref(tunnel_config));
}
......@@ -211,7 +211,7 @@ void linphone_tunnel_remove_server(LinphoneTunnel *tunnel, LinphoneTunnelConfig
MSList *elem = ms_list_find(tunnel->config_list, tunnel_config);
if(elem != NULL) {
tunnel->config_list = ms_list_remove(tunnel->config_list, tunnel_config);
linphone_tunnel_config_destroy(tunnel_config);
linphone_tunnel_config_unref(tunnel_config);
linphone_tunnel_refresh_config(tunnel);
linphone_tunnel_save_config(tunnel);
}
......
......@@ -196,6 +196,20 @@ LINPHONE_PUBLIC void linphone_tunnel_config_unref(LinphoneTunnelConfig *cfg);
*/
LINPHONE_PUBLIC void linphone_tunnel_config_destroy(LinphoneTunnelConfig *tunnel);
/**
* Store a user data in the tunnel config object
* @param cfg the tunnel config
* @param ud the user data
**/
LINPHONE_PUBLIC void linphone_tunnel_config_set_user_data(LinphoneTunnelConfig *cfg, void *ud);
/**
* Retrieve user data from the tunnel config
* @param cfg the tunnel config
* @return the user data
**/
LINPHONE_PUBLIC void *linphone_tunnel_config_get_user_data(LinphoneTunnelConfig *cfg);
/**
* Add a tunnel server configuration.
* @param tunnel LinphoneTunnel object
......
......@@ -37,6 +37,7 @@ LinphoneTunnelConfig *linphone_tunnel_config_new() {
LinphoneTunnelConfig *ltc = belle_sip_object_new(LinphoneTunnelConfig);
ltc->remote_udp_mirror_port = 12345;
ltc->delay = 1000;
ltc->port = 443;
return ltc;
}
......
......@@ -90,6 +90,7 @@ static jobject handler_obj=NULL;
static jobject create_java_linphone_content(JNIEnv *env, const LinphoneContent *content);
static jobject create_java_linphone_buffer(JNIEnv *env, const LinphoneBuffer *buffer);
static LinphoneBuffer* create_c_linphone_buffer_from_java_linphone_buffer(JNIEnv *env, jobject jbuffer);
static jobject getTunnelConfig(JNIEnv *env, LinphoneTunnelConfig *cfg);
#ifdef ANDROID
void linphone_android_log_handler(int prio, char *str) {
......@@ -171,6 +172,14 @@ extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setDebugMode(JNIE
}
}
extern "C" jobject Java_org_linphone_core_LinphoneCoreFactoryImpl__1createTunnelConfig(JNIEnv* env, jobject thiz){
jobject jobj;
LinphoneTunnelConfig *cfg = linphone_tunnel_config_new();
jobj = getTunnelConfig(env, cfg); //this will take a ref.
linphone_tunnel_config_unref(cfg);
return jobj;
}
extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_enableLogCollection(JNIEnv* env
,jobject thiz
,jboolean enable) {
......@@ -3776,6 +3785,15 @@ extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_createDefaultCallParams
return (jlong) linphone_core_create_default_call_parameters((LinphoneCore*)lc);
}
/*
* Class: org_linphone_core_LinphoneCoreImpl
* Method: createCallParams
* Signature: (JJ)J
*/
JNIEXPORT jlong JNICALL Java_org_linphone_core_LinphoneCoreImpl_createCallParams(JNIEnv *env, jobject jcore, jlong coreptr, jlong callptr){
return (jlong)linphone_core_create_call_params((LinphoneCore*)coreptr, (LinphoneCall*)callptr);
}
extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getRemoteParams(JNIEnv *env, jobject thiz, jlong lc){
if (linphone_call_get_remote_params((LinphoneCall*)lc) == NULL) {
return (jlong) 0;
......@@ -4244,24 +4262,7 @@ extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelAddServerAndMirror
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);
env->DeleteLocalRef(TunnelConfigClass);
} else {
ms_error("LinphoneCore.tunnelAddServer(): tunnel feature is not enabled");
}
......@@ -4269,31 +4270,21 @@ extern "C" void Java_org_linphone_core_LinphoneCoreImpl_tunnelAddServer(JNIEnv *
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");
jclass tunnelConfigClass = env->FindClass("org/linphone/core/TunnelConfigImpl");
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);
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));
LinphoneTunnelConfig *conf = (LinphoneTunnelConfig *)it->data;
jobject elt = getTunnelConfig(env, conf);
env->SetObjectArrayElement(tunnelConfigArray, i, elt);
env->DeleteLocalRef(TunnelConfigClass);
}
}
env->DeleteLocalRef(tunnelConfigClass);
return tunnelConfigArray;
}
......@@ -6321,3 +6312,134 @@ JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneCallImpl_setListener(JNIEn
LinphoneCall *call = (LinphoneCall *)ptr;
linphone_call_set_next_video_frame_decoded_callback(call, _next_video_frame_decoded_callback, listener);
}
/*
* returns the java TunnelConfig associated with a C LinphoneTunnelConfig.
**/
static jobject getTunnelConfig(JNIEnv *env, LinphoneTunnelConfig *cfg){
jobject jobj=0;
if (cfg != NULL){
jclass tunnelConfigClass = env->FindClass("org/linphone/core/TunnelConfigImpl");
jmethodID ctor = env->GetMethodID(tunnelConfigClass,"<init>", "(j)V");
void *up=linphone_tunnel_config_get_user_data(cfg);
if (up==NULL){
jobj=env->NewObject(tunnelConfigClass,ctor,(jlong)cfg);
linphone_tunnel_config_set_user_data(cfg,(void*)env->NewWeakGlobalRef(jobj));
linphone_tunnel_config_ref(cfg);
}else{
//promote the weak ref to local ref
jobj=env->NewLocalRef((jobject)up);
if (jobj == NULL){
//the weak ref was dead
jobj=env->NewObject(tunnelConfigClass,ctor,(jlong)cfg);
linphone_tunnel_config_set_user_data(cfg,(void*)env->NewWeakGlobalRef(jobj));
}
}
env->DeleteLocalRef(tunnelConfigClass);
}
return jobj;
}
/*
* Class: org_linphone_core_TunnelConfigImpl
* Method: getHost
* Signature: (J)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_linphone_core_TunnelConfigImpl_getHost(JNIEnv *env, jobject obj, jlong ptr){
LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
const char *host = linphone_tunnel_config_get_host(cfg);
if (host){
return env->NewStringUTF(host);
}
return NULL;
}
/*
* Class: org_linphone_core_TunnelConfigImpl
* Method: setHost
* Signature: (JLjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_linphone_core_TunnelConfigImpl_setHost(JNIEnv *env, jobject obj, jlong ptr, jstring jstr){
LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
const char* host = jstr ? env->GetStringUTFChars(jstr, NULL) : NULL;
linphone_tunnel_config_set_host(cfg, host);
if (jstr) env->ReleaseStringUTFChars(jstr, host);
}
/*
* Class: org_linphone_core_TunnelConfigImpl
* Method: getPort
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_org_linphone_core_TunnelConfigImpl_getPort(JNIEnv *env, jobject jobj, jlong ptr){
LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
return linphone_tunnel_config_get_port(cfg);
}
/*
* Class: org_linphone_core_TunnelConfigImpl
* Method: setPort
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_org_linphone_core_TunnelConfigImpl_setPort(JNIEnv *env, jobject jobj, jlong ptr, jint port){
LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
linphone_tunnel_config_set_port(cfg, port);
}
/*
* Class: org_linphone_core_TunnelConfigImpl
* Method: getRemoteUdpMirrorPort
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_org_linphone_core_TunnelConfigImpl_getRemoteUdpMirrorPort(JNIEnv *env, jobject jobj, jlong ptr){
LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
return linphone_tunnel_config_get_remote_udp_mirror_port(cfg);
}
/*
* Class: org_linphone_core_TunnelConfigImpl
* Method: setRemoteUdpMirrorPort
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_org_linphone_core_TunnelConfigImpl_setRemoteUdpMirrorPort(JNIEnv *env, jobject jobj, jlong ptr, jint port){
LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
linphone_tunnel_config_set_remote_udp_mirror_port(cfg, port);
}
/*
* Class: org_linphone_core_TunnelConfigImpl
* Method: getDelay
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_org_linphone_core_TunnelConfigImpl_getDelay(JNIEnv *env, jobject jobj, jlong ptr){
LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
return linphone_tunnel_config_get_delay(cfg);
}
/*
* Class: org_linphone_core_TunnelConfigImpl
* Method: setDelay
* Signature: (JI)I
*/
JNIEXPORT void JNICALL Java_org_linphone_core_TunnelConfigImpl_setDelay(JNIEnv *env, jobject jobj, jlong ptr, jint delay){
LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
linphone_tunnel_config_set_delay(cfg, delay);
}
/*
* Class: org_linphone_core_TunnelConfigImpl
* Method: destroy
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_org_linphone_core_TunnelConfigImpl_destroy(JNIEnv *env, jobject jobj, jlong ptr){
LinphoneTunnelConfig *cfg = (LinphoneTunnelConfig *)ptr;
linphone_tunnel_config_set_user_data(cfg, NULL);
linphone_tunnel_config_unref(cfg);
}
......@@ -1127,9 +1127,20 @@ public interface LinphoneCore {
/**
* Get default call parameters reflecting current linphone core configuration
* @return LinphoneCallParams
* @deprecated use LinphoneCore.createCallParams().
*/
LinphoneCallParams createDefaultCallParameters();
/**
* Create a LinphoneCallParams suitable to be used for a new incoming call or an established call, in
* methods LinphoneCore.inviteAddressWithParams(), LinphoneCore.updateCall(), LinphoneCore.acceptCallWithParams(), LinphoneCore.acceptCallUpdate().
* The call parameter is optional: when creating a LinphoneCallParams for an outgoing call that is about to be created,
* it shall be set to null.
* @param call (optional)
* @return a LinphoneCallParams object, representing the call settings guessed from the current LinphoneCore and compatible with the call object if any.
*/
LinphoneCallParams createCallParams(LinphoneCall call);
/**
* Sets the path to a wav file used for ringing.
*
......
......@@ -167,4 +167,9 @@ abstract public class LinphoneCoreFactory {
abstract public PresenceModel createPresenceModel();
abstract public PresenceModel createPresenceModel(PresenceActivityType type, String description);
abstract public PresenceModel createPresenceModel(PresenceActivityType type, String description, String note, String lang);
/*
* Create TunnelConfig object, used to configure voip anti blocking extension.
*/
abstract public TunnelConfig createTunnelConfig();
}
package org.linphone.core;
/**
* The TunnelConfig interface allows to configure information about a tunnel server (voip anti blocking).
* @author smorlat
*
*/
public interface TunnelConfig {
/**
* Get the hostname of the tunnel server
* @return
*/
String getHost();
/**
* Set the hostname (or ip address) of the tunnel server.
* @param host
*/
void setHost(String host);
/**
* Get the port where to connect.
* @return
*/
int getPort();
/**
* Set the port where to connect to the tunnel server.
* When not set, the default value is used (443).
* @param port
*/
void setPort(int port);
/**
* Get the remote udp mirror port, which is used to check udp connectivity of the network.
* @return
*/
int getRemoteUdpMirrorPort();
/**
* Set the udp mirror port, which is used to check udp connectivity.
* When not set, a default value of 12345 is used.
* @param remoteUdpMirrorPort
*/
void setRemoteUdpMirrorPort(int remoteUdpMirrorPort);
/**
* Get the maximum amount of time for waiting for UDP packets to come back during
* the UDP connectivity check, in milliseconds.
*
* @return
*/
int getDelay();
/**
* Set the maximum amount of time for waiting for UDP packets to come back during
* the UDP connectivity check, in milliseconds.
*/
void setDelay(int delay);
}
......@@ -193,4 +193,10 @@ public class LinphoneCoreFactoryImpl extends LinphoneCoreFactory {
public PresenceModel createPresenceModel(PresenceActivityType type, String description, String note, String lang) {
return new PresenceModelImpl(type, description, note, lang);
}
private native Object _createTunnelConfig();
@Override
public TunnelConfig createTunnelConfig() {
return (TunnelConfig)_createTunnelConfig();
}
}
......@@ -1517,4 +1517,12 @@ class LinphoneCoreImpl implements LinphoneCore {
public String getVideoPreset() {
return getVideoPreset(nativePtr);
}
private native long createCallParams(long nativePtr, long callPtr);
@Override
public LinphoneCallParams createCallParams(LinphoneCall call) {
long callptr = 0;
if (call!=null) callptr = ((LinphoneCallImpl)call).nativePtr;
long ptr = createCallParams(nativePtr, callptr);
return new LinphoneCallParamsImpl(ptr);
}
}
package org.linphone.core;
public class TunnelConfig {
private String host = null;
private int port = 443;
private int remoteUdpMirrorPort = 12345;
private int delay = 1000;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public int getRemoteUdpMirrorPort() {
return remoteUdpMirrorPort;
}
public void setRemoteUdpMirrorPort(int remoteUdpMirrorPort) {
this.remoteUdpMirrorPort = remoteUdpMirrorPort;
}
public int getDelay() {
return delay;
}
public void setDelay(int delay) {
this.delay = delay;
}
}
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