Commit b10609f8 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Use getCore methods to synchronize Java wrapper

parent b8925209
......@@ -78,6 +78,17 @@ ENUMS_LIST = {
'XmlRpcRequestStatus': 'XmlRpcRequest',
}
CORE_ACCESSOR_LIST = [
'Call',
'ChatRoom',
'Event',
'Friend',
'FriendList',
'NatPolicy',
'Player',
'ProxyConfig'
]
##########################################################################
class JavaTranslator(object):
......@@ -271,12 +282,12 @@ class JavaTranslator(object):
def translate_argument(self, _arg, native=False, jni=False):
return '{0} {1}'.format(self.translate_type(_arg.type, native, jni), self.translate_argument_name(_arg.name))
def translate_property(self, _property):
def translate_property(self, _property, _hasCoreAccessor):
properties = []
if _property.getter is not None:
properties.append(self.translate_method(_property.getter))
properties.append(self.translate_method(_property.getter, _hasCoreAccessor))
if _property.setter is not None:
properties.append(self.translate_method(_property.setter))
properties.append(self.translate_method(_property.setter, _hasCoreAccessor))
return properties
def translate_jni_property(self, className, _property):
......@@ -317,7 +328,7 @@ class JavaTranslator(object):
def generate_set_listener(self, _class):
return self.generate_listener('setListener', _class)
def translate_method(self, _method):
def translate_method(self, _method, _hasCoreAccessor=False):
methodDict = {}
methodDict['return'] = self.translate_type(_method.returnType, isReturn=True)
......@@ -328,6 +339,8 @@ class JavaTranslator(object):
methodDict['convertInputClassArrayToLongArray'] = False
methodDict['name'] = _method.name.to_camel_case(lower=True)
methodDict['isNotGetCore'] = not methodDict['name'] == 'getCore'
methodDict['hasCoreAccessor'] = _hasCoreAccessor
methodDict['exception'] = self.throws_exception(_method.returnType)
methodDict['enumCast'] = type(_method.returnType) is AbsApi.EnumType
......@@ -459,16 +472,17 @@ class JavaTranslator(object):
classDict['isLinphoneCore'] = _class.name.to_camel_case() == "Core"
classDict['doc'] = _class.briefDescription.translate(self.docTranslator) if _class.briefDescription is not None else None
hasCoreAccessor = _class.name.to_camel_case() in CORE_ACCESSOR_LIST
for _property in _class.properties:
try:
classDict['methods'] += self.translate_property(_property)
classDict['methods'] += self.translate_property(_property, hasCoreAccessor)
classDict['jniMethods'] += self.translate_jni_property(_class.name, _property)
except AbsApi.Error as e:
logging.error('error while translating {0} property: {1}'.format(_property.name.to_snake_case(), e.args[0]))
for method in _class.instanceMethods:
try:
methodDict = self.translate_method(method)
methodDict = self.translate_method(method, hasCoreAccessor)
jniMethodDict = self.translate_jni_method(_class.name, method)
classDict['methods'].append(methodDict)
classDict['jniMethods'].append(jniMethodDict)
......@@ -477,7 +491,7 @@ class JavaTranslator(object):
for method in _class.classMethods:
try:
methodDict = self.translate_method(method)
methodDict = self.translate_method(method, hasCoreAccessor)
jniMethodDict = self.translate_jni_method(_class.name, method, True)
classDict['methods'].append(methodDict)
classDict['jniMethods'].append(jniMethodDict)
......
......@@ -181,9 +181,11 @@ class {{classImplName}} {{#isLinphoneFactory}}extends{{/isLinphoneFactory}}{{#is
{{#methods}}
private native {{return_native}} {{name}}({{native_params}});
@Override
public {{return}} {{name}}({{params}}) {{#exception}}throws CoreException{{/exception}} {
synchronized public {{return}} {{name}}({{params}}) {{#exception}}throws CoreException{{/exception}} {
{{#hasCoreAccessor}}{{#isNotGetCore}}synchronized(getCore()) { {{/isNotGetCore}}{{/hasCoreAccessor}}
{{#exception}}int exceptionResult = {{/exception}}{{return_keyword}}{{#enumCast}}{{return}}.fromInt({{/enumCast}}{{#classCast}}({{return}}){{/classCast}}{{name}}(nativePtr{{native_params_impl}}){{#enumCast}}){{/enumCast}};{{#exception}}
if (exceptionResult != 0) throw new CoreException("{{name}} returned value " + exceptionResult);{{/exception}}
if (exceptionResult != 0) throw new CoreException("{{name}} returned value " + exceptionResult);{{/exception}}{{#hasCoreAccessor}}{{#isNotGetCore}}
}{{/isNotGetCore}}{{/hasCoreAccessor}}
}
{{/methods}}
......
......@@ -220,6 +220,7 @@ public:
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
......@@ -298,7 +299,7 @@ static {{return}} {{callbackName}}({{params}}) {
jobject jlistener = (jobject) {{cPrefix}}_cbs_get_user_data(cbs);
if (jlistener == NULL) {
ms_warning("{{name}}() notification without listener");
ms_warning("{{callbackName}}() notification without listener");
return{{returnIfFail}};
}
......@@ -403,8 +404,6 @@ jobject Java_{{jni_package}}CoreImpl_getMediastreamerFactory(JNIEnv *env, jobjec
jobject Java_{{jni_package}}FactoryImpl_createCore(JNIEnv *env, jobject thiz, jobject jfactory, jobject jlistener, jstring jconfig_path, jstring jfactory_config_path, jobject jcontext) {
LinphoneFactory *cptr = linphone_factory_get();
SetObjectNativePtr(env, jfactory, (jlong)cptr); // Set the C factory ptr as Factory.nativePtr for next factory calls
LinphoneCoreCbs *cbs = linphone_factory_create_core_cbs(cptr);
jobject listener = env->NewGlobalRef(jlistener);
......
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