mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-20 12:38:09 +00:00
Added JNI bindings for LpConfig + extended java LpConfig
This commit is contained in:
parent
03723b2225
commit
b8453d1bc1
3 changed files with 234 additions and 3 deletions
|
|
@ -3034,7 +3034,7 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_publish(JNIEnv
|
|||
return jev;
|
||||
}
|
||||
|
||||
|
||||
// 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);
|
||||
|
|
@ -3061,6 +3061,99 @@ extern "C" void Java_org_linphone_core_LpConfigImpl_setInt(JNIEnv *env, jobject
|
|||
env->ReleaseStringUTFChars(key, ckey);
|
||||
}
|
||||
|
||||
extern "C" jint Java_org_linphone_core_LpConfigImpl_getInt(JNIEnv *env, jobject thiz, jlong lpc,
|
||||
jstring section, jstring key, jint defaultValue) {
|
||||
const char *csection = env->GetStringUTFChars(section, NULL);
|
||||
const char *ckey = env->GetStringUTFChars(key, NULL);
|
||||
int returnValue = lp_config_get_int((LpConfig *)lpc, csection, ckey, (int) defaultValue);
|
||||
env->ReleaseStringUTFChars(section, csection);
|
||||
env->ReleaseStringUTFChars(key, ckey);
|
||||
return (jint) returnValue;
|
||||
}
|
||||
|
||||
extern "C" void Java_org_linphone_core_LpConfigImpl_setFloat(JNIEnv *env, jobject thiz, jlong lpc,
|
||||
jstring section, jstring key, jfloat value) {
|
||||
const char *csection = env->GetStringUTFChars(section, NULL);
|
||||
const char *ckey = env->GetStringUTFChars(key, NULL);
|
||||
lp_config_set_float((LpConfig *)lpc, csection, ckey, (float) value);
|
||||
env->ReleaseStringUTFChars(section, csection);
|
||||
env->ReleaseStringUTFChars(key, ckey);
|
||||
}
|
||||
|
||||
extern "C" jfloat Java_org_linphone_core_LpConfigImpl_getFloat(JNIEnv *env, jobject thiz, jlong lpc,
|
||||
jstring section, jstring key, jfloat defaultValue) {
|
||||
const char *csection = env->GetStringUTFChars(section, NULL);
|
||||
const char *ckey = env->GetStringUTFChars(key, NULL);
|
||||
float returnValue = lp_config_get_float((LpConfig *)lpc, csection, ckey, (float) defaultValue);
|
||||
env->ReleaseStringUTFChars(section, csection);
|
||||
env->ReleaseStringUTFChars(key, ckey);
|
||||
return (jfloat) returnValue;
|
||||
}
|
||||
|
||||
extern "C" void Java_org_linphone_core_LpConfigImpl_setBool(JNIEnv *env, jobject thiz, jlong lpc,
|
||||
jstring section, jstring key, jboolean value) {
|
||||
const char *csection = env->GetStringUTFChars(section, NULL);
|
||||
const char *ckey = env->GetStringUTFChars(key, NULL);
|
||||
lp_config_set_int((LpConfig *)lpc, csection, ckey, value ? 1 : 0);
|
||||
env->ReleaseStringUTFChars(section, csection);
|
||||
env->ReleaseStringUTFChars(key, ckey);
|
||||
}
|
||||
|
||||
extern "C" jboolean Java_org_linphone_core_LpConfigImpl_getBool(JNIEnv *env, jobject thiz, jlong lpc,
|
||||
jstring section, jstring key, jboolean defaultValue) {
|
||||
const char *csection = env->GetStringUTFChars(section, NULL);
|
||||
const char *ckey = env->GetStringUTFChars(key, NULL);
|
||||
int returnValue = lp_config_get_int((LpConfig *)lpc, csection, ckey, defaultValue ? 1 : 0);
|
||||
env->ReleaseStringUTFChars(section, csection);
|
||||
env->ReleaseStringUTFChars(key, ckey);
|
||||
return (jboolean) returnValue == 1;
|
||||
}
|
||||
|
||||
extern "C" void Java_org_linphone_core_LpConfigImpl_setString(JNIEnv *env, jobject thiz, jlong lpc,
|
||||
jstring section, jstring key, jstring value) {
|
||||
const char *csection = env->GetStringUTFChars(section, NULL);
|
||||
const char *ckey = env->GetStringUTFChars(key, NULL);
|
||||
const char *cvalue = env->GetStringUTFChars(value, NULL);
|
||||
lp_config_set_string((LpConfig *)lpc, csection, ckey, cvalue);
|
||||
env->ReleaseStringUTFChars(section, csection);
|
||||
env->ReleaseStringUTFChars(key, ckey);
|
||||
env->ReleaseStringUTFChars(value, cvalue);
|
||||
}
|
||||
|
||||
extern "C" jstring Java_org_linphone_core_LpConfigImpl_getString(JNIEnv *env, jobject thiz, jlong lpc,
|
||||
jstring section, jstring key, jstring defaultValue) {
|
||||
const char *csection = env->GetStringUTFChars(section, NULL);
|
||||
const char *ckey = env->GetStringUTFChars(key, NULL);
|
||||
const char *cvalue = env->GetStringUTFChars(defaultValue, NULL);
|
||||
const char *returnValue = lp_config_get_string((LpConfig *)lpc, csection, ckey, cvalue);
|
||||
env->ReleaseStringUTFChars(section, csection);
|
||||
env->ReleaseStringUTFChars(key, ckey);
|
||||
env->ReleaseStringUTFChars(defaultValue, cvalue);
|
||||
return returnValue ? env->NewStringUTF(returnValue) : NULL;
|
||||
}
|
||||
extern "C" void Java_org_linphone_core_LpConfigImpl_setIntRange(JNIEnv *env, jobject thiz, jlong lpc,
|
||||
jstring section, jstring key, jint min, jint max) {
|
||||
const char *csection = env->GetStringUTFChars(section, NULL);
|
||||
const char *ckey = env->GetStringUTFChars(key, NULL);
|
||||
lp_config_set_range((LpConfig *)lpc, csection, ckey, min, max);
|
||||
env->ReleaseStringUTFChars(section, csection);
|
||||
env->ReleaseStringUTFChars(key, ckey);
|
||||
}
|
||||
|
||||
extern "C" jintArray Java_org_linphone_core_LpConfigImpl_getIntRange(JNIEnv *env, jobject thiz, jlong lpc,
|
||||
jstring section, jstring key, jint defaultmin, jint defaultmax) {
|
||||
const char *csection = env->GetStringUTFChars(section, NULL);
|
||||
const char *ckey = env->GetStringUTFChars(key, NULL);
|
||||
int *values = (int*)calloc(2, sizeof(int));
|
||||
lp_config_get_range((LpConfig *)lpc, csection, ckey, &values[0], &values[1], defaultmin, defaultmax);
|
||||
jintArray returnValues = env->NewIntArray(2);
|
||||
env->SetIntArrayRegion(returnValues, 0, 2, values);
|
||||
ms_free(values);
|
||||
env->ReleaseStringUTFChars(section, csection);
|
||||
env->ReleaseStringUTFChars(key, ckey);
|
||||
return returnValues;
|
||||
}
|
||||
|
||||
static jobject create_java_linphone_content(JNIEnv *env, const LinphoneContent *content){
|
||||
jclass contentClass;
|
||||
jmethodID ctor;
|
||||
|
|
|
|||
|
|
@ -42,9 +42,89 @@ public interface LpConfig {
|
|||
|
||||
/**
|
||||
* Sets an integer config item
|
||||
* @param key
|
||||
* @param section the section in the lpconfig
|
||||
* @param key the name of the setting
|
||||
* @param value the value of the setting
|
||||
*/
|
||||
void setInt(String section, String key, int value);
|
||||
|
||||
/**
|
||||
* Sets an float config item
|
||||
* @param section the section in the lpconfig
|
||||
* @param key the name of the setting
|
||||
* @param value the value of the setting
|
||||
*/
|
||||
void setFloat(String section, String key, float value);
|
||||
|
||||
/**
|
||||
* Sets an boolean config item
|
||||
* @param section the section in the lpconfig
|
||||
* @param key the name of the setting
|
||||
* @param value the value of the setting
|
||||
*/
|
||||
void setBool(String section, String key, boolean value);
|
||||
|
||||
/**
|
||||
* Sets an string config item
|
||||
* @param section the section in the lpconfig
|
||||
* @param key the name of the setting
|
||||
* @param value the value of the setting
|
||||
*/
|
||||
void setString(String section, String key, String value);
|
||||
|
||||
/**
|
||||
* Sets an integer range config item
|
||||
* @param section the section in the lpconfig
|
||||
* @param key the name of the setting
|
||||
* @param min the min of the range
|
||||
* @param max the max of the range
|
||||
*/
|
||||
void setIntRange(String section, String key, int min, int max);
|
||||
|
||||
/**
|
||||
* Gets a int from the config
|
||||
* @param section the section in the lpconfig
|
||||
* @param key the name of the setting
|
||||
* @param defaultValue the default value if not set
|
||||
* @return the value of the setting or the default value if not set
|
||||
*/
|
||||
int getInt(String section, String key, int defaultValue);
|
||||
|
||||
/**
|
||||
* Gets a float from the config
|
||||
* @param section the section in the lpconfig
|
||||
* @param key the name of the setting
|
||||
* @param defaultValue the default value if not set
|
||||
* @return the value of the setting or the default value if not set
|
||||
*/
|
||||
float getFloat(String section, String key, float defaultValue);
|
||||
|
||||
/**
|
||||
* Gets a boolean from the config
|
||||
* @param section the section in the lpconfig
|
||||
* @param key the name of the setting
|
||||
* @param defaultValue the default value if not set
|
||||
* @return the value of the setting or the default value if not set
|
||||
*/
|
||||
boolean getBool(String section, String key, boolean defaultValue);
|
||||
|
||||
/**
|
||||
* Gets a string from the config
|
||||
* @param section the section in the lpconfig
|
||||
* @param key the name of the setting
|
||||
* @param defaultValue the default value if not set
|
||||
* @return the value of the setting or the default value if not set
|
||||
*/
|
||||
String getString(String section, String key, String defaultValue);
|
||||
|
||||
/**
|
||||
* Gets a int range from the config
|
||||
* @param section the section in the lpconfig
|
||||
* @param key the name of the setting
|
||||
* @param defaultValue the default value if not set
|
||||
* @return the value of the setting or the default value if not set
|
||||
*/
|
||||
int[] getIntRange(String section, String key, int defaultMin, int defaultMax);
|
||||
|
||||
/**
|
||||
* Synchronize LpConfig with file
|
||||
|
|
|
|||
|
|
@ -26,15 +26,17 @@ class LpConfigImpl implements LpConfig {
|
|||
boolean ownPtr = false;
|
||||
|
||||
public LpConfigImpl(long ptr) {
|
||||
nativePtr=ptr;
|
||||
nativePtr = ptr;
|
||||
}
|
||||
|
||||
private native long newLpConfigImpl(String file);
|
||||
private native void delete(long ptr);
|
||||
|
||||
public LpConfigImpl(String file) {
|
||||
nativePtr = newLpConfigImpl(file);
|
||||
ownPtr = true;
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
if(ownPtr) {
|
||||
delete(nativePtr);
|
||||
|
|
@ -42,13 +44,69 @@ class LpConfigImpl implements LpConfig {
|
|||
}
|
||||
|
||||
private native void sync(long ptr);
|
||||
@Override
|
||||
public void sync() {
|
||||
sync(nativePtr);
|
||||
}
|
||||
|
||||
private native void setInt(long ptr, String section, String key, int value);
|
||||
@Override
|
||||
public void setInt(String section, String key, int value) {
|
||||
setInt(nativePtr, section, key, value);
|
||||
}
|
||||
|
||||
private native void setFloat(long ptr, String section, String key, float value);
|
||||
@Override
|
||||
public void setFloat(String section, String key, float value) {
|
||||
setFloat(nativePtr, section, key, value);
|
||||
}
|
||||
|
||||
private native void setBool(long ptr, String section, String key, boolean value);
|
||||
@Override
|
||||
public void setBool(String section, String key, boolean value) {
|
||||
setBool(nativePtr, section, key, value);
|
||||
}
|
||||
|
||||
private native void setString(long ptr, String section, String key, String value);
|
||||
@Override
|
||||
public void setString(String section, String key, String value) {
|
||||
setString(nativePtr, section, key, value);
|
||||
}
|
||||
|
||||
private native void setIntRange(long ptr, String section, String key, int min, int max);
|
||||
@Override
|
||||
public void setIntRange(String section, String key, int min, int max) {
|
||||
setIntRange(nativePtr, section, key, min, max);
|
||||
}
|
||||
|
||||
private native int getInt(long ptr, String section, String key, int defaultValue);
|
||||
@Override
|
||||
public int getInt(String section, String key, int defaultValue) {
|
||||
return getInt(nativePtr, section, key, defaultValue);
|
||||
}
|
||||
|
||||
private native float getFloat(long ptr, String section, String key, float defaultValue);
|
||||
@Override
|
||||
public float getFloat(String section, String key, float defaultValue) {
|
||||
return getFloat(nativePtr, section, key, defaultValue);
|
||||
}
|
||||
|
||||
private native boolean getBool(long ptr, String section, String key, boolean defaultValue);
|
||||
@Override
|
||||
public boolean getBool(String section, String key, boolean defaultValue) {
|
||||
return getBool(nativePtr, section, key, defaultValue);
|
||||
}
|
||||
|
||||
private native String getString(long ptr, String section, String key, String defaultValue);
|
||||
@Override
|
||||
public String getString(String section, String key, String defaultValue) {
|
||||
return getString(nativePtr, section, key, defaultValue);
|
||||
}
|
||||
|
||||
private native int[] getIntRange(long ptr, String section, String key, int defaultMin, int defaultMax);
|
||||
@Override
|
||||
public int[] getIntRange(String section, String key, int defaultMin, int defaultMax) {
|
||||
return getIntRange(nativePtr, section, key, defaultMin, defaultMax);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue