Commit 5cbf79d6 authored by Erwan Croze's avatar Erwan Croze 👋🏻

JNI for country list

parent 7a2470c3
......@@ -203,6 +203,38 @@ extern "C" void Java_org_linphone_core_LinphoneCoreFactoryImpl_setLogCollectionP
linphone_core_set_log_collection_path(path);
ReleaseStringUTFChars(env, jpath, path);
}
extern "C" jobjectArray Java_org_linphone_core_LinphoneCoreFactoryImpl_getAllDialPlanNative(JNIEnv *env, jobject thiz) {
LinphoneDialPlan *countries;
jclass addr_class = env->FindClass("org/linphone/core/DialPlanImpl");
jmethodID addr_constructor = env->GetMethodID(addr_class, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)V");
jobjectArray jaddr_array;
int i, size = 0;
countries = (LinphoneDialPlan *)linphone_dial_plan_get_all();
while (countries[size].country != NULL) size++;
jaddr_array = env->NewObjectArray(size, addr_class, NULL);
for (i=0; i < size ; i++) {
jstring jcountry = env->NewStringUTF(countries[i].country);
jstring jiso = env->NewStringUTF(countries[i].iso_country_code);
jstring jccc = env->NewStringUTF(countries[i].ccc);
jint jnnl = (jint)countries[i].nnl;
jstring jicp = env->NewStringUTF(countries[i].icp);
jobject jaddr = env->NewObject(addr_class, addr_constructor, jcountry, jiso, jccc, jnnl, jicp);
env->SetObjectArrayElement(jaddr_array, i, jaddr);
env->DeleteLocalRef(jcountry);
env->DeleteLocalRef(jiso);
env->DeleteLocalRef(jccc);
env->DeleteLocalRef(jicp);
}
return jaddr_array;
}
// LinphoneCore
class LinphoneJavaBindings {
......
package org.linphone.core;
/**
* Dial plan
*/
public interface DialPlan {
String getCountryCode();
String getCountryName();
String getCountryCallingCode();
int getNumberLength();
String getUsualPrefix();
}
......@@ -23,13 +23,15 @@ import android.content.Context;
import org.linphone.tools.OpenH264DownloadHelper;
import java.util.ArrayList;
abstract public class LinphoneCoreFactory {
protected Context fcontext;
private static String factoryName = "org.linphone.core.LinphoneCoreFactoryImpl";
static LinphoneCoreFactory theLinphoneCoreFactory;
static LinphoneCoreFactory theLinphoneCoreFactory;
/**
* Indicate the name of the class used by this factory
* @param className
......@@ -37,8 +39,8 @@ abstract public class LinphoneCoreFactory {
public static void setFactoryClassName (String className) {
factoryName = className;
}
public static final synchronized LinphoneCoreFactory instance() {
try {
if (theLinphoneCoreFactory == null) {
......@@ -67,7 +69,7 @@ abstract public class LinphoneCoreFactory {
* @param realm
* */
abstract public LinphoneAuthInfo createAuthInfo(String username, String userid, String passwd, String ha1, String realm, String domain);
/**
* Create a LinphoneCore object. The LinphoneCore is the root for all liblinphone operations. You need only one per application.
* @param listener listener to receive notifications from the core
......@@ -91,10 +93,10 @@ abstract public class LinphoneCoreFactory {
/**
* Constructs a LinphoneAddress object
* @param username
* @param username
* @param domain
* @param displayName
* @return
* @return
*/
abstract public LinphoneAddress createLinphoneAddress(String username,String domain,String displayName);
/**
......@@ -106,14 +108,14 @@ abstract public class LinphoneCoreFactory {
abstract public LinphoneAddress createLinphoneAddress(String address) throws LinphoneCoreException;
abstract public LpConfig createLpConfig(String file);
abstract public LpConfig createLpConfigFromString(String buffer);
/**
* Enable verbose traces
* @param enable true to enable debug mode, false to disable it
* @param tag Tag which prefixes each log message.
*/
abstract public void setDebugMode(boolean enable, String tag);
/**
* Enable the linphone core log collection to upload logs on a server.
*/
......@@ -124,7 +126,7 @@ abstract public class LinphoneCoreFactory {
* @param path The path where the log files will be written.
*/
abstract public void setLogCollectionPath(String path);
abstract public void setLogHandler(LinphoneLogHandler handler);
/**
......@@ -132,20 +134,20 @@ abstract public class LinphoneCoreFactory {
* @return a new OpenH264DownloadHelper
*/
abstract public OpenH264DownloadHelper createOpenH264DownloadHelper();
/**
* Create a LinphoneFriend, similar to {@link #createLinphoneFriend()} + {@link LinphoneFriend#setAddress(LinphoneAddress)}
* Create a LinphoneFriend, similar to {@link #createLinphoneFriend()} + {@link LinphoneFriend#setAddress(LinphoneAddress)}
* @param friendUri a buddy address, must be a sip uri like sip:joe@sip.linphone.org
* @return a new LinphoneFriend with address initialized
*/
abstract public LinphoneFriend createLinphoneFriend(String friendUri);
/**
* Create a new LinphoneFriend
* @return
*/
abstract public LinphoneFriend createLinphoneFriend();
/**
* Create a LinphoneContent object from string data.
*/
......@@ -155,7 +157,7 @@ abstract public class LinphoneCoreFactory {
* Create a LinphoneContent object from byte array.
*/
abstract public LinphoneContent createLinphoneContent(String type, String subType, byte[] data, String encoding);
/**
* Create a PresenceActivity object.
*/
......@@ -186,4 +188,10 @@ abstract public class LinphoneCoreFactory {
* Create LinphoneAccountCreator object
*/
abstract public LinphoneAccountCreator createAccountCreator(LinphoneCore lc, String url);
/**
* Array of countries list
* @return countries list
*/
abstract public DialPlan[] getAllDialPlan();
}
package org.linphone.core;
public class DialPlanImpl implements DialPlan {
private final String countryName;
private final String countryCode;
private final String countryCallingCode;
private final int numberLength;
private final String usualPrefix;
public DialPlanImpl(String countryName, String countryCode, String countryCallingCode, int numberLength, String usualPrefix) {
this.countryName = countryName;
this.countryCode = countryCode;
this.countryCallingCode = countryCallingCode;
this.numberLength = numberLength;
this.usualPrefix = usualPrefix;
}
@Override
public final String getCountryCode() {
return countryCode;
}
@Override
public final String getCountryName() {
return countryName;
}
@Override
public final String getCountryCallingCode() {
return countryCallingCode;
}
@Override
public final int getNumberLength() {
return numberLength;
}
@Override
public final String getUsualPrefix() {
return usualPrefix;
}
}
......@@ -22,6 +22,7 @@ import android.content.Context;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.linphone.mediastream.Log;
......@@ -31,7 +32,7 @@ import org.linphone.tools.OpenH264DownloadHelper;
public class LinphoneCoreFactoryImpl extends LinphoneCoreFactory {
public static String ABI;
private static boolean loadOptionalLibrary(String s) {
try {
System.loadLibrary(s);
......@@ -244,4 +245,10 @@ public class LinphoneCoreFactoryImpl extends LinphoneCoreFactory {
public LinphoneAccountCreator createAccountCreator(LinphoneCore lc, String url) {
return new LinphoneAccountCreatorImpl(lc, url);
}
private native DialPlan[] getAllDialPlanNative();
@Override
public DialPlan[] getAllDialPlan(){
return getAllDialPlanNative();
}
}
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