aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-05-23 17:22:21 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-07-03 16:08:55 +0200
commitdba61b453444af7093e07538e4d8b1b07ab387ad (patch)
treef50cbf20f30ee6bdbefcdcee3532d5d7e61d0df9
parentcbfac5dadfa6713e124aba7400937abd4c8daf93 (diff)
downloadexternal_libqmi-dba61b453444af7093e07538e4d8b1b07ab387ad.zip
external_libqmi-dba61b453444af7093e07538e4d8b1b07ab387ad.tar.gz
external_libqmi-dba61b453444af7093e07538e4d8b1b07ab387ad.tar.bz2
qmi-codegen: include struct TLV contents in printable strings
-rw-r--r--build-aux/qmi-codegen/Field.py13
-rw-r--r--build-aux/qmi-codegen/FieldStruct.py52
-rw-r--r--build-aux/qmi-codegen/FieldStructResult.py46
-rw-r--r--build-aux/qmi-codegen/Message.py23
4 files changed, 130 insertions, 4 deletions
diff --git a/build-aux/qmi-codegen/Field.py b/build-aux/qmi-codegen/Field.py
index ee934ff..bb3e691 100644
--- a/build-aux/qmi-codegen/Field.py
+++ b/build-aux/qmi-codegen/Field.py
@@ -217,8 +217,21 @@ class Field:
'${lp} break;\n')
f.write(string.Template(template).substitute(translations))
+
def emit_output_tlv_get(self, f, line_prefix):
'''
Subclasses can implement the method to emit the required TLV retrieval
'''
pass
+
+
+ def emit_output_tlv_get_printable(self, f):
+ translations = { 'underscore' : utils.build_underscore_name (self.fullname) }
+ template = (
+ 'static gchar *\n'
+ '${underscore}_get_printable (\n'
+ ' QmiMessage *self)\n'
+ '{\n'
+ ' return NULL;\n'
+ '}\n')
+ f.write(string.Template(template).substitute(translations))
diff --git a/build-aux/qmi-codegen/FieldStruct.py b/build-aux/qmi-codegen/FieldStruct.py
index 83eda4c..6264291 100644
--- a/build-aux/qmi-codegen/FieldStruct.py
+++ b/build-aux/qmi-codegen/FieldStruct.py
@@ -119,3 +119,55 @@ class FieldStruct(Field):
template = (
'${lp}}\n')
f.write(string.Template(template).substitute(translations))
+
+ def emit_output_tlv_get_printable(self, f):
+ translations = { 'name' : self.name,
+ 'underscore' : utils.build_underscore_name (self.fullname),
+ 'container_underscore' : utils.build_underscore_name (self.prefix),
+ 'field_type' : self.field_type,
+ 'tlv_id' : self.id_enum_name,
+ 'variable_name' : self.variable_name }
+
+ template = (
+ '\n'
+ 'static gchar *\n'
+ '${underscore}_get_printable (\n'
+ ' QmiMessage *self)\n'
+ '{\n'
+ ' GString *printable;\n'
+ ' ${field_type}Packed tmp;\n'
+ '\n'
+ ' printable = g_string_new ("");\n'
+ ' g_assert (qmi_message_tlv_get (self,\n'
+ ' ${tlv_id},\n'
+ ' sizeof (tmp),\n'
+ ' &tmp,\n'
+ ' NULL));\n')
+ f.write(string.Template(template).substitute(translations))
+
+ for struct_field in self.contents.members:
+ translations['name_struct_field'] = struct_field['name']
+ translations['underscore_struct_field'] = utils.build_underscore_name(struct_field['name'])
+ translations['endianfix'] = utils.he_from_le ('tmp.' + utils.build_underscore_name(struct_field['name']),
+ 'tmp.' + utils.build_underscore_name(struct_field['name']),
+ struct_field['format'])
+ template = (
+ ' ${endianfix};'
+ ' g_string_append_printf (printable,\n')
+
+ if struct_field['format'] == 'guint8' or \
+ struct_field['format'] == 'guint16' or \
+ struct_field['format'] == 'guin32':
+ template += (
+ ' "[${name_struct_field} = %u] ",\n'
+ ' (guint)tmp.${underscore_struct_field});\n')
+ else:
+ template += (
+ ' "[${name_struct_field} = %d] ",\n'
+ ' (gint)tmp.${underscore_struct_field});\n')
+ f.write(string.Template(template).substitute(translations))
+
+ f.write(
+ '\n'
+ ' return g_string_free (printable, FALSE);\n'
+ '}\n')
diff --git a/build-aux/qmi-codegen/FieldStructResult.py b/build-aux/qmi-codegen/FieldStructResult.py
index ead0ef7..6711a54 100644
--- a/build-aux/qmi-codegen/FieldStructResult.py
+++ b/build-aux/qmi-codegen/FieldStructResult.py
@@ -90,3 +90,49 @@ class FieldStructResult(FieldStruct):
' return FALSE;\n'
'}\n')
cfile.write(string.Template(template).substitute(translations))
+
+ def emit_output_tlv_get_printable(self, f):
+ translations = { 'name' : self.name,
+ 'underscore' : utils.build_underscore_name (self.fullname),
+ 'container_underscore' : utils.build_underscore_name (self.prefix),
+ 'field_type' : self.field_type,
+ 'tlv_id' : self.id_enum_name,
+ 'variable_name' : self.variable_name }
+
+ template = (
+ '\n'
+ 'static gchar *\n'
+ '${underscore}_get_printable (\n'
+ ' QmiMessage *self)\n'
+ '{\n'
+ ' GString *printable;\n'
+ ' ${field_type}Packed tmp;\n'
+ '\n'
+ ' printable = g_string_new ("");\n'
+ ' g_assert (qmi_message_tlv_get (self,\n'
+ ' ${tlv_id},\n'
+ ' sizeof (tmp),\n'
+ ' &tmp,\n'
+ ' NULL));\n')
+ f.write(string.Template(template).substitute(translations))
+
+ for struct_field in self.contents.members:
+ translations['name_struct_field'] = struct_field['name']
+ translations['underscore_struct_field'] = utils.build_underscore_name(struct_field['name'])
+ translations['endianfix'] = utils.he_from_le ('tmp.' + utils.build_underscore_name(struct_field['name']),
+ 'tmp.' + utils.build_underscore_name(struct_field['name']),
+ struct_field['format'])
+ template = (
+ ' ${endianfix};')
+
+ f.write(
+ ' if (tmp.error_status == QMI_STATUS_SUCCESS)\n'
+ ' g_string_append (printable,\n'
+ ' "SUCCESS");\n'
+ ' else\n'
+ ' g_string_append_printf (printable,\n'
+ ' "FAILURE: %s",\n'
+ ' qmi_protocol_error_get_string ((QmiProtocolError) tmp.error_code));\n'
+ '\n'
+ ' return g_string_free (printable, FALSE);\n'
+ '}\n')
diff --git a/build-aux/qmi-codegen/Message.py b/build-aux/qmi-codegen/Message.py
index a2ec70e..b98da47 100644
--- a/build-aux/qmi-codegen/Message.py
+++ b/build-aux/qmi-codegen/Message.py
@@ -220,6 +220,13 @@ class Message:
def __emit_get_printable(self, hfile, cfile):
+
+ if self.input.fields is not None:
+ for field in self.input.fields:
+ field.emit_output_tlv_get_printable(cfile)
+ for field in self.output.fields:
+ field.emit_output_tlv_get_printable(cfile)
+
translations = { 'name' : self.name,
'service' : self.service,
'id' : self.id,
@@ -241,17 +248,20 @@ class Message:
' struct ${underscore}_context *ctx)\n'
'{\n'
' const gchar *tlv_type_str = NULL;\n'
+ ' gchar *translated_value;\n'
'\n'
' if (!qmi_message_is_response (ctx->self)) {\n'
' switch (type) {\n')
if self.input.fields is not None:
for field in self.input.fields:
+ translations['underscore_field'] = utils.build_underscore_name(field.fullname)
translations['field_enum'] = field.id_enum_name
translations['field_name'] = field.name
field_template = (
' case ${field_enum}:\n'
' tlv_type_str = "${field_name}";\n'
+ ' translated_value = ${underscore_field}_get_printable (ctx->self);\n'
' break;\n')
template += string.Template(field_template).substitute(translations)
@@ -263,11 +273,13 @@ class Message:
' switch (type) {\n')
for field in self.output.fields:
+ translations['underscore_field'] = utils.build_underscore_name(field.fullname)
translations['field_enum'] = field.id_enum_name
translations['field_name'] = field.name
field_template = (
' case ${field_enum}:\n'
' tlv_type_str = "${field_name}";\n'
+ ' translated_value = ${underscore_field}_get_printable (ctx->self);\n'
' break;\n')
template += string.Template(field_template).substitute(translations)
@@ -295,14 +307,17 @@ class Message:
' value_hex = qmi_utils_str_hex (value, length, \':\');\n'
' g_string_append_printf (ctx->printable,\n'
' "%sTLV:\\n"\n'
- ' "%s type = \\"%s\\" (0x%02x)\\n"\n'
- ' "%s length = %u\\n"\n'
- ' "%s value = %s\\n",\n'
+ ' "%s type = \\"%s\\" (0x%02x)\\n"\n'
+ ' "%s length = %u\\n"\n'
+ ' "%s value = %s\\n"\n'
+ ' "%s translated = %s\\n",\n'
' ctx->line_prefix,\n'
' ctx->line_prefix, tlv_type_str, type,\n'
' ctx->line_prefix, length,\n'
- ' ctx->line_prefix, value_hex);\n'
+ ' ctx->line_prefix, value_hex,\n'
+ ' ctx->line_prefix, translated_value ? translated_value : "");\n'
' g_free (value_hex);\n'
+ ' g_free (translated_value);\n'
' }\n'
'}\n'
'\n'