diff options
-rw-r--r-- | build-aux/mbim-codegen/Message.py | 2 | ||||
-rw-r--r-- | build-aux/mbim-codegen/ObjectList.py | 23 | ||||
-rw-r--r-- | build-aux/mbim-codegen/Struct.py | 90 |
3 files changed, 82 insertions, 33 deletions
diff --git a/build-aux/mbim-codegen/Message.py b/build-aux/mbim-codegen/Message.py index aae6784..4adea86 100644 --- a/build-aux/mbim-codegen/Message.py +++ b/build-aux/mbim-codegen/Message.py @@ -602,7 +602,7 @@ class Message: ' if (${field} != NULL)\n' ' *${field} = tmp;\n' ' else\n' - ' ${struct_name}_free (tmp);\n' + ' _${struct_name}_free (tmp);\n' ' offset += bytes_read;\n') elif field['format'] == 'struct-array': inner_template += ( diff --git a/build-aux/mbim-codegen/ObjectList.py b/build-aux/mbim-codegen/ObjectList.py index 5198b69..1aa27e4 100644 --- a/build-aux/mbim-codegen/ObjectList.py +++ b/build-aux/mbim-codegen/ObjectList.py @@ -25,6 +25,22 @@ from Struct import Struct import utils """ +Check field to see if it holds a struct +""" +def set_struct_usage(struct, fields): + for field in fields: + if field['format'] == 'struct' and field['struct-type'] == struct.name: + struct.single_member = True + break + if field['format'] == 'ref-struct-array' and field['struct-type'] == struct.name: + struct.array_member = True + break + if field['format'] == 'struct-array' and field['struct-type'] == struct.name: + struct.array_member = True + break + + +""" The ObjectList class handles the generation of all commands and types for a given specific service """ @@ -46,6 +62,13 @@ class ObjectList: else: raise ValueError('Cannot handle object type \'%s\'' % object_dictionary['type']) + # Populate struct usages + for struct in self.struct_list: + for command in self.command_list: + set_struct_usage(struct, command.query) + set_struct_usage(struct, command.set) + set_struct_usage(struct, command.response) + set_struct_usage(struct, command.notification) """ Emit the structs and commands handling implementation diff --git a/build-aux/mbim-codegen/Struct.py b/build-aux/mbim-codegen/Struct.py index 1321fd9..2f6bf90 100644 --- a/build-aux/mbim-codegen/Struct.py +++ b/build-aux/mbim-codegen/Struct.py @@ -34,6 +34,11 @@ class Struct: self.name = dictionary['name'] self.contents = dictionary['contents'] + # Whether the struct is used as a single field, or as an array of + # fields. Will be updated after having created the object. + self.single_member = False + self.array_member = False + # Check whether the struct is composed of fixed-sized fields self.size = 0 for field in self.contents: @@ -158,22 +163,19 @@ class Struct: def _emit_free(self, hfile, cfile): translations = { 'name' : self.name, 'name_underscore' : utils.build_underscore_name_from_camelcase(self.name) } - template = ( - '\n' - 'void ${name_underscore}_free (${name} *var);\n' - 'void ${name_underscore}_array_free (${name} **array);\n') - hfile.write(string.Template(template).substitute(translations)) + template = '' + + if self.single_member == True: + template = ( + '\n' + 'void ${name_underscore}_free (${name} *var);\n') + hfile.write(string.Template(template).substitute(translations)) + template = ( '\n' - '/**\n' - ' * ${name_underscore}_free:\n' - ' * @var: a #${name}.\n' - ' *\n' - ' * Frees the memory allocated for the #${name}.\n' - ' */\n' - 'void\n' - '${name_underscore}_free (${name} *var)\n' + 'static void\n' + '_${name_underscore}_free (${name} *var)\n' '{\n' ' if (!var)\n' ' return;\n' @@ -217,28 +219,52 @@ class Struct: template += ( ' g_free (var);\n' - '}\n' - '\n' - '/**\n' - ' * ${name_underscore}_array_free:\n' - ' * @array: a #NULL-terminated array of #${name} structs.\n' - ' *\n' - ' * Frees the memory allocated for the array of #${name}s.\n' - ' */\n' - 'void\n' - '${name_underscore}_array_free (${name} **array)\n' - '{\n' - ' guint32 i;\n' - '\n' - ' if (!array)\n' - ' return;\n' - '\n' - ' for (i = 0; array[i]; i++)\n' - ' ${name_underscore}_free (array[i]);\n' - ' g_free (array);\n' '}\n') cfile.write(string.Template(template).substitute(translations)) + if self.single_member == True: + template = ( + '\n' + '/**\n' + ' * ${name_underscore}_free:\n' + ' * @var: a #${name}.\n' + ' *\n' + ' * Frees the memory allocated for the #${name}.\n' + ' */\n' + 'void\n' + '${name_underscore}_free (${name} *var)\n' + '{\n' + ' _${name_underscore}_free (var)\n' + '}\n') + + if self.array_member: + template = ( + '\n' + 'void ${name_underscore}_array_free (${name} **array);\n') + hfile.write(string.Template(template).substitute(translations)) + + template = ( + '\n' + '/**\n' + ' * ${name_underscore}_array_free:\n' + ' * @array: a #NULL-terminated array of #${name} structs.\n' + ' *\n' + ' * Frees the memory allocated for the array of #${name}s.\n' + ' */\n' + 'void\n' + '${name_underscore}_array_free (${name} **array)\n' + '{\n' + ' guint32 i;\n' + '\n' + ' if (!array)\n' + ' return;\n' + '\n' + ' for (i = 0; array[i]; i++)\n' + ' _${name_underscore}_free (array[i]);\n' + ' g_free (array);\n' + '}\n') + cfile.write(string.Template(template).substitute(translations)) + """ Emit the type's read methods |