Commit 1e09e1ca authored by DanmeiChen's avatar DanmeiChen

remove useless code

parent 4d7ae6ff
......@@ -1314,7 +1314,7 @@ class SwiftLangTranslator(CLikeLangTranslator):
if type(_type.parent) is Argument:
return 'String'
else:
res = 'IntPtr' # Return as IntPtr and get string with Marshal.PtrToStringAnsi()
res = 'IntPtr' # TODO check
else:
return 'String'
elif _type.name == 'character':
......@@ -1323,9 +1323,9 @@ class SwiftLangTranslator(CLikeLangTranslator):
else:
res = 'CChar'
elif _type.name == 'time':
res = 'Int' #TODO check
res = 'Int'
elif _type.name == 'size':
res = 'Int' #TODO check
res = 'Int'
elif _type.name == 'floatant':
if _type.size is not None and _type.isref:
return 'UnsafeMutablePointer<Float>'
......@@ -1334,7 +1334,7 @@ class SwiftLangTranslator(CLikeLangTranslator):
elif _type.name == 'string_array':
if dllImport or type(_type.parent) is Argument:
return 'IntPtr'
return 'IntPtr' # TODO:check
else:
return '[String]'
else:
......
......@@ -157,24 +157,10 @@ class SwiftTranslator(object):
listenerDict = {}
c_name_setter = listenedClass.name.to_snake_case(fullName=True) + '_cbs_set_' + method.name.to_snake_case()[3:]
delegate_name_public = method.name.translate(self.nameTranslator) + "Delegate"
delegate_name_private = delegate_name_public + "Private"
listenerDict['cb_setter'] = {}
listenerDict['cb_setter']['name'] = c_name_setter
listenerDict['name_private'] = delegate_name_private
listenerDict['delegate'] = {}
listenerDict['delegate']['name_public'] = delegate_name_public
listenerDict['delegate']['name_private'] = delegate_name_private
var_name_public = method.name.to_snake_case() + '_public'
var_name_private = method.name.to_snake_case() + '_private'
listenerDict['delegate']['var_public'] = var_name_public
listenerDict['delegate']['var_private'] = var_name_private
listenerDict['delegate']['cb_name'] = method.name.to_snake_case()
listenerDict['delegate']['name'] = method.name.translate(self.nameTranslator)
listenerDict['delegate']['interfaceClassName'] = listenedClass.name.translate(self.nameTranslator)
listenerDict['delegate']['isSimpleListener'] = listenedClass.singlelistener
listenerDict['delegate']['isMultiListener'] = listenedClass.multilistener
listenerDict['delegate']['params_public'] = ""
listenerDict['delegate']['params_private'] = ""
......@@ -190,9 +176,6 @@ class SwiftTranslator(object):
listenerDict['delegate']['params_private'] += ', '
listenerDict['delegate']['params'] += ', '
#if normalType == dllImportType:
# listenerDict['delegate']['params'] += argName + ": " + argName
#else:
if normalType == "Bool":
listenerDict['delegate']['params'] += argName + ": " + argName + ">0"
elif self.is_linphone_type(arg.type, True, dllImport=False) and type(arg.type) is AbsApi.ClassType:
......@@ -209,6 +192,8 @@ class SwiftTranslator(object):
listenerDict['delegate']['params'] += argName + ": " + argName + "sList"
elif normalType == "String":
listenerDict['delegate']['params'] += argName + ": charArrayToString(charPointer: " + argName +")!"
elif normalType == "Int":
listenerDict['delegate']['params'] += argName + ": Int(" + argName + ")"
else:
print 'Not supported yet: ' + delegate_name_public
return {}
......@@ -225,20 +210,14 @@ class SwiftTranslator(object):
def generate_getter_for_listener_callbacks(self, _class, classname):
methodDict = self.init_method_dict()
c_name = _class.name.to_snake_case(fullName=True) + '_get_callbacks'
#methodDict['prototype'] = "static extern IntPtr {c_name}(IntPtr thiz);".format(classname = classname, c_name = c_name)
methodDict['listener'] = True
methodDict['getListener'] = True
#methodDict['has_property'] = FALSE
methodDict['property_static'] = ''
methodDict['property_return'] = classname
methodDict['impl']['name'] = 'getDelegate'
methodDict['impl']['args'] = ''
methodDict['has_getter'] = True
methodDict['impl']['return'] = classname + 'Cbs'
methodDict['name'] = 'getDelegate'
methodDict['args'] = ''
methodDict['impl']['c_name'] = c_name
methodDict['is_class'] = True
methodDict['c_name'] = c_name
methodDict['addListener'] = False
return methodDict
......@@ -247,37 +226,28 @@ class SwiftTranslator(object):
def generate_add_for_listener_callbacks(self, _class, classname):
methodDict = self.init_method_dict()
c_name = _class.name.to_snake_case(fullName=True) + '_add_callbacks'
#methodDict['prototype'] = "static extern void {c_name}(IntPtr thiz, IntPtr cbs);".format(classname = classname, c_name = c_name)
methodDict['listener'] = True
methodDict['impl']['static'] = ''
methodDict['impl']['type'] = 'void'
methodDict['impl']['name'] = 'addDelegate'
#methodDict['impl']['return'] = ''
methodDict['impl']['c_name'] = c_name
methodDict['impl']['nativePtr'] = 'nativePtr, '
methodDict['impl']['args'] = 'delegate: ' + classname + 'Delegate'
methodDict['impl']['c_args'] = 'cbs != null ? cbs.nativePtr : IntPtr.Zero'
methodDict['impl']['addListener'] = True
methodDict['impl']['removeListener'] = False
methodDict['name'] = 'addDelegate'
methodDict['c_name'] = c_name
methodDict['args'] = 'delegate: ' + classname + 'Delegate'
methodDict['addListener'] = True
methodDict['removeListener'] = False
return methodDict
def generate_remove_for_listener_callbacks(self, _class, classname):
methodDict = self.init_method_dict()
c_name = _class.name.to_snake_case(fullName=True) + '_remove_callbacks'
#methodDict['prototype'] = "static extern void {c_name}(IntPtr thiz, IntPtr cbs);".format(classname = classname, c_name = c_name)
methodDict['impl']['static'] = ''
methodDict['listener'] = True
methodDict['impl']['type'] = 'void'
methodDict['impl']['name'] = 'removeDelegate'
#methodDict['impl']['return'] = ''
methodDict['impl']['c_name'] = c_name
methodDict['impl']['nativePtr'] = 'nativePtr, '
methodDict['impl']['args'] = 'delegate: ' + classname + 'Delegate'
methodDict['impl']['c_args'] = 'cbs != null ? cbs.nativePtr : IntPtr.Zero'
methodDict['name'] = 'removeDelegate'
methodDict['c_name'] = c_name
methodDict['args'] = 'delegate: ' + classname + 'Delegate'
methodDict['removeListener'] = True
methodDict['impl']['addListener'] = False
methodDict['impl']['removeListener'] = True
methodDict['addListener'] = False
return methodDict
......@@ -416,6 +386,7 @@ class SwiftTranslator(object):
methodDict = self.translate_method(prop, static, False)
methodDict['property_name'] = name
methodDict['func_name'] = "set" + name.capitalize()
methodDict['has_property'] = True
methodDict['has_getter'] = False
methodDict['has_setter'] = True
......@@ -458,6 +429,7 @@ class SwiftTranslator(object):
methodDict['setter_c_name'] = methodDictSet['setter_c_name']
methodDict['enum_type'] = methodDictSet['enum_type']
methodDict['int_method'] = methodDictSet['int_method']
methodDict['func_name'] = methodDictSet['func_name']
return methodDict
......
......@@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import Foundation
import linphone
//////////////////// region enums ////////////////////
// MARK: region enums
{{#enums}}
{{#enum}}
{{#doc}}
......@@ -64,7 +64,7 @@ public enum {{enumName}}:Int
{{/enums}}
//////////////////// region utils ////////////////////
// MARK: region utils
func charArrayToString(charPointer: UnsafePointer<CChar>?) -> String? {
return charPointer != nil ? String(cString: charPointer!) : nil
}
......@@ -78,6 +78,7 @@ public class LinphoneObject {
}
deinit {
belle_sip_object_data_set(UnsafeMutablePointer(cPtr), "swiftRef", nil, nil)
belle_sip_object_unref(UnsafeMutableRawPointer(cPtr))
}
}
......@@ -94,7 +95,7 @@ func StringArrayToBctbxList(list: [String]) -> UnsafeMutablePointer<bctbx_list_t
func BctbxListToStringArray(list: UnsafeMutablePointer<bctbx_list_t>) -> [String]? {
var sList = [String]()
var cList = list
while (cList != nil) {
while (cList.pointee.data != nil) {
sList.append(String(cString: unsafeBitCast(cList.pointee.data, to: UnsafePointer<CChar>.self)))
cList = UnsafeMutablePointer<bctbx_list_t>(cList.pointee.next)
}
......@@ -113,8 +114,11 @@ protocol LinphoneObjectDelegate {
var cPtr: OpaquePointer {get set}
}
enum LinphoneError: Error {
case exception(result: String)
}
//////////////////// region Delegates ////////////////////
// MARK: region Delegates
{{#interfaces}}
{{#interface}}
......@@ -146,6 +150,11 @@ public class {{interfaceName}} : LinphoneObjectDelegate
{{/methods}}
}
deinit {
belle_sip_object_data_set(UnsafeMutablePointer(cPtr), "swiftRef", nil, nil)
belle_sip_object_unref(UnsafeMutableRawPointer(cPtr))
}
{{#methods}}
{{#delegate}}
func {{cb_name}}({{{params_public}}}){}
......@@ -156,7 +165,7 @@ public class {{interfaceName}} : LinphoneObjectDelegate
{{/interfaces}}
//////////////////// region classes ////////////////////
// MARK: region classes
{{#classes}}
{{#_class}}
......@@ -261,8 +270,10 @@ public class {{className}} : LinphoneObject
{
{{#has_getter}}
{{#has_setter}}
{{^exception}}
get
{
{{/exception}}
{{/has_setter}}
{{#is_callbacks}}
let cObject = {{getter_c_name}}(cPtr)
......@@ -312,10 +323,13 @@ public class {{className}} : LinphoneObject
{{/is_class_list}}
{{/is_callbacks}}
{{#has_setter}}
{{^exception}}
}
{{/exception}}
{{/has_setter}}
{{/has_getter}}
{{#has_setter}}
{{^exception}}
{{#has_getter}}
set
{{/has_getter}}
......@@ -324,22 +338,22 @@ public class {{className}} : LinphoneObject
{{/has_getter}}
{
{{#is_string}}
{{#exception}}let exception_result = {{/exception}}{{setter_c_name}}(cPtr, newValue)
{{setter_c_name}}(cPtr, newValue)
{{/is_string}}
{{#is_bool}}
{{#exception}}let exception_result = {{/exception}}{{setter_c_name}}(cPtr, newValue==true ? 1:0)
{{setter_c_name}}(cPtr, newValue==true ? 1:0)
{{/is_bool}}
{{#is_class}}
{{#exception}}let exception_result = {{/exception}}{{setter_c_name}}(cPtr, newValue?.cPtr)
{{setter_c_name}}(cPtr, newValue?.cPtr)
{{/is_class}}
{{#is_enum}}
{{#exception}}let exception_result = {{/exception}}{{setter_c_name}}(cPtr, Linphone{{{return}}}(rawValue: {{enum_type}}(newValue{{^has_getter}}!{{/has_getter}}.rawValue)))
{{setter_c_name}}(cPtr, Linphone{{{return}}}(rawValue: {{enum_type}}(newValue{{^has_getter}}!{{/has_getter}}.rawValue)))
{{/is_enum}}
{{#is_int}}
{{#exception}}let exception_result = {{/exception}}{{setter_c_name}}(cPtr, {{int_method}}(newValue))
{{setter_c_name}}(cPtr, {{int_method}}(newValue))
{{/is_int}}
{{#is_generic}}
{{#exception}}let exception_result = {{/exception}}{{setter_c_name}}(cPtr, newValue)
{{setter_c_name}}(cPtr, newValue)
{{/is_generic}}
{{#is_string_list}}
var cList: UnsafeMutablePointer<bctbx_list_t>? = nil
......@@ -347,27 +361,66 @@ public class {{className}} : LinphoneObject
let sData:NSString = data as NSString
cList = bctbx_list_append(cList, unsafeBitCast(sData.utf8String, to: UnsafeMutablePointer<CChar>.self))
}
{{#exception}}let exception_result = {{/exception}}{{setter_c_name}}(cPtr, cList)
{{setter_c_name}}(cPtr, cList)
{{/is_string_list}}
{{#is_class_list}}
var cList: UnsafeMutablePointer<bctbx_list_t>? = nil
for data in newValue {
cList = bctbx_list_append(cList, UnsafeMutableRawPointer(data.cPtr))
}
{{#exception}}let exception_result = {{/exception}}{{setter_c_name}}(cPtr, cList)
{{setter_c_name}}(cPtr, cList)
{{/is_class_list}}
{{#exception}}
if (exception_result != 0) {
print("{{property_name}} setter returned value \(exception_result)")
}
{{/exception}}
}
{{/exception}}
{{/has_setter}}
}
{{#has_setter}}
{{#exception}}
func {{func_name}}(newValue: {{{return}}}) throws
{
{{#is_string}}
let exception_result = {{setter_c_name}}(cPtr, newValue)
{{/is_string}}
{{#is_bool}}
let exception_result = {{setter_c_name}}(cPtr, newValue==true ? 1:0)
{{/is_bool}}
{{#is_class}}
let exception_result = {{setter_c_name}}(cPtr, newValue.cPtr)
{{/is_class}}
{{#is_enum}}
let exception_result = {{setter_c_name}}(cPtr, Linphone{{{return}}}(rawValue: {{enum_type}}(newValue{{^has_getter}}!{{/has_getter}}.rawValue)))
{{/is_enum}}
{{#is_int}}
let exception_result = {{setter_c_name}}(cPtr, {{int_method}}(newValue))
{{/is_int}}
{{#is_generic}}
let exception_result = {{setter_c_name}}(cPtr, newValue)
{{/is_generic}}
{{#is_string_list}}
var cList: UnsafeMutablePointer<bctbx_list_t>? = nil
for data in newValue {
let sData:NSString = data as NSString
cList = bctbx_list_append(cList, unsafeBitCast(sData.utf8String, to: UnsafeMutablePointer<CChar>.self))
}
let exception_result = {{setter_c_name}}(cPtr, cList)
{{/is_string_list}}
{{#is_class_list}}
var cList: UnsafeMutablePointer<bctbx_list_t>? = nil
for data in newValue {
cList = bctbx_list_append(cList, UnsafeMutableRawPointer(data.cPtr))
}
let exception_result = {{setter_c_name}}(cPtr, cList)
{{/is_class_list}}
guard exception_result == 0 else {
throw LinphoneError.exception(result: "username setter returned value \(exception_result)")
}
}
{{/exception}}
{{/has_setter}}
{{/has_property}}
{{#listener}}
{{#impl}}
func {{name}}({{#args}}delegate: {{className}}Delegate{{/args}}){{#return}} -> {{className}}Delegate?{{/return}}
func {{name}}({{#args}}delegate: {{className}}Delegate{{/args}}){{#property_return}} -> {{className}}Delegate?{{/property_return}}
{
{{#getListener}}
let cObject = {{c_name}}(cPtr)
......@@ -384,16 +437,14 @@ public class {{className}} : LinphoneObject
{{c_name}}(cPtr, delegate.cPtr)
{{/removeListener}}
}
{{/impl}}
{{/listener}}
{{^listener}}
{{#impl}}
{{#doc}}
{{#lines}}
/// {{{line}}}
{{/lines}}
{{/doc}}
{{static}} func {{name}}({{{args}}}) {{#return}}-> {{{type}}}{{#is_string}}?{{/is_string}}{{/return}}
{{static}} func {{name}}({{{args}}}){{#exception}} throws{{/exception}} {{#return}}-> {{{type}}}{{#is_string}}?{{/is_string}}{{/return}}
{
{{#is_string}}
{{return}}charArrayToString(charPointer: {{c_name}}({{cPtr}}{{{c_args}}}))
......@@ -407,24 +458,24 @@ public class {{className}} : LinphoneObject
{{#is_enum}}
{{#exception}}let exception_result = {{/exception}}{{#return}}{{return}}{{{type}}}(rawValue: Int({{/return}}{{c_name}}({{cPtr}}{{{c_args}}}){{#return}}.rawValue))!{{/return}}
{{#exception}}
if (exception_result != 0) {
print("{{name}} returned value \(exception_result)")
guard exception_result == 0 else {
throw LinphoneError.exception(result: "{{name}} returned value \(exception_result)")
}
{{/exception}}
{{/is_enum}}
{{#is_int}}
{{#exception}}let exception_result = {{/exception}}{{return}}{{{type}}}({{c_name}}({{cPtr}}{{{c_args}}}))
{{#exception}}
if (exception_result != 0) {
print("{{name}} returned value \(exception_result)")
guard exception_result == 0 else {
throw LinphoneError.exception(result: "{{name}} returned value \(exception_result)")
}
{{/exception}}
{{/is_int}}
{{#is_generic}}
{{#exception}}let exception_result = {{/exception}}{{return}}{{c_name}}({{cPtr}}{{{c_args}}})
{{#exception}}
if (exception_result != 0) {
print("{{name}} returned value \(exception_result)")
guard exception_result == 0 else {
throw LinphoneError.exception(result: "{{name}} returned value \(exception_result)")
}
{{/exception}}
{{/is_generic}}
......@@ -449,7 +500,6 @@ public class {{className}} : LinphoneObject
{{/is_class_list}}
}
{{/impl}}
{{/listener}}
{{/dllImports}}
}
{{/_class}}
......
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