Commit a6cfecf3 authored by Ghislain MARY's avatar Ghislain MARY

Handle events in classes other than LinphoneCore.

Callbacks getters still need to be implemented correctly.
parent 1656945e
......@@ -95,7 +95,7 @@ void linphone_chat_message_cbs_set_user_data(LinphoneChatMessageCbs *cbs, void *
* @param[in] cbs LinphoneChatMessageCbs object.
* @return The current message state changed callback.
*/
LinphoneChatMessageMsgStateChangedCb linphone_chat_message_cbs_get_msg_state_changed(const LinphoneChatMessageCbs *cbs) {
LinphoneChatMessageCbsMsgStateChangedCb linphone_chat_message_cbs_get_msg_state_changed(const LinphoneChatMessageCbs *cbs) {
return cbs->msg_state_changed;
}
......@@ -104,7 +104,7 @@ LinphoneChatMessageMsgStateChangedCb linphone_chat_message_cbs_get_msg_state_cha
* @param[in] cbs LinphoneChatMessageCbs object.
* @param[in] cb The message state changed callback to be used.
*/
void linphone_chat_message_cbs_set_msg_state_changed(LinphoneChatMessageCbs *cbs, LinphoneChatMessageMsgStateChangedCb cb) {
void linphone_chat_message_cbs_set_msg_state_changed(LinphoneChatMessageCbs *cbs, LinphoneChatMessageCbsMsgStateChangedCb cb) {
cbs->msg_state_changed = cb;
}
......@@ -113,7 +113,7 @@ void linphone_chat_message_cbs_set_msg_state_changed(LinphoneChatMessageCbs *cbs
* @param[in] cbs LinphoneChatMessageCbs object.
* @return The current file transfer receive callback.
*/
LinphoneChatMessageFileTransferRecvCb linphone_chat_message_cbs_get_file_transfer_recv(const LinphoneChatMessageCbs *cbs) {
LinphoneChatMessageCbsFileTransferRecvCb linphone_chat_message_cbs_get_file_transfer_recv(const LinphoneChatMessageCbs *cbs) {
return cbs->file_transfer_recv;
}
......@@ -122,7 +122,7 @@ LinphoneChatMessageFileTransferRecvCb linphone_chat_message_cbs_get_file_transfe
* @param[in] cbs LinphoneChatMessageCbs object.
* @param[in] cb The file transfer receive callback to be used.
*/
void linphone_chat_message_cbs_set_file_transfer_recv(LinphoneChatMessageCbs *cbs, LinphoneChatMessageFileTransferRecvCb cb) {
void linphone_chat_message_cbs_set_file_transfer_recv(LinphoneChatMessageCbs *cbs, LinphoneChatMessageCbsFileTransferRecvCb cb) {
cbs->file_transfer_recv = cb;
}
......@@ -131,7 +131,7 @@ void linphone_chat_message_cbs_set_file_transfer_recv(LinphoneChatMessageCbs *cb
* @param[in] cbs LinphoneChatMessageCbs object.
* @return The current file transfer send callback.
*/
LinphoneChatMessageFileTransferSendCb linphone_chat_message_cbs_get_file_transfer_send(const LinphoneChatMessageCbs *cbs) {
LinphoneChatMessageCbsFileTransferSendCb linphone_chat_message_cbs_get_file_transfer_send(const LinphoneChatMessageCbs *cbs) {
return cbs->file_transfer_send;
}
......@@ -140,7 +140,7 @@ LinphoneChatMessageFileTransferSendCb linphone_chat_message_cbs_get_file_transfe
* @param[in] cbs LinphoneChatMessageCbs object.
* @param[in] cb The file transfer send callback to be used.
*/
void linphone_chat_message_cbs_set_file_transfer_send(LinphoneChatMessageCbs *cbs, LinphoneChatMessageFileTransferSendCb cb) {
void linphone_chat_message_cbs_set_file_transfer_send(LinphoneChatMessageCbs *cbs, LinphoneChatMessageCbsFileTransferSendCb cb) {
cbs->file_transfer_send = cb;
}
......@@ -149,7 +149,7 @@ void linphone_chat_message_cbs_set_file_transfer_send(LinphoneChatMessageCbs *cb
* @param[in] cbs LinphoneChatMessageCbs object.
* @return The current file transfer progress indication callback.
*/
LinphoneChatMessageFileTransferProgressIndicationCb linphone_chat_message_cbs_get_file_transfer_progress_indication(const LinphoneChatMessageCbs *cbs) {
LinphoneChatMessageCbsFileTransferProgressIndicationCb linphone_chat_message_cbs_get_file_transfer_progress_indication(const LinphoneChatMessageCbs *cbs) {
return cbs->file_transfer_progress_indication;
}
......@@ -158,7 +158,7 @@ LinphoneChatMessageFileTransferProgressIndicationCb linphone_chat_message_cbs_ge
* @param[in] cbs LinphoneChatMessageCbs object.
* @param[in] cb The file transfer progress indication callback to be used.
*/
void linphone_chat_message_cbs_set_file_transfer_progress_indication(LinphoneChatMessageCbs *cbs, LinphoneChatMessageFileTransferProgressIndicationCb cb) {
void linphone_chat_message_cbs_set_file_transfer_progress_indication(LinphoneChatMessageCbs *cbs, LinphoneChatMessageCbsFileTransferProgressIndicationCb cb) {
cbs->file_transfer_progress_indication = cb;
}
......
......@@ -1331,9 +1331,10 @@ typedef enum _LinphoneChatMessageState {
/**
* Call back used to notify message delivery status
*@param msg #LinphoneChatMessage object
*@param status LinphoneChatMessageState
*@param ud application user data
* @param msg #LinphoneChatMessage object
* @param status LinphoneChatMessageState
* @param ud application user data
* @deprecated
*/
typedef void (*LinphoneChatMessageStateChangedCb)(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud);
......@@ -1342,7 +1343,7 @@ typedef void (*LinphoneChatMessageStateChangedCb)(LinphoneChatMessage* msg,Linph
* @param msg #LinphoneChatMessage object
* @param status LinphoneChatMessageState
*/
typedef void (*LinphoneChatMessageMsgStateChangedCb)(LinphoneChatMessage* msg, LinphoneChatMessageState state);
typedef void (*LinphoneChatMessageCbsMsgStateChangedCb)(LinphoneChatMessage* msg, LinphoneChatMessageState state);
/**
* File transfer receive callback prototype. This function is called by the core upon an incoming File transfer is started. This function may be call several time for the same file in case of large file.
......@@ -1353,7 +1354,7 @@ typedef void (*LinphoneChatMessageMsgStateChangedCb)(LinphoneChatMessage* msg, L
* @param size number of bytes to be read from buff. 0 means end of file.
*
*/
typedef void (*LinphoneChatMessageFileTransferRecvCb)(LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size);
typedef void (*LinphoneChatMessageCbsFileTransferRecvCb)(LinphoneChatMessage *message, const LinphoneContent* content, const char* buff, size_t size);
/**
* File transfer send callback prototype. This function is called by the core upon an outgoing File transfer is started. This function is called until size is set to 0.
......@@ -1365,7 +1366,7 @@ typedef void (*LinphoneChatMessageFileTransferRecvCb)(LinphoneChatMessage *messa
* @param size as input value, it represents the number of bytes expected by the framework. As output value, it means the number of bytes wrote by the application in the buffer. 0 means end of file.
*
*/
typedef void (*LinphoneChatMessageFileTransferSendCb)(LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size);
typedef void (*LinphoneChatMessageCbsFileTransferSendCb)(LinphoneChatMessage *message, const LinphoneContent* content, char* buff, size_t* size);
/**
* File transfer progress indication callback prototype.
......@@ -1375,7 +1376,7 @@ typedef void (*LinphoneChatMessageFileTransferSendCb)(LinphoneChatMessage *messa
* @param offset The number of bytes sent/received since the beginning of the transfer.
* @param total The total number of bytes to be sent/received.
*/
typedef void (*LinphoneChatMessageFileTransferProgressIndicationCb)(LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total);
typedef void (*LinphoneChatMessageCbsFileTransferProgressIndicationCb)(LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total);
LINPHONE_PUBLIC void linphone_core_set_chat_database_path(LinphoneCore *lc, const char *path);
LINPHONE_PUBLIC LinphoneChatRoom * linphone_core_create_chat_room(LinphoneCore *lc, const char *to);
......@@ -1515,14 +1516,14 @@ LINPHONE_PUBLIC LinphoneChatMessageCbs * linphone_chat_message_cbs_ref(LinphoneC
LINPHONE_PUBLIC void linphone_chat_message_cbs_unref(LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void *linphone_chat_message_cbs_get_user_data(const LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void linphone_chat_message_cbs_set_user_data(LinphoneChatMessageCbs *cbs, void *ud);
LINPHONE_PUBLIC LinphoneChatMessageMsgStateChangedCb linphone_chat_message_cbs_get_msg_state_changed(const LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void linphone_chat_message_cbs_set_msg_state_changed(LinphoneChatMessageCbs *cbs, LinphoneChatMessageMsgStateChangedCb cb);
LINPHONE_PUBLIC LinphoneChatMessageFileTransferRecvCb linphone_chat_message_cbs_get_file_transfer_recv(const LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void linphone_chat_message_cbs_set_file_transfer_recv(LinphoneChatMessageCbs *cbs, LinphoneChatMessageFileTransferRecvCb cb);
LINPHONE_PUBLIC LinphoneChatMessageFileTransferSendCb linphone_chat_message_cbs_get_file_transfer_send(const LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void linphone_chat_message_cbs_set_file_transfer_send(LinphoneChatMessageCbs *cbs, LinphoneChatMessageFileTransferSendCb cb);
LINPHONE_PUBLIC LinphoneChatMessageFileTransferProgressIndicationCb linphone_chat_message_cbs_get_file_transfer_progress_indication(const LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void linphone_chat_message_cbs_set_file_transfer_progress_indication(LinphoneChatMessageCbs *cbs, LinphoneChatMessageFileTransferProgressIndicationCb cb);
LINPHONE_PUBLIC LinphoneChatMessageCbsMsgStateChangedCb linphone_chat_message_cbs_get_msg_state_changed(const LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void linphone_chat_message_cbs_set_msg_state_changed(LinphoneChatMessageCbs *cbs, LinphoneChatMessageCbsMsgStateChangedCb cb);
LINPHONE_PUBLIC LinphoneChatMessageCbsFileTransferRecvCb linphone_chat_message_cbs_get_file_transfer_recv(const LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void linphone_chat_message_cbs_set_file_transfer_recv(LinphoneChatMessageCbs *cbs, LinphoneChatMessageCbsFileTransferRecvCb cb);
LINPHONE_PUBLIC LinphoneChatMessageCbsFileTransferSendCb linphone_chat_message_cbs_get_file_transfer_send(const LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void linphone_chat_message_cbs_set_file_transfer_send(LinphoneChatMessageCbs *cbs, LinphoneChatMessageCbsFileTransferSendCb cb);
LINPHONE_PUBLIC LinphoneChatMessageCbsFileTransferProgressIndicationCb linphone_chat_message_cbs_get_file_transfer_progress_indication(const LinphoneChatMessageCbs *cbs);
LINPHONE_PUBLIC void linphone_chat_message_cbs_set_file_transfer_progress_indication(LinphoneChatMessageCbs *cbs, LinphoneChatMessageCbsFileTransferProgressIndicationCb cb);
/**
* @}
......
......@@ -149,10 +149,10 @@ typedef struct _CallCallbackObj
struct _LinphoneChatMessageCbs {
belle_sip_object_t base;
void *user_data;
LinphoneChatMessageMsgStateChangedCb msg_state_changed;
LinphoneChatMessageFileTransferRecvCb file_transfer_recv; /**< Callback to store file received attached to a #LinphoneChatMessage */
LinphoneChatMessageFileTransferSendCb file_transfer_send; /**< Callback to collect file chunk to be sent for a #LinphoneChatMessage */
LinphoneChatMessageFileTransferProgressIndicationCb file_transfer_progress_indication; /**< Callback to indicate file transfer progress */
LinphoneChatMessageCbsMsgStateChangedCb msg_state_changed;
LinphoneChatMessageCbsFileTransferRecvCb file_transfer_recv; /**< Callback to store file received attached to a #LinphoneChatMessage */
LinphoneChatMessageCbsFileTransferSendCb file_transfer_send; /**< Callback to collect file chunk to be sent for a #LinphoneChatMessage */
LinphoneChatMessageCbsFileTransferProgressIndicationCb file_transfer_progress_indication; /**< Callback to indicate file transfer progress */
};
BELLE_SIP_DECLARE_VPTR(LinphoneChatMessageCbs);
......
......@@ -198,15 +198,15 @@ class CClass(CObject):
def __addClassMethod(self, f):
name = f.name[len(self.cFunctionPrefix):]
if string.find(name, 'get_') == 0 and len(f.arguments) == 0:
if name.startswith('get_') and len(f.arguments) == 0:
self.__addPropertyGetter(name[4:], f)
elif string.find(name, 'is_') == 0 and len(f.arguments) == 0 and f.returnArgument.ctype == 'bool_t':
elif name.startswith('is_') and len(f.arguments) == 0 and f.returnArgument.ctype == 'bool_t':
self.__addPropertyGetter(name[3:], f)
elif string.rfind(name, '_enabled') == (len(name) - 8) and len(f.arguments) == 0 and f.returnArgument.ctype == 'bool_t':
elif name.endswith('_enabled') and len(f.arguments) == 0 and f.returnArgument.ctype == 'bool_t':
self.__addPropertyGetter(name, f)
elif string.find(name, 'set_') == 0 and len(f.arguments) == 1:
elif name.startswith('set_') and len(f.arguments) == 1:
self.__addPropertySetter(name[4:], f)
elif string.find(name, 'enable_') == 0 and len(f.arguments) == 1 and f.arguments[0].ctype == 'bool_t':
elif name.startswith('enable_') and len(f.arguments) == 1 and f.arguments[0].ctype == 'bool_t':
self.__addPropertySetter(name[7:] + '_enabled', f)
else:
if not f.name in self.classMethods:
......@@ -214,15 +214,15 @@ class CClass(CObject):
def __addInstanceMethod(self, f):
name = f.name[len(self.cFunctionPrefix):]
if string.find(name, 'get_') == 0 and len(f.arguments) == 1:
if name.startswith('get_') and len(f.arguments) == 1:
self.__addPropertyGetter(name[4:], f)
elif string.find(name, 'is_') == 0 and len(f.arguments) == 1 and f.returnArgument.ctype == 'bool_t':
elif name.startswith('is_') and len(f.arguments) == 1 and f.returnArgument.ctype == 'bool_t':
self.__addPropertyGetter(name[3:], f)
elif string.rfind(name, '_enabled') == (len(name) - 8) and len(f.arguments) == 1 and f.returnArgument.ctype == 'bool_t':
elif name.endswith('_enabled') and len(f.arguments) == 1 and f.returnArgument.ctype == 'bool_t':
self.__addPropertyGetter(name, f)
elif string.find(name, 'set_') == 0 and len(f.arguments) == 2:
elif name.startswith('set_') and len(f.arguments) == 2:
self.__addPropertySetter(name[4:], f)
elif string.find(name, 'enable_') == 0 and len(f.arguments) == 2 and f.arguments[1].ctype == 'bool_t':
elif name.startswith('enable_') and len(f.arguments) == 2 and f.arguments[1].ctype == 'bool_t':
self.__addPropertySetter(name[7:] + '_enabled', f)
else:
if not f.name in self.instanceMethods:
......@@ -314,12 +314,12 @@ class Project:
def __discoverClasses(self):
for td in self.__typedefs:
if string.find(td.definition, 'enum ') == 0:
if td.definition.startswith('enum '):
for e in self.enums:
if (e.associatedTypedef is None) and td.definition[5:] == e.name:
e.associatedTypedef = td
break
elif string.find(td.definition, 'struct ') == 0:
elif td.definition.startswith('struct '):
structFound = False
for st in self.__structs:
if (st.associatedTypedef is None) and td.definition[7:] == st.name:
......@@ -333,7 +333,7 @@ class Project:
st.associatedTypedef = td
self.add(st)
for td in self.__typedefs:
if string.find(td.definition, 'struct ') == 0:
if td.definition.startswith('struct '):
for st in self.__structs:
if st.associatedTypedef == td:
self.add(CClass(st))
......@@ -346,9 +346,18 @@ class Project:
# Sort classes by length of name (longest first), so that methods are put in the right class
self.classes.sort(key = lambda c: len(c.name), reverse = True)
for e in self.__events:
eventAdded = False
for c in self.classes:
if string.find(e.name, c.name) == 0:
if c.name.endswith('Cbs') and e.name.startswith(c.name):
c.addEvent(e)
eventAdded = True
break
if not eventAdded:
for c in self.classes:
if e.name.startswith(c.name):
c.addEvent(e)
eventAdded = True
break
for f in self.__functions:
for c in self.classes:
if c.cFunctionPrefix == f.name[0 : len(c.cFunctionPrefix)]:
......@@ -417,9 +426,9 @@ class Project:
def __parseCTypedefMemberdef(self, node):
name = node.find('./name').text
definition = node.find('./definition').text
if string.find(definition, 'typedef ') == 0:
if definition.startswith('typedef '):
definition = definition[8 :]
if string.rfind(name, 'Cb') == len(name) - 2:
if name.endswith('Cb'):
pos = string.find(definition, "(*")
if pos == -1:
return None
......
......@@ -201,9 +201,9 @@ static PyObject * pylinphone_Core_class_method_new(PyObject *cls, PyObject *args
}
Py_INCREF(_vtable_dict);
self->vtable_dict = _vtable_dict;
{{#events}}
{{#core_events}}
{{{event_vtable_reference}}}
{{/events}}
{{/core_events}}
pylinphone_trace(1, "[PYLINPHONE] >>> %s(%p, \"%s\", \"%s\")", __FUNCTION__, _vtable_dict, _config_path, _factory_config_path);
cresult = linphone_core_new(&_vtable, _config_path, _factory_config_path, self);
......@@ -243,9 +243,9 @@ static PyObject * pylinphone_Core_class_method_new_with_config(PyObject *cls, Py
}
Py_INCREF(_vtable_dict);
self->vtable_dict = _vtable_dict;
{{#events}}
{{#core_events}}
{{{event_vtable_reference}}}
{{/events}}
{{/core_events}}
pylinphone_trace(1, "[PYLINPHONE] >>> %s(%p [%p])", __FUNCTION__, _config, _config_native_ptr);
cresult = linphone_core_new_with_config(&_vtable, _config_native_ptr, self);
......
......@@ -25,9 +25,12 @@ def strip_leading_linphone(s):
else:
return s
def compute_event_name(s):
def is_callback(s):
return s.startswith('Linphone') and s.endswith('Cb')
def compute_event_name(s, className):
s = strip_leading_linphone(s)
s = s[4:-2] # Remove leading 'Core' and tailing 'Cb'
s = s[len(className):-2] # Remove leading class name and tailing 'Cb'
event_name = ''
first = True
for l in s:
......@@ -198,6 +201,10 @@ class ArgumentType:
self.convert_func = 'PyInt_AsLong'
self.fmt_str = 'i'
self.cfmt_str = '%d'
elif is_callback(self.complete_type):
self.type_str = 'callable'
self.check_func = 'PyCallable_Check'
self.cnativefmt_str = None
elif '*' in splitted_type:
self.type_str = 'linphone.' + strip_leading_linphone(self.basic_type)
self.use_native_pointer = True
......@@ -245,7 +252,9 @@ class MethodDefinition:
arg_contained_type = xml_method_arg.get('containedtype')
argument_type = ArgumentType(arg_type, arg_complete_type, arg_contained_type, self.linphone_module)
self.parse_tuple_format += argument_type.fmt_str
if argument_type.fmt_str == 'O' and argument_type.use_native_pointer:
if is_callback(arg_complete_type):
body += "\tPyObject * {arg_name};\n".format(arg_name=arg_name)
elif argument_type.fmt_str == 'O' and argument_type.use_native_pointer:
body += "\tPyObject * " + arg_name + ";\n"
body += "\t" + arg_complete_type + " " + arg_name + "_native_ptr = NULL;\n"
elif argument_type.fmt_str == 'O' and argument_type.convert_func is not None:
......@@ -308,7 +317,7 @@ class MethodDefinition:
argument_type = ArgumentType(arg_type, arg_complete_type, arg_contained_type, self.linphone_module)
fmt += argument_type.cfmt_str
args.append(arg_name)
if argument_type.fmt_str == 'O':
if argument_type.fmt_str == 'O' and argument_type.cnativefmt_str is not None:
fmt += ' [' + argument_type.cnativefmt_str + ']'
if argument_type.use_native_pointer:
args.append(arg_name + '_native_ptr')
......@@ -663,6 +672,12 @@ class SetterMethodDefinition(MethodDefinition):
}}
""".format(checknotnone=checknotnone, checkfunc=self.first_argument_type.check_func, attribute_name=self.attribute_name, type_str=self.first_argument_type.type_str)
attribute_conversion_code = ''
callback_setting_code = ''
if is_callback(self.first_argument_type.complete_type):
callback_setting_code = \
"""Py_XDECREF(((pylinphone_{class_name}Object *)self)->{callback_name});
((pylinphone_{class_name}Object *)self)->{callback_name} = Py_INCREF(value);
""".format(class_name=self.class_['class_name'], callback_name=compute_event_name(self.first_arg_complete_type, self.class_['class_name']))
if (self.first_argument_type.convert_func is None) or \
(self.first_argument_type.fmt_str == 'O' and self.first_argument_type.convert_func is not None):
attribute_conversion_code += "{arg_name} = value;\n".format(arg_name="_" + self.first_arg_name)
......@@ -693,14 +708,21 @@ class SetterMethodDefinition(MethodDefinition):
}}
{attribute_type_check_code}
{attribute_conversion_code}
{callback_setting_code}
{attribute_native_ptr_check_code}
""".format(attribute_name=self.attribute_name,
native_ptr_check_code=self.format_class_native_pointer_check(True),
attribute_type_check_code=attribute_type_check_code,
attribute_conversion_code=attribute_conversion_code,
callback_setting_code=callback_setting_code,
attribute_native_ptr_check_code=attribute_native_ptr_check_code)
def format_c_function_call(self):
if is_callback(self.first_argument_type.complete_type):
return \
""" {method_name}(native_ptr, pylinphone_{class_name}_callback_{callback_name});
pylinphone_dispatch_messages();
""".format(method_name=self.method_node.get('name'), class_name=self.class_['class_name'], callback_name=compute_event_name(self.first_argument_type.complete_type, self.class_['class_name']))
suffix = ''
if self.first_argument_type.fmt_str == 'O' and self.first_argument_type.use_native_pointer:
suffix = '_native_ptr'
......@@ -735,11 +757,19 @@ class EventCallbackMethodDefinition(MethodDefinition):
MethodDefinition.__init__(self, linphone_module, class_, method_node)
def format_local_variables_definition(self):
class_name = self.class_['event_class']
nocallbacks_class_name = class_name
if class_name.endswith('Cbs'):
nocallbacks_class_name = class_name[:-3]
common = \
""" pylinphone_CoreObject *pylc = (pylinphone_CoreObject *)linphone_core_get_user_data(lc);
""" pylinphone_{class_name}Object *pyself = (pylinphone_{class_name}Object *){function_prefix}get_user_data(self);
PyObject *func;
PyObject *args;
PyGILState_STATE pygil_state;"""
PyGILState_STATE pygil_state;""".format(class_name=nocallbacks_class_name, function_prefix=self.find_class_definition(nocallbacks_class_name)['class_c_function_prefix'])
if class_name.endswith('Cbs'):
common += """
pylinphone_{class_name}Object *pycbs = (pylinphone_{class_name}Object *){cbs_function_prefix}get_user_data({function_prefix}get_callbacks(self));
""".format(class_name=class_name, cbs_function_prefix=self.find_class_definition(class_name)['class_c_function_prefix'], function_prefix=self.find_class_definition(nocallbacks_class_name)['class_c_function_prefix'])
specific = ''
for xml_method_arg in self.xml_method_args:
arg_name = xml_method_arg.get('name')
......@@ -752,15 +782,22 @@ class EventCallbackMethodDefinition(MethodDefinition):
return "{common}\n{specific}".format(common=common, specific=specific)
def format_arguments_parsing(self):
return \
""" if (Py_REFCNT(pylc) <= 0) return;
func = PyDict_GetItemString(pylc->vtable_dict, "{name}");
if self.class_['event_class'] == 'Core':
return \
""" if (Py_REFCNT(pyself) <= 0) return;
func = PyDict_GetItemString(pyself->vtable_dict, "{name}");
pygil_state = PyGILState_Ensure();
""".format(name=self.class_['event_name'])
else:
return \
""" if (Py_REFCNT(pyself) <= 0) return;
func = pycbs->{event_name};
pygil_state = PyGILState_Ensure();
""".format(event_name=self.class_['event_name'])
def format_enter_trace(self):
fmt = '%p'
args = ['lc']
args = ['self']
for xml_method_arg in self.xml_method_args:
arg_name = xml_method_arg.get('name')
arg_type = xml_method_arg.get('type')
......@@ -779,7 +816,7 @@ class EventCallbackMethodDefinition(MethodDefinition):
def format_c_function_call(self):
create_python_objects_code = ''
fmt = 'O'
args = ['pylc']
args = ['pyself']
for xml_method_arg in self.xml_method_args:
arg_name = xml_method_arg.get('name')
arg_type = xml_method_arg.get('type')
......@@ -817,17 +854,21 @@ class EventCallbackMethodDefinition(MethodDefinition):
def format(self):
body = MethodDefinition.format(self)
arguments = ['LinphoneCore * lc']
class_name = self.class_['event_class']
nocallbacks_class_name = class_name
if class_name.endswith('Cbs'):
nocallbacks_class_name = class_name[:-3]
arguments = ['Linphone' + nocallbacks_class_name + ' * self']
for xml_method_arg in self.xml_method_args:
arg_name = xml_method_arg.get('name')
arg_type = xml_method_arg.get('type')
arg_complete_type = xml_method_arg.get('completetype')
arguments.append(arg_complete_type + ' ' + arg_name)
definition = \
"""static void pylinphone_Core_callback_{event_name}({arguments}) {{
"""static void pylinphone_{class_name}_callback_{event_name}({arguments}) {{
{body}
}}
""".format(event_name=self.class_['event_name'], arguments=', '.join(arguments), body=body)
""".format(class_name=class_name, event_name=self.class_['event_name'], arguments=', '.join(arguments), body=body)
return definition
......@@ -863,7 +904,7 @@ class LinphoneModule(object):
e['enum_doc'] = self.__replace_doc_special_chars(e['enum_doc'])
self.enums.append(e)
self.enum_names.append(e['enum_name'])
self.events = []
self.core_events = []
self.classes = []
xml_classes = tree.findall("./classes/class")
for xml_class in xml_classes:
......@@ -886,35 +927,39 @@ class LinphoneModule(object):
c['class_hand_written_properties'] = []
c['class_object_members'] = []
c['class_object_members_code'] = ''
c['class_events'] = []
if c['class_name'] == 'Core':
c['class_object_members'].append("vtable_dict")
c['class_object_members_code'] = "\tPyObject *vtable_dict;"
xml_events = xml_class.findall("./events/event")
for xml_event in xml_events:
if xml_event.get('deprecated') == 'true':
xml_events = xml_class.findall("./events/event")
for xml_event in xml_events:
if xml_event.get('deprecated') == 'true':
continue
if xml_event.get('name') in blacklisted_events:
continue
if xml_event.get('name') in blacklisted_events:
continue
ev = {}
ev['event_xml_node'] = xml_event
ev['event_cname'] = xml_event.get('name')
ev['event_name'] = compute_event_name(ev['event_cname'])
ev['event_doc'] = self.__format_doc(xml_event.find('briefdescription'), xml_event.find('detaileddescription'))
self.events.append(ev)
ev = {}
ev['event_class'] = c['class_name']
ev['event_xml_node'] = xml_event
ev['event_cname'] = xml_event.get('name')
ev['event_name'] = compute_event_name(ev['event_cname'], c['class_name'])
ev['event_doc'] = self.__format_doc(xml_event.find('briefdescription'), xml_event.find('detaileddescription'))
if c['class_name'] == 'Core':
self.core_events.append(ev)
else:
c['class_events'].append(ev)
c['class_object_members'].append(ev['event_name'])
c['class_object_members_code'] += "\tPyObject *" + ev['event_name'] + ";\n"
for hand_written_code in hand_written_codes:
if hand_written_code._class == c['class_name']:
if isinstance(hand_written_code, HandWrittenClassMethod):
print "HandWrittenClassMethod"
m = {}
m['method_name'] = hand_written_code.name
c['class_type_hand_written_methods'].append(m)
elif isinstance(hand_written_code, HandWrittenInstanceMethod):
print "HandWrittenInstanceMethod"
m = {}
m['method_name'] = hand_written_code.name
c['class_instance_hand_written_methods'].append(m)
elif isinstance(hand_written_code, HandWrittenProperty):
print "HandWrittenProperty"
p = {}
p['property_name'] = hand_written_code.name
if hand_written_code.getter_cfunction is None:
......@@ -992,9 +1037,12 @@ class LinphoneModule(object):
c['class_properties'].append(p)
self.classes.append(c)
# Format events definitions
for ev in self.events:
for ev in self.core_events:
ev['event_callback_definition'] = EventCallbackMethodDefinition(self, ev, ev['event_xml_node']).format()
ev['event_vtable_reference'] = "_vtable.{name} = pylinphone_Core_callback_{name};".format(name=ev['event_name'])
for c in self.classes:
for ev in c['class_events']:
ev['event_callback_definition'] = EventCallbackMethodDefinition(self, ev, ev['event_xml_node']).format()
# Format methods' bodies
for c in self.classes:
xml_new_method = c['class_xml_node'].find("./classmethods/classmethod[@name='" + c['class_c_function_prefix'] + "new']")
......
......@@ -97,9 +97,15 @@ MSList * PyList_AsMSListOf{{c_contained_type}}(PyObject *pyl) {
{{/mslist_types}}
{{#events}}
{{#core_events}}
{{{event_callback_definition}}}
{{/events}}
{{/core_events}}
{{#classes}}
{{#class_events}}
{{{event_callback_definition}}}
{{/class_events}}
{{/classes}}
{{#classes}}
......
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