summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-07-04 15:59:23 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-07-04 16:00:39 +0200
commit6979e2752a2e2d1b4f72fc8d62bb1e31fd36f2e8 (patch)
tree12d825fa0b5d82da464bf7c069879c489171cddf
parenta966f1c37b2573594a6963f13015fddd645e96c3 (diff)
qmi-codegen: handle uints of arbitrary sizes
The code generator can now handle uints of arbitrary sizes (<= guint64), which are read into guint64 variables.
-rw-r--r--build-aux/qmi-codegen/VariableInteger.py81
-rw-r--r--build-aux/qmi-codegen/utils.py3
2 files changed, 65 insertions, 19 deletions
diff --git a/build-aux/qmi-codegen/VariableInteger.py b/build-aux/qmi-codegen/VariableInteger.py
index 5c28933..96642da 100644
--- a/build-aux/qmi-codegen/VariableInteger.py
+++ b/build-aux/qmi-codegen/VariableInteger.py
@@ -24,7 +24,7 @@ from Variable import Variable
"""
Variable type for signed/unsigned Integers
-('guint8', 'gint8', 'guint16', 'gint16', 'guint32', 'gint32', 'guint64', 'gint64' formats)
+('guint8', 'gint8', 'guint16', 'gint16', 'guint32', 'gint32', 'guint64', 'gint64' 'guint-sized' formats)
"""
class VariableInteger(Variable):
@@ -36,8 +36,17 @@ class VariableInteger(Variable):
# Call the parent constructor
Variable.__init__(self, dictionary)
- self.private_format = self.format
- self.public_format = dictionary['public-format'] if 'public-format' in dictionary else self.private_format
+ self.guint_sized_size = ''
+ if self.format == "guint-sized":
+ if 'guint-size' not in dictionary:
+ raise RuntimeError('Format \'guint-sized\' requires \'guint-size\' parameter')
+ else:
+ self.guint_sized_size = dictionary['guint-size']
+ self.private_format = 'guint64'
+ self.public_format = 'guint64'
+ else:
+ self.private_format = self.format
+ self.public_format = dictionary['public-format'] if 'public-format' in dictionary else self.private_format
"""
@@ -47,11 +56,20 @@ class VariableInteger(Variable):
translations = { 'lp' : line_prefix,
'public_format' : self.public_format,
'private_format' : self.private_format,
+ 'len' : self.guint_sized_size,
'variable_name' : variable_name,
'buffer_name' : buffer_name,
'buffer_len' : buffer_len }
- if self.private_format == self.public_format:
+ if self.format == 'guint-sized':
+ template = (
+ '${lp}/* Read the ${len}-byte long variable from the buffer */\n'
+ '${lp}qmi_utils_read_sized_guint_from_buffer (\n'
+ '${lp} &${buffer_name},\n'
+ '${lp} &${buffer_len},\n'
+ '${lp} ${len},\n'
+ '${lp} &(${variable_name}));\n')
+ elif self.private_format == self.public_format:
template = (
'${lp}/* Read the ${private_format} variable from the buffer */\n'
'${lp}qmi_utils_read_${private_format}_from_buffer (\n'
@@ -79,10 +97,20 @@ class VariableInteger(Variable):
def emit_buffer_write(self, f, line_prefix, variable_name, buffer_name, buffer_len):
translations = { 'lp' : line_prefix,
'private_format' : self.private_format,
+ 'len' : self.guint_sized_size,
'variable_name' : variable_name,
'buffer_name' : buffer_name,
'buffer_len' : buffer_len }
- if self.private_format == self.public_format:
+
+ if self.format == 'guint-sized':
+ template = (
+ '${lp}/* Write the ${len}-byte long variable to the buffer */\n'
+ '${lp}qmi_utils_write_sized_guint_to_buffer (\n'
+ '${lp} &${buffer_name},\n'
+ '${lp} &${buffer_len},\n'
+ '${lp} ${len},\n'
+ '${lp} &(${variable_name}));\n')
+ elif self.private_format == self.public_format:
template = (
'${lp}/* Write the ${private_format} variable to the buffer */\n'
'${lp}qmi_utils_write_${private_format}_to_buffer (\n'
@@ -131,25 +159,42 @@ class VariableInteger(Variable):
translations = { 'lp' : line_prefix,
'private_format' : self.private_format,
+ 'len' : self.guint_sized_size,
'printable' : printable,
'buffer_name' : buffer_name,
'buffer_len' : buffer_len,
'common_format' : common_format,
'common_cast' : common_cast }
- template = (
- '\n'
- '${lp}{\n'
- '${lp} ${private_format} tmp;\n'
- '\n'
- '${lp} /* Read the ${private_format} variable from the buffer */\n'
- '${lp} qmi_utils_read_${private_format}_from_buffer (\n'
- '${lp} &${buffer_name},\n'
- '${lp} &${buffer_len},\n'
- '${lp} &tmp);\n'
- '\n'
- '${lp} g_string_append_printf (${printable}, "${common_format}", ${common_cast}tmp);\n'
- '${lp}}\n')
+ if self.format == 'guint-sized':
+ template = (
+ '\n'
+ '${lp}{\n'
+ '${lp} ${private_format} tmp;\n'
+ '\n'
+ '${lp} /* Read the ${len}-byte long variable from the buffer */\n'
+ '${lp} qmi_utils_read_sized_guint_from_buffer (\n'
+ '${lp} &${buffer_name},\n'
+ '${lp} &${buffer_len},\n'
+ '${lp} ${len},\n'
+ '${lp} &tmp);\n'
+ '\n'
+ '${lp} g_string_append_printf (${printable}, "${common_format}", ${common_cast}tmp);\n'
+ '${lp}}\n')
+ else:
+ template = (
+ '\n'
+ '${lp}{\n'
+ '${lp} ${private_format} tmp;\n'
+ '\n'
+ '${lp} /* Read the ${private_format} variable from the buffer */\n'
+ '${lp} qmi_utils_read_${private_format}_from_buffer (\n'
+ '${lp} &${buffer_name},\n'
+ '${lp} &${buffer_len},\n'
+ '${lp} &tmp);\n'
+ '\n'
+ '${lp} g_string_append_printf (${printable}, "${common_format}", ${common_cast}tmp);\n'
+ '${lp}}\n')
f.write(string.Template(template).substitute(translations))
diff --git a/build-aux/qmi-codegen/utils.py b/build-aux/qmi-codegen/utils.py
index 239e03b..cd10695 100644
--- a/build-aux/qmi-codegen/utils.py
+++ b/build-aux/qmi-codegen/utils.py
@@ -172,7 +172,8 @@ def format_is_unsigned_integer(fmt):
if fmt == 'guint8' or \
fmt == 'guint16' or \
fmt == 'guint32' or \
- fmt == 'guint64':
+ fmt == 'guint64' or \
+ fmt == 'guint-sized' :
return True
else:
return False