aboutsummaryrefslogtreecommitdiffstats
path: root/build-aux/qmi-codegen
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-05-21 10:27:53 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-07-03 16:08:54 +0200
commit536a5896781dd38570a5e36dddd85cf13af0a05f (patch)
tree43b5bd64e7ba53228c59c494d8fca0e6aa4dbca1 /build-aux/qmi-codegen
parent86670ea3e99da9f3fcc017d1f5289658b14b91b9 (diff)
downloadexternal_libqmi-536a5896781dd38570a5e36dddd85cf13af0a05f.zip
external_libqmi-536a5896781dd38570a5e36dddd85cf13af0a05f.tar.gz
external_libqmi-536a5896781dd38570a5e36dddd85cf13af0a05f.tar.bz2
qmi-codegen: support new 'string' TLV fields
Diffstat (limited to 'build-aux/qmi-codegen')
-rw-r--r--build-aux/qmi-codegen/Container.py3
-rw-r--r--build-aux/qmi-codegen/FieldString.py73
2 files changed, 76 insertions, 0 deletions
diff --git a/build-aux/qmi-codegen/Container.py b/build-aux/qmi-codegen/Container.py
index e263fbf..8250bcd 100644
--- a/build-aux/qmi-codegen/Container.py
+++ b/build-aux/qmi-codegen/Container.py
@@ -21,6 +21,7 @@
import string
import utils
+from FieldString import FieldString
from FieldStruct import FieldStruct
from FieldStructResult import FieldStructResult
from FieldArray import FieldArray
@@ -77,6 +78,8 @@ class Container:
if field_dictionary['type'] == 'TLV':
if field_dictionary['format'] == 'array':
self.fields.append(FieldArray(self.fullname, field_dictionary))
+ elif field_dictionary['format'] == 'string':
+ self.fields.append(FieldString(self.fullname, field_dictionary))
elif field_dictionary['format'] == 'struct':
if field_dictionary['name'] == 'Result':
self.fields.append(FieldStructResult(self.fullname, field_dictionary))
diff --git a/build-aux/qmi-codegen/FieldString.py b/build-aux/qmi-codegen/FieldString.py
new file mode 100644
index 0000000..fdc60ab
--- /dev/null
+++ b/build-aux/qmi-codegen/FieldString.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python
+# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your option) any
+# later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Copyright (C) 2012 Lanedo GmbH
+#
+
+import string
+
+import utils
+from Field import Field
+
+class FieldString(Field):
+ """
+ The FieldString class takes care of handling 'string' format based
+ Input and Output TLVs
+ """
+
+ def __init__(self, prefix, dictionary):
+ # Call the parent constructor
+ Field.__init__(self, prefix, dictionary)
+
+ # The field type will be the given string name
+ self.field_type = 'gchar *'
+ # The string needs to get disposed
+ self.dispose = 'g_free'
+
+
+ def emit_input_tlv_add(self, cfile, line_prefix):
+ # TODO
+ pass
+
+
+ def emit_output_tlv_get(self, f, line_prefix):
+ translations = { 'name' : self.name,
+ 'container_underscore' : utils.build_underscore_name (self.prefix),
+ 'field_type' : self.field_type,
+ 'tlv_id' : self.id_enum_name,
+ 'variable_name' : self.variable_name,
+ 'lp' : line_prefix,
+ 'error' : 'error' if self.mandatory == 'yes' else 'NULL'}
+
+ template = (
+ '${lp}self->${variable_name} = qmi_message_tlv_get_string (message,\n'
+ '${lp} ${tlv_id},\n'
+ '${lp} ${error});\n'
+ '${lp}if (self->${variable_name}) {\n'
+ '${lp} self->${variable_name}_set = TRUE;\n')
+
+ if self.mandatory is 'yes':
+ template += (
+ '${lp}} else {\n'
+ '${lp} g_prefix_error (error, \"Couldn\'t get the ${name} TLV: \");\n'
+ '${lp} ${container_underscore}_unref (self);\n'
+ '${lp} return NULL;\n'
+ '${lp}}\n')
+ else:
+ template += (
+ '${lp}}\n')
+ f.write(string.Template(template).substitute(translations))