Implement instance methods and add a blacklist of C functions that must not be wrapped.

This commit is contained in:
Ghislain MARY 2014-07-09 17:26:05 +02:00
parent 6c0efc3ebc
commit 62d58437ea
3 changed files with 27 additions and 14 deletions

View file

@ -26,10 +26,19 @@ sys.path.append(os.path.realpath(__file__))
from apixml2python.linphone import LinphoneModule
blacklisted_functions = [
'linphone_auth_info_write_config',
'lp_config_for_each_entry',
'lp_config_for_each_section',
'lp_config_get_range',
'lp_config_load_dict_to_section',
'lp_config_section_to_dict'
]
def generate(apixmlfile):
tree = ET.parse(apixmlfile)
renderer = pystache.Renderer()
m = LinphoneModule(tree)
m = LinphoneModule(tree, blacklisted_functions)
f = open("linphone.c", "w")
f.write(renderer.render(m))

View file

@ -98,8 +98,8 @@ class MethodDefinition:
if self.return_type != 'void':
self.body += "cresult = "
self.body += self.method_node.get('name') + "("
if self.method_type != 'classmethod':
self.body += "pylinphone_" + self.class_['class_name'] + "_get_native_ptr(self)"
if self.self_arg is not None:
self.body += "native_ptr"
if len(self.arg_names) > 0:
self.body += ', '
self.body += ', '.join(self.arg_names) + ");\n"
@ -194,7 +194,7 @@ class MethodDefinition:
class LinphoneModule(object):
def __init__(self, tree):
def __init__(self, tree, blacklisted_functions):
self.enums = []
xml_enums = tree.findall("./enums/enum")
for xml_enum in xml_enums:
@ -220,15 +220,22 @@ class LinphoneModule(object):
c['class_type_methods'] = []
xml_type_methods = xml_class.findall("./classmethods/classmethod")
for xml_type_method in xml_type_methods:
method_name = xml_type_method.get('name')
if method_name in blacklisted_functions:
continue
m = {}
m['method_name'] = xml_type_method.get('name').replace(c['class_c_function_prefix'], '')
m['method_name'] = method_name.replace(c['class_c_function_prefix'], '')
m['method_body'] = self.__format_method_body(xml_type_method, c)
c['class_type_methods'].append(m)
c['class_instance_methods'] = []
xml_instance_methods = xml_class.findall("./instancemethods/instancemethod")
for xml_instance_method in xml_instance_methods:
method_name = xml_instance_method.get('name')
if method_name in blacklisted_functions:
continue
m = {}
m['method_name'] = xml_instance_method.get('name').replace(c['class_c_function_prefix'], '')
m['method_name'] = method_name.replace(c['class_c_function_prefix'], '')
m['method_body'] = self.__format_method_body(xml_instance_method, c)
c['class_instance_methods'].append(m)
c['class_properties'] = []
xml_properties = xml_class.findall("./properties/property")

View file

@ -57,9 +57,7 @@ static void pylinphone_log(const char *level, const char *fmt) {
{{#classes}}
static PyTypeObject pylinphone_{{class_name}}Type;
{{/classes}}
{{#classes}}
@ -69,8 +67,8 @@ typedef struct {
{{class_cname}} *native_ptr;
} pylinphone_{{class_name}}Object;
static {{class_cname}} * pylinphone_{{class_name}}_get_native_ptr(pylinphone_{{class_name}}Object *self) {
return self->native_ptr;
static {{class_cname}} * pylinphone_{{class_name}}_get_native_ptr(PyObject *self) {
return ((pylinphone_{{class_name}}Object *)self)->native_ptr;
}
static PyObject * pylinphone_{{class_name}}_new_from_native_ptr(PyTypeObject *type, {{class_cname}} *native_ptr) {
@ -106,8 +104,7 @@ static PyObject * pylinphone_{{class_name}}_class_method_{{method_name}}(PyObjec
{{#class_instance_methods}}
static PyObject * pylinphone_{{class_name}}_instance_method_{{method_name}}(PyObject *self, PyObject *args) {
// TODO: Fill implementation
Py_RETURN_NONE;
{{{method_body}}}
}
{{/class_instance_methods}}
@ -127,11 +124,11 @@ static PyMethodDef pylinphone_{{class_name}}_instance_methods[] = {
{{#class_properties}}
static PyObject * pylinphone_{{class_name}}_{{getter_name}}(pylinphone_{{class_name}}Object *self, void *closure) {
static PyObject * pylinphone_{{class_name}}_{{getter_name}}(PyObject *self, void *closure) {
{{{getter_body}}}
}
static int pylinphone_{{class_name}}_{{setter_name}}(pylinphone_{{class_name}}Object *self, PyObject *value, void *closure) {
static int pylinphone_{{class_name}}_{{setter_name}}(PyObject *self, PyObject *value, void *closure) {
{{{setter_body}}}
return 0;
}