diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-11-02 13:13:47 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-11-02 13:13:47 +0100 |
commit | d07c5e14b97610a14c7bf4fb20f8ac280fff8f0e (patch) | |
tree | d904438cf64266e64411b9063addda2565021f0e /build-aux | |
parent | 94addc296e434f4c4352fa33f8b921a5c9b91494 (diff) | |
download | external_libqmi-d07c5e14b97610a14c7bf4fb20f8ac280fff8f0e.zip external_libqmi-d07c5e14b97610a14c7bf4fb20f8ac280fff8f0e.tar.gz external_libqmi-d07c5e14b97610a14c7bf4fb20f8ac280fff8f0e.tar.bz2 |
qmi-codegen: translate the values of enums/flags in traces
Diffstat (limited to 'build-aux')
-rw-r--r-- | build-aux/qmi-codegen/VariableInteger.py | 53 | ||||
-rw-r--r-- | build-aux/qmi-codegen/utils.py | 1 | ||||
-rw-r--r-- | build-aux/templates/qmi-enum-types-template.c | 11 | ||||
-rw-r--r-- | build-aux/templates/qmi-enum-types-template.h | 8 | ||||
-rw-r--r-- | build-aux/templates/qmi-flags64-types-template.h | 6 |
5 files changed, 52 insertions, 27 deletions
diff --git a/build-aux/qmi-codegen/VariableInteger.py b/build-aux/qmi-codegen/VariableInteger.py index 63d1d02..201c34d 100644 --- a/build-aux/qmi-codegen/VariableInteger.py +++ b/build-aux/qmi-codegen/VariableInteger.py @@ -183,6 +183,7 @@ class VariableInteger(Variable): def emit_get_printable(self, f, line_prefix, printable, buffer_name, buffer_len): common_format = '' common_cast = '' + if self.private_format == 'guint8': common_format = '%u' common_cast = '(guint)' @@ -204,6 +205,7 @@ class VariableInteger(Variable): translations = { 'lp' : line_prefix, 'private_format' : self.private_format, + 'public_format' : self.public_format, 'len' : self.guint_sized_size, 'printable' : printable, 'buffer_name' : buffer_name, @@ -211,13 +213,14 @@ class VariableInteger(Variable): 'common_format' : common_format, 'common_cast' : common_cast, 'endian' : self.endian } + template = ( + '\n' + '${lp}{\n' + '${lp} ${private_format} tmp;\n' + '\n') if self.format == 'guint-sized': - template = ( - '\n' - '${lp}{\n' - '${lp} ${private_format} tmp;\n' - '\n' + 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' @@ -225,15 +228,9 @@ class VariableInteger(Variable): '${lp} ${len},\n' '${lp} ${endian},\n' '${lp} &tmp);\n' - '\n' - '${lp} g_string_append_printf (${printable}, "${common_format}", ${common_cast}tmp);\n' - '${lp}}\n') + '\n') else: - template = ( - '\n' - '${lp}{\n' - '${lp} ${private_format} tmp;\n' - '\n' + template += ( '${lp} /* Read the ${private_format} variable from the buffer */\n' '${lp} qmi_utils_read_${private_format}_from_buffer (\n' '${lp} &${buffer_name},\n' @@ -243,9 +240,35 @@ class VariableInteger(Variable): '${lp} ${endian},\n') template += ( '${lp} &tmp);\n' + '\n') + + if self.public_format == 'gboolean': + template += ( + '${lp} g_string_append_printf (${printable}, "%s", tmp ? "yes" : "no");\n') + elif self.public_format != self.private_format: + translations['public_type_underscore'] = utils.build_underscore_name_from_camelcase(self.public_format) + translations['public_type_underscore_upper'] = string.upper(utils.build_underscore_name_from_camelcase(self.public_format)) + template += ( + '#if defined __${public_type_underscore_upper}_IS_ENUM__\n' + '${lp} g_string_append_printf (${printable}, "%s", ${public_type_underscore}_get_string ((${public_format})tmp));\n' + '#elif defined __${public_type_underscore_upper}_IS_FLAGS__\n' + '${lp} {\n' + '${lp} gchar *flags_str;\n' '\n' - '${lp} g_string_append_printf (${printable}, "${common_format}", ${common_cast}tmp);\n' - '${lp}}\n') + '${lp} flags_str = ${public_type_underscore}_build_string_from_mask ((${public_format})tmp);\n' + '${lp} g_string_append_printf (${printable}, "%s", flags_str);\n' + '${lp} g_free (flags_str);\n' + '${lp} }\n' + '#else\n' + '# error unexpected public format: ${public_format}\n' + '#endif\n') + else: + template += ( + '${lp} g_string_append_printf (${printable}, "${common_format}", ${common_cast}tmp);\n') + + template += ( + '${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 9530f03..113a78b 100644 --- a/build-aux/qmi-codegen/utils.py +++ b/build-aux/qmi-codegen/utils.py @@ -115,6 +115,7 @@ def add_source_start(f, output_name): "\n" "#include \"${name}.h\"\n" "#include \"qmi-enum-types.h\"\n" + "#include \"qmi-enum-types-private.h\"\n" "#include \"qmi-flags64-types.h\"\n" "#include \"qmi-error-types.h\"\n" "#include \"qmi-device.h\"\n" diff --git a/build-aux/templates/qmi-enum-types-template.c b/build-aux/templates/qmi-enum-types-template.c index db29eec..635147f 100644 --- a/build-aux/templates/qmi-enum-types-template.c +++ b/build-aux/templates/qmi-enum-types-template.c @@ -17,9 +17,6 @@ static const G@Type@Value @enum_name@_values[] = { }; /* Define type-specific symbols */ -#undef __QMI_IS_ENUM__ -#undef __QMI_IS_FLAGS__ -#define __QMI_IS_@TYPE@__ GType @enum_name@_get_type (void) @@ -39,7 +36,7 @@ GType /* Enum-specific method to get the value as a string. * We get the nick of the GEnumValue. Note that this will be * valid even if the GEnumClass is not referenced anywhere. */ -#if defined __QMI_IS_ENUM__ +#if defined __@ENUMNAME@_IS_ENUM__ /** * @enum_name@_get_string: * @val: a @EnumName@. @@ -60,13 +57,13 @@ const gchar * return NULL; } -#endif /* __QMI_IS_ENUM__ */ +#endif /* __@ENUMNAME@_IS_ENUM__ */ /* Flags-specific method to build a string with the given mask. * We get a comma separated list of the nicks of the GFlagsValues. * Note that this will be valid even if the GFlagsClass is not referenced * anywhere. */ -#if defined __QMI_IS_FLAGS__ +#if defined __@ENUMNAME@_IS_FLAGS__ /** * @enum_name@_build_string_from_mask: * @mask: bitmask of @EnumName@ values. @@ -113,7 +110,7 @@ gchar * return (str ? g_string_free (str, FALSE) : NULL); } -#endif /* __QMI_IS_FLAGS__ */ +#endif /* __@ENUMNAME@_IS_FLAGS__ */ /*** END value-tail ***/ diff --git a/build-aux/templates/qmi-enum-types-template.h b/build-aux/templates/qmi-enum-types-template.h index bdcd4e7..31e0732 100644 --- a/build-aux/templates/qmi-enum-types-template.h +++ b/build-aux/templates/qmi-enum-types-template.h @@ -15,15 +15,13 @@ GType @enum_name@_get_type (void) G_GNUC_CONST; #define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) /* Define type-specific symbols */ -#undef __QMI_IS_ENUM__ -#undef __QMI_IS_FLAGS_ -#define __QMI_IS_@TYPE@__ +#define __@ENUMNAME@_IS_@TYPE@__ -#if defined __QMI_IS_ENUM__ +#if defined __@ENUMNAME@_IS_ENUM__ const gchar *@enum_name@_get_string (@EnumName@ val); #endif -#if defined __QMI_IS_FLAGS__ +#if defined __@ENUMNAME@_IS_FLAGS__ gchar *@enum_name@_build_string_from_mask (@EnumName@ mask); #endif diff --git a/build-aux/templates/qmi-flags64-types-template.h b/build-aux/templates/qmi-flags64-types-template.h index 20d44a7..981d0e1 100644 --- a/build-aux/templates/qmi-flags64-types-template.h +++ b/build-aux/templates/qmi-flags64-types-template.h @@ -12,6 +12,12 @@ G_BEGIN_DECLS /*** BEGIN value-header ***/ +#define __@ENUMNAME@_IS_@TYPE@__ + +#if defined __@ENUMNAME@_IS_ENUM__ +#error Only flags expected, @EnumName@ is an enumeration +#endif + gchar *@enum_name@_build_string_from_mask (@EnumName@ mask); /*** END value-header ***/ |