Commit 8b8dcb3f authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Few changes in java wrapper for factory + added LinphoneJavaBindings

parent 3d10bbc9
......@@ -233,6 +233,7 @@ class JavaTranslator(object):
methodDict['classCName'] = 'Linphone' + className.to_camel_case()
methodDict['className'] = className.to_camel_case()
methodDict['classImplName'] = className.to_camel_case() + 'Impl'
methodDict['cPrefix'] = 'linphone_' + className.to_snake_case()
methodDict['jniPath'] = self.jni_path
methodDict['return'] = self.translate_type(_method.returnType, jni=True, isReturn=True)
......@@ -406,6 +407,7 @@ class JavaClass(object):
def __init__(self, package, _class, translator):
self._class = translator.translate_class(_class)
self.isLinphoneFactory = self._class['isLinphoneFactory']
self.isNotLinphoneFactory = not self.isLinphoneFactory
self.cName = 'Linphone' + _class.name.to_camel_case()
self.cPrefix = 'linphone_' + _class.name.to_snake_case()
self.packageName = package
......@@ -436,6 +438,8 @@ class Jni(object):
self.jni_path += directory + '/'
def add_object(self, javaClass):
if javaClass.className == 'Factory':
return
obj = {
'jniPrefix': self.jni_package,
'jniPath': self.jni_path,
......
......@@ -94,6 +94,7 @@ public interface {{className}} {
*/
public Object getUserData();
{{#isNotLinphoneFactory}}
{{#staticMethods}}
{{#doc}}
/**
......@@ -105,6 +106,7 @@ public interface {{className}} {
public {{return}} {{name}}({{params}}){{#exception}} throws CoreException{{/exception}}{{#enumCast}} throws CoreException{{/enumCast}};
{{/staticMethods}}
{{/isNotLinphoneFactory}}
}
class {{classImplName}} implements {{className}} {
......@@ -147,6 +149,7 @@ class {{classImplName}} implements {{className}} {
}
{{/methods}}
{{#isNotLinphoneFactory}}
private native void unref(long ptr);
protected void finalize() throws Throwable {
if (nativePtr != 0) {
......@@ -155,6 +158,7 @@ class {{classImplName}} implements {{className}} {
}
super.finalize();
}
{{/isNotLinphoneFactory}}
public void setUserData(Object data) {
userData = data;
......@@ -164,9 +168,11 @@ class {{classImplName}} implements {{className}} {
return userData;
}
{{#isNotLinphoneFactory}}
{{#staticMethods}}
@Override
public native {{return_native}} {{name}}({{static_native_params}});
{{/staticMethods}}
{{/isNotLinphoneFactory}}
}
\ No newline at end of file
......@@ -41,13 +41,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <belle-sip/wakelock.h>
#endif /* __ANDROID__ */
static JavaVM *jvm=0;
static JavaVM *jvm = NULL;
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *ajvm, void *reserved) {
#ifdef __ANDROID__
ms_set_jvm(ajvm);
#endif /* __ANDROID__ */
jvm=ajvm;
jvm = ajvm;
return JNI_VERSION_1_2;
}
......@@ -67,14 +67,38 @@ static jlong GetObjectNativePtr(JNIEnv *env, jobject object) {
return nativePtr;
}
class LinphoneJavaBindings {
public:
LinphoneJavaBindings(JNIEnv *env) {
{{#objects}}
{{cPrefix}}_class = (jclass)env->NewGlobalRef(env->FindClass("{{jniPath}}{{classImplName}}"));
{{cPrefix}}_class_constructor = env->GetMethodID({{cPrefix}}_class, "<init>", "(J)V");
{{/objects}}
}
~LinphoneJavaBindings() {
JNIEnv *env = 0;
jvm->AttachCurrentThread(&env,NULL);
{{#objects}}
env->DeleteGlobalRef({{cPrefix}}_class);
{{/objects}}
}
{{#objects}}
jclass {{cPrefix}}_class;
jmethodID {{cPrefix}}_class_constructor;
{{/objects}}
};
{{#objects}}
jobject get{{className}}(JNIEnv *env, {{classCName}} *ptr) {
jobject jobj = 0;
if (ptr != NULL) {
void *up = {{cPrefix}}_get_user_data(ptr);
jclass {{cPrefix}}_class = env->FindClass("{{jniPath}}{{classImplName}}");
jmethodID {{cPrefix}}_constructor = env->GetMethodID({{cPrefix}}_class, "<init>", "(J)V");
//TODO get ljb
jclass {{cPrefix}}_class = ljb->{{cPrefix}}_class;
jmethodID {{cPrefix}}_constructor = ljb->{{cPrefix}}_class_constructor;
if (up == NULL) {
jobj = env->NewObject({{cPrefix}}_class, {{cPrefix}}_constructor, (jlong)ptr);
......@@ -135,7 +159,9 @@ void Java_{{jniPrefix}}{{classImplName}}_unref(JNIEnv* env, jobject thiz, jlong
{{/lists}}{{#hasListReturn}}
bctbx_list_t *list = {{c_name}}({{#notStatic}}cptr{{/notStatic}}{{params_impl}});
size_t count = bctbx_list_size(list);
{{#isRealObjectArray}}jobjectArray jni_list_result = env->NewObjectArray(count, env->FindClass("{{jniPath}}{{objectClassImplName}}"), NULL);{{/isRealObjectArray}}
{{#isRealObjectArray}}
//TODO get ljb
jobjectArray jni_list_result = env->NewObjectArray(count, ljb->{{cPrefix}}_class, NULL);{{/isRealObjectArray}}
{{#isStringObjectArray}}jobjectArray jni_list_result = env->NewObjectArray(count, env->FindClass("java/lang/String"), env->NewStringUTF(""));{{/isStringObjectArray}}
for (size_t i = 0; i < count; i++) {
{{#isRealObjectArray}}
......
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