diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2014-05-27 14:02:12 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2014-05-28 12:39:00 +0200 |
commit | e1193a99b702296a6c5ab2496268712868eb91e0 (patch) | |
tree | 94735ae2c0a82aa929dbab23c8f53bea711f75ee | |
parent | 8f8231fead42825847613a7ce7b0be2d79f19b92 (diff) |
qmi-codegen: handle 'gfloat' types
-rw-r--r-- | build-aux/qmi-codegen/VariableFactory.py | 2 | ||||
-rw-r--r-- | build-aux/qmi-codegen/VariableInteger.py | 17 | ||||
-rw-r--r-- | build-aux/qmi-codegen/utils.py | 9 | ||||
-rw-r--r-- | docs/reference/libqmi-glib/libqmi-glib-common.sections | 1 | ||||
-rw-r--r-- | src/libqmi-glib/qmi-utils.c | 33 | ||||
-rw-r--r-- | src/libqmi-glib/qmi-utils.h | 4 |
6 files changed, 61 insertions, 5 deletions
diff --git a/build-aux/qmi-codegen/VariableFactory.py b/build-aux/qmi-codegen/VariableFactory.py index 48b1541..2b6004f 100644 --- a/build-aux/qmi-codegen/VariableFactory.py +++ b/build-aux/qmi-codegen/VariableFactory.py @@ -33,6 +33,8 @@ in the given dictionary def create_variable(dictionary, new_type_name, container_type): if utils.format_is_integer(dictionary['format']): return VariableInteger(dictionary) + elif utils.format_is_float(dictionary['format']): + return VariableInteger(dictionary) elif dictionary['format'] == 'string': return VariableString(dictionary) elif dictionary['format'] == 'struct': diff --git a/build-aux/qmi-codegen/VariableInteger.py b/build-aux/qmi-codegen/VariableInteger.py index 4fe58b7..235b552 100644 --- a/build-aux/qmi-codegen/VariableInteger.py +++ b/build-aux/qmi-codegen/VariableInteger.py @@ -23,8 +23,13 @@ import utils from Variable import Variable """ -Variable type for signed/unsigned Integers -('guint8', 'gint8', 'guint16', 'gint16', 'guint32', 'gint32', 'guint64', 'gint64' 'guint-sized' formats) +Variable type for signed/unsigned Integers and floating point numbers: + 'guint8', 'gint8' + 'guint16', 'gint16' + 'guint32', 'gint32' + 'guint64', 'gint64' + 'guint-sized' + 'gfloat' """ class VariableInteger(Variable): @@ -76,7 +81,7 @@ class VariableInteger(Variable): '${lp}qmi_utils_read_${private_format}_from_buffer (\n' '${lp} &${buffer_name},\n' '${lp} &${buffer_len},\n') - if self.private_format != 'guint8' and self.private_format != 'gint8': + if self.private_format != 'guint8' and self.private_format != 'gint8' and self.private_format != 'gfloat': template += ( '${lp} ${endian},\n') template += ( @@ -117,7 +122,7 @@ class VariableInteger(Variable): elif self.private_format == 'guint16' or self.private_format == 'gint16': template += ( '${lp}${variable_name} += 2;\n') - elif self.private_format == 'guint32' or self.private_format == 'gint32': + elif self.private_format == 'guint32' or self.private_format == 'gint32' or self.private_format == 'gfloat': template += ( '${lp}${variable_name} += 4;\n') elif self.private_format == 'guint64' or self.private_format == 'gint64': @@ -202,6 +207,8 @@ class VariableInteger(Variable): common_format = '%" G_GINT32_FORMAT "' elif self.private_format == 'gint64': common_format = '%" G_GINT64_FORMAT "' + elif self.private_format == 'gfloat': + common_format = '%f' translations = { 'lp' : line_prefix, 'private_format' : self.private_format, @@ -235,7 +242,7 @@ class VariableInteger(Variable): '${lp} qmi_utils_read_${private_format}_from_buffer (\n' '${lp} &${buffer_name},\n' '${lp} &${buffer_len},\n') - if self.private_format != 'guint8' and self.private_format != 'gint8': + if self.private_format != 'guint8' and self.private_format != 'gint8' and self.private_format != 'gfloat': template += ( '${lp} ${endian},\n') template += ( diff --git a/build-aux/qmi-codegen/utils.py b/build-aux/qmi-codegen/utils.py index 2d8e356..4b0f9ec 100644 --- a/build-aux/qmi-codegen/utils.py +++ b/build-aux/qmi-codegen/utils.py @@ -232,6 +232,15 @@ def format_is_signed_integer(fmt): else: return False +""" +Returns True if the given format corresponds to a basic floating point type +""" +def format_is_float(fmt): + if fmt == 'gfloat': + return True + else: + return False + """ Returns True if the given format corresponds to a basic signed or unsigned diff --git a/docs/reference/libqmi-glib/libqmi-glib-common.sections b/docs/reference/libqmi-glib/libqmi-glib-common.sections index 245d8ed..504b770 100644 --- a/docs/reference/libqmi-glib/libqmi-glib-common.sections +++ b/docs/reference/libqmi-glib/libqmi-glib-common.sections @@ -853,6 +853,7 @@ qmi_utils_read_gint32_from_buffer qmi_utils_read_guint64_from_buffer qmi_utils_read_gint64_from_buffer qmi_utils_read_sized_guint_from_buffer +qmi_utils_read_gfloat_from_buffer qmi_utils_read_string_from_buffer qmi_utils_read_fixed_size_string_from_buffer <SUBSECTION Writers> diff --git a/src/libqmi-glib/qmi-utils.c b/src/libqmi-glib/qmi-utils.c index 8482277..f85970d 100644 --- a/src/libqmi-glib/qmi-utils.c +++ b/src/libqmi-glib/qmi-utils.c @@ -456,6 +456,39 @@ qmi_utils_read_sized_guint_from_buffer (const guint8 **buffer, } /** + * qmi_utils_read_gfloat_from_buffer: + * @buffer: a buffer with raw binary data. + * @buffer_size: size of @buffer. + * @out: return location for the read variable. + * + * Reads a 32-bit floating-point number from the buffer. + * + * The user needs to make sure that at least 4 bytes are available + * in the buffer. + * + * Also note that both @buffer and @buffer_size get updated after the 4 bytes + * read. + */ +void +qmi_utils_read_gfloat_from_buffer (const guint8 **buffer, + guint16 *buffer_size, + gfloat *out) +{ + g_assert (out != NULL); + g_assert (buffer != NULL); + g_assert (buffer_size != NULL); + g_assert (*buffer_size >= 4); + + /* Yeah, do this for now */ + memcpy (out, &((*buffer)[0]), 4); + + print_read_bytes_trace ("gfloat", &(*buffer)[0], out, 4); + + *buffer = &((*buffer)[4]); + *buffer_size = (*buffer_size) - 4; +} + +/** * qmi_utils_write_guint8_to_buffer: * @buffer: a buffer. * @buffer_size: size of @buffer. diff --git a/src/libqmi-glib/qmi-utils.h b/src/libqmi-glib/qmi-utils.h index 3f39182..b4cf43c 100644 --- a/src/libqmi-glib/qmi-utils.h +++ b/src/libqmi-glib/qmi-utils.h @@ -87,6 +87,10 @@ void qmi_utils_read_sized_guint_from_buffer (const guint8 **buffer, QmiEndian endian, guint64 *out); +void qmi_utils_read_gfloat_from_buffer (const guint8 **buffer, + guint16 *buffer_size, + gfloat *out); + void qmi_utils_write_guint8_to_buffer (guint8 **buffer, guint16 *buffer_size, guint8 *in); |