[PATCH 2/4] qmi-codegen: add support for gdouble
Thomas Weißschuh
thomas at t-8ch.de
Sun Jan 28 15:50:39 UTC 2018
---
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,
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.
--
2.16.1
More information about the libqmi-devel
mailing list