aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build-aux/qmi-codegen/Field.py32
-rw-r--r--build-aux/qmi-codegen/Message.py15
-rw-r--r--build-aux/qmi-codegen/Variable.py2
-rw-r--r--build-aux/qmi-codegen/VariableArray.py14
-rw-r--r--build-aux/qmi-codegen/VariableInteger.py63
-rw-r--r--build-aux/qmi-codegen/VariableSequence.py4
-rw-r--r--build-aux/qmi-codegen/VariableString.py48
-rw-r--r--build-aux/qmi-codegen/VariableStruct.py4
8 files changed, 71 insertions, 111 deletions
diff --git a/build-aux/qmi-codegen/Field.py b/build-aux/qmi-codegen/Field.py
index 784dc64..c4b395a 100644
--- a/build-aux/qmi-codegen/Field.py
+++ b/build-aux/qmi-codegen/Field.py
@@ -216,41 +216,29 @@ class Field:
Emit the code responsible for adding the TLV to the QMI message
"""
def emit_input_tlv_add(self, f, line_prefix):
- error_label = 'ERR_EMIT_BUFFER_OVERFLOW_' + self.id_enum_name
translations = { 'name' : self.name,
'tlv_id' : self.id_enum_name,
'variable_name' : self.variable_name,
- 'error_label' : error_label,
'lp' : line_prefix }
template = (
- '${lp}guint8 buffer[1024];\n'
- '${lp}guint16 buffer_len = 1024;\n'
- '${lp}guint8 *buffer_aux = buffer;\n'
+ '${lp}gsize tlv_offset;\n'
+ '\n'
+ '${lp}if (!(tlv_offset = qmi_message_tlv_write_init (self, (guint8)${tlv_id}, error))) {\n'
+ '${lp} g_prefix_error (error, "Cannot initialize TLV \'${name}\': ");\n'
+ '${lp} goto error_out;\n'
+ '${lp}}\n'
'\n')
f.write(string.Template(template).substitute(translations))
# Now, write the contents of the variable into the buffer
- self.variable.emit_buffer_write(f, line_prefix, 'input->' + self.variable_name, 'buffer_aux', 'buffer_len', error_label)
+ self.variable.emit_buffer_write(f, line_prefix, self.name, 'input->' + self.variable_name)
template = (
'\n'
- '${lp}if (FALSE) {\n'
- '${lp} ${error_label}:\n'
- '${lp} g_set_error (error, QMI_CORE_ERROR, QMI_CORE_ERROR_TLV_TOO_LONG, "result larger then 1024 bytes");\n'
- '${lp} goto OUT_${error_label};\n'
- '${lp}}\n'
- '\n'
- '${lp}g_assert (buffer_len <= 1024);\n'
- '${lp}if (!qmi_message_add_raw_tlv (self,\n'
- '${lp} (guint8)${tlv_id},\n'
- '${lp} buffer,\n'
- '${lp} (1024 - buffer_len),\n'
- '${lp} error)) {\n'
- '${lp} OUT_${error_label}:\n'
- '${lp} g_prefix_error (error, \"Couldn\'t set the ${name} TLV: \");\n'
- '${lp} qmi_message_unref (self);\n'
- '${lp} return NULL;\n'
+ '${lp}if (!qmi_message_tlv_write_complete (self, tlv_offset, error)) {\n'
+ '${lp} g_prefix_error (error, "Cannot complete TLV \'${name}\': ");\n'
+ '${lp} goto error_out;\n'
'${lp}}\n')
f.write(string.Template(template).substitute(translations))
diff --git a/build-aux/qmi-codegen/Message.py b/build-aux/qmi-codegen/Message.py
index 70179e5..7060006 100644
--- a/build-aux/qmi-codegen/Message.py
+++ b/build-aux/qmi-codegen/Message.py
@@ -133,8 +133,7 @@ class Message:
' QMI_CORE_ERROR,\n'
' QMI_CORE_ERROR_INVALID_ARGS,\n'
' "Message \'${name}\' has mandatory TLVs");\n'
- ' qmi_message_unref (self);\n'
- ' return NULL;\n'
+ ' goto error_out;\n'
' }\n')
cfile.write(string.Template(template).substitute(translations))
@@ -158,15 +157,21 @@ class Message:
' 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')
+ ' goto error_out;\n')
cfile.write(string.Template(template).substitute(translations))
cfile.write(
' }\n')
cfile.write(
'\n'
- ' return self;\n'
+ ' return self;\n')
+ if self.input.fields is not None:
+ cfile.write(
+ '\n'
+ 'error_out:\n'
+ ' qmi_message_unref (self);\n'
+ ' return NULL;\n')
+ cfile.write(
'}\n')
diff --git a/build-aux/qmi-codegen/Variable.py b/build-aux/qmi-codegen/Variable.py
index fbc93f5..a364399 100644
--- a/build-aux/qmi-codegen/Variable.py
+++ b/build-aux/qmi-codegen/Variable.py
@@ -81,7 +81,7 @@ class Variable:
Emits the code involved in writing the variable to the raw byte stream
from the specific private format.
"""
- def emit_buffer_write(self, f, line_prefix, variable_name, buffer_name, buffer_len, error_label):
+ def emit_buffer_write(self, f, line_prefix, tlv_name, variable_name):
pass
diff --git a/build-aux/qmi-codegen/VariableArray.py b/build-aux/qmi-codegen/VariableArray.py
index 793bbc1..68284c8 100644
--- a/build-aux/qmi-codegen/VariableArray.py
+++ b/build-aux/qmi-codegen/VariableArray.py
@@ -296,12 +296,10 @@ class VariableArray(Variable):
Writing an array to the raw byte buffer is just about providing a loop to
write every array element one by one.
"""
- def emit_buffer_write(self, f, line_prefix, variable_name, buffer_name, buffer_len, error_label):
+ def emit_buffer_write(self, f, line_prefix, tlv_name, variable_name):
common_var_prefix = utils.build_underscore_name(self.name)
- translations = { 'lp' : line_prefix,
- 'variable_name' : variable_name,
- 'buffer_name' : buffer_name,
- 'buffer_len' : buffer_len,
+ translations = { 'lp' : line_prefix,
+ 'variable_name' : variable_name,
'common_var_prefix' : common_var_prefix }
template = (
@@ -319,10 +317,10 @@ class VariableArray(Variable):
'${lp} ${common_var_prefix}_n_items = (${array_size_element_format}) ${variable_name}->len;\n')
f.write(string.Template(template).substitute(translations))
- self.array_size_element.emit_buffer_write(f, line_prefix + ' ', common_var_prefix + '_n_items', buffer_name, buffer_len, error_label)
+ self.array_size_element.emit_buffer_write(f, line_prefix + ' ', tlv_name, common_var_prefix + '_n_items')
if self.array_sequence_element != '':
- self.array_sequence_element.emit_buffer_write(f, line_prefix + ' ', variable_name + '_sequence', buffer_name, buffer_len, error_label)
+ self.array_sequence_element.emit_buffer_write(f, line_prefix + ' ', tlv_name, variable_name + '_sequence')
template = (
@@ -330,7 +328,7 @@ class VariableArray(Variable):
'${lp} for (${common_var_prefix}_i = 0; ${common_var_prefix}_i < ${variable_name}->len; ${common_var_prefix}_i++) {\n')
f.write(string.Template(template).substitute(translations))
- self.array_element.emit_buffer_write(f, line_prefix + ' ', 'g_array_index (' + variable_name + ', ' + self.array_element.public_format + ',' + common_var_prefix + '_i)', buffer_name, buffer_len, error_label)
+ self.array_element.emit_buffer_write(f, line_prefix + ' ', tlv_name, 'g_array_index (' + variable_name + ', ' + self.array_element.public_format + ',' + common_var_prefix + '_i)')
template = (
'${lp} }\n'
diff --git a/build-aux/qmi-codegen/VariableInteger.py b/build-aux/qmi-codegen/VariableInteger.py
index 37e587d..02d5b80 100644
--- a/build-aux/qmi-codegen/VariableInteger.py
+++ b/build-aux/qmi-codegen/VariableInteger.py
@@ -156,60 +156,43 @@ class VariableInteger(Variable):
"""
Write a single integer to the raw byte buffer
"""
- def emit_buffer_write(self, f, line_prefix, variable_name, buffer_name, buffer_len, error_label):
+ def emit_buffer_write(self, f, line_prefix, tlv_name, variable_name):
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,
- 'error_label' : error_label,
- 'endian' : self.endian }
+ 'tlv_name' : tlv_name,
+ 'variable_name' : variable_name }
+
+ if self.private_format != 'guint8' and self.private_format != 'gint8':
+ translations['endian'] = ' ' + self.endian + ','
+ else:
+ translations['endian'] = ''
if self.format == 'guint-sized':
template = (
'${lp}/* Write the ${len}-byte long variable to the buffer */\n'
- '${lp}if (${buffer_len} < ${len})\n'
- '${lp} goto ${error_label};\n'
- '${lp}qmi_utils_write_sized_guint_to_buffer (\n'
- '${lp} &${buffer_name},\n'
- '${lp} &${buffer_len},\n'
- '${lp} ${len},\n'
- '${lp} ${endian},\n'
- '${lp} &(${variable_name}));\n')
+ '${lp}if (!qmi_message_tlv_write_sized_guint (self, ${len},${endian} ${variable_name}, error)) {\n'
+ '${lp} g_prefix_error (error, "Cannot write sized integer in TLV \'${tlv_name}\': ");\n'
+ '${lp} goto error_out;\n'
+ '${lp}}\n')
elif self.private_format == self.public_format:
- translations['byte_size'] = VariableInteger.fixed_type_byte_size(self.private_format)
template = (
'${lp}/* Write the ${private_format} variable to the buffer */\n'
- '${lp}if (${buffer_len} < ${byte_size})\n'
- '${lp} goto ${error_label};\n'
- '${lp}else\n'
- '${lp} qmi_utils_write_${private_format}_to_buffer (\n'
- '${lp} &${buffer_name},\n'
- '${lp} &${buffer_len},\n')
- if self.private_format != 'guint8' and self.private_format != 'gint8':
- template += (
- '${lp} ${endian},\n')
- template += (
- '${lp} &(${variable_name}));\n')
+ '${lp}if (!qmi_message_tlv_write_${private_format} (self,${endian} ${variable_name}, error)) {\n'
+ '${lp} g_prefix_error (error, "Cannot write integer in TLV \'${tlv_name}\': ");\n'
+ '${lp} goto error_out;\n'
+ '${lp}}\n')
else:
- translations['byte_size'] = VariableInteger.fixed_type_byte_size(self.private_format)
template = (
- '${lp}if (${buffer_len} < ${byte_size})\n'
- '${lp} goto ${error_label};\n'
- '${lp}else {\n'
+ '${lp}{\n'
'${lp} ${private_format} tmp;\n'
'\n'
- '${lp} tmp = (${private_format})${variable_name};\n'
+ '${lp} tmp = (${private_format}) ${variable_name};\n'
'${lp} /* Write the ${private_format} variable to the buffer */\n'
- '${lp} qmi_utils_write_${private_format}_to_buffer (\n'
- '${lp} &${buffer_name},\n'
- '${lp} &${buffer_len},\n')
- if self.private_format != 'guint8' and self.private_format != 'gint8':
- template += (
- '${lp} ${endian},\n')
- template += (
- '${lp} &tmp);\n'
+ '${lp} if (!qmi_message_tlv_write_${private_format} (self,${endian} tmp, error)) {\n'
+ '${lp} g_prefix_error (error, "Cannot write enum in TLV \'${tlv_name}\': ");\n'
+ '${lp} goto error_out;\n'
+ '${lp} }\n'
'${lp}}\n')
f.write(string.Template(template).substitute(translations))
@@ -217,7 +200,7 @@ class VariableInteger(Variable):
"""
Get the integer as a printable string.
"""
- def emit_get_printable(self, f, line_prefix, printable, buffer_name, buffer_len):
+ def emit_get_printable(self, f, line_prefix):
common_format = ''
common_cast = ''
diff --git a/build-aux/qmi-codegen/VariableSequence.py b/build-aux/qmi-codegen/VariableSequence.py
index bacc541..03dd2d7 100644
--- a/build-aux/qmi-codegen/VariableSequence.py
+++ b/build-aux/qmi-codegen/VariableSequence.py
@@ -92,9 +92,9 @@ class VariableSequence(Variable):
Writing the contents of a sequence is just about writing each of the sequence
fields one by one.
"""
- def emit_buffer_write(self, f, line_prefix, variable_name, buffer_name, buffer_len, error_label):
+ def emit_buffer_write(self, f, line_prefix, tlv_name, variable_name):
for member in self.members:
- member['object'].emit_buffer_write(f, line_prefix, variable_name + '_' + member['name'], buffer_name, buffer_len, error_label)
+ member['object'].emit_buffer_write(f, line_prefix, tlv_name, variable_name + '_' + member['name'])
"""
diff --git a/build-aux/qmi-codegen/VariableString.py b/build-aux/qmi-codegen/VariableString.py
index 9678fbd..44fe50e 100644
--- a/build-aux/qmi-codegen/VariableString.py
+++ b/build-aux/qmi-codegen/VariableString.py
@@ -43,27 +43,32 @@ class VariableString(Variable):
# Fixed-size strings
self.needs_dispose = False
self.length_prefix_size = 0
+ self.n_size_prefix_bytes = 0
self.fixed_size = dictionary['fixed-size']
self.max_size = ''
else:
self.is_fixed_size = False
+ self.fixed_size = '-1'
# Variable-length strings in heap
self.needs_dispose = True
if 'size-prefix-format' in dictionary:
if dictionary['size-prefix-format'] == 'guint8':
self.length_prefix_size = 8
+ self.n_size_prefix_bytes = 1
elif dictionary['size-prefix-format'] == 'guint16':
self.length_prefix_size = 16
+ self.n_size_prefix_bytes = 2
else:
raise ValueError('Invalid size prefix format (%s): not guint8 or guint16' % dictionary['size-prefix-format'])
# Strings which are given as the full value of a TLV and which don't have
# a explicit 'size-prefix-format' will NOT have a length prefix
elif 'type' in dictionary and dictionary['type'] == 'TLV':
self.length_prefix_size = 0
+ self.n_size_prefix_bytes = 0
else:
# Default to UINT8
self.length_prefix_size = 8
- self.fixed_size = ''
+ self.n_size_prefix_bytes = 1
self.max_size = dictionary['max-size'] if 'max-size' in dictionary else ''
@@ -157,37 +162,18 @@ class VariableString(Variable):
"""
Write a string to the raw byte buffer.
"""
- def emit_buffer_write(self, f, line_prefix, variable_name, buffer_name, buffer_len, error_label):
- translations = { 'lp' : line_prefix,
- 'variable_name' : variable_name,
- 'buffer_name' : buffer_name,
- 'error_label' : error_label,
- 'buffer_len' : buffer_len }
+ def emit_buffer_write(self, f, line_prefix, tlv_name, variable_name):
+ translations = { 'lp' : line_prefix,
+ 'tlv_name' : tlv_name,
+ 'variable_name' : variable_name,
+ 'fixed_size' : self.fixed_size,
+ 'n_size_prefix_bytes' : self.n_size_prefix_bytes }
- if self.is_fixed_size:
- translations['fixed_size'] = self.fixed_size
- template = (
- '${lp}/* Write the fixed-size string variable to the buffer */\n'
- '${lp}if (${buffer_len} < ${fixed_size})\n'
- '${lp} goto ${error_label};\n'
- '${lp}else\n'
- '${lp} qmi_utils_write_fixed_size_string_to_buffer (\n'
- '${lp} &${buffer_name},\n'
- '${lp} &${buffer_len},\n'
- '${lp} ${fixed_size},\n'
- '${lp} ${variable_name});\n')
- else:
- translations['length_prefix_size'] = self.length_prefix_size
- template = (
- '${lp}/* Write the string variable to the buffer */\n'
- '${lp}if (!${variable_name} || ${buffer_len} < ${length_prefix_size} + strlen (${variable_name}))\n'
- '${lp} goto ${error_label};\n'
- '${lp}else\n'
- '${lp} qmi_utils_write_string_to_buffer (\n'
- '${lp} &${buffer_name},\n'
- '${lp} &${buffer_len},\n'
- '${lp} ${length_prefix_size},\n'
- '${lp} ${variable_name});\n')
+ template = (
+ '${lp}if (!qmi_message_tlv_write_string (self, ${n_size_prefix_bytes}, ${variable_name}, ${fixed_size}, error)) {\n'
+ '${lp} g_prefix_error (error, "Cannot write string in TLV \'${tlv_name}\': ");\n'
+ '${lp} goto error_out;\n'
+ '${lp}}\n')
f.write(string.Template(template).substitute(translations))
diff --git a/build-aux/qmi-codegen/VariableStruct.py b/build-aux/qmi-codegen/VariableStruct.py
index 041e6ab..1e96e5d 100644
--- a/build-aux/qmi-codegen/VariableStruct.py
+++ b/build-aux/qmi-codegen/VariableStruct.py
@@ -121,9 +121,9 @@ class VariableStruct(Variable):
Writing the contents of a struct is just about writing each of the struct
fields one by one.
"""
- def emit_buffer_write(self, f, line_prefix, variable_name, buffer_name, buffer_len, error_label):
+ def emit_buffer_write(self, f, line_prefix, tlv_name, variable_name):
for member in self.members:
- member['object'].emit_buffer_write(f, line_prefix, variable_name + '.' + member['name'], buffer_name, buffer_len, error_label)
+ member['object'].emit_buffer_write(f, line_prefix, tlv_name, variable_name + '.' + member['name'])
"""