Commit 8ce4bac3 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Fixed callbacks with list param not being wrapped correctly in Java wrapper

parent 4a86761f
......@@ -428,6 +428,7 @@ class JavaTranslator(object):
methodDict['jobjects'] = []
methodDict['jenums'] = []
methodDict['jstrings'] = []
methodDict['jlists'] = []
methodDict['params'] = ''
methodDict['jparams'] = '('
methodDict['params_impl'] = ''
......@@ -458,7 +459,15 @@ class JavaTranslator(object):
methodDict['jenums'].append({'enumName': argname, 'cEnumPrefix': arg.type.desc.name.to_snake_case(fullName=True)})
elif isinstance(arg.type, AbsApi.ListType):
methodDict['jparams'] += '[L' + self.jni_path + arg.type.containedTypeDesc.desc.name.to_camel_case() + ';'
methodDict['params_impl'] += 'NULL'
methodDict['params_impl'] += 'j_' + argname
if isinstance( arg.type.containedTypeDesc, AbsApi.BaseType):
methodDict['jlists'].append({'list_name': argname, 'isRealObjectArray':False, 'isStringObjectArray':True})
elif isinstance( arg.type.containedTypeDesc, AbsApi.ClassType):
cprefix = 'linphone_' + arg.type.containedTypeDesc.desc.name.to_snake_case()
classcname = 'Linphone' + arg.type.containedTypeDesc.desc.name.to_camel_case()
classname = arg.type.containedTypeDesc.desc.name.to_camel_case()
methodDict['jlists'].append({'list_name': argname, 'objectCPrefix':cprefix, 'objectClassCName':classcname, 'objectClassName':classname, 'isRealObjectArray':True, 'isStringObjectArray':False})
methodDict['jparams'] += ')'
if (methodDict['return'] == 'void'):
......
......@@ -334,6 +334,29 @@ static {{return}} {{callbackName}}({{params}}) {
{{#jstrings}}
jstring j_{{stringName}} = {{stringName}} ? get_jstring_from_char(env, {{stringName}}) : NULL;
{{/jstrings}}
{{#jlists}}
bctbx_list_t *list_it = (bctbx_list_t *){{list_name}};
size_t count = bctbx_list_size({{list_name}});
{{#isRealObjectArray}}
LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_factory_get_user_data(linphone_factory_get());
jobjectArray j_{{list_name}} = env->NewObjectArray((int)count, ljb->{{objectCPrefix}}_class, NULL);{{/isRealObjectArray}}
{{#isStringObjectArray}}jobjectArray j_{{list_name}} = env->NewObjectArray((int)count, env->FindClass("java/lang/String"), env->NewStringUTF(""));{{/isStringObjectArray}}
int i = 0;
while (list_it != NULL) {
{{#isRealObjectArray}}
{{objectClassCName}}* c_object = ({{objectClassCName}}*)list_it->data;
jobject object = get{{objectClassName}}(env, c_object, TRUE);
{{/isRealObjectArray}}
{{#isStringObjectArray}}const char *cstring = (const char *)list_it->data;
jstring object = cstring ? get_jstring_from_char(env, cstring) : 0;{{/isStringObjectArray}}
if (object != 0) {
env->SetObjectArrayElement(j_{{list_name}}, (int)i, object);
{{#isRealObjectArray}}env->DeleteLocalRef(object);{{/isRealObjectArray}}
}
list_it = bctbx_list_next(list_it);
i += 1;
}
{{/jlists}}
{{#hasReturn}}{{jniUpcallType}} jni_upcall_result = {{/hasReturn}}env->{{jniUpcallMethod}}(jlistener, jcallback, {{params_impl}});
{{#hasReturn}}
......
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