[PATCH 2/4] qmi-codegen: add support for gdouble
Dan Williams
dcbw at redhat.com
Fri Feb 9 15:48:18 UTC 2018
On Sun, 2018-01-28 at 16:50 +0100, Thomas Weißschuh wrote:
> ---
> build-aux/qmi-codegen/VariableInteger.py | 4 +++-
> build-aux/qmi-codegen/utils.py | 5 +---
> .../libqmi-glib/libqmi-glib-common.sections | 1 +
> src/libqmi-glib/qmi-message.c | 27
> ++++++++++++++++++++++
> src/libqmi-glib/qmi-message.h | 26
> +++++++++++++++++++++
> 5 files changed, 58 insertions(+), 5 deletions(-)
>
> diff --git a/build-aux/qmi-codegen/VariableInteger.py b/build-
> aux/qmi-codegen/VariableInteger.py
> index 12d2a77..1a3001e 100644
> --- a/build-aux/qmi-codegen/VariableInteger.py
> +++ b/build-aux/qmi-codegen/VariableInteger.py
> @@ -30,7 +30,7 @@ Variable type for signed/unsigned Integers and
> floating point numbers:
> 'guint32', 'gint32'
> 'guint64', 'gint64'
> 'guint-sized'
> - 'gfloat'
> + 'gfloat', 'gdouble'
> """
> class VariableInteger(Variable):
>
> @@ -185,6 +185,8 @@ class VariableInteger(Variable):
> common_format = '%" G_GINT64_FORMAT "'
> elif self.private_format == 'gfloat':
> common_format = '%f'
> + elif self.private_format == 'gdouble':
> + common_format = '%f'
>
> translations = { 'lp' : line_prefix,
> 'private_format' : self.private_format,
>
In the patches I did, there were two more spots that I changed:
emit_buffer_read() and emit_buffer_write()
not sure if those are needed but since they handled gfloat
specifically, I figured they needed changing for gdouble too. Here's
the patch I used for that:
diff --git a/build-aux/qmi-codegen/VariableInteger.py b/build-aux/qmi-codegen/VariableInteger.py
index 12d2a77..4df665e 100644
--- a/build-aux/qmi-codegen/VariableInteger.py
+++ b/build-aux/qmi-codegen/VariableInteger.py
@@ -30,7 +30,7 @@ Variable type for signed/unsigned Integers and floating point numbers:
'guint32', 'gint32'
'guint64', 'gint64'
'guint-sized'
- 'gfloat'
+ 'gfloat' 'gdouble'
"""
class VariableInteger(Variable):
@@ -66,7 +66,7 @@ class VariableInteger(Variable):
'private_format' : self.private_format,
'len' : self.guint_sized_size }
- if self.private_format != 'guint8' and self.private_format != 'gint8' and self.private_format != 'gfloat':
+ if utils.format_is_endian(self.private_format):
translations['endian'] = ' ' + self.endian + ','
else:
translations['endian'] = ''
@@ -183,7 +183,7 @@ class VariableInteger(Variable):
common_format = '%" G_GINT32_FORMAT "'
elif self.private_format == 'gint64':
common_format = '%" G_GINT64_FORMAT "'
- elif self.private_format == 'gfloat':
+ elif utils.format_is_float(self.private_format):
common_format = '%f'
translations = { 'lp' : line_prefix,
@@ -193,7 +193,7 @@ class VariableInteger(Variable):
'common_format' : common_format,
'common_cast' : common_cast }
- if self.private_format != 'guint8' and self.private_format != 'gint8' and self.private_format != 'gfloat':
+ if utils.format_is_endian(self.private_format):
translations['endian'] = ' ' + self.endian + ','
else:
translations['endian'] = ''
diff --git a/build-aux/qmi-codegen/utils.py b/build-aux/qmi-codegen/utils.py
index a4044dd..51ce7cb 100644
--- a/build-aux/qmi-codegen/utils.py
+++ b/build-aux/qmi-codegen/utils.py
@@ -239,11 +239,19 @@ def format_is_signed_integer(fmt):
Returns True if the given format corresponds to a basic floating point type
"""
def format_is_float(fmt):
- if fmt == 'gfloat':
+ if fmt == 'gfloat' or fmt == 'gdouble':
return True
else:
return False
+"""
+Returns True if the given format requires endian conversion
+"""
+def format_is_endian(fmt):
+ if fmt != 'guint8' and fmt != 'gint8' and not format_is_float(fmt):
+ return True
+ else:
+ return False
"""
Returns True if the given format corresponds to a basic signed or unsigned
> diff --git a/build-aux/qmi-codegen/utils.py b/build-aux/qmi-
> codegen/utils.py
> index a4044dd..5e6fee7 100644
> --- a/build-aux/qmi-codegen/utils.py
> +++ b/build-aux/qmi-codegen/utils.py
> @@ -239,10 +239,7 @@ def format_is_signed_integer(fmt):
> 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
> + return fmt in ('gfloat', 'gdouble')
>
>
> """
> diff --git a/docs/reference/libqmi-glib/libqmi-glib-common.sections
> b/docs/reference/libqmi-glib/libqmi-glib-common.sections
> index f74a9ca..c1a5600 100644
> --- a/docs/reference/libqmi-glib/libqmi-glib-common.sections
> +++ b/docs/reference/libqmi-glib/libqmi-glib-common.sections
> @@ -1148,6 +1148,7 @@ qmi_message_tlv_read_guint64
> qmi_message_tlv_read_gint64
> qmi_message_tlv_read_sized_guint
> qmi_message_tlv_read_gfloat
> +qmi_message_tlv_read_gdouble
> qmi_message_tlv_read_string
> qmi_message_tlv_read_fixed_size_string
> <SUBSECTION RAW TLVs>
> diff --git a/src/libqmi-glib/qmi-message.c b/src/libqmi-glib/qmi-
> message.c
> index 308fc00..0159dd7 100644
> --- a/src/libqmi-glib/qmi-message.c
> +++ b/src/libqmi-glib/qmi-message.c
> @@ -1176,6 +1176,33 @@ qmi_message_tlv_read_gfloat
> (QmiMessage *self,
> return TRUE;
> }
>
> +gboolean
> +qmi_message_tlv_read_gdouble (QmiMessage *self,
> + gsize tlv_offset,
> + gsize *offset,
> + QmiEndian endian,
> + gdouble *out,
> + GError **error)
> +{
> + const guint8 *ptr;
> +
> + g_return_val_if_fail (self != NULL, FALSE);
> + g_return_val_if_fail (offset != NULL, FALSE);
> + g_return_val_if_fail (out != NULL, FALSE);
> +
> + if (!(ptr = tlv_error_if_read_overflow (self, tlv_offset,
> *offset, 8, error)))
> + return FALSE;
> +
> + /* Yeah, do this for now */
> + memcpy (out, ptr, 8);
> + if (endian == QMI_ENDIAN_BIG)
> + *out = GDOUBLE_FROM_BE (*out);
> + else
> + *out = GDOUBLE_FROM_LE (*out);
> + *offset = *offset + 8;
> + return TRUE;
> +}
> +
> gboolean
> qmi_message_tlv_read_string (QmiMessage *self,
> gsize tlv_offset,
> diff --git a/src/libqmi-glib/qmi-message.h b/src/libqmi-glib/qmi-
> message.h
> index c15f071..bd9c6b3 100644
> --- a/src/libqmi-glib/qmi-message.h
> +++ b/src/libqmi-glib/qmi-message.h
> @@ -853,6 +853,32 @@ gboolean qmi_message_tlv_read_gfloat
> (QmiMessage *self,
> gfloat *out,
> GError **error);
>
> +/**
> + * qmi_message_tlv_read_gdouble:
> + * @self: a #QmiMessage.
> + * @tlv_offset: offset that was returned by
> qmi_message_tlv_read_init().
> + * @offset: address of a the offset within the TLV value.
> + * @endian: target endianness, swapped from host byte order if
> necessary.
> + * @out: return location for the read #gdouble.
> + * @error: return location for error or %NULL.
> + *
> + * Reads a 64-bit floating-point number from the TLV.
> + *
> + * @offset needs to point to a valid @gsize specifying the index to
> start
> + * reading from within the TLV value (0 for the first item). If the
> variable
> + * is successfully read, @offset will be updated to point past the
> read item.
> + *
> + * Returns: %TRUE if the variable is successfully read, otherwise
> %FALSE is returned and @error is set.
> + *
> + * Since: 1.21
> + */
> +gboolean qmi_message_tlv_read_gdouble (QmiMessage *self,
> + gsize tlv_offset,
> + gsize *offset,
> + QmiEndian endian,
> + gdouble *out,
> + GError **error);
> +
> /**
> * qmi_message_tlv_read_string:
> * @self: a #QmiMessage.
More information about the libqmi-devel
mailing list