Commit a7ad7997 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Added JNI method to create LpConfig from buffer

parent 026bbe8d
......@@ -5330,12 +5330,19 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_publish(JNIEnv
// LpConfig
extern "C" jlong Java_org_linphone_core_LpConfigImpl_newLpConfigImpl(JNIEnv *env, jobject thiz, jstring file) {
const char *cfile = env->GetStringUTFChars(file, NULL);
LpConfig *lp = lp_config_new(cfile);
const char *cfile = env->GetStringUTFChars(file, NULL);
LpConfig *lp = lp_config_new(cfile);
env->ReleaseStringUTFChars(file, cfile);
return (jlong) lp;
}
extern "C" jlong Java_org_linphone_core_LpConfigImpl_newLpConfigImplFromBuffer(JNIEnv *env, jobject thiz, jstring buffer) {
const char *cbuffer = env->GetStringUTFChars(buffer, NULL);
LpConfig *lp = lp_config_new_from_buffer(cbuffer);
env->ReleaseStringUTFChars(buffer, cbuffer);
return (jlong) lp;
}
extern "C" void Java_org_linphone_core_LpConfigImpl_sync(JNIEnv *env, jobject thiz, jlong lpc) {
LpConfig *lp = (LpConfig *)lpc;
lp_config_sync(lp);
......
......@@ -103,6 +103,7 @@ 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
......
......@@ -85,7 +85,11 @@ public class LinphoneCoreFactoryImpl extends LinphoneCoreFactory {
@Override
public LpConfig createLpConfig(String file) {
return new LpConfigImpl(file);
return LpConfigImpl.fromFile(file);
}
public LpConfig createLpConfigFromString(String buffer) {
return LpConfigImpl.fromBuffer(buffer);
}
@Override
......
......@@ -18,11 +18,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone.core;
class LpConfigImpl implements LpConfig {
private final long nativePtr;
private long nativePtr;
boolean ownPtr = false;
public LpConfigImpl(long ptr) {
......@@ -30,13 +28,34 @@ class LpConfigImpl implements LpConfig {
}
private native long newLpConfigImpl(String file);
private native long newLpConfigImplFromBuffer(String buffer);
private native void delete(long ptr);
@Deprecated
public LpConfigImpl(String file) {
nativePtr = newLpConfigImpl(file);
ownPtr = true;
}
private LpConfigImpl() {
nativePtr = -1;
ownPtr = false;
}
public static LpConfigImpl fromFile(String file) {
LpConfigImpl impl = new LpConfigImpl();
impl.nativePtr = impl.newLpConfigImpl(file);
impl.ownPtr = true;
return impl;
}
public static LpConfigImpl fromBuffer(String buffer) {
LpConfigImpl impl = new LpConfigImpl();
impl.nativePtr = impl.newLpConfigImplFromBuffer(buffer);
impl.ownPtr = true;
return impl;
}
protected void finalize() throws Throwable {
if(ownPtr) {
delete(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