diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-05-22 13:58:32 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-07-03 16:08:54 +0200 |
commit | f01a927934c3f0e02fddd56d3e7f3d824bb71721 (patch) | |
tree | 595170142a71c66b7b2def8e4a72553d4087addb /build-aux/qmi-codegen | |
parent | 02d2ba64714931e5f75c0099dae670d64ad1437d (diff) | |
download | external_libqmi-f01a927934c3f0e02fddd56d3e7f3d824bb71721.zip external_libqmi-f01a927934c3f0e02fddd56d3e7f3d824bb71721.tar.gz external_libqmi-f01a927934c3f0e02fddd56d3e7f3d824bb71721.tar.bz2 |
qmi-codegen: improve input bundles
Simplify the field-type-specific TLV adding, as well as the mandatory field
checkings.
Diffstat (limited to 'build-aux/qmi-codegen')
-rw-r--r-- | build-aux/qmi-codegen/Field.py | 20 | ||||
-rw-r--r-- | build-aux/qmi-codegen/FieldBasic.py | 36 | ||||
-rw-r--r-- | build-aux/qmi-codegen/FieldString.py | 17 | ||||
-rw-r--r-- | build-aux/qmi-codegen/FieldStruct.py | 29 | ||||
-rw-r--r-- | build-aux/qmi-codegen/Message.py | 64 | ||||
-rw-r--r-- | build-aux/qmi-codegen/utils.py | 2 |
6 files changed, 105 insertions, 63 deletions
diff --git a/build-aux/qmi-codegen/Field.py b/build-aux/qmi-codegen/Field.py index 8133008..a644747 100644 --- a/build-aux/qmi-codegen/Field.py +++ b/build-aux/qmi-codegen/Field.py @@ -174,26 +174,6 @@ class Field: '\n') cfile.write(string.Template(template).substitute(translations)) - - def emit_input_mandatory_check(self, f, line_prefix): - if self.mandatory == 'yes': - translations = { 'name' : self.name, - 'variable_name' : self.variable_name, - 'lp' : line_prefix } - - template = ( - '\n' - '${lp}if (!input || !input->${variable_name}_set) {\n' - '${lp} g_set_error (error,\n' - '${lp} QMI_CORE_ERROR,\n' - '${lp} QMI_CORE_ERROR_INVALID_ARGS,\n' - '${lp} "Missing mandatory TLV \'${name}\'");\n' - '${lp} qmi_message_unref (self);\n' - '${lp} return NULL;\n' - '${lp}}\n') - - f.write(string.Template(template).substitute(translations)) - def emit_input_tlv_add(self, f, line_prefix): ''' Subclasses can implement the method to emit the required TLV adding diff --git a/build-aux/qmi-codegen/FieldBasic.py b/build-aux/qmi-codegen/FieldBasic.py index 9905c71..3be67a8 100644 --- a/build-aux/qmi-codegen/FieldBasic.py +++ b/build-aux/qmi-codegen/FieldBasic.py @@ -39,33 +39,31 @@ class FieldBasic(Field): self.field_type = self.format; def emit_input_tlv_add(self, cfile, line_prefix): - translations = { 'name' : self.name, - 'tlv_id' : self.id_enum_name, - 'field_type' : self.field_type, - 'set_variable' : utils.le_from_he ('input->' + self.variable_name, 'tmp', self.field_type), - 'lp' : line_prefix } + translations = { 'name' : self.name, + 'tlv_id' : self.id_enum_name, + 'field_type' : self.field_type, + 'variable_name' : self.variable_name, + 'set_variable' : utils.le_from_he ('input->' + self.variable_name, 'tmp', self.field_type), + 'lp' : line_prefix } template = ( - '${lp}/* Try to add the \'${name}\' TLV */\n' - '${lp}{\n' - '${lp} ${field_type} tmp;\n' + '${lp}${field_type} tmp;\n' '\n' - '${lp} ${set_variable};\n' + '${lp}${set_variable};\n' '\n' - '${lp} if (!qmi_message_tlv_add (self,\n' - '${lp} (guint8)${tlv_id},\n' - '${lp} sizeof (tmp),\n' - '${lp} &tmp,\n' - '${lp} error)) {\n' - '${lp} g_prefix_error (error, \"Couldn\'t set the ${name} TLV: \");\n' - '${lp} qmi_message_unref (self);\n' - '${lp} return NULL;\n' - '${lp} }\n' + '${lp}if (!qmi_message_tlv_add (self,\n' + '${lp} (guint8)${tlv_id},\n' + '${lp} sizeof (tmp),\n' + '${lp} &tmp,\n' + '${lp} error)) {\n' + '${lp} g_prefix_error (error, \"Couldn\'t set the ${name} TLV: \");\n' + '${lp} qmi_message_unref (self);\n' + '${lp} return NULL;\n' '${lp}}\n') cfile.write(string.Template(template).substitute(translations)) - def emit_output_tlv_get(self, f, line_prefix): + def emit_output_tlv_get(self, cfile, line_prefix): translations = { 'name' : self.name, 'container_underscore' : utils.build_underscore_name (self.prefix), 'tlv_id' : self.id_enum_name, diff --git a/build-aux/qmi-codegen/FieldString.py b/build-aux/qmi-codegen/FieldString.py index 168a6ac..075d8c0 100644 --- a/build-aux/qmi-codegen/FieldString.py +++ b/build-aux/qmi-codegen/FieldString.py @@ -42,8 +42,21 @@ class FieldString(Field): def emit_input_tlv_add(self, cfile, line_prefix): - # TODO - pass + translations = { 'name' : self.name, + 'tlv_id' : self.id_enum_name, + 'variable_name' : self.variable_name, + 'lp' : line_prefix } + template = ( + '${lp}if (!qmi_message_tlv_add (self,\n' + '${lp} (guint8)${tlv_id},\n' + '${lp} strlen (input->${variable_name}) + 1,\n' + '${lp} input->${variable_name},\n' + '${lp} error)) {\n' + '${lp} g_prefix_error (error, \"Couldn\'t set the \'${name}\' TLV: \");\n' + '${lp} qmi_message_unref (self);\n' + '${lp} return NULL;\n' + '${lp}}\n') + cfile.write(string.Template(template).substitute(translations)) def emit_output_tlv_get(self, f, line_prefix): diff --git a/build-aux/qmi-codegen/FieldStruct.py b/build-aux/qmi-codegen/FieldStruct.py index e6b4f0b..2bd834f 100644 --- a/build-aux/qmi-codegen/FieldStruct.py +++ b/build-aux/qmi-codegen/FieldStruct.py @@ -57,30 +57,27 @@ class FieldStruct(Field): 'lp' : line_prefix } template = ( - '${lp}/* Try to add the \'${name}\' TLV */\n' - '${lp}{\n' - '${lp} ${field_type} tmp;\n' + '${lp}${field_type} tmp;\n' '\n') cfile.write(string.Template(template).substitute(translations)) # uint32 and uint16 fields need to be converted to host-endianness for struct_field in self.contents.members: - cfile.write('%s %s;\n' % (line_prefix, - utils.le_from_he ('input->' + self.variable_name + '.' + utils.build_underscore_name(struct_field['name']), - 'tmp.' + utils.build_underscore_name(struct_field['name']), - struct_field['type']))) + cfile.write('%s%s;\n' % (line_prefix, + utils.le_from_he ('input->' + self.variable_name + '.' + utils.build_underscore_name(struct_field['name']), + 'tmp.' + utils.build_underscore_name(struct_field['name']), + struct_field['type']))) template = ( '\n' - '${lp} if (!qmi_message_tlv_add (self,\n' - '${lp} (guint8)${tlv_id},\n' - '${lp} sizeof (tmp),\n' - '${lp} &tmp,\n' - '${lp} error)) {\n' - '${lp} g_prefix_error (error, \"Couldn\'t set the ${name} TLV: \");\n' - '${lp} qmi_message_unref (self);\n' - '${lp} return NULL;\n' - '${lp} }\n' + '${lp}if (!qmi_message_tlv_add (self,\n' + '${lp} (guint8)${tlv_id},\n' + '${lp} sizeof (tmp),\n' + '${lp} &tmp,\n' + '${lp} error)) {\n' + '${lp} g_prefix_error (error, \"Couldn\'t set the ${name} TLV: \");\n' + '${lp} qmi_message_unref (self);\n' + '${lp} return NULL;\n' '${lp}}\n') cfile.write(string.Template(template).substitute(translations)) diff --git a/build-aux/qmi-codegen/Message.py b/build-aux/qmi-codegen/Message.py index 4a67b07..5be7feb 100644 --- a/build-aux/qmi-codegen/Message.py +++ b/build-aux/qmi-codegen/Message.py @@ -62,7 +62,8 @@ class Message: def __emit_request_creator(self, hfile, cfile): - translations = { 'service' : self.service, + translations = { 'name' : self.name, + 'service' : self.service, 'container' : utils.build_camelcase_name (self.input.fullname), 'underscore' : utils.build_underscore_name (self.fullname), 'message_id' : self.id_enum_name } @@ -95,16 +96,67 @@ class Message: ' self = qmi_message_new (QMI_SERVICE_${service},\n' ' cid,\n' ' transaction_id,\n' - ' ${message_id});\n' - '\n' % input_arg_template) + ' ${message_id});\n' % input_arg_template) cfile.write(string.Template(template).substitute(translations)) if self.input.fields is not None: + # Count how many mandatory fields we have + n_mandatory = 0 for field in self.input.fields: - field.emit_input_mandatory_check(cfile, ' ') - field.emit_input_tlv_add(cfile, ' ') - + if field.mandatory == 'yes': + n_mandatory += 1 + + if n_mandatory == 0: + # If we don't have mandatory fields, we do allow to have + # a NULL input + cfile.write( + '\n' + ' /* All TLVs are optional, we allow NULL input */\n' + ' if (!input)\n' + ' return self;\n') + else: + # If we do have mandatory fields, issue error if no input + # given. + cfile.write( + '\n' + ' /* There is at least one mandatory TLV, don\'t allow NULL input */\n' + ' if (!input) {\n' + ' g_set_error (error,\n' + ' QMI_CORE_ERROR,\n' + ' QMI_CORE_ERROR_INVALID_ARGS,\n' + ' "Message \'${name}\' has mandatory TLVs");\n' + ' qmi_message_unref (self);\n' + ' return NULL;\n' + ' }\n') + + # Now iterate fields + for field in self.input.fields: + translations['tlv_name'] = field.name + translations['variable_name'] = field.variable_name + template = ( + '\n' + ' /* Try to add the \'${tlv_name}\' TLV */\n' + ' if (input->${variable_name}_set) {\n') + cfile.write(string.Template(template).substitute(translations)) + + # Emit the TLV getter + field.emit_input_tlv_add(cfile, ' ') + + if field.mandatory == 'yes': + template = ( + ' } else {\n' + ' g_set_error (error,\n' + ' QMI_CORE_ERROR,\n' + ' QMI_CORE_ERROR_INVALID_ARGS,\n' + ' "Missing mandatory TLV \'${tlv_name}\' in message \'${name}\'");\n' + ' qmi_message_unref (self);\n' + ' return NULL;\n') + cfile.write(string.Template(template).substitute(translations)) + + cfile.write( + ' }\n') cfile.write( + '\n' ' return self;\n' '}\n') diff --git a/build-aux/qmi-codegen/utils.py b/build-aux/qmi-codegen/utils.py index 5c14f5b..3bc2343 100644 --- a/build-aux/qmi-codegen/utils.py +++ b/build-aux/qmi-codegen/utils.py @@ -89,6 +89,8 @@ def add_header_stop(f, output_name): def add_source_start(f, output_name): template = string.Template ( "\n" + "#include <string.h>\n" + "\n" "#include \"${name}.h\"\n" "#include \"qmi-error-types.h\"\n" "#include \"qmi-device.h\"\n" |