aboutsummaryrefslogtreecommitdiffstats
path: root/build-aux
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-07-05 16:17:26 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-07-23 12:51:47 +0200
commit5ad07e7bc714dcb66b74deed610a3b61729f7839 (patch)
tree7055c802fbb9cafb6567489d852ad87398f45a8e /build-aux
parent3b7620a1286e731d345faf8e50fd32c570c696d3 (diff)
qmi-codegen: create new boxed types for the input/output bundles
Diffstat (limited to 'build-aux')
-rw-r--r--build-aux/qmi-codegen/Container.py20
-rw-r--r--build-aux/qmi-codegen/utils.py15
2 files changed, 35 insertions, 0 deletions
diff --git a/build-aux/qmi-codegen/Container.py b/build-aux/qmi-codegen/Container.py
index aa7a5e7..3de932a 100644
--- a/build-aux/qmi-codegen/Container.py
+++ b/build-aux/qmi-codegen/Container.py
@@ -113,9 +113,12 @@ class Container:
Emit new container types
"""
def __emit_types(self, hfile, cfile, translations):
+ translations['type_macro'] = 'QMI_TYPE_' + utils.remove_prefix(utils.build_underscore_uppercase_name(self.fullname), 'QMI_')
# Emit types header
template = (
'\n'
+ 'GType ${underscore}_get_type (void) G_GNUC_CONST;\n'
+ '#define ${type_macro} (${underscore}_get_type ())\n'
'typedef struct _${camelcase} ${camelcase};\n')
hfile.write(string.Template(template).substitute(translations))
@@ -160,6 +163,23 @@ class Container:
# Emit container core source
template = (
'\n'
+ 'GType\n'
+ '${underscore}_get_type (void)\n'
+ '{\n'
+ ' static volatile gsize g_define_type_id__volatile = 0;\n'
+ '\n'
+ ' if (g_once_init_enter (&g_define_type_id__volatile)) {\n'
+ ' GType g_define_type_id =\n'
+ ' g_boxed_type_register_static (g_intern_static_string ("${camelcase}"),\n'
+ ' (GBoxedCopyFunc) ${underscore}_ref,\n'
+ ' (GBoxedFreeFunc) ${underscore}_unref);\n'
+ '\n'
+ ' g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);\n'
+ ' }\n'
+ '\n'
+ ' return g_define_type_id__volatile;\n'
+ '}\n'
+ '\n'
'/**\n'
' * ${underscore}_ref:\n'
' * @self: a #${camelcase}.\n'
diff --git a/build-aux/qmi-codegen/utils.py b/build-aux/qmi-codegen/utils.py
index cd10695..1969d4a 100644
--- a/build-aux/qmi-codegen/utils.py
+++ b/build-aux/qmi-codegen/utils.py
@@ -132,6 +132,14 @@ def build_underscore_name(name):
"""
+Build an underscore uppercase name from the given full name
+e.g.: "This is a message" --> "THIS_IS_A_MESSAGE"
+"""
+def build_underscore_uppercase_name(name):
+ return string.upper(string.replace (name, ' ', '_'))
+
+
+"""
Build an underscore name from the given camelcase name
e.g.: "ThisIsAMessage" --> "this_is_a_message"
"""
@@ -149,6 +157,13 @@ def build_camelcase_name(name):
"""
+Remove the given prefix from the string
+"""
+def remove_prefix(line, prefix):
+ return line[len(prefix):] if line.startswith(prefix) else line
+
+
+"""
Read the contents of the JSON file, skipping lines prefixed with '//', which are
considered comments.
"""